// JavaScript Document
// 头部通用导航
var nav = {
	 open:false,
	 topOver:false,
	 leftOver:false,
	 rigOver:false,
     start:function(value){
		nav.openNav(value);
	    this.topSw();
		this.leftSw();
		this.rigSw();
		$('.btnCloseNav').click(function(){
	        nav.topOver = false;
			nav.leftOver = false;
			nav.rigOver = false;
		    nav.init();
		})
	 },
	 topSw:function(){
		 $('#navAllpLink').hover(
		    function(){                 // 一级分类
				nav.topOver = true;
				$('.navShowRigBox').hide();
				$('.navFirUL li').attr('class','');
				if($('.navBox:visible').length>0) return false;
				$(this).attr('class','navBg_02');
				$('.navBox').slideDown(400);
	        },
			function(){
				nav.topOver = false;
				nav.init();
			}
		 )
	 },
	 leftSw:function(){
		$('.navFirUL li').hover(
		    function(){
				 nav.leftOver = true;
				 $('.navBox').show();
				 $('.navFirUL li').removeClass('navHovLI');
				 $('.navShowRigBox').hide();
				 $(this).attr('class','navHovLI');
				 var offset = $(this).offset();
				 var Boxtop = offset.top  + 2;
				 var Boxleft = offset.left + 140;
				 if($('.whiteBorder').length == 0){
				    $('<div class="whiteBorder"> </div>').insertBefore($('.top'));
				 }
				 $('.whiteBorder').show().css({left:Boxleft,top:Boxtop});
				 var num = $('.navFirUL li[class="navHovLI"]').index() - 1;
				 if(num > 1){
					$('.navShowRigBox').eq(num).css({top:(num-1)*34 + 8});
				 }
				 $('.navShowRigBox').eq(num).show();
			},
			function(){
				nav.leftOver = false;
				nav.init();
		    }
		 )
	 },
	 rigSw:function(){
	     $('.navShowRigBox').hover(
		    function(){
			    nav.rigOver = true;
			},
			function(){
			    nav.rigOver = false;
				nav.init();
			}
	     )
	 },
	 init:function(){
		 setTimeout(function(){
			 if(nav.topOver || nav.leftOver || nav.rigOver){
				 return;
			 }
			 $('.whiteBorder').hide();
			 $('.navShowRigBox').hide();
			 $('.navFirUL li').attr('class','');
			 if(!nav.open){
				 $('.navBg_02').attr('class','navBg');
				 $('.navBox').hide();
			 }
		 },50);
	 },
	 openNav:function(value){
		 if(value){
			 $('.navBg').attr('class','navBg_02');
			 $('.navBox').show();
			 this.open = value;
		 }
	 }
}


//商品分类
	
var pro = {
	close:false,
	leftOver:true,
	rigOver:true,
	start:function(){
	    pro.LiEvt();
		pro.RigEvt();
	},
	LiEvt:function(){
		$('.navPro li').hover(
		     function(){
				 pro.leftOver = false;
				 $('.proRig').hide();
				 $('.navPro li').removeClass('navHovLI'); 
				 var index = $(this).index();
				 $(this).attr('class','navHovLI'); 
				 var offset = $(this).offset();
				 var Boxtop = offset.top  - 10;
				 var Boxleft = offset.left + 150;
				 if($('.whiteBorder02').length == 0){
				    $('<div class="whiteBorder02"> </div>').insertBefore($('.top'));
				 }
				 $('.whiteBorder02').show().css({left:Boxleft-5,top:Boxtop+12});
				 $('.proRig').eq(index).css({'left':Boxleft,'top':Boxtop}).show();
			 },
			 function(){
				 pro.leftOver = true;
				 pro.closeNav();
			 }
		)
	},
	RigEvt:function(){
	    $('.proRig').hover(
		     function(){
			     pro.rigOver = false;
			 },
			 function(){
				 pro.rigOver = true;
				 pro.closeNav();
			 }
		)
	},
	init:function(){
	   $('.navPro li').removeClass('navHovLI'); 
	   $('.proRig').hide();
	   $('.whiteBorder02').hide();
	},
	closeNav:function(){
		setTimeout(function(){
			 if(pro.leftOver && pro.rigOver){
				 pro.init();	 
			 }
		},100)
	}
}



