/*---------------------------------------compare------------------------------------------*/
var initScrollY=0;
var proIDs=new Array();
function compare(){
	if ($("#compare").get(0)==null){
		$("body").append("<div id='compare'><h6><a title='清空' class='close' onclick='clearCompare()'></a>商品比较</h6><div class='comPro'><ul id='comProlist'></ul><img src='/images/compare_15.gif' id='compareImg' onclick='openCompare()'/></div></div>")	
		$("#compare").css({position:"absolute",top:"220px",right:"0px"});
		isCoo();
	}
	if ($.browser.msie){
		var defaultY=document.documentElement.scrollTop;
		var perceH=0.3*(defaultY-initScrollY);
		if(perceH>0){perceH=Math.ceil(perceH);}
		else {perceH=Math.floor(perceH);}
		$("#compare").get(0).style.top=parseInt($("#compare").get(0).style.top)+perceH+"px";
		initScrollY=initScrollY+perceH;
		setTimeout("compare()",50)
	}else{
		window.onscroll=function(){
			$("#compare").get(0).style.top=parseInt($("#compare").get(0).style.top)+"px";
			$("#compare").get(0).style.position="fixed";
		}
	}
}
function clearCompare(){
	$("#comProlist").empty();
	$("#compare").hide();
	createCookie("compare","");
	proIDs=new Array();
}
function addToCompare(checkobj,checkid,checkProName){
	$("#compare").show();
	$(".comPro").show();
	var proIDsTemp=proIDs.join(".");
	if (proIDsTemp.indexOf(checkid)==-1){
		if (proIDs.length<3){
			proIDs.push(checkid);
			$("#comProlist").append("<li id='check_"+ checkid +"'><a title='删除' class='close' onclick='reduceCompare("+ checkid +")'></a>"+checkProName+"</li>");
			writeCompare(checkid,checkProName);
		}else{
			alert("对不起，最多可以选择三种商品进行对比！");
		}
	}else{
		alert("对不起，您已经选择此商品！");
		return;
	}	
}
function reduceCompare(checkid){
	$("#check_"+ checkid).remove();
	$.each(proIDs,function(i,n){
		if (checkid==n){
			proIDs.splice(i,1);			
		}
	});
	var coo=readCookie("compare");
	var idindexstart=coo.indexOf(checkid);
	var idindexend=coo.indexOf("|||",idindexstart)+3;
	var delStr=coo.substring(idindexstart,idindexend);
	var innerStr=coo.replace(delStr,"")
	createCookie("compare",innerStr);
	if (proIDs.length==0){$(".comPro").hide();}
}
function openCompare(){
	switch (proIDs.length){
		case 1:
			alert("对不起，最少选择两种商品进行对比！");
			break;
		case 2:
			window.open("/pcompare.aspx?s1="+ proIDs[0] +"&s2="+ proIDs[1]);
			break;
		case 3:
			window.open("/pcompare.aspx?s1="+ proIDs[0] +"&s2="+ proIDs[1] +"&s3="+ proIDs[2]);
			break;	
		default:
			alert("请选择2-3件商品进行对比！");
			return;
	}	
}
function writeCompare(checkid,checkProName){
	var compareList=readCookie("compare");
	if (compareList==null){compareList="";}
	compareList+=checkid+"||"+escape(checkProName)+"|||";
	createCookie("compare",compareList);
}
function isCoo(){
	var coo=readCookie("compare");
	if (coo){
		var cootemp=coo.split("|||");
		var compareListTemp="";
		for(var i=0;i<cootemp.length-1;i++){
			compareListTemp+="<li id='check_"+ cootemp[i].split("||")[0] +"'><a title='删除' class='close' onclick='reduceCompare("+ cootemp[i].split("||")[0] +")'></a>"+unescape(cootemp[i].split("||")[1])+"</li>";
			proIDs.push(cootemp[i].split("||")[0]);
		}
		$("#comProlist").html(compareListTemp);
		$("#compare").show();
		$(".comPro").show();
	}	
}
/*---------------------------------------cookie------------------------------------------*/
function createCookie(name,value,days,Tdom){
	var Tdom=(Tdom)?Tdom:"/";
	if (days){
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}else{
		var expires = "";		
	}
	document.cookie = name+"="+value+expires+"; path="+Tdom;
}
function readCookie(name){
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++){
		var c = ca[i];
		while (c.charAt(0)==' ') {c = c.substring(1,c.length);}
		if (c.indexOf(nameEQ) == 0) {return c.substring(nameEQ.length,c.length);}
	}
	return null;
}
/*---------------------------------------marquee------------------------------------------*/
var timera=null;
var tag=1;
var Stag="stop";
var marqueeHeight=168;
var maxTop;
var minTop;
var marqueeObj;
var dpps=12;
var originalObj;
var cloneObj;
function marquee(Mtimes){
	clearTimeout(timera);
	Mtimes=Mtimes?Mtimes:2;
	marqueeObj=document.getElementById("NewProduct").getElementsByTagName("ul");
	maxTop=-marqueeHeight*Mtimes;
	minTop=marqueeHeight*Mtimes;
	if (marqueeObj.length==1){
		originalObj=marqueeObj[0];
		cloneObj=originalObj.cloneNode(true);
		originalObj.parentNode.appendChild(cloneObj);
		marqueeObj[0].style.top=0+"px";
		marqueeObj[1].style.top=minTop+"px";
	}
	if ((tag==0&&marqueeObj[0].offsetTop==0)||marqueeObj[0].offsetTop/tag==-marqueeHeight){
		tag++;
		Stag="stop";
		clearTimeout(timera);
		timera=setTimeout("marquee("+ Mtimes +")",5000);
	}else{
		Stag="continue";
		marqueeObj[0].style.top=marqueeObj[0].offsetTop-dpps+"px"
		marqueeObj[1].style.top=marqueeObj[1].offsetTop-dpps+"px"
		if (marqueeObj[0].offsetTop==maxTop){
			marqueeObj[0].style.top=minTop+"px";
			tag=-Mtimes;;
		}
		if (marqueeObj[1].offsetTop==maxTop){
			marqueeObj[1].style.top=minTop+"px";
		}
		timera=setTimeout("marquee("+ Mtimes +")",30)
	}
}
/*---------------------------------------SwitchTab------------------------------------------*/
function SwitchTab(IDprefix,order,TagAmount,status){
	switch (status){
		case "S1":
			var TagObj=OOO(IDprefix+"Option","li");
			var TagArr=new Array();
			for (var i=0;i<TagObj.length;i++){
				TagArr.push(TagObj[i].id.split("_Option_")[1]);
			}
			for (var i=0;i<TagArr.length;i++){
				OOO(IDprefix+"Option_"+TagArr[i]).className=(TagArr[i]==order)?"curr":"";
				OOO(IDprefix+"Con_"+TagArr[i]).className=(TagArr[i]==order)?"default":"disNone";
			}
			break;
		default:
			for (var i=0;i<TagAmount;i++){
				OOO(IDprefix+"Option_"+i).className=(i==order)?"curr":"";
				OOO(IDprefix+"Con_"+i).className=(i==order)?"default":"disNone";
			}
			//rankEffect();
			return;
	}
}
/*---------------------------------------showSort------------------------------------------*/
function showSort(obj){
	$("#"+obj+" h3").click(function(){
		this.className=(this.className=="open")?"":"open";
		$("#EFF_ul_"+this.id.substr(7)).get(0).className=(this.className=="open")?"open":"";
	});
}
/*---------------------------------------OOO------------------------------------------*/
function OOO(obj,ele){
	if (obj&&!ele){return document.getElementById(obj);}
	else if (obj&&ele){return document.getElementById(obj).getElementsByTagName(ele);}
	else {return false;}
}
/*---------------------------------------MyCart------------------------------------------*/
//var Dtimeout;
//var Dspeed;
var Dtimer=null;
var Dtimer2=null;
var Mdisplay=false;
var hideDiv;
var Container;
var button;
var jqShowObj;
var offset;
var height;
var width;
var btnHeight;
var btnWidth;
function initDMenu(obj,showobj,Dtimeout,Dspeed){
//	Dtimeout=Dtimeout?Dtimeout:300;
//	Dspeed=Dspeed?Dspeed:100;
	hideDiv=$("<div style='z-index:10000;'></div>");
	Container=$("<div id=\"Container\"></div>");
	hideDiv.append(Container);
	button=$(obj);
	jqShowObj=$(showobj);
	offset=button.offset();
	height=jqShowObj.height();
	width=jqShowObj.width();
	btnHeight=button.height();
	btnWidth=button.width();
	$(document.body).prepend(hideDiv);
}
function showDMenu(){
	if (Mdisplay==true){
		return false;
	}else{
		Mdisplay=true;
		Container.css({margin:"0 auto",width:btnWidth+"px",height:btnHeight+"px"});
		hideDiv.css({position:"absolute",top:offset.top+16+"px",left:button.offset().left-35+"px",height:height+"px",width:width+"px"}).show();
		Container.css({border:"1px solid #666666"});
		Container.animate({marginTop:10,height:height+4,width:width+4,opacity:'100'},100,function(){
			jqShowObj.show();
			Container.append(jqShowObj);
			Container.css({border:"0px"});
			jqShowObj.mouseover(function(){
				clearTimeout(Dtimer);clearTimeout(Dtimer2);
			}).mouseout(function(){
				hideDMenu();
			});			
		});
	}
}
function hideDMenu(){
	clearTimeout(Dtimer);
	clearTimeout(Dtimer2);
	Dtimer=setTimeout(function(){
		Container.css({border:"1px solid #666666"});
		$(document.body).prepend(jqShowObj);
		jqShowObj.hide();
		Container.empty();
		Container.animate({width:btnWidth,height:btnHeight,marginTop:'0',opacity:'0'},100,function(){
			Container.hide();
			hideDiv.hide();
			Mdisplay=false;
			});
		}, 100); 
}
/*---------------------------------------showTip------------------------------------------*/
var display=false;
var display2=false;
var display3=false;
function showTip(proobj){
	var TipDivW=$(proobj).width();
	var TipDivH=$(proobj).height();
	var TipDiv=$("<div id='c01tip' style='z-index:20000;position:absolute;width:"+ eval(TipDivW+5) +"px;height:"+ eval(TipDivH+5) +"px;'><div style='position:absolute;margin:5px 0 0 5px;width:"+ TipDivW +"px;height:"+ TipDivH +"px;background:#BCBEC0;z-index:20001;'></div></div>")
	if (display==false){
		TipDiv.append($(proobj));
		$(document.body).prepend(TipDiv);
		$(proobj).show();
		display=true;
	}else{
		$("#c01tip").show();
	}
	$("#c01tip").css({top:parseInt(document.documentElement.scrollTop + (document.documentElement.clientHeight-$("#c01tip").height())/2 )+"px",left:(document.documentElement.clientWidth-$("#c01tip").width())/2 +"px"})
	$("#Tip_viewCart,#Tip_continue,.Tip_Close").click(function(){
		$("#c01tip").fadeOut();
	});
}
function showTip2(proobj){
	var TipDivW=$(proobj).width();
	var TipDivH=$(proobj).height();
	var TipDiv=$("<div id='c02tip' style='z-index:20000;position:absolute;width:"+ eval(TipDivW+5) +"px;height:"+ eval(TipDivH+5) +"px;'><div style='position:absolute;margin:5px 0 0 5px;width:"+ TipDivW +"px;height:"+ TipDivH +"px;background:#BCBEC0;z-index:20001;'></div></div>")
	if (display2==false){
		TipDiv.append($(proobj));
		$(document.body).prepend(TipDiv);
		$(proobj).show();
		display2=true;
	}else{
		$("#c02tip").show();
	}
	$("#c02tip").css({top:parseInt(document.documentElement.scrollTop + (document.documentElement.clientHeight-$("#c02tip").height())/2 )+"px",left:(document.documentElement.clientWidth-$("#c02tip").width())/2 +"px"})
	$(".Tip_Close").click(function(){
		$("#c02tip").fadeOut();
	});
	timer_5=setTimeout("showTime()",1000);
}
function showTip3(proobj){
	var TipDivW=$(proobj).width();
	var TipDivH=$(proobj).height();
	var TipDiv=$("<div id='c03tip' style='z-index:20000;position:absolute;width:"+ eval(TipDivW+5) +"px;height:"+ eval(TipDivH+5) +"px;'><div style='position:absolute;margin:5px 0 0 5px;width:"+ TipDivW +"px;height:"+ TipDivH +"px;background:#BCBEC0;z-index:20001;'></div></div>")
	if (display3==false){
		TipDiv.append($(proobj));
		$(document.body).prepend(TipDiv);
		$(proobj).show();
		display3=true;
	}else{
		$("#c03tip").show();
	}
	$("#c03tip").css({top:parseInt(document.documentElement.scrollTop + (document.documentElement.clientHeight-$("#c03tip").height())/2 )+"px",left:(document.documentElement.clientWidth-$("#c03tip").width())/2 +"px"})
	$("#Tip_notice,.Tip_Close").click(function(){
		$("#c03tip").fadeOut();
	});
}
function showTime(){
	clearTimeout(timer_5);
	var overtime=parseInt($("#timer_5").html())-1;	
	if (overtime==0){
		$("#c02tip").fadeOut();
		//clearTimeout(timer_5);
		return;
	}
	$("#timer_5").html(overtime);
	timer_5=setTimeout("showTime()",1000)
}
/*---------------------------------------showNotice------------------------------------------*/
//var noticedisplay=false;
function showNotice(obj,noticetype,offX,offY){
	//alert(obj.name)
	var noticeX=$(obj).offset().left;
	var noticeT=$(obj).offset().top;
	var noticeW=$(obj).width();
	var noticeH=$(obj).height();
	var offX=(!offX)?60:offX;
	var offY=(!offY)?2:offY;
	//alert(noticeX)
	if ($("#"+noticetype).get(0)==null){
		var newNotice=document.createElement("span");
		$(newNotice).attr("id",noticetype)
		$(newNotice).css({position:"absolute",top:noticeT+noticeH+ offY +"px",left:noticeX-offX+"px",background:"#FFF9D9","z-index":"50000",padding:"5px",border:"1px solid #F88E00"});
		$(document.body).prepend($(newNotice));
		$(newNotice).html(obj.name);
		//noticedisplay=true;
	}else{
		$("#"+noticetype).css({top:noticeT+noticeH+ offY +"px",left:noticeX- offX +"px"});
		$("#"+noticetype).show();
	}
}
/*---------------------------------------openwin------------------------------------------*/
function opennewWin(url,newwinT,newwinW,newwinH){ 
	window.open(url,newwinT,"width="+ newwinW +",height="+ newwinH +",toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no,status=no");
}
/*------------------------------------------------------------------------------------------------------------------------------*/
$(function(){
	$("#Myfadodobuy,#ServiceCenter").mouseover(function(){
		this.className="dis";
	}).bind("mouseleave",function(){
		this.className="";		
	})
	$("#Nav li").click(function(){
		$(this).siblings().removeClass("curr");
		this.className="curr";
	});
	initDMenu("#CartSwitch_wrap","#MyCart");
	$("#CartSwitch_wrap").mouseover(function(){
		clearTimeout(Dtimer);
		height=$("#MyCart").height();
		Dtimer=setTimeout("showDMenu()",100); 
	}).bind("mouseleave",function(){
		clearTimeout(Dtimer); 
		if(Mdisplay==true){
			Dtimer2=setTimeout("hideDMenu()",100);
		}
	}); 
})
/*ResumeError*/
function ResumeError(){return true;} 
window.onerror = ResumeError;
if ($.browser.msie&&$.browser.version<"7.0"){
	try {document.execCommand("BackgroundImageCache", false, true);}
	catch(err){}
}