var mainNum = 1;

$(document).ready(function(){ 
	$("#slider").easySlider({
		'speed'	:	300,
		'lastShow'	:	true,
		'firstShow'	:	true,
		'prevId': 'prevBtn',
		'nextId': 'nextBtn',
		'firstId': 'firstBtn',
		'lastId': 'lastBtn',
		'flexId': 'flexBtn',
		'prevId2': 'mc_prev_button',
		'nextId2': 'mc_next_button',
		'firstId2': 'mc_first_button',
		'lastId2': 'mc_last_button',
		'flexId2': 'mc_flex_button',
		'flexShow'	:	true
	}); 
	$("#slider2").easySlider({
		'speed'	:	300,
		'lastShow'	:	true,
		'firstShow'	:	true,
		'prevId': 'prevBtn',
		'nextId': 'nextBtn',
		'firstId': 'firstBtn',
		'lastId': 'lastBtn',
		'flexId': 'flexBtn',
		'prevId2': 'mc_prev_button',
		'nextId2': 'mc_next_button',
		'firstId2': 'mc_first_button',
		'lastId2': 'mc_last_button',
		'flexId2': 'mc_flex_button',
		'flexShow'	:	true
	}); 
	$("#slider3").easySlider({
		'speed'	:	300,
		'lastShow'	:	true,
		'firstShow'	:	true,
		'prevId': 'prevBtn3',
		'nextId': 'nextBtn3',
		'firstId': 'firstBtn3',
		'lastId': 'lastBtn3',
		'flexId': 'flexBtn3',
		'prevId2': 'mc_prev_button3',
		'nextId2': 'mc_next_button3',
		'firstId2': 'mc_first_button3',
		'lastId2': 'mc_last_button3',
		'flexId2': 'mc_flex_button3',
		'vertical': true,
		'flexShow'	:	true
	}); 
	$("#slider4").easySlider({
		'speed'	:	300,
		'lastShow'	:	true,
		'firstShow'	:	true,
		'prevId': 'prevBtn4',
		'nextId': 'nextBtn4',
		'firstId': 'firstBtn4',
		'lastId': 'lastBtn4',
		'flexId': 'flexBtn4',
		'prevId2': 'mc_prev_button4',
		'nextId2': 'mc_next_button4',
		'firstId2': 'mc_first_button4',
		'lastId2': 'mc_last_button4',
		'flexId2': 'mc_flex_button4',
		'flexShow'	:	true
	}); 
	$(".ps").hover(function(){
		if(this.src.slice( -6, -3 )!="_x."){
			this.src = this.src.substring(0,this.src.length-4)+"_x"+this.src.slice(-4);
		}
	});
	$(".ps").mouseout(function(){
		if(this.src.slice( -6, -3 )=="_x."){
			this.src = this.src.substring(0,this.src.length-6)+this.src.slice(-4);
		}
	});
	$("a.zoom").fancybox({
		'overlayOpacity'	:	0.7,
		'overlayColor'		:	'#FFF',
		'zoomSpeedIn'		:	300,
		'zoomSpeedOut'		:	200,
		'callbackOnShow'	:	true
	});
	
	$('.accordion_head').click(function() {
		$(this).next().slideToggle("fast",cart_open_icon_change() );
	}).next().hide();
	
	if ( document.getElementById('height_keep') ) document.getElementById('height_keep').style.height = "326px";
	if ( document.getElementById('shop_cart') ) showCart()
	messageCheck();
}); 

var AboutNum = 0;
var change_page = 0;

function cart_open_icon_change() {
	var obj = document.getElementById("cart_open_icon");
	var obj2 = document.getElementById("shop_cart_include");
	if ( obj2.style.display == "block" ) {
		obj.src='images/shop_button_down.jpg';
	} else {
		obj.src='images/shop_button_up.jpg';
	}
}

function changeAbout(num){
	var height = document.getElementById('about_right_area').clientHeight;
	if ( height < document.getElementById('about_left_area').clientHeight ) height = document.getElementById('about_left_area').clientHeight;
	document.getElementById('about_left_area').style.height = height+"px";
	if ( AboutNum == 0 ) {
		AboutNum = num;
		$("#about_right_area").fadeOut("slow",function(num){
			sendRequest( "POST", "a"+AboutNum+".html", "", false, changeAboutSet_result );
		});
	}
}
function changeAboutSet_result(xmlhttp){
	document.getElementById('about_right_area').innerHTML = xmlhttp.responseText;
	$("#about_right_area").fadeIn("normal");
	document.getElementById('about_left_area').style.height="";
	ss_init();
	AboutNum = 0;
}