var hFocAD = {
	dTime:'',
	goTimer:'',
	btnTimer:'',
    start:function(){
		hFocAD.dTime = 4000;
		hFocAD.init();
	},
	init:function(){
		$('.hFocTit span:last').css({'width':'138px','border-right':'none'});
		$('.hFocTit span').each(function(i){
		    $(this).attr('tag',i);								 
		})
	    setTimeout('hFocAD.playAd()',hFocAD.dTime);
		hFocAD.btnEvt();
	},
	playAd:function(){
		var curTag = parseInt($('.hFocTit span[class="hov"]').attr('tag'));
		var tarTag = '';
		if(curTag == 3){
		    tarTag = 0;	
	    }else{
		    tarTag = curTag + 1;	
		}
		$('.hFocTit span').removeClass('hov').eq(tarTag).addClass('hov');
	    $('.hFocBox ul').animate({'left':-tarTag*558},400,function(){
		    hFocAD.goTimer = setTimeout('hFocAD.playAd()',hFocAD.dTime);
		});
	},
	btnEvt:function(){
	    $('.hFocTit span').mouseover(function(){							   
		    if($('.hFocBox ul').is(':animated')){
			    $('.hFocBox ul').stop();
			}
			if($(this).attr('class') == 'hov') return;
			clearTimeout(hFocAD.goTimer);
			clearTimeout(hFocAD.btnTimer);
		    var tarTag = parseInt($(this).attr('tag'));
			$('.hFocTit span').removeClass('hov').eq(tarTag).addClass('hov');									  
			$('.hFocBox ul').animate({'left':-tarTag*558},400,function(){
			    hFocAD.btnTimer =	setTimeout('hFocAD.playAd()',hFocAD.dTime);													   											   
			})
		})	
	}
}

/*首页广告*/
var homeImgAD = {
	 timeOut:'',
     start:function(){
	    var num = $('.homeAdImgUL li').length;
		var ItemHTML = '';
		$('.homeImgAd h3').text($('.homeAdImgUL img').eq(0).attr('title'));
		$('.homeAdImgUL').css('width',num*558 + 'px');
		for(i=1; i<=num; i++){
		    ItemHTML += '<li>' + i + '</li>';
		}
		$('.homeAdItemUL').html(ItemHTML);
		$('.homeAdItemUL>li:first').addClass('homeAdItem_Hov');
		$('.homeAdItemUL li').mouseover(function(){
		    var hovIndex = $('.homeAdItemUL li[class="homeAdItem_Hov"]').index();
			var handIndex = $(this).index();
			if(hovIndex != handIndex){
				clearTimeout(homeImgAD.timeOut);
			    homeImgAD.nextImg(handIndex);
			}
		})
		homeImgAD.timeOut = setTimeout('homeImgAD.nextImg("undefined")',2000);
	 },
	 nextImg:function(goNum){
	    var index = $('.homeAdItemUL li[class="homeAdItem_Hov"]').index();
		var num = $('.homeAdImgUL li').length;
		$('.homeAdItemUL li[class="homeAdItem_Hov"]').removeClass('homeAdItem_Hov');
		if(index == num-1){
			index = -1;
		}
		if(goNum == undefined||goNum == 'undefined'){
		    goNum = index + 1;
	    }
		$('.homeAdItemUL li').eq(goNum).addClass('homeAdItem_Hov');
		$('.homeImgAd h3').stop().stop();
		$('.homeAdImgUL').stop();
	    $('.homeAdImgUL').animate({left:(-1)*goNum*558 + 'px'});
		$('.homeImgAd h3').animate({height:0},100).animate({height:'30px'},400);
		$('.homeImgAd h3').text($('.homeAdImgUL img').eq(goNum).attr('title'));
		homeImgAD.timeOut = setTimeout('homeImgAD.nextImg("undefined")',2000);
	 }
}


