$(function(){
    var page = 1;
    var i = 3; //每版放3个图片
    //向后 按钮
		 var len = $("#list").find("li").length;
		 var page_count = Math.ceil(len / i) ;   //只要不是整数，就往大的方向取最小的整数
		 var span_code='';
	  	for(j=1; j<=page_count;){
			if(j==1) span_code =  '<span class="current dics">' + i + '</span>';
			else
			span_code = span_code + '<span class="dics">' + i + '</span>';
			j++;
	  }
	 		 $("#home-content-bottom-right-top").html(span_code)

    $("a#next").click(function(){    //绑定click事件
		 var v_width = 579 ;
		 var len = $("#list").find("li").length;
		 var page_count = Math.ceil(len / i) ;   //只要不是整数，就往大的方向取最小的整数
		 if( !$("#list").is(":animated") ){    //判断“视频内容展示区域”是否正在处于动画
			  if( page == page_count ){  //已经到最后一个版面了,如果再向后，必须跳转到第一个版面。
				$("#list").animate({ left : '0px'}, "slow"); //通过改变left值，跳转到第一个版面
				page = 1;
				}else{
				$("#list").animate({ left : '-='+v_width }, "slow");  //通过改变left值，达到每次换一个版面
				page++;
			 }
		 }
		 $("#home-content-bottom-right-top").find("span.dics").eq((page-1)).addClass("current").siblings().removeClass("current");
   });
    //往前 按钮
    $("a#prev").click(function(){
		 var v_width = 579;
		 var len = $("#list").find("li").length;
		 var page_count = Math.ceil(len / i) ;   //只要不是整数，就往大的方向取最小的整数
		 if( !$("#list").is(":animated") ){    //判断“视频内容展示区域”是否正在处于动画
		 	 if( page == 1 ){  //已经到第一个版面了,如果再向前，必须跳转到最后一个版面。
				$("#list").animate({ left : '-='+v_width*(page_count-1) }, "slow");
				page = page_count;
			}else{
				$("#list").animate({ left : '+='+v_width }, "slow");
				page--;
			}
		}
		$("#home-content-bottom-right-top").find("span.dics").eq((page-1)).addClass("current").siblings().removeClass("current");
    });
});
/*$(function(){
	var page = 1;
    var i = 1; //每版放3个图片
    //向后 按钮
    $("a#next-1").click(function(){
		var v_width = 980;
		var len = $("#list-1").find("li").length;
		var page_count = Math.ceil(len / i) ; 
		 if( !$("#llist-1").is(":animated") ){  
			  if( page == page_count ){  //已经到最后一个版面了,如果再向后，必须跳转到第一个版面。
				$("#list-1").animate({ left : '0px'}, "slow"); //通过改变left值，跳转到第一个版面
				page = 1;
				}else{
				$("#list-1").animate({ left : '-='+v_width }, "slow");  //通过改变left值，达到每次换一个版面
				page++;
			 }
		}
	});
	
	$("a#prev-1").click(function(){
		 var v_width = 980;
		 var len = $("#list-1").find("li").length;
		 var page_count = Math.ceil(len / i) ; 
		 if( !$("#list-1").is(":animated") ){ 
		 	 if( page == 1 ){ 
				$("#list-1").animate({ left : '-='+v_width*(page_count-1) }, "slow");
				page = page_count;
			}else{
				$("#list-1").animate({ left : '+='+v_width }, "slow");
				page--;
			}
		}
    });
});*/
/*自动*/
var ttt = null, tt = null;
$(document).ready(function() {
/*$("#home-bigimage-box").hover( 
		function () { 
		clearInterval(tt);
		}, 
		function () { 
			tt = setInterval("$('a#next-1').click()",5000);
		} 
		);*/
$("#home-content-bottom-right").hover( 
		function () { 
		clearInterval(ttt);
		}, 
		function () { 
			ttt = setInterval("$('a#next').click()",4000);
		} 
		);
})
//tt = setInterval("$('a#next-1').click()",5000);
ttt = setInterval("$('a#next').click()",4000);

function show_pop(element,id,last){
	if($('#popup_layer').length>0){$('#popup_layer').remove();}
	var newNode = document.createElement("div");
	newNode.id = 'popup_layer';
	newNode.className = 'product-box-2';
	pop_parent = $(element).parent().parent().parent().parent().prev().prev();
	//alert($(element).parent().parent().parent().parent().prev().prev().attr('id'));
	if(last)
		document.getElementById(pop_parent.attr('id')).appendChild(newNode);
	else
		element.parentNode.parentNode.parentNode.parentNode.appendChild(newNode);
	newNode.innerHTML = '<a href="javascript:void(0)" onclick="$(\'#popup_layer\').remove();"><p class="close" >Close <img src="skin1/_images/XX.jpg" width="15" height="15" alt="Close" /></p></a><div class="product-box-2-middle" style="text-align:center; vertical-align:middle;"><img src="skin1/_images/ajax-loader.gif" ><div>';

	$().ajaxSend(
		function(){
		}
	);
					
	$().ajaxComplete(
		function(){
		}
	);
	
	_post = 'productid='+id;
	$.ajax({
		type: "POST",
		url: "get_sizes.php",
		data: _post,
		cache:false,
		error: function() {
			alert("System Error !!");
		},
		success: function(cmsg){
			newNode.innerHTML = cmsg;
			return false;
		}
	});
}

