﻿/// <reference path="jquery-1.2.6-vsdoc-cn.js" />

$(document).ready(function()
{
	SwitchBoxDetail(1);
    SwitchBoxDetail(2);
	Pictures();
    ProductRecommend();    
});

function SwitchBoxDetail(num)
{
   $("#tagcontent"+num+" .tab_content:not(:first)").hide();
   $("#tagtitle"+num+" li").each(function(i){
       $(this).mousedown(
	   	  function(){
		  $("#tagtitle"+num+" li.nowtag").removeClass("nowtag");
		  $(this).addClass("nowtag");
		  $("#tagcontent"+num+" .tab_content:visible").hide();
		  $("#tagcontent"+num+" .tab_content:eq(" + i + ")").fadeIn(400);
	  });
   });
}

function ProductRecommend()
{
    $("#RecommondBtn").click(function()
        {   
            window.clipboardData.setData("Text",$("#Hidden1").val());
            alert("推荐商品名称与地址已经复制，请粘贴到您的QQ/MSN/taobao/Email/BBS/博客上推荐给您的好友！");
        }
    );
}

function SubmitKeyClick(button) 
{    
if (event.keyCode == 13) 
{        
event.keyCode=9; 
event.returnValue = false; 
document.all[button].click(); 
} 
} 

function Pictures()
{
    $("#sPicture ul li").each(function(i)
    {
       $(this).mouseover(
       function()
       {
        var path=$("#sPicture ul li img:eq("+i+")").attr("src").replace("s.","m.");
        $(".bigimg").attr("src",path).fadeIn(250);
        $("#sPicture ul li.selected").removeClass("selected");
        $("#sPicture ul li:eq("+i+")").addClass("selected");                                
        $("#preview2 img").attr("src",path.replace("m.",".").replace("s.",".")).fadeIn(250);
        $("#aimg").attr("href",path.replace("m.",".").replace("s.","."));
       });      
    });    
}

$(function(){
	var zoompos = {x:0,y:0};
	var $pre = $("#preview2");
	var $preimg = $("#preview2 img");
	var p_w  = parseInt( $preimg.css("width"),10);
	var p_h  = parseInt( $preimg.css("height"),10);
	$("#aimg").bind("mouseenter",function(e){
		var $this  = $(this);
		var $zoom = $this.find(".zoomplePopup");
		$zoom.show();
		$pre.show();
		PositionPopupZoom( $this , $zoom , e.pageX , e.pageY , p_w , p_h );
		$this.bind("mousemove",function(e){
			setTimeout(function(){
				PositionPopupZoom( $this , $zoom , e.pageX , e.pageY , p_w , p_h);
			},10);
		});
	}).bind("mouseleave",function(){
		var $this  = $(this);
		var $zoom = $this.find(".zoomplePopup");
		$zoom.hide();
		$pre.hide();
		$this.unbind("mousemove");
	});

	function PositionPopupZoom( wrap , zoom , x , y , w , h){
		var wrapLeft = wrap.offset().left;
		var wrapTop =  wrap.offset().top;
		var zoomWidth = zoom.width();
		var zoomHeight = zoom.height();
		var wrapWidth = wrap.width();
		var wrapHeight = wrap.height();
		zoompos.x =  x -wrapLeft - (zoomWidth/2);
		zoompos.y =  y -wrapTop- (zoomHeight/2);
		if( zoompos.x <= 0 ){
			zoompos.x  =  0;
		}
		if( zoompos.y <= 0 ){
			zoompos.y  =  0;
		}
		if( zoompos.x + zoomWidth >= wrapWidth){
			zoompos.x  = wrapWidth  -  zoomWidth; 
		}
		if( zoompos.y + zoomHeight >= wrapHeight){
			zoompos.y  = wrapHeight  -  zoomHeight; 
		}

		var xRatio = w / wrapWidth;  
		var yRatio = h / wrapHeight;

		zoom.css({left:zoompos.x,top:zoompos.y});
		$preimg.css({left: -(zoompos.x * parseInt(xRatio, 10)) , top:  -(zoompos.y * parseInt(yRatio, 10))  }); 
	}
});