/*  首页移动广告*/
var adMov = {
	len:0,
	num:3,
    start:function(newNum){
		if(newNum){
		    adMov.num = newNum;
		}
		adMov.len = $('.inner a').length;
		adMov.btnEvt();
	},
	btnEvt:function(){
	    $('.homeCenLeftBtn').click(function(){
		     if(adMov.len < 4) return;
			 if( $('.inner').is(':animated') ) return;
			 $('.inner a:lt(' + adMov.num + ')').clone().insertAfter( $('.inner a:last') );
			 $('.inner').animate({ 'left': -adMov.num*120 },500,function(){
			     $('.inner a:lt(' + adMov.num + ')').remove();
				 $('.inner').css({'left':0})
			 })
		})
		$('.homeCenRigBtn').click(function(){
		     if(adMov.len < 4) return;
			 if( $('.inner').is(':animated') ) return;
			 $('.inner a:gt(' + (adMov.len - adMov.num - 1) + ')').clone().insertBefore( $('.inner a:first') );
			 $('.inner').css({ 'left':-adMov.num*120 });
			 $('.inner').animate({ 'left': 0 },500,function(){
			     $('.inner a:gt(' + (adMov.len -1) + ')').remove();
				 $('.inner').css({'left':0});
			 })


		})
	}
}

/* 商品数量添加减少 */
var proNum = {
    start:function(){
	    $('.reduceS').click(function(){
			var Reg = /^[0-9]*[1-9][0-9]*$/;    //正整数
		    var txtVal = $(this).next().val();
			if(txtVal != '' && Reg.test(txtVal)&& parseInt(txtVal)>0){
				$(this).next().val(--txtVal);
			}
		});
		$('.addS').click(function(){
		   	var Reg = /^[0-9]*[1-9][0-9]*$/;
		    var txtVal = $(this).prev().val();
			if(txtVal != ''&& (Reg.test(txtVal)|| parseInt(txtVal)==0)){
				$(this).prev().val(++txtVal);
			}
		})
	}
}


// JavaScript Document
var selTxt = {                //下拉框
      start:function(){
		   var objAry = $('.selectCom');
		   var num = objAry.length;
		   if(num>0){
			   for(var i=0; i<num; i++){
				   this.init(objAry[i]);
			   }
		   }
	  },
      init:function(objDiv){
		  var Input = objDiv.getElementsByTagName('input')[0];
		  var Input02 = objDiv.getElementsByTagName('input')[1];
		  var Span = objDiv.getElementsByTagName('span')[0];
		  var UL = objDiv.getElementsByTagName('ul')[0];
		  var num = UL.getElementsByTagName('li').length;
		  var DivL = objDiv.style.width.substring(0,objDiv.style.width.length-2);
		  var InputNum = parseInt(DivL) - 30;
		  var ULNum = parseInt(DivL) - 2;
		  Input.style.width = InputNum + 'px';
		  UL.style.width = ULNum + 'px';
		  objDiv.onclick = function(){
			    var ULdis = this.getElementsByTagName('ul')[0].style.display;
				$('.selectCom').each(function(){
					   if($(this)[0].getElementsByTagName('ul')[0].style.display == "block"){
							 $(this)[0].getElementsByTagName('ul')[0].style.display = "none";
					   }
				})
			    if(ULdis == 'block') return;                                                     //如果本身是打开的，则关闭
				UL.style.display = 'block';
				  if(num>10){
					 UL.style.height = 260 + 'px';
					 UL.style.overflowY = 'scroll';
				  }else{
					 UL.style.height = num*26+'px';
				  }
				  for(var i=0; i<num; i++){
					   selTxt.overLI(UL,i);
					   selTxt.outLI(UL,i);
					   selTxt.clickLI(objDiv,Input,Input02,Span,UL,i);
				  }
				if(navigator.userAgent.indexOf('MSIE') > 0 ){           <!-- 防止事件冒泡 -->
					 window.event.cancelBubble = true
					}else{
					 event.stopPropagation();
				}
				document.onclick = function(){
					if( UL.style.display == 'block' ){
						UL.style.display = 'none';
					}
				}
		  }
		  objDiv.onmouseover = function(){
			 Input.className = 'selTxtHov';
		     Span.className = 'selectBtnHover';
		  }
		  objDiv.onmouseout = function(){
			 if(UL.style.display != 'block'){
				 Input.className = '';
				 Span.className = 'selectBtn';
			 }
		  }
	  },
	  hoverClass:function(objDiv){
		   var Input = objDiv.getElementsByTagName('input')[0];
		   var Input02 = objDiv.getElementsByTagName('input')[1];
		   var Span = objDiv.getElementsByTagName('span')[0];
		   var UL = objDiv.getElementsByTagName('ul')[0];
		   var num = UL.getElementsByTagName('li').length;
	       Input.className = 'textHover';
		   Span.className = 'selectBtnHover';
		   if(UL){
		      UL.style.display = 'block';
			  if(num>10){
			     UL.style.height = 260 + 'px';
				 UL.style.overflowY = 'scroll';
			  }else{
				 UL.style.height = num*26+'px';
			  }
			  for(var i=0; i<num; i++){
				   selTxt.overLI(UL,i);
				   selTxt.outLI(UL,i);
				   selTxt.clickLI(objDiv,Input,Input02,Span,UL,i);
			  }
		   }
	  },
	  outClass:function(objDiv){
		 var Input = objDiv.getElementsByTagName('input')[0];
		 var Span = objDiv.getElementsByTagName('span')[0];
		 var UL = objDiv.getElementsByTagName('ul')[0];

		 if( UL.style.display == 'block'){
			Input.className = 'textCom';
		    Span.className = 'selectBtn';
			UL.style.display = 'none';
		 }
	  },
	  overLI:function(UL,i){
	       UL.getElementsByTagName('li')[i].onmouseover  = function(){
		       this.style.background =  '#fffccc';
		   }
	  },
	  outLI:function(UL,i){
	       UL.getElementsByTagName('li')[i].onmouseout  = function(){
		       this.style.background =  '#ffffff';
		   }
	  },
	  clickLI:function(objDiv,Input,Input02,Span,UL,i){
	      UL.getElementsByTagName('li')[i].onclick = function(event){
		      Input.value = this.innerText||this.textContent||'';
			  Input02.value = this.id;
			  selTxt.outClass(objDiv);
			  if(navigator.userAgent.indexOf('MSIE') > 0 ){            <!-- 防止事件冒泡 -->
				 window.event.cancelBubble = true
				}else{
				 event.stopPropagation();
			  }
		  }
	  }
}

