var webIndex = {};
webIndex.flagForm=null;

webIndex.boxyLoginObj = null;
webIndex.boxyOrderObj = null;
webIndex.intervalSecondSkipHandle = 0;
webIndex.animateStepFactor = 4 ;
webIndex.animateStep = 160 * webIndex.animateStepFactor;
webIndex.middleRecStepFactor = 5;

webIndex.rightCooperatorFun = function(){
	$("#rightCooperatorDiv > div").click(function(){
		$("#rightCooperatorDiv").children("div").each(function(){
			$(this).children("div:last").hide();
			$(this).children("div:first").children("div:last").children("img:last").hide();
			$(this).children("div:first").children("div:last").children("img:first").show();			
		});
		$(this).children("div:last").show();
		$(this).children("div:first").children("div:last").children("img:first").hide();
		$(this).children("div:first").children("div:last").children("img:last").show();
	});
};

webIndex.secondSkipFun = function(){
	var productDivs = $("#sotreListUl > li");
	
	productDivs.each(
	    function(){
	    	var secondSpans = $(this).children("div:last").children("span") ; 
	    	
	    	var totalSecond = secondSpans.eq(0).text();
	    	if(totalSecond <= 0){
	    		window.clearInterval(advertisementHover.intervalSecondSkipHandle);
	    		return;
	    	}
	    	secondSpans.eq(0).text(--totalSecond);
	    	var secondReader = new secondReaderName.SecondReader(totalSecond);
	    	secondReader.calc();
	    	secondSpans.eq(1).text(secondReader.hour);
	    	secondSpans.eq(2).text(secondReader.minute);
	    	secondSpans.eq(3).text(secondReader.second);
	    }
	);
};

webIndex.intervalSecondSkipFun = function(){
	webIndex.intervalSecondSkipHandle = window.setInterval(webIndex.secondSkipFun,1000);
};

webIndex.showOrHide = function(objId,justShow){
	var obj =  $("#"+objId);
	if(justShow == true){
		obj.show();		
	}else if(justShow == false){
		obj.hide();
	}else{
		var oldDisplay = obj.css("display");
		if(oldDisplay == "none"){
			obj.show();
		}else{
			obj.hide();
		}
	}
};

webIndex.animateAtFirstFun = function(){
	webIndex.showOrHide("indexLeftArrowhead");
	webIndex.showOrHide("indexLeftArrowhead2");
};

webIndex.animateAtLastFun = function(){
	webIndex.showOrHide("indexRightArrowhead");
	webIndex.showOrHide("indexRightArrowhead2");
};

webIndex.animateMoveRebackFun = function(firstFlag,lastFlag,maxStep){
	if(firstFlag > 1){
		webIndex.showOrHide("indexLeftArrowhead",true);
		webIndex.showOrHide("indexLeftArrowhead2",false);
	}	
	if(lastFlag < maxStep){
		webIndex.showOrHide("indexRightArrowhead",true);
		webIndex.showOrHide("indexRightArrowhead2",false);
	}
};

webIndex.scrollAtFirstFun = function(){
	webIndex.showOrHide("secondLeftScrollArrowhead");
	webIndex.showOrHide("secondLeftScrollArrowhead2");
};

webIndex.scrollAtLastFun = function(){
	webIndex.showOrHide("secondRightScrollArrowhead");
	webIndex.showOrHide("secondRightScrollArrowhead2");

};

webIndex.scrollMoveRebackFun = function(firstFlag,lastFlag,maxStep){
	if(firstFlag > 1){
		webIndex.showOrHide("secondLeftScrollArrowhead",true);
		webIndex.showOrHide("secondLeftScrollArrowhead2",false);
		
	}
	if(lastFlag < maxStep){
		webIndex.showOrHide("secondRightScrollArrowhead",true);
		webIndex.showOrHide("secondRightScrollArrowhead2",false);
		
	}	
};

webIndex.getAnimateMaxStep = function(containerId,childrenTagName,factor){
	var result =  $("#"+containerId).children(childrenTagName).length ;
	result = (result % factor) == 0 ? result / factor : parseInt(result / factor )+1;
	return result < 0 ? 0 : result;	
};

webIndex.getCooperatorProductFun = function(cooperatorId){
	var productUrl = indexJsp.getCooperatorProductUrl;
	if(null == productUrl){
		return;
	}
	productUrl += "?cooperatorId="+cooperatorId;
	$("#cooperatorProductDiv").load(productUrl);	
};

webIndex.middleCooperatorLiMouseEnterFun = function(curLiObj){
	  if(curLiObj.length < 1) return;
	  var curTop  = ($(curLiObj).position().top )% (50 * webIndex.middleRecStepFactor);
	  $("#borderDiv").css("top",curTop);
	  var cooperatorId = $(curLiObj).attr("name");
	  if(cooperatorId){
		  webIndex.getCooperatorProductFun(cooperatorId);
	  }
};




webIndex.middleCooperatorLiHoverFun = function(){
	$("#middleRecommendCooperatorUl > li").hover(
	  function(){ 
		  var curObj = this;
		  window.setTimeout(function(){webIndex.middleCooperatorLiMouseEnterFun(curObj)},200);			  
	  },
	  function(){}			
	);
};

