$(function() {
/*窗口变化时运行*/
$(window).resize(function() {
	$("#home-imgshow").width($(window).width());
});
/*search*/	
	$("#search-box").css("height","31px");
	$("#search-btn").click(function(){
		$(this).hide();
		$("#search").show();	
		$("#search-submit").show();
	});
	$("#search-box").hover(function(){
		//$("#search").toggle();	
	},function(){
		$("#search-submit").hide();
		$("#search").fadeOut("slow");
		$("#search-btn").show();
	});
/**/
$(".color-select-box p").click(function(){
		$(".color-select-drop").css("display","block");
	});
$(".color-select-box").hover(function(){
		
	},function(){
		$(".color-select-drop").css("display","none");
	});
$(".color-select-drop a").click(function(){
		$("#color-img").attr("src",$(this).find(".color-img").attr("src"));
		$("#color-name").html($(this).find(".color-name").html());
		$(".color-select-drop").css("display","none");
		$("#color").val($(this).find("#optionid").attr("title"));
		
		
		$("#productdetails-img").attr("src2",$(this).find(".color-img").attr("alt"));
		$("#productdetails-img").LoadingImg();
		
		return false;
	});
	
/**/
$("#productdetails-show-box ul li a").click(function(){
		$("#productdetails-img").attr("src2",$(this).attr("href"));
		$("#productdetails-img").LoadingImg();
		return false;
	});
	
/**/
$("#rider-show li a").click(function(){
	$("#rider-tv iframe").attr("src",$(this).attr("href"));
	return false;
	});
});
/*product-scroll*/	
$(function(){
	$(".btn-style-01").height($(".product-show").height());
	//var product_len = Number($(".product-show ul").find("li").length);
	$("#list-1").width(($(".product-show ul li").width()+2)*$(".product-show ul").find("li").length);
	
    var page = 1;
    var i = 3; //每版放i个图片
	var v_width = ($(".product-show ul li").width()+2)*i;
	var len = $(".product-show ul").find("li").length;
	var page_count = Math.ceil(len / i) ; 
    $("a#next-01").click(function (){   
		 if( !$("#list-1").is(":animated") ){   
			  if( page == page_count ){  
				$("#list-1").animate({ left : '0px'}, "slow");
				page = 1;
				}else{
				$("#list-1").animate({ left : '-='+v_width }, "slow");  
				page++;
			 }
		 }
		 return false;
   });
    $("a#prev-01").click(function(){
		 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--;
			}
		}
		;
		return false;
    });	
});
/*home-banner*/
$(function() {
$("#home-imgshow").width($(window).width());
	var index = 0;
	var v_height = $("#home-imgshow-box").height(); 
	var speed = 800;
	var len = $("#home-imgshow").find("li").length;
	
	$("#imgnav-box li").click(function(){
   		index = $("#imgnav-box li").index(this);
   		showImg(index);
		return false;
	}); 
	var MyTime;
	$('#home-banner').hover(function(){
		 if(MyTime){
		 	clearInterval(MyTime);
		 }
	},function(){
		 MyTime = setInterval(function(){
		   showImg(index);
		 index++;
		 if(index==len){index=0;}
		 } , 3000);
	});
	
	function showImg(i){
		$("#home-imgshow").stop(true,false).animate({top : -v_height*i},speed);
		$("#imgnav-box").find("a").removeClass("banner-on");
		$("#imgnav-box").find("a").eq(i).addClass("banner-on");
		$("#banner-link").attr("href",$("#home-imgshow").find("a").eq(i).attr("href"));
	}	
});
/*TV*/
$(function(){
	$("#list-2").width(($("#rider-show ul li").width()+5)*$("#rider-show ul").find("li").length);
    var page = 1;
    var i = 3; //每版放i个图片
	var v_width = ($("#rider-show ul li").width()+5)*i;
	var len = $("#rider-show ul").find("li").length;
	var page_count = Math.ceil(len / i) ; 
    $("a#next-02").click(function (){   
		 if( !$("#list-2").is(":animated") ){   
			  if( page == page_count ){  
				$("#list-2").animate({ left : '0px'}, "slow");
				page = 1;
				}else{
				$("#list-2").animate({ left : '-='+v_width }, "slow");  
				page++;
			 }
		 }
		 return false;
   });
    $("a#prev-02").click(function(){
		 if( !$("#list-2").is(":animated") ){   
		 	 if( page == 1 ){  
				$("#list-2").animate({ left : '-='+v_width*(page_count-1) }, "slow");
				page = page_count;
			}else{
				$("#list-2").animate({ left : '+='+v_width }, "slow");
				page--;
			}
		}
		;
		return false;
    });	
});