var downBtn={
	start:function(){
		$('.S_arr').parent().parent().mouseover(function(event){
		   if(navigator.userAgent.indexOf('MSIE') > 0 ) window.event.cancelBubble = true
		   $('.out_d').hide();
		   if($(this).next().attr('class') == 'out_d'){
			  var width = $(this).width();
			  var left = $(this).offset().left;
			  var top = $(this).offset().top;
			  if($(this).hasClass('aBtn')){
				 $(this).next().show().css({'left':left,'top':top + 23,'width':width+3}); 
			  }else{
				 $(this).next().show().css({'left':left,'top':top + 19,'width':width+3}); 
			  }
			  
			  var arror = $(this).find('.S_arr');
		      downBtn.brArror(arror);
		   }
		})
		.mouseout(function(event){
			if(navigator.userAgent.indexOf('MSIE') > 0 ) window.event.cancelBubble = true
			$(this).next().hide();
			$(this).find('.S_arr').removeAttr('style');
		})
		
		$('.out_d').mouseover(function(event){
		   $(this).show();
		   var arror = $(this).prev().find('.S_arr');
		   downBtn.brArror(arror);
		   if(navigator.userAgent.indexOf('MSIE') > 0 ) window.event.cancelBubble = true
		}).mouseout(function(event){
		   $(this).hide();
		   $(this).prev().find('.S_arr').removeAttr('style');
		   if(navigator.userAgent.indexOf('MSIE') > 0 ) window.event.cancelBubble = true
		})
	},
	brArror:function(arrEle){
		arrEle.css({'background-position':'-12px -3px'});  
	}
}

