/*vancl 图片放大镜效果部分应用 开始*/
var webUrl = 'http://www.vsnoon.com';
var isH = false;
var bigPXoffset;
var bigPYoffset;

jQuery(document).ready(function(){
	setoffset();
});
       
$(function(){
if($(".size li").length==1)
{
    $(".size li").eq(0).click();
}
});
 if ($.browser.msie)
 {
   document.execCommand("BackgroundImageCache", false,true);
 }
//设置放大镜图片的位
function setoffset()
{
	    $(".jqzoom").jqzoom(
	    {
	            zoomWidth: 400,		
	            zoomHeight:380
	    });
	    
        isH = true;
        var width=document.body.clientWidth;
        //根据不同页面设置不同值
        if(pagename=="ProductInfoNew")
        {
    		if(width>1024)
    		{
    			bigPXoffset=484;
        	}
        	else
            {
        		bigPXoffset=389;
            }
        }
        if(pagename=="ProductInfo_green")
        {
    		if(width>1024)
    		{
    			bigPXoffset=715;
        	}
        	else
            {
        		bigPXoffset=580;
            }
        }
}
function setShoppingUrl()
{
    if(checkurl(location.href)) setCookie("ShoppingBackUrl",location.href,30);//设置返回页面
}

function backShoppingUrl(urls)
{
    var Url=getCookie("ShoppingBackUrl");
    if(Url=="" || Url==undefined)Url="/";
    location.href=Url;
}
function checkurl(url)
{
    if(url.indexOf("Edit_InRow")>-1)
    {
        return false;
    }
    return true;
}

function mycarousel_initCallback(carousel){
      var index = 0;
      $("#mycarousel li img").eq(index).attr("class","curr");
      
		$("#mycarousel li").hover(function(){
		    index=$("#mycarousel li").index(this);
			$("#productImage")[0].src = this.getElementsByTagName("img")[0].src.replace("small","460");
			$("#BigViewImage").attr("href",this.getElementsByTagName("img")[0].src.replace("small","big"));
			$(this).siblings().each(function(){
					this.getElementsByTagName("img")[0].className="";
			})
			this.getElementsByTagName("img")[0].className="curr";

		},
		function(){
			$("#productImage")[0].src = this.getElementsByTagName("img")[0].src.replace("small","460");
			this.getElementsByTagName("img")[0].className="curr";

		},
		function(){
		    var currIndex = $("#mycarousel li").index(this);
		    if(!(index == currIndex))
		    {
		        this.getElementsByTagName("img")[0].className="";
		    }
		    $("#productImage")[0].src = $("#mycarousel li img").eq(index).attr("src").replace("small","460");
		}
		);
      
/*		$("#mycarousel li").hover(function(){
			$("#productImage")[0].src = this.getElementsByTagName("img")[0].src.replace("small","middle");
			this.getElementsByTagName("img")[0].className="curr";

		},
		function(){
		    var currIndex = $("#mycarousel li").index(this);
		    if(!(index == currIndex))
		    {
		        this.getElementsByTagName("img")[0].className="";
		    }
		    $("#productImage")[0].src = $("#mycarousel li img").eq(index).attr("src").replace("small","middle");
		});*/
		
		
		temp_carousel=carousel;
		// Disable autoscrolling if the user clicks the prev or next button.
		carousel.buttonNext.hover(function() {
			t1=setInterval("temp_carousel.buttonNext.click()",500);
			  if(typeof t2!="undefined")clearInterval(t2);
		},
		 function() {
		   clearInterval(t1);
		});
		carousel.buttonPrev.hover(function() {
			t2=setInterval("temp_carousel.buttonPrev.click()",500);
			 if(t1!=undefined)clearInterval(t1);
		}, function(){
			 clearInterval(t2);
		});
};
function mycarousel_initCallback2(carousel){
		temp_carousel1=carousel;
		// Disable autoscrolling if the user clicks the prev or next button.
		carousel.buttonNext.hover(function() {
			t3=setInterval("temp_carousel1.buttonNext.click()",5);
			  if(typeof t4!="undefined")clearInterval(t4);
		},
		 function() {
		   clearInterval(t3);
		});
		carousel.buttonPrev.hover(function() {
			t4=setInterval("temp_carousel1.buttonPrev.click()",5);
			 if(t3!=undefined)clearInterval(t3);
		}, function(){
			 clearInterval(t4);
		});
		
};

jQuery(document).ready(function(){
	
  jQuery('#mycarousel').jcarousel({initCallback:mycarousel_initCallback});
  
	//setShoppingUrl();
});