webIndex.middleCooperatorLiDefaultFun = function(){
	var first=$("#middleRecommendCooperatorUl > li").eq(0);
	webIndex.middleCooperatorLiMouseEnterFun(first);	
};

webIndex.middleRecScrollMoveRebackFun = function(firstFlag,lastFlag){
	var curLiObj = $("#middleRecommendCooperatorUl > li").eq((firstFlag - 1) * webIndex.middleRecStepFactor);
	webIndex.middleCooperatorLiMouseEnterFun(curLiObj);
};

webIndex.midSecondTagFun = function(){
	$("#midSecondTag >div").hover(
		function(){  
			$(this).css("margin-top","0px").css("line-height","31px").css("height","31px");	
			$(this).siblings("div").css("margin-top","13px").css("line-height","18px").css("height","18px");	
		},
		function(){
				
		}
   );
	new webCommon.TagNavigation("midSecondTag","div","","","midSecondContainer","div",["mouseenter"]).bindAction();	
};

webIndex.hotCooperatorDivHoverFun = function(){
	$("#hotCooperatorDiv > div").hover(
	   function(){
		   $(this).children("div").addClass("kx4").removeClass("kx3");
	   },
	   function(){
		   $(this).children("div").removeClass("kx4").addClass("kx3");		   
	   }
	);
};

webIndex.couponNaviFun = function(){
	//alert($("map[name='Map']").length);
	$("map[name='Map']").children("area").click(
	    function(){
	      //alert($("map[name='Map']").children("area").length);
	    	var itemIndex = $("map[name='Map']").children("area").index(this);
	    	//alert(itemIndex);
	    	$("#rightFourthTagNavi").children("div").hide();
	    	$("#rightFourthContainerDiv").children("div").hide();
	    	$("#rightFourthTagNavi").children("div").eq(itemIndex).show();
	    	$("#rightFourthContainerDiv").children("div").eq(itemIndex).show();	    	
	    
	    }	
	);
};



webIndex.recommendActiveULHoverFun = function(){
	
	$("#recommendActiveUL > li").hover(
	   function(){
		  $(this).css("background-color","#f3f3f3");
	   },
	   function(){
		  $(this).css("background-color","");
	   }
	);
};

webIndex.loginFirstBoxHintFun = function(){
	var timeoutHandler = 0;
	var HideHint = function(obj){
		$("#loginFirstBoxHintDiv > div").hide();
		//$(obj).hide();
	};
	$("#loginFirstBoxDiv > div").hover(
			function(){ 
				 window.clearTimeout(timeoutHandler); 
				var indexItem = $("#loginFirstBoxDiv > div").index(this);
				if(indexItem < 1){
					return;
				}
				$("#loginFirstBoxHintDiv > div").eq(indexItem - 1).show();
			},
			function(){
				//$("#loginFirstBoxHintDiv > div").hide();
				//var objItem = this;
				//timeoutHandler = window.setTimeout(HideHint,1);
				HideHint();
			}
	);	
	$("#loginFirstBoxHintDiv > div").hover(
	   function(){
		 window.clearTimeout(timeoutHandler);  
	   },
	   function(){
		  // var objItem = this;
		   timeoutHandler = window.setTimeout(HideHint,1);
	   }
	);	
};

/*提交表单*/
webIndex.cpsSubmit = function(aObj){
	var href = aObj.attr("href");
	var codeA = aObj.attr("code");
	var urlA = aObj.attr("url");
	var flag = getIsLogin();
	if(!flag){
		webIndex.flagForm=aObj;
		//$('#popup_unlogin_div').dialog("open");	
		webIndex.boxyLoginObj.show();
		return false;
	}
	$("#cps_form").children("input[name='url']").attr("value",urlA);
	$("#cps_form").get(0).code.value = codeA;
	$("#cps_form").attr("action", href + "/mall/linktech/purchase_cps.htm");
	$("#cps_form").get(0).submit();
	return false;
};



webIndex.cpsSubmitSure = function(){
	var aObj=webIndex.flagForm;
	if(aObj==null){return;}
	var href = aObj.attr("href");
	var codeA = aObj.attr("code");
	var urlA = aObj.attr("url");
	$("#cps_form").children("input[name='url']").attr("value",urlA);
	$("#cps_form").get(0).code.value = codeA;
	$("#cps_form").attr("action", href + "/mall/linktech/purchase_cps.htm");
	$("#cps_form").get(0).submit();
};

webIndex.linktechAClickFun = function(){
	$("a[name='linktech_cps']").click(function(){
			var aObj = $(this);
			webIndex.cpsSubmit(aObj);
			return false;
	   }
	);
};
webIndex.closeUnloginDialog = function(obj){
	var isLoginB = getIsLogin();
	  if(obj=="show" && isLoginB == true){	
		  webIndex.boxyOrderObj.show();
	 }
	  webIndex.cpsSubmitSure();
	  webIndex.boxyLoginObj.hide();
 }; 
 webIndex.getIndexUserMsgFun = function(){
	 var myUrl = $("#index_user_msg_div").attr("name")+"?ts="+new Date().getTime();
	 $.ajax({url:myUrl,success:function(data){$("#index_user_msg_div").html(data);},async:false});
	 //$("#index_user_msg_div").load(myUrl);
 }