<!-- 表格颜色控制  -->
var tabColor = {    
   mainTab:function(){
	   var tabObj =  $('.tabCom');
	   if(!tabObj.length>0) return ;                    //表格是否存在
	   $('.tabCom thead tr :input[type="checkbox"]').click(function(){
			var nextTbody = $(this).parent().parent().parent().next();	
			var tabListBox = $(this).parent().parent().parent().parent().parent();
		    if($(this).attr('checked') == true){ 
				nextTbody.find('input[type="checkbox"]').attr('checked',true);
				nextTbody.find('tr').css('background','#ffffcc');
				if(tabListBox.find('table').length == tabListBox.find('thead input:checked').length){
				     tabListBox.prev().find('input[type="checkbox"]').attr('checked',true);	
				}
			}else{
				nextTbody.find('input[type="checkbox"]').attr('checked',false);
				nextTbody.find('tr').css('background','#fff');
				tabListBox.prev().find('input[type="checkbox"]').attr('checked',false);	
			}															
	  })
	  var Tbody = $('.tabCom').find('tbody');
	  Tbody.find('tr input:[type="checkbox"]').click(function(){
		   var thisTr = $(this).parent().parent();	
		   var tabListBox = thisTr.parent().parent().parent();
		   var outTabInput = tabListBox.prev().find('input[type="checkbox"]');
		   if($(this).attr('checked') == true){
			  thisTr.css('background','#ffffcc');
		   }else{
			  thisTr.css('background','#fff');
		   }
		   var total = thisTr.parent().find('tr').length;
		   var num = thisTr.parent().find('tr input[type="checkbox"]:checked').length;
		   var topCheckBox = thisTr.parent().prev().find('tr input[type="checkbox"]');
		   if(num == total){
			   topCheckBox.attr('checked',true);
			   var topCheckedNum = tabListBox.find('thead input:checked').length;
			   if(tabListBox.find('table').length == topCheckedNum){
				  outTabInput.attr('checked',true);    
			   }
		   }else if(num < total){
			   topCheckBox.attr('checked',false);
			   outTabInput.attr('checked',false);
		   }
	  })
	  $('.weSiteTit').find('input[type="checkbox"]').click(function(){
		  if($(this).attr('checked') == true){
			 $(this).parent().next().find('table input:[type="checkbox"]').attr('checked',true);
			 $(this).parent().next().find('tbody tr').css('background','#ffffcc');
		  }else{
			 $(this).parent().next().find('table input:[type="checkbox"]').attr('checked',false);
			 $(this).parent().next().find('tbody tr').css('background','#fff');
		  }
      })
	  
	  $('.tabCom tbody tr').mouseover(function(){
		   if($(this).find(':checkbox')[0]&&$(this).find(':checkbox').attr('checked') == false||!$(this).find(':checkbox')[0]){
			   $(this).css('background','#f8fdfe');
		   }									   
	  })
	  $('.tabCom tbody tr').mouseout(function(){
		   if($(this).find(':checkbox')[0]&&$(this).find(':checkbox').attr('checked') == false||!$(this).find(':checkbox')[0]){
			   $(this).css('background','#fff');
		   }									   
	  })
   }
}

<!---  统一页面统一提示框控制 --->
var tip = {
	delayT:10000,
    show:function(str,flag){
	    if(flag == false){
			$('.pageIn').css('background','#fdf9f2');
			$('.pageIn p').css('color','red').html(str);
		}else{
			$('.pageIn').css('background','#f2fce6');
			$('.pageIn p').css('color','#244600').html(str);
		}
		$('.pageTip').slideDown(300);
		$('.pageClose').unbind();
		$('.pageClose').click(function(){
		    $('.pageTip').slideUp(300);							   
		})
		var closeTip = setTimeout(function(){
		    if($('.pageTip:visible').length>0){
				$('.pageTip').slideUp(300);
			}						   
		},tip.delayT);
	}	
}
car = {
	state:false,
	timer:null,
	start:function(){
		this.evt();
	},
	evt:function(){
		$('.goPay').hover(
			function(){
				var offset = $(this).offset();
		        $('.goPayDown').css({left:offset.left, top:offset.top+26}).slideDown();		
				car.state = false;
			},
			function(){
				car.state = true;
				car.closeBox();
			}					   
		)
		$('.goPayDown').hover(
		    function(){
				car.state = false;
			},
			function(){
				car.state = true;
				car.closeBox();
			}
		)
	},
	closeBox:function(){
		clearTimeout(this.timer);
		this.timer = setTimeout(function(){
			if(car.state){
				$('.goPayDown').slideUp();
			}				
		},200)
	}
}

window.onload = function(){
   selTxt.start();                          /*下拉框*/
}


