$(document).ready(function(){

	$("#header ul li a").mouseover(function(){
		$(this).fadeTo("fast","0.6");
	}).mouseout(function(){
		$(this).fadeTo("fast","0.9");
	});
	
	sc_top();
	var aaa= $("#container").offset().left;

	$(".cart_middle_btn2").click(function(event){
		event.preventDefault();
		var cst = 1;
		if ( $("#cst_sel").size() > 0){
			cst = $("#cst_sel").children(':selected').attr("rel");
		}
		//alert(cst);
		var nmb =  $(this).attr("rel");
		cart_in_detail(nmb,cst);
	});


	$(".item_sort_chk").click(function(event){
		//event.preventDefault();
		//alert(  $(this).attr("value")  );
		var val =  $(this).attr("value");
		item_sort_order(val);
	});


	$(".item_disp_nmb_chk").click(function(event){
		//event.preventDefault();
		var val =  $(this).attr("value");
		item_sort_limit_nmb(val);
	});


	$(".img_sam").click(function(event){
		event.preventDefault();
		var val =  $(this).attr("rel");
		large_img_change(val);
	});

	$(".custom_chk").click(function(event){
		//event.preventDefault();
		var val =  $(this).attr("value");
		//alert( $("#acc_price").html() );
		acc_customeize(val);
	});


	$("#cst_sel").change(function(event){
		var val =  $(this).attr("value");
		//alert( val );
		acc_customeize(val);
	});


/*
	$(":checkbox[name^='acc_chk']:checked").each(function(){
	   alert($(this).val());
	});
*/

	$(".item_retrieval_chk").click(function(event){
		var n = $(":checkbox[name^='acc_chk']:checked").length;
		if ( n == 0 ){
			event.preventDefault();
			alert("必ず１つ以上チェックして下さい。");
			return;
		}
		var name =  $(this).attr("name");
		var val =  $(this).attr("checked");
		item_sort_retrieval(name , val);
	});


	$(".item_disp_chk").click(function(event){
		//event.preventDefault();
		var val =  $(this).attr("value");
		item_disp(val);
	});

	cart_renew();

});


jQuery().ajaxStart(function() {
	$("#ajax_replace").before('<div id="loading"><span>Loading</span></div>');
});

jQuery().ajaxStop(function() {
	$("#loading").remove();
});


/* スクロール */
$(window).scroll(function(){
	set_menu_position();
	set_gt_position();
});

$(window).bind("resize",function(){
	set_menu_position();
	set_gt_position();
});	



function set_menu_position(){
/*	
	var win_top;
	if ( document.documentElement.scrollTop > 0 ){
		win_top = document.documentElement.scrollTop;
	}else{
		win_top = document.body.scrollTop;		
	}
*/
	//objY = $("#bd").position().top;
	//$("#header").css("top", win_top);
	
	//win_top = $(document).scrollTop();
	//$("#header").animate({top : win_top},{duration: 0, queue: "false"});
	
	ct_objX = $("#container").offset().left;
	objX = ct_objX + 25- $(window).scrollLeft();
	
	$("#header").css("left", objX);
	$("#test").html(ct_objX);
		
}


function set_gt_position(){
	
	if ($.browser.msie && $.browser.version == 6){

	}else{
		//get top
		var win_top;
/*	
		if ( document.documentElement.scrollTop > 0 ){
			win_top = document.documentElement.scrollTop;
		}else{
			win_top = document.body.scrollTop;		
		}
*/
		win_top = $(document).scrollTop();

		//get disp height
		//var disp_height  = document.documentElement.clientHeight;
		var win_height = $(window).height();
		//get bottom
		
		var win_bottom = win_top+win_height;
	
		var obj_top = win_bottom - 50;
		$("#gotoTop").css("top", obj_top );
	}
}

function sc_top(){
	jQuery.easing.quart = function (x, t, b, c, d) {
	    return -c * ((t=t/d-1)*t*t*t - 1) + b;
	};  

    $('#gotoTop').bind("click",function (event) {
		event.preventDefault();
        $('html,body').animate({ scrollTop: 0 }, 1000, 'quart');
    });
}


function cart_in(nmb,cst){
	$("#cart_inside").fadeTo("fast" , "0.01" , function(){
		$.post(
		    "/cmn/cart_ajax.php",                      // リクエストURL
		    {"nmb": nmb , "val": "1" , "act": "cart_in" , "cst" : cst}, // データ
		    function(data, status) {
		        // 通信成功時にデータを表示
				$("#cart_inside").html(data)
				.fadeTo("fast" , "1.00" );		    },
		    "html"                                 // 応答データ形式
		);

	});
}