$(document).ready(function(){
  try{
	var tempArray = ["mouseenter"];
	new webCommon.TagNavigation("rightFirstTagNavi","span","spanChecked","","rightContainerDiv","ul",tempArray).bindAction();
	new webCommon.TagNavigation("rightSecondTagNavi","span","spanChecked","","rightSecondContainerDiv","div",tempArray).bindAction();
	new webCommon.TagNavigation("rightThirdTagNavi","div","smallrushtitt","smallrushtitt2","rightThirdContainerDiv","div",tempArray).bindAction();
	//new webCommon.TagNavigation("rightFourthTagNavi","div","smallrushtitt","smallrushtitt2","rightFourthContainerDiv","div",tempArray).bindAction();
	new webCommon.TagNavigation("leftHotTab","div","recolist","recolist2","leftHOtContainer","div",tempArray).bindAction();
	
	webIndex.rightCooperatorFun();
	webIndex.intervalSecondSkipFun();
	
	var animateAd =new AnimateAd("middleSecondScrollUl",true,webIndex.getAnimateMaxStep("middleSecondScrollUl","li",1),
			1,1,600,410,
			webIndex.scrollAtFirstFun,webIndex.scrollAtLastFun,webIndex.scrollMoveRebackFun
    );
	
	var storeUlAnimateAd =new AnimateAd("sotreListUl",true,webIndex.getAnimateMaxStep("sotreListUl","li",webIndex.animateStepFactor),
			1,1,600,
			webIndex.animateStep,
			webIndex.animateAtFirstFun,webIndex.animateAtLastFun,webIndex.animateMoveRebackFun);
			//webIndex.animateAtFirstFun,null,webIndex.animateMoveRebackFun );
	
	var middleFirstScrollUlAnimateAd = new AnimateAd("middleFirstScrollUl",true,webIndex.getAnimateMaxStep("middleFirstScrollUl","li",1),
			1,1,600,410);
	
	$("#indexLeftArrowhead").bind("click",function(){
		storeUlAnimateAd.positiveMoveFun();
	});
	$("#indexRightArrowhead").bind("click",function(){		
		storeUlAnimateAd.negativeMoveFun();
	});
	
    var handlerObjs = adForm.$("idNum12").getElementsByTagName("li");
	adForm.ready("idTransformView2", "idSlider2",540,2,handlerObjs,"on",false);
	
	$("#secondLeftScrollArrowhead").bind("click",function(){
	   animateAd.positiveMoveFun();
	   middleFirstScrollUlAnimateAd.positiveMoveFun();
	});
	$("#secondRightScrollArrowhead").bind("click",function(){			
	   animateAd.negativeMoveFun();
	   middleFirstScrollUlAnimateAd.negativeMoveFun();
	});
	webIndex.middleCooperatorLiHoverFun();
	
	webIndex.middleCooperatorLiDefaultFun();
	var middleRecScroll =new AnimateAd("middleRecommendCooperatorUl",false,webIndex.getAnimateMaxStep("middleRecommendCooperatorUl","li",5),
			1,1,600,250,
			null,null,webIndex.middleRecScrollMoveRebackFun
    );
	$("#middleRecLeftArrowhead").click(function(){ 
		middleRecScroll.positiveMoveFun();
	});
	
	$("#middleRecRightArrowhead").click(function(){ 
		middleRecScroll.negativeMoveFun();
	});
	
	webIndex.midSecondTagFun();
	
	new webCommon.TagNavigation("rightPromotionNavUL","li","dianka","","rightPromotionContainerDiv","div",tempArray).bindAction();
	webIndex.couponNaviFun();
	webIndex.hotCooperatorDivHoverFun();
	webIndex.recommendActiveULHoverFun();
	webIndex.loginFirstBoxHintFun();
	webIndex.linktechAClickFun();	
	webIndex.boxyLoginObj = new Boxy("#popup_unlogin_div",{modal:true,show:false});
	webIndex.boxyOrderObj = new Boxy("#kuangbox_l",{modal:true,show:false});
	//webIndex.getIndexUserMsgFun();
	$("img[name='closeImg']").click(function(){
		webIndex.boxyLoginObj.hide();  
		webIndex.boxyOrderObj.hide();});
  }catch(e){alert(e);}
});


function changeColor(){
	$("#denglufuck").attr("style","color:#ff6600");
  }
  function closeColor(){
	  $("#denglufuck").attr("style","color:#da4901");
  }
  function changeColorzhi(){
		$("#denglufuckzhi").attr("style","color:#1d4eb6");
	  }
	  function closeColorzhi(){
		  $("#denglufuckzhi").attr("style","color:#15377e");
	  }
	  function changeColorzhiRegeist(){
			$("#dengluregeist").attr("style","color:#ff6600");
		  }
		  function closeColorzhiRegeist(){
			  $("#dengluregeist").attr("style","color:#da4901");
		  }