// JavaScript Document

$(document).ready(function(){
 	$("#psse li").mouseover(function(){
		  clearTimeout(t);
		  movethis($('#psse li').index(this)); 
	});
	
	
	
	$("#psgd ul").mouseover(function(){
		clearTimeout(t);
		reccc=$('#psgd ul').index(this)+1;
		t=setTimeout("movethis("+reccc+")",6000);
	});
	$(".row>li").hover(
            function () {$(this).find('>a').stop().animate({ paddingLeft: "8px" }, 'fast');}, 
            function () {$(this).find('>a').stop().animate({ paddingLeft: "0px" }, 'fast');}
     );
	 
	$("#product_sepic img").mouseover(function(){
		$(".jqzoom img").attr("jqimg",$(this).attr("src"));
		$(".jqzoom img").attr("src",$(this).attr("src"));
		DrawImage($(".jqzoom img")[0],240,180);
	});
	
	$(".jqzoom img").click(function(){
		api_gallery=[];
		api_gallery[0]=$("#product_sepic img:eq(0)").attr("src");
		pic1=$("#product_sepic img:eq(1)").attr("src");
		pic2=$("#product_sepic img:eq(2)").attr("src");
		pic3=$("#product_sepic img:eq(3)").attr("src");
		if(pic1!=undefined)
		api_gallery[1]=pic1;
		if(pic2!=undefined)
		api_gallery[2]=pic2;
		if(pic3!=undefined)
		api_gallery[3]=pic3;
		/*api_gallery=[$("#product_sepic img:eq(0)").attr("src"),$("#product_sepic img:eq(1)").attr("src"),$("#product_sepic img:eq(2)").attr("src"),$("#product_sepic img:eq(3)").attr("src")];*/
		api_titles=['','','',''];
		api_descriptions=['','','',''];		
		$.prettyPhoto.open(api_gallery,api_titles,api_descriptions); 
	})
	
	$(".jqzoom").jqueryzoom({
			xzoom:430,
			yzoom:250,
			offset:10,
			position:"right",
			preload:1,
			lens:0
	});
		

});

function movethis(rec){
	clearTimeout(t);
	$("#psgd").clearQueue();
	$('#psse li').removeClass(); 
	$('#psse li')[rec].className="se";
	rec1=rec;
	wid=rec1*-960;
	$("#psgd").animate({left:wid+"px"},"slow");
	if(rec>=5){
		rec=0;
		t=setTimeout("movethis(0)",6000);
	}else{
		recere=rec+1
		t=setTimeout("movethis("+recere+")",6000);
	}
}
t=setTimeout("movethis(2)",6000)

function DrawImage(ImgD,iwidth,iheight){
    //参数(图片,允许的宽度,允许的高度)
    var image=new Image();
    image.src=ImgD.src;
    if(image.width>0 && image.height>0){
    flag=true;
    if(image.width/image.height>= iwidth/iheight){
        if(image.width>iwidth){
        ImgD.width=iwidth;
        ImgD.height=(image.height*iwidth)/image.width;
        }else{
        ImgD.width=image.width; 
        ImgD.height=image.height;
        }
        ImgD.alt=image.width+"×"+image.height;
        }
    else{
        if(image.height>iheight){ 
        ImgD.height=iheight;
        ImgD.width=(image.width*iheight)/image.height;   
        }else{
        ImgD.width=image.width; 
        ImgD.height=image.height;
        }
        ImgD.alt=image.width+"×"+image.height;
        }
    }
	runw=(iwidth-ImgD.width)/2;
	runh=(iheight-ImgD.height)/2;
	ImgD.parentNode.style.marginLeft=runw+'px';
	ImgD.parentNode.style.marginTop=runh+'px';
	//return runw
	//alert(iwidth+'--'+iheight+'--'+ImgD.width+'--'+ImgD.height+'---'+runh);
} 

