(function() {
	$.absen || ($.absen = {});
	$.absen.productView = {};
	$.absen.productView.extend = function (subClass, superClass) {
		var F = function() {};
		F.prototype = superClass.prototype;
		subClass.prototype = new F();
		superClass.prototype.constructor = superClass;
		subClass.prototype.constructor = subClass;
		subClass.base = superClass.prototype;
	}
})();
$PV = $.absen.productView;
$PV.PicDetail = function() {
	var img = $("#product_imgs_box");
	if (img.length == 0)	return;
	var tq = null;
	var tq2 =null;
	var smalls = img.find(".product_s_images ul a");
	var move = true;
	var cur = 0;
	var preview = $('#preview');
	img = img.find("img").eq(0);
	smalls.each(function(i) {
		$(this).click(function(e) {
			e.preventDefault();
			if (!move || cur == i) return;
			tq = new Image();
			smalls.eq(cur).parent().removeClass("on");
			tq.src = this.href;
			preview.find('img').attr('src',tq.src);
			tq = $(tq);
			if (cur > i) {
			   tq2 = new Image();
			   var str=this.href;
			   str=str.substring(0,str.length-5)+".jpg";
			   tq2.src=str;
			   tq2=$(tq2);
				img.before(tq2);
				tq.css("marginTop", -304);
				tq.animate({marginTop:0}, 500, function() {
					img.remove();
					img = tq2;
					tq2 = null;
					tq=null;
					move = true;
				});
			} else {
			   tq2 = new Image();
			   var str=this.href;
			   str=str.substring(0,str.length-5)+".jpg";	
			   tq2.src=str;
			   tq2=$(tq2);			   		    
				img.parent().append(tq2);
				img.animate({marginTop:-304}, 500, function() {
					img.remove();
					img = tq2;
					tq = null;
					tq2 = null;					
					move = true;
				});
			}
			move = false;
			cur = i;
			smalls.eq(cur).parent().addClass("on");
		});
	});
}
$PV.imgscroll = function(){
	var btn_next = $('#btn_next');
	var btn_prev = $('#btn_prev')
	var ul = btn_next.next().find('ul');
	
	var len = ul.find('li').length;
	var i = 0 ;
	if (len > 4) {
		
		ul.css("width", 62 * len)
		btn_next.click(function(e) {
			if(i>=len-4){return;}
			i++;
			moveS(i);
			e.preventDefault();
			$(this).removeClass("on");
		}).mouseover(function(e) {
			if (!this.enab)  return;
			$(this).addClass("on");
		}).mouseout(function(e) {
			if (!this.enab)  return;
			$(this).removeClass("on");
		});
		
		btn_prev.click(function(e) {
			if(i<=0){return;}
			i--;
			moveS(i);
			e.preventDefault();
			$(this).removeClass("on");
		}).mouseover(function(e) {
			if (!this.enab)  return;
			$(this).addClass("on");
		}).mouseout(function(e) {
			if (!this.enab)  return;
			$(this).removeClass("on");
		});
	}
	function moveS(i) {
		ul.animate({marginLeft:-60 * i}, 500)
	}
}

$PV.imgzoom = function() {
	var zoompos = {x:0,y:0};
	var $pre = $("#preview");
	var $preimg = $("#preview img");
	var p_w  = parseInt( $preimg.css("width"),10);
	var p_h  = parseInt( $preimg.css("height"),10);
	$(".zoomple").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");
	}).click(function(){
		return false;
	});
	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)) , top:  -(zoompos.y * parseInt(yRatio)) }); 
	}		

}


function show(i){
	$('.fond_wrong').eq(i).find('a').show();	
}