function changeSupporter(btn) {
	if ( document.getElementById('supporter_link1') ) document.getElementById('supporter_link1').style.display = "none";
	if ( document.getElementById('supporter_link2') ) document.getElementById('supporter_link2').style.display = "none";
	if ( document.getElementById('supporter_link3') ) document.getElementById('supporter_link3').style.display = "none";
	if ( document.getElementById('supporter_link4') ) document.getElementById('supporter_link4').style.display = "none";
	if ( document.getElementById('supporter_link5') ) document.getElementById('supporter_link5').style.display = "none";
	change_page=btn-1;
	if ( document.getElementById('supporter_link'+btn) ) document.getElementById('supporter_link'+btn).style.display = "";
	$('a#mc_flex_button').click();
}

function changeMainSupporter(btn) {
	var num = mainNum;
	mainNum = btn;
	$("#supporter"+num).fadeOut("fast",function(){
		$("#supporter"+mainNum).fadeIn("slow",function(){
			height = document.getElementById('supporter'+mainNum).clientHeight;
			document.getElementById('height_keep').style.height = height + "px";
		});
	});
}

function changeSupporterList(btn) {
	if ( btn == 1 ) {
		$('a#mc_first_button3').click();
	} else if ( btn == 9 ) {
		$('a#mc_last_button3').click();
	} else if ( btn >= 2 || btn <= 8 ) {
		change_page=btn-1;
		$('a#mc_flex_button3').click();
	}
}

function changeContent(btn) {
	if ( document.getElementById('content_link1') ) document.getElementById('content_link1').style.display = "none";
	if ( document.getElementById('content_link2') ) document.getElementById('content_link2').style.display = "none";
	if ( document.getElementById('content_link3') ) document.getElementById('content_link3').style.display = "none";
	if ( btn == 1 ) {
		if ( document.getElementById('content_link1') ) document.getElementById('content_link1').style.display = "";
		$('a#mc_first_button').click();
	} else if ( btn == 3 ) {
		if ( document.getElementById('content_link3') ) document.getElementById('content_link3').style.display = "";
		$('a#mc_last_button').click();
	} else if ( btn == 2 ) {
		change_page=1;
		if ( document.getElementById('content_link2') ) document.getElementById('content_link2').style.display = "";
		$('a#mc_flex_button').click();
	}
}

function changeItem(btn) {
	change_page=( btn - 1 );
	$('a#mc_flex_button4').click();
}

function logout() {
	if ( confirm('ログアウトしてもよろしいですか') ) window.location.href='logout.html';
}

function messageCheck() {
	$.ajax({
		url : "check_message.php",
		type : "post",
		data : ({ genkimura: 'OK' }),
		success: function(request) {
			//送信後の処理
			var tmp = request.split("<!--mcstudio-->");
			if ( tmp[0] == 'display' )
			alert( tmp[1] );
		}
	});
}

function sendCart(num) {
	var item = document.getElementById('item['+num+']').options[document.getElementById('item['+num+']').selectedIndex].value;
	var amount = document.getElementById('amount['+num+']').options[document.getElementById('amount['+num+']').selectedIndex].value;
	$.ajax({
		url : "send_cart.php",
		type : "post",
		data : "item="+item+"&amount="+amount,
		error: function(request) {
			alert('送信に失敗しました');
		},
		success: function(request) {
			//送信後の処理
			var tmp = request.split("<!--mcstudio-->");
			if ( tmp[0] == 'NG' ) {
				document.getElementById('error['+num+']').innerHTML = tmp[1];
			} else if ( tmp[0] == 'OK' ) {
				document.getElementById('error['+num+']').innerHTML = '<br />カートに追加しました';
				displayCart( request );
				if ( document.getElementById('shop_cart_include').style.display == 'none' ) $("#cart_open_link").click();
				setTimeout( "messageHide("+num+")", 5000 );
			}
		}
	});
}

function messageHide(num) {
	document.getElementById('error['+num+']').innerHTML = '';
}

function deleteCart(item) {
	$.ajax({
		url : "send_cart.php",
		type : "post",
		data : "item="+item+"&amount=delete",
		error: function(request) {
			alert('送信に失敗しました');
		},
		success: function(request) {
			//送信後の処理
			var tmp = request.split("<!--mcstudio-->");
			if ( tmp[0] == 'NG' ) {
			} else if ( tmp[0] == 'OK' ) {
				displayCart( request );
			}
		}
	});
}

function showCart(){
	$.ajax({
		url : "send_cart.php",
		type : "post",
		error: function(request) {
			alert('送信に失敗しました');
		},
		success: function(request) {
			displayCart(request);
		}
	});
}

function displayCart( request ) {
	var tmp = request.split("<!--mcstudio-->");
	document.getElementById('total_price').innerHTML = tmp[1];
	document.getElementById('item_cart_area').innerHTML = tmp[2];
	$(".ps").hover(function(){
		if(this.src.slice( -6, -3 )!="_x."){
			this.src = this.src.substring(0,this.src.length-4)+"_x"+this.src.slice(-4);
		}
	});
	$(".ps").mouseout(function(){
		if(this.src.slice( -6, -3 )=="_x."){
			this.src = this.src.substring(0,this.src.length-6)+this.src.slice(-4);
		}
	});
}