function CheckAmount(form,prefix){
	if (!form)
		return;
	if (prefix)
		var reg = new RegExp("^"+prefix, "");
	for (var i = 0; i < form.elements.length; i++) {
		if (form.elements[i].type == "text" && (!prefix || form.elements[i].name.search(reg) == 0) && !form.elements[i].disabled){
			if($.trim(form.elements[i].value) != '' && $.trim(form.elements[i].value) != 0) return true;
		}
	}
	alert('please fill the Qty!');
	return false;
}
$('popup_layer').hover( 
		function () { 
		void(0);
		}, 
		function () { 
		void(0);
		} 
		);

/*Ajax for checkout*/

function update_shipping_account(id){
	$("#shipping_handling").html("Add to the invoice");
	$("#shipping").attr("value",'Add to the invoice');
	$("#shipping_account>option").remove();
	$.ajax({
		type: "POST",
		url: "get_shipping_info.php",
		data: 'sid='+id+"&update=ture",
		cache:false,
		error: function() {
			alert("System Error !!");
		},
		success: function(cmsg){
			//alert(cmsg);
			$("#shipping_account").html(cmsg);
		}
	});
}

function change_address(sid,pid){
	var discounted;
	if(sid == "b" || sid == "s"){
		$("#drop_ship").hide();
		$("#discounted").html("$"+discounted_total.toFixed(2));
		$("#s_contact").attr("value",s_contact);
	}
	else{
		$("#drop_ship").show();
		discounted = discounted_total + 7.5;
		$("#discounted").html("$"+discounted.toFixed(2));
		$("#s_contact").attr("value",sid);
	}
	$.ajax({
		type: "POST",
		url: "get_shipping_info.php",
		data: 'sid='+sid+"&pid="+pid,
		cache:false,
		error: function() {
			alert("System Error !!");
		},
		success: function(cmsg){
				update_shipping_account(sid)
			
			//alert(cmsg);
			$("#shippping_info").html(cmsg);
		}
	});
}

function change_show_price(option){
	$.ajax({
		type: "POST",
		url: "show_price.php",
		data: 'option='+option,
		cache:false,
		error: function() {
			alert("System Error !!");
		},
		success: function(cmsg){
		}
	});
}

function check_sku(id,value){
	if($.trim($("#"+id).val()) != ""){
		if($("#c_"+id).val() == "0"){
			$("#"+id).focus();
			alert("Item # is Invalid. Please revise");
			$("#"+id).css("border", "solid 1px #ff0000");
			$("#c_"+id).val("0");
		}
		else{
			$("#"+id).css("border", "solid 1px #478484");
			$("#c_"+id).val("1");
		}
		/*alert("#c_"+id)
		alert($("#c_"+id).val())*/
		/*$.ajax({
			type: "POST",
			url: "check_sku.php",
			data: 'sku='+value,
			cache:false,
			error: function() {
				alert("System Error !!");
			},
			success: function(cmsg){
				if(cmsg == "0"){
					alert("Item # is Invalid. Please revise");
					$("#"+id).css("border", "solid 1px #ff0000");
					$("#"+id).focus();
				}
				else{$("#"+id).css("border", "solid 1px #478484");}
			}
		});*/
	}else{$("#"+id).css("border", "solid 1px #cccccc");$("#c_"+id).val("1");}
}

function check_sku_n(id,value){
	if($.trim(value) != ""){
		$.ajax({
			type: "POST",
			url: "check_sku.php",
			data: 'sku='+value,
			cache:false,
			error: function() {
				alert("System Error !!");
			},
			success: function(cmsg){
				//alert(cmsg)
				if(cmsg == "0"){
					$("#c_"+id).val("0");
				}
				else{$("#c_"+id).val("1");}
				//alert($("#c_"+id).val())
			}
		});
	}else{$("#c_"+id).val("1");}
	//alert(value)
	//alert($("#c_"+id).val())
}

function Get_Rates(zipcode){
	zipcode = $.trim(zipcode);
	var check_zipcode = /^\d{5}$/gi;
	if(check_zipcode.test(zipcode)){
		var loading = "<div style='text-align:center; vertical-align:middle'><img src='skin1/_images/lightbox/lightbox-ico-loading.gif' /></div>";
		$("#shipping_list").html(loading);
		$.ajax({
			type: "POST",
			url: "shipping_calculate.php",
			data: 'zipcode='+zipcode,
			cache:false,
			error: function() {
				alert("System Error !!");
			},
			success: function(cmsg){
				$("#shipping_list").html(cmsg);
			}
		});
	}
	else
	{alert("ZipCode is invalid, please revise!");}
}

