// ============================================================ 
// jQuery と prototype コンフリクト回避
// ============================================================ 
jQuery.noConflict();
var $j = jQuery;

// ============================================================ 
// 開閉式コンテンツ
// ============================================================ 
var arr1 = ["#header1", "#header2"];
var arr2 = ["#footer1", "#footer2", "#footer3", "#footer4"];

$j(function() {
	$j("#header1, #header2").hide();
	
	$j(".head1").click(function () {
		slideToggle1("#header1", arr1);
	});

	$j(".head2").click(function () {
		slideToggle1("#header2", arr1);
	});

	$j(".footer1").click(function () {
		slideToggle1("#footer1", arr2);
	});

	$j(".footer2").click(function () {
		slideToggle1("#footer2", arr2);
	});
	
	$j(".footer3").click(function () {
		slideToggle1("#footer3", arr2);
	});
	
	$j(".footer4").click(function () {
		slideToggle1("#footer4", arr2);
	});
});

function slideToggle1(id, arr) {
	// スライドの速度
	var spd = 400;
	// 開閉コンテンツ
	var arr = arr;
	// フラグ
	var flag = true;
	
	for(i=0; i<arr.length; i++) {
		if($j(arr[i]).css("display")!="none") {
			flag = false;
			var n = i;
			$j(arr[i]).slideUp("slow", function() {
				if(id!=arr[n]) {
					$j(id).slideDown(spd);
				}
			});
		} else {
			if(i==arr.length-1 && $j(id).css("display")=="none") {
				if(flag) $j(id).slideDown(spd);
			}
		}
	}
}

// ============================================================ 
// ロールオーバー
// ============================================================ 
var rollover = {
	swap:function(){
		$j("img.swap").each(function(i) {
			var imgsrc = this.src;
			var dot = imgsrc.lastIndexOf(".");
			var imgsrc_on = imgsrc.substr(0, dot) + '_on' + imgsrc.substr(dot, 4);
			$j("<img>").attr("src", imgsrc_on);
			
			if(!imgsrc.match("_on")) {
				$j(this).hover(
					function() { this.src = imgsrc_on; },
					function() { this.src = imgsrc; }
				);
			}
		});
	}
}

$j(function() {
	rollover.swap();
});

// ============================================================ 
// 商品一覧切り換え
// ============================================================  
	
	function itemListSize() {
		var spd = 400;
		
		// Cookie
		if(!$j.cookie("ITEMLIST_SIZE1")) {
		}else{
			if($j.cookie("ITEMLIST_SIZE1")=="s") {
				$j(".gallery").removeClass("itemlist-s itemlist-m itemlist-l");
				$j(".gallery").addClass("itemlist-s");
				$j(".txt-number, .txt-name, .txt-brand, .txt-price, .txt-price-sale").hide();
			}
			if($j.cookie("ITEMLIST_SIZE1")=="m") {
				$j(".gallery").removeClass("itemlist-s itemlist-m itemlist-l");
				$j(".gallery").addClass("itemlist-m");
				$j(".txt-number, .txt-name, .txt-brand, .txt-price, .txt-price-sale").show();
			}
			if($j.cookie("ITEMLIST_SIZE1")=="l") {
				$j(".gallery").removeClass("itemlist-s itemlist-m itemlist-l");
				$j(".gallery").addClass("itemlist-l");
				$j(".txt-number, .txt-name, .txt-brand, .txt-price, .txt-price-sale").show();
			}
		}
		
		$j(".gallery").hide();
		$j(".gallery").fadeIn(spd);
		
		
		$j("#size-l").click(function() {
			if($j(".gallery").attr("class")!="gallery itemlist-l") {
				$j(".gallery").removeClass("itemlist-s itemlist-m itemlist-l");
				$j(".gallery").addClass("itemlist-l");
				
				$j(".txt-number, .txt-name, .txt-brand, .txt-price, .txt-price-sale").show();
				$j(".gallery").hide();
				$j(".gallery").fadeIn(spd);
				
				$j.cookie("ITEMLIST_SIZE1", "l", { path: '/', expires: 30 });
			}
		});
		
		$j("#size-m").click(function() {
			if($j(".gallery").attr("class")!="gallery itemlist-m") {
				$j(".gallery").removeClass("itemlist-s itemlist-m itemlist-l");
				$j(".gallery").addClass("itemlist-m");
	
				$j(".txt-number, .txt-name, .txt-brand, .txt-price, .txt-price-sale").show();
				$j(".gallery").hide();
				$j(".gallery").fadeIn(spd);
				
				$j.cookie("ITEMLIST_SIZE1", "m", { path: '/', expires: 30 });
			}
		});
		
		$j("#size-s").click(function() {
			if($j(".gallery").attr("class")!="gallery itemlist-s") {
				$j(".gallery").removeClass("itemlist-s itemlist-m itemlist-l");
				$j(".gallery").addClass("itemlist-s");
				
				$j(".txt-number, .txt-name, .txt-brand, .txt-price, .txt-price-sale").hide();
				$j(".gallery").hide();
				$j(".gallery").fadeIn(spd);
				
				$j.cookie("ITEMLIST_SIZE1", "s", { path: '/', expires: 30 });
			}
		});
		
	}
	