$(function(){
	var vidoe_width= 622;
	$(".pop-up-box").width($(window).width()).height($(document).height());
	var pop_left = ($(window).width()- vidoe_width )/2 + "px";
	var scrollTop = $(document).scrollTop();
	var pop_top = ($(window).height()-$(".pop-up-box #specifications-box").height())/2+scrollTop + "px";
	if(($(window).height()-$(".pop-up-box #specifications-box").height())/2 <= 0){
		$("#specifications-box").css({ "left": pop_left , "top": ($(document).height()-$(".pop-up-box #specifications-box").height())/2 });
	}else{
		$("#specifications-box").css({ "left": pop_left , "top": pop_top });
	}
	/*$(window).scroll(function(){
		var pop_left = ($(window).width()- vidoe_width)/2 + "px";
		var scrollTop = $(document).scrollTop();
		var pop_top = ($(window).height()-$(".pop-up-box #specifications-box").height())/2+scrollTop + "px";
		if(($(window).height()-$(".pop-up-box #specifications-box").height())/2 <= 0){
			$("#specifications-box").css({ "left": pop_left , "top": scrollTop });
		}else{
			$("#specifications-box").css({ "left": pop_left , "top": pop_top });
		}
	});*/
	/*窗口变化时运行*/
	$(window).resize(function() {
		var pop_left = ($(window).width()- vidoe_width)/2 + "px";
		var scrollTop = $(document).scrollTop();
		var pop_top = ($(window).height()-$(".pop-up-box #specifications-box").height())/2+scrollTop + "px";
		if(($(window).height()-$(".pop-up-box #specifications-box").height())/2 <= 0){
			$("#specifications-box").css({ "left": pop_left , "top": "0" });
		}else{
			$("#specifications-box").css({ "left": pop_left , "top": pop_top });
		}
	});
	$("#pop-up-click").click(function(){
		$(".pop-up-box").show();
		return false;
	});
	$("#close-btn").click(function(){
		$(".pop-up-box").hide();
	});
	
});
$(function() {
 $.fn.LoadingImg = function() {
  return this.each(function() {
   var that = this;
   var src = $(this).attr("src2");
   var img = new Image();
   img.src = src;
   var loading = $("<img alt=\"loading...\" class=\"loading-img\" title=\"loading...\" src=\"/skin/massimomotor/_images/loading.gif\" />");
   $(this).after(loading);
   $(this).hide();
   $(img).load(function() {
    loading.remove();
    $(that).attr("src", src);
    $(that).show();
   });

  });
 };
 //$("img").LoadingImg();
});
function picmd(pdate)
{
	var pdates = pdate.split("|");
	var purl = "product.php?productid="+pdates[0];
	
	
	//alert(pdates[0]);
	$("#show_product_id").val(pdates[0]);
	$("#show_product_name").html(pdates[1]);
	
	var price = pdates[2].split(".");
	//alert(price[1]);
	$("#show_product_price1").html(price[0]);
	$("#show_product_price2").html("."+price[1]);
	
	$("#productdetails-img").attr("src2",(pdates[3]));
	$("#productdetails-img").LoadingImg();
	
	$("#show_product_url1").attr("href",(purl));
	$("#show_product_url2").attr("href",(purl));
}
