$(document).ready(function(){
	
	var xiu = {
		
		active_ctrl:function(auto,h,layer,sec){
			var auto = auto; delay = sec*1000;
			var slideup = function(auto,time){ if(auto){ setTimeout(function(){ layer.animate({'height':'0'},time); },time); } }
			slideup(auto,delay);
			h.click(function(){ auto=true; time='fast'; slideup(auto,time); })
		},
		event_last:function(o,cls){ o.addClass(cls); }
		,
		m_click_html:function(o,str){
			var $this = o.find(':text'); $this.attr({value:str});
			$this.click(function(){ $this.attr('value') == str ? $this.attr({value:''}) : str; });
			$this.blur(function(){ $this.attr('value') == '' ? $this.attr({value:str}) : $this.attr({value:$this.attr('value')}); });
		},
		m_OverOut:function(o,h,layer,cls){
			var timeout;
			o.hover(function(){clearTimeout(timeout); layer.show(); h.removeClass(cls);}
			,function(){timeout = setTimeout(function(){layer.hide(); h.addClass(cls);},200);})	
		},
		m_hover:function(o,tag,layer,cls,cls1){
			o.hover(function(){$(this).addClass(cls1); o.children(tag).addClass(cls); layer.show();}
			,function(){o.children(tag).removeClass(cls); layer.hide(); $(this).removeClass(cls1)})
		},
		m_enter:function(o,tags,cls){
			o.each(function(idx){
				$(this).mouseover(function(){
					$(this).addClass(cls).siblings().removeClass(cls); $(this).parent().nextAll(tags).hide();
					$(this).parent().nextAll(tags).eq(idx).show();
				})	
			})
		},
		event_allType:function(o,oo,layer,tag,tag1,cls,on){
			o.hover(function(){
				$(this).addClass(cls); $(this).children(oo).children(tag1).addClass(on); $(this).children(layer).find(tag).show();
			}
			,function(){
				$(this).removeClass(cls); $(this).children(oo).find(tag1).removeClass(on); $(this).children(layer).find(tag).hide();
			})
		},
		index_pro_tab:function(layer,o,tags,$a,cls){
			o.each(function(idx){				
				$(this).mouseover(function(){
					var more_a = layer.children($a);
					more_a.attr('href',$(this).children($a).attr('href'));
					$(this).addClass(cls).siblings().removeClass(cls);
					$(this).parent().parent().nextAll(tags).hide();
					$(this).parent().parent().nextAll(tags).eq(idx).show();
				})	
			})
		},
		son_pro_tab:function(t,layer,cls){
			t.each(function(index){
				$(this).mouseover(function(){
					$(this).addClass(cls).siblings().removeClass(cls); layer.eq(index).show().siblings().hide();
				})	
			})	
		},
		index_top:function(t,cls){
			t.each(function(index){
				$(this).mouseover(function(){
					$(this).addClass(cls).siblings().removeClass(cls);
					$(this).parent().nextAll('ul').hide(); $(this).parent().nextAll('ul').eq(index).show();
					$(this).parent().nextAll('ul').eq(index).find('h5').show();
					$(this).parent().nextAll('ul').eq(index).find('.hover_box').hide();
					$(this).parent().nextAll('ul').eq(index).find('h5:lt(3)').hide();
					$(this).parent().nextAll('ul').eq(index).find('.hover_box:lt(3)').show();
					
					var $this = $(this).parent().nextAll('ul').eq(index).find('h5');
					var $layer = $(this).parent().nextAll('ul').eq(index).find('.hover_box');
					$this.mouseover(function(){
						$this.show();$layer.hide(); $this.eq(0).hide(); $this.eq(1).hide(); $layer.eq(0).show(); $layer.eq(1).show();
						$(this).hide(); $(this).next('.hover_box').show();
					})
				})
			})
		},
		son_top:function(h,layer){
			h.mouseover(function(){
				h.show(); layer.hide(); layer.eq(0).show(); layer.eq(1).show(); h.eq(0).hide(); h.eq(1).hide();
				$(this).hide(); $(this).next("div").show();	
			})	
		},
		 
		tab_auto_control:function(auto,h,layer,cls,time){
			
			var len = h.length, interval, timeout, auto = auto, a=0, delay=time*1000;
			
			layer.eq(0).fadeIn("slow"); h.eq(0).addClass(cls);
			
			//效果控制
			var fade = function(b){ layer.stop(true,true);layer.hide(); layer.eq(b).show(); a=b; }
			var autoFade = function(){
				if(a == (len-1)){ a=0; fade(a); h.removeClass(cls); h.eq(a).addClass(cls); }
				else{ a++; fade(a); h.removeClass(cls); h.eq(a).addClass(cls); }	
			};
			if(auto && len>1){ interval = setInterval(autoFade,delay); }
			h.each(function(index){
				$(this).mouseover(function(){
					$this = $(this); clearInterval(interval);
					timeout = setTimeout(function(){ $this.addClass(cls).siblings().removeClass(cls); fade(index) },250);	
				})
				.mouseout(function(){ if(auto && len>1){ clearTimeout(timeout); interval = setInterval(autoFade,delay); } })
			});
			layer.each(function(index){
				$(this)
				.mouseover(function(){clearInterval(interval);})
				.mouseout(function(){ if(auto && len>1){ interval = setInterval(autoFade,delay); } })
			});
		}
	}
	
	//调用集合方法
	xiu.active_ctrl(false,$('.closex'),$('.activeBox'),3);
	xiu.m_hover($('#mine'),'a',$('#my_xiu'),'hover','relax');
	xiu.m_hover($('#bag'),'a',$('#my_bag'),'hover','relax');
	xiu.m_enter($('.kill_t >span'),'div','curr');
	xiu.m_OverOut($('.son_Gtype'),$('.son_Gtype >h3'),$('.gtype_con'),'hover');
	xiu.event_allType($('.gtype_con li'),$('.gtype_one'),$('.layer_con'),'div','a','hover','on');
	xiu.tab_auto_control(true,$(".handle >span"),$(".img_list li"),"curr",3);
	
	xiu.index_top($('#tab_t >span'),'curr');
	xiu.son_top($(".top_ten h5"),$(".hover_box"));
	xiu.index_pro_tab($('#pro_type1'),$('#pro_type1 >span'),'div','a','curr');
	xiu.index_pro_tab($('#pro_type2'),$('#pro_type2 >span'),'div','a','curr');
	xiu.index_pro_tab($('#pro_type3'),$('#pro_type3 >span'),'div','a','curr');
	xiu.index_pro_tab($('#pro_type4'),$('#pro_type4 >span'),'div','a','curr');
	xiu.index_pro_tab($('#pro_type5'),$('#pro_type5 >span'),'div','a','curr');
	xiu.son_pro_tab($(".link_box >span"),$(".tab_con >ul"),"curr");	
});



	$(document).ready(function(){
	$(".img_list li a span").each(function(){
	var maxwidth=60;
	if($(this).text().length>maxwidth){
	$(this).text($(this).text().substring(0,maxwidth)+"...");
	}
	});
	});