jQuery(document).ready(function() {
    jQuery('#mycarousel2').jcarousel();
});

jQuery(document).ready(function() {
    jQuery('#mycarousel3').jcarousel();
});

/*vancl 图片放大镜效果部分应用结束*/
/*获得评论列表开始*/
function commlist(pagetype)
{
	var page=$("#commpage").val();
	var totalpage=$("#totalpage").val();
	var prodid=$("#hiddenProdID").val();
	switch(pagetype)
	{
	  case 1:
		  page=1;
		  break;
	  case 2:
		  page=parseInt(page)-1;
		  break;
	  case 3:
		  page=parseInt(page)+1;
		  break;
	  case 4:
		  page=totalpage;
		  break;
	}
	if(page<=1)
	{
		page=1;
	}
	//将page放入隐藏域
	$("#commpage").val(page);
    var param = {'page':page,'type':'commlist','prodid':prodid,'totalpage':totalpage};
	$.getJSON(webUrl+"/ajaxdo/prodComment.php?t="+Math.random(),param,	
	function(data){
		alert(data.pagenum);
		$("#commpage").val(page);
		$("#totalpage").val(data.pagenum);
		$("#commlist").html(data.comment);
	});
}

/*新版获得评论列表开始*/
function commlist(pagetype)
{
	var page=$("#commpage").val();
	var totalpage=$("#totalpage").val();
	var prodid=$("#hiddenProdID").val();
	switch(pagetype)
	{
	  case 1:
		  page=1;
		  break;
	  case 2:
		  page=parseInt(page)-1;
		  break;
	  case 3:
		  page=parseInt(page)+1;
		  break;
	  case 4:
		  page=totalpage;
		  break;
	}
	if(page<=1)
	{
		page=1;
	}
	//将page放入隐藏域
	$("#commpage").val(page);
    var param = {'page':page,'type':'commlistnew','prodid':prodid,'totalpage':totalpage};
	$.getJSON(webUrl+"/ajaxdo/prodComment.php?t="+Math.random(),param,	
	function(data){
		$("#commpage").val(page);
		$("#totalpage").val(data.pagenum);
		$("#commlist").html(data.comment);
	});
}

/*获得评论列表结束*/
function cus_boxShow(){
      $('#cus_alert').show();
      window.clearTimeout(cus_boxShow);
}
 
$(function()
{
	commlist(1);//页面加载时显示第一页评论
    setTimeout('cus_boxShow()', 1000*10);
}); 
  
(function($) {
   $(function() {
    var oldTopValue = parseInt($('#cus_alert').css('top'));
    var showInfo = function() {
      $('#cus_alert').animate({
       'top': oldTopValue + $(window).scrollTop()
      }, 200);
	  
      var handScroll = setTimeout(showInfo, 200);      
    };
    showInfo();   
   });
})(jQuery);

/*添加评论结束*/
/*js中好用時間格式化函數
 * 调用 showtime = new Date().format("yyyy-MM-dd hh:mm:ss");
 * */
Date.prototype.format = function(format)   
{   
   var o = {   
     "M+" : this.getMonth()+1, //month   
     "d+" : this.getDate(),    //day   
     "h+" : this.getHours(),   //hour   
     "m+" : this.getMinutes(), //minute   
     "s+" : this.getSeconds(), //second   
     "q+" : Math.floor((this.getMonth()+3)/3), //quarter   
     "S" : this.getMilliseconds() //millisecond   
   }   
   if(/(y+)/.test(format)) format=format.replace(RegExp.$1,   
     (this.getFullYear()+"").substr(4 - RegExp.$1.length));   
   for(var k in o)if(new RegExp("("+ k +")").test(format))   
     format = format.replace(RegExp.$1,   
       RegExp.$1.length==1 ? o[k] :    
         ("00"+ o[k]).substr((""+ o[k]).length));   
   return format;   
} 
//显示评论弹出框
function showcommdiv()
{
	var proCode=$("#hiddenProdID").val();
	/*if($.cookie('comment'+proCode)=='true')
	{
     	ymPrompt.alert({message:'您已经评论过了！',width:330,height:160,title:'提示信息'});
     	$.unblockUI();
		//ymPrompt.alert({message:'您已经评论过了！',width:330,height:160,title:'提示信息',handler:function handler(tp){if(tp=='ok'){$.unblockUI();}}});
     	return false;
	}*/
	
	$.blockUI({
        message:$('#commdiv'),css: {
			top: '100px',
			left: '268px',
            width: '521px',height:'233px'
        }
	});
	
}