function cart_in_detail(nmb,cst){
	$("#cart_inside").fadeTo("fast" , "0.01" , function(){
		$.post(
		    "/cmn/cart_ajax.php",                      // リクエストURL
		    {"nmb": nmb , "val": "1" , "act": "cart_in_detail" , "cst" : cst}, // データ
		    function(data, status) {
		        // 通信成功時にデータを表示
				$("#cart_inside").html(data)
				.fadeTo("fast" , "1.00" );		    },
		    "html"                                 // 応答データ形式
		);

	});
}


function cart_renew(){

	$("#loading").css( "display", "none");
	//$("#loading").css({ background: "none"});
	$("#cart_inside").fadeTo("fast" , "0.01" , function(){

		$.post(
		    "/cmn/cart_ajax.php",                      // リクエストURL
		    {"act": "cart_renew"}, // データ
		    function(data, status) {
		        // 通信成功時にデータを表示
				$("#cart_inside").html(data)
				.fadeTo("fast" , "1.00" );
		    },
		    "html"                                 // 応答データ形式
		);
	});
	
	//$("#loading").css({display: "block"});

}


function item_sort_order(val){

	$("#ajax_replace").fadeTo("fast" , "0.01" , function(){
		$.post(
		    "/cmn/item_sort_ajax.php",                      // リクエストURL
		    { "sort_act" : "sort" , "val": val }, // データ
		    function(data, status) {
		        // 通信成功時にデータを表示
				$("#ajax_replace").html(data)
				.fadeTo("fast" , "1.00" );
		    },
		    "html"                                 // 応答データ形式
		);
		
	});
	
	
}


function item_sort_limit(val){

	$("#ajax_replace").fadeTo("fast" , "0.01" , function(){

		$.post(
		    "/cmn/item_sort_ajax.php",                      // リクエストURL
		    { "sort_act" : "limit" , "val": val }, // データ
		    function(data, status) {
		        // 通信成功時にデータを表示
				
				$("#ajax_replace").html(data)
				.fadeTo("fast" , "1.00" );
		    },
		    "html"                                 // 応答データ形式
		);
	});

}

function item_sort_limit_nmb(val){

	$("#ajax_replace").fadeTo("fast" , "0.01" , function(){

		$.post(
		    "/cmn/item_sort_ajax.php",                      // リクエストURL
		    { "sort_act" : "limit_nmb" , "val": val }, // データ
		    function(data, status) {
		        // 通信成功時にデータを表示
				
				$("#ajax_replace").html(data)
				.fadeTo("fast" , "1.00" );
		    },
		    "html"                                 // 応答データ形式
		);
	});

}

function item_sort_retrieval(name , val){

	$("#ajax_replace").fadeTo("fast" , "0.01" , function(){

		$.post(
		    "/cmn/item_sort_ajax.php",                      // リクエストURL
		    { "sort_act" : "retrieval" , "name": name  , "val": val }, // データ
		    function(data, status) {
		        // 通信成功時にデータを表示
				
				$("#ajax_replace").html(data)
				.fadeTo("fast" , "1.00" );
		    },
		    "html"                                 // 応答データ形式
		);
	});

}

function item_disp(val){
	
	//loading img

	$("#ajax_replace").fadeTo("fast" , "0.01" , function(){
		
		
		$.post(
		    "/cmn/item_sort_ajax.php",                      // リクエストURL
		    { "sort_act" : "disp" , "val": val }, // データ
		    function(data, status) {
		        // 通信成功時にデータを表示
				$("#ajax_replace").html(data)
				.fadeTo("fast" , "1.00" );
		    },
		    "html"                                 // 応答データ形式
		);
	});
	

}

function large_img_change(val){
	$("#img_large").fadeTo("fast", "0.01", function(){
		$("#img_large").attr("src", val)
		.fadeTo("fast", "1.00");
	});
}

function acc_customeize(val){

	var nmb = $(".cart_middle_btn2").attr("rel");
	$.post(
	    "/cmn/cart_ajax.php",                      // リクエストURL
	    { "act" : "chk_item_price" , "val": nmb }, // データ
	    function(data, status) {
	        // 通信成功時にデータを表示
			
			price= data.split(",");

	var price1 = parseInt(price[0]) + parseInt(val);
	$("#acc_price").fadeTo("fast", "0.01", function(){
		$("#acc_price").html(price1)
		.fadeTo("fast", "1.00");
	});
	var price2 = parseInt(price[1]) + parseInt(val);
	$("#acc_price2").fadeTo("fast", "0.01", function(){
		$("#acc_price2").html(price2)
		.fadeTo("fast", "1.00");
	});

	    },
	    "html" 
	);
	


	
	

}


