//数字かをチェックする
//チェック後正しければbuy.phpへ
function checkNumber(){	
	document.buyform.submit();
	return false;
}

//ディスプレイの表示・非表示
var switchFlg = false;
function displaySwitch() {
	if(switchFlg == false) {
		$("#sizeList").css("display", "block");
		switchFlg = true;
	}else{
		$("#sizeList").css("display", "none");
		switchFlg = false;	
	}
}
$(function() {

	//クリックでカレントにクラスを追加。
	//カレント以外にオーバーとアウトを反応させる。
	var selects = $("#imgBox > li")
	selects.click(function(){
		var indexs = selects.index(this);
		selects.removeClass("current");
		selects.eq(indexs).addClass("current");
		
		$("#imgBox > li").bind("mouseover", function(){
			if(!selects.eq(indexs))$(this).css("border-color", "red");
		});
		$("#imgBox > li").bind("mouseout", function(){
			if(!selects.eq(indexs))$(this).css("border-color", "black");
		});
		
		var imgStr = $(this).find("img").attr("src");
		var start = imgStr.indexOf("f=")+2;
		var end = imgStr.indexOf("jpg")+3;
		var srcValue = imgStr.substring(start,end);
		
		$("#targetImage").fadeOut(200,	function() {
		$(".itemImg").empty();
		$(".itemImg").append("<img src='" + srcValue + "' id='targetImage' />");
		
		$("#targetImage").css("display", "none");
			$("#targetImage").ready(function() {
				$("#targetImage").fadeIn(1200);
			});
		});	
		
	});
	var zoom_flg = false;
	ww = $(window).width();
	wh = $(window).height();
	contH = $(document).height() + 300;
	$("#zoom").click(function() {
		if(zoom_flg == false){
			$("#wrapper").before("<div class='blackScreen'></div><iframe scrolling='no' frameborder='0' id='shim'></iframe>");
			
			$("#shim").css("display", "block");
			if(ww <= 1220) {
				$(".blackScreen").width(1220);
				$("#shim").width(1220);
			}else{
				$(".blackScreen").css("width", "100%");
				$("#shim").css("width", "100%");
			}
			$("#shim").css("height", contH);
			
			posX = ww/2 - ($("#zoomItem").width())/2;
			posY = wh/2 - ($("#zoomItem").height())/2;
			if(posY <= 0) {
				posY = 10;
			}
			
			$("#zoomItem").fadeIn("slow");
			$("#zoomItem").css("left", posX);
			$("#zoomItem").css("top", posY);
			
			
			zoom_flg = true;
			return false;
		}
	});
	$("#zoomItem").click(function() {
		if(zoom_flg == true){
			$(".blackScreen").fadeOut("slow", backRemove);
			$("#zoomItem").fadeOut("slow");
			zoom_flg= false;
			return;
		}
	});
});
function backRemove() {
	$(".blackScreen").remove();
	$("#shim").remove();
}
function scrolls(){
	if(ww <= 1220) {
		$(".blackScreen").width(1220);
	}else{
		$(".blackScreen").css("width", "100%");
	}
	if(wh <= contH) {
		$(".blackScreen").height(contH);		
	}
}
function resizeW() {

	ww = $(window).width();
	wh = $(window).height();
	
	posX = ww/2 - ($("#zoomItem").width())/2;
	posY = wh/2 - ($("#zoomItem").height())/2;
	if(posY <= 0) {
		posY = 10;
	}
	$("#zoomItem").css("left", posX);
	$("#zoomItem").css("top", posY);
	
	if(ww <= 1220) {
		$(".blackScreen").width(1220);
	}else{
		$(".blackScreen").css("width", "100%");
	}
	if(wh <= contH) {
		$(".blackScreen").height(contH);		
	}
	
}
$(window).bind("resize", resizeW);
$(window).bind("scroll", scrolls);