function wrongShow(o){
	var text = $(o).parents().find('td').eq(0).text();							  
	$('#seachtext').text(text+" ");	
	var width = document.documentElement.clientWidth - 3;
	if( window.screen.availHeight < document.body.clientHeight ){
		 height = document.body.clientHeight;
	 }else{
		 height = window.screen.availHeight;
	 }
	var newobj = document.createElement('div');
	newobj.setAttribute('id','bigdiv');
	newobj.style.position = "absolute" ;
	newobj.style.left = "0px" ;	
	newobj.style.top = "0px" ;	
	newobj.style.background = "#666666" ;
	newobj.style.width = width + "px" ;
	newobj.style.height = height +"px" ;
	newobj.style.opacity = 0.6 ;
	newobj.style.filter="alpha(opacity=60)";
	newobj.style.zIndex = 100001; 
	document.body.appendChild(newobj);	
	var selfW = (document.documentElement.clientWidth - $('.pro_wrongOut').width())/2 ;
	var selfH = (document.documentElement.clientHeight - $('.pro_wrongOut').height())/2 ;
	$('.pro_wrongOut').css('z-index',100002);
	$('.pro_wrongOut').css('top',$(window).scrollTop()+selfH);
	$('.pro_wrongOut').css('left',selfW);
	$('.pro_wrongOut').css("display","block");
	
}

function wrongRemove(){
	$('.pro_wrongOut').hide();
	document.body.removeChild( document.getElementById("bigdiv") );
}

function hide(i){
	$('.fond_wrong').eq(i).find('a').hide();
}

var SN_Scroll = function(id,left,right,width,cur){
	SN_Scroll.i = 0 ;
	var len = $("#"+id).find("li:visible").length ;
	$("#"+id).find("ul").css("width", width * len);	
	$("#"+id).find("."+left).find('a').click(function(e){
		e.preventDefault();											  
		if(SN_Scroll.i<=0){
			return false;
		}
		len = $("#"+id).find("li:visible").length ;
		$("#"+id).find("ul").css("width", width * len);	
		SN_Scroll.i--;
		$("#"+id).find("ul").stop().animate({marginLeft:-width*cur*SN_Scroll.i},300);	
	});
	
	$("#"+id).find("."+right).find('a').click(function(e){
	    e.preventDefault();													   
		if(SN_Scroll.i>=(Math.floor(len/cur)==len/cur?len/cur-1:Math.floor(len/cur))){
			return false;
		}
		len = $("#"+id).find("li:visible").length ;
		$("#"+id).find("ul").css("width", width * len);	
		SN_Scroll.i++;	
		$("#"+id).find("ul").stop().animate({marginLeft:-width*cur*SN_Scroll.i},300);
	});
}


var SN_SeeScroll = function(id,left,right,w,cur){
	var i = 0 ;
	var len = $("#"+id).find("li").length ;
	$("#"+id).find("ul").css("width", w * len);	
	$("#"+id).find("."+left).find('a').click(function(e){
		e.preventDefault();											  
		if(i<=0){
			return false;
		}
		i--;
		$("#"+id).find("ul").stop().animate({marginLeft:-w*cur*i},300);	
	});
	
	$("#"+id).find("."+right).find('a').click(function(e){
		e.preventDefault();														   
		if(i>=(Math.floor(len/cur)==len/cur?len/cur-1:Math.floor(len/cur))){
			return false;
		}
		i++;	
		$("#"+id).find("ul").stop().animate({marginLeft : -700*i});			
	});
}
var AllproTab = function(id,hideId){
var tatol=0;
	$("#"+id).find("li").each(function(i){
 		if($(this).find("a em").html()!='')
		tatol+=parseInt($(this).find("a em").html());
		$(this).find("a").click(function(e){
			e.preventDefault();	
			$("#"+id).find(".pro_tabmore a").removeClass('on');	
			$(this).addClass("on").parent().siblings().find("a").removeClass('on');	
			if(i==0){
				$("#"+hideId).find("li").show();
				
			}else{
				$("#"+hideId).find("li").hide();
				$("#"+hideId).find("li.list0"+i).show();
			}
			$("#"+hideId).find("ul").css("marginLeft",0);
			SN_Scroll.i=0;
		});	
		
	});
	$("#fitting_tatol").text('('+tatol+')');
	$("#fitting").attr("title","鍏ㄩ儴閰嶄欢("+tatol+")");
}
function showbigimg(str)
{
  document.getElementById("bigimg").src=str;
  if (document.getElementById("imgpreview"))
  {
	document.getElementById("imgpreview").src=str;
  }
}
