$(function() {
	$('.search input').bind('focus',function(){
		$(this).parent().addClass("hover");	
	});
	$('.search input').bind('blur',function(){
		$(this).parent().removeClass("hover");
	});
	$('.input').bind('focus',function(){
		$(this).addClass("hover");
	});
	$('.input').bind('blur',function(){
		$(this).removeClass("hover");
	});
	
	$(".right-slide-link").click(function(){
		$("body").addClass("right-slide-on");						  
	})
	$(".right-slide .close-btn").click(function(){
		$("body").removeClass("right-slide-on");						  
	})
	
	
	//新闻选项卡
	$(document).ready(function () {
		function tab(i) {
			$(i).children().mouseover(function () { //触发方式//click//mouseover
				$(this).siblings().removeClass();
				$(this).addClass('current');
				$(this).parent().siblings('.tab-box').hide();
				$(this).parent().siblings('.tab-box').eq($(this).index()).show();
				$('.tab-line').animate({ left: $(this).position().left,width:$(this).width()}); 
			})
		}
		//tab调用 
		$(function () {
			tab('.tab-nav');
		})
		
	});
	
	
	$('.form input').bind('focus',function(){
		if($(this).val()==""){
			$(this).next("label").hide();	
		}
	});
	$('.form input').bind('blur',function(){
		if(!$(this).val()){
			$(this).next("label").show();	
		}
	});
	
	$(window).scroll(function () {
		w_height = $(window).height();
		if (jQuery(window).scrollTop() < w_height-60 ) {
			jQuery('.page-banner .image').css('margin-top', $(window).scrollTop() / 2);
		}
	});
	
	jQuery('.page-banner').addClass("hover");
	
	
	
	var timeout = -1;
	var nav   = $(".nav ul"),
		loc   = location.href,
		links = nav.find("a"),
		link  = null,
		tag   = 0,
		width = 0,
		left  = 0,
		indicator = $("<li class='indicator'></li>");

	if (tag === 0) {
		//init(links.eq(0));
	}

	function init(link) {
		width = link.innerWidth();
		left  = link.offset().left - ($(window).width()-$(".wrapper").width())/2 -$(".wrapper").width()+$('.nav').width()+parseInt($('.nav').css('marginRight'));	
		nav.append(indicator.css("left", left)
			.css({"width":width, "left":left}, 500, function() {
				//links.hover(hoverOn, hoverOut);
		}));
	}
	
	function hoverOn() {
		link = $(".nav .hover a");
		control(link.innerWidth(), link.offset().left - ($(window).width()-$(".wrapper").width())/2 - $(".wrapper").width()+$('.nav').width()+parseInt($('.nav').css('marginRight')));
	}
	
	function hoverOut() {
		control(width, left);
	}
	function control(width, left) {
		indicator.stop().css({"width":width, "left":left}, 300);
	}
	
	if($("#nav").length>0){
		if($("#nav .current a").length>0){
			init($(".nav .current a"));
		}else{
			init(links.eq(0));
		}
	}
	
	$(window).resize(function() {	
		if($("#nav").length>0){
			if($("#nav .current a").length>0){
				init($(".nav .current a"));
			}else{
				init(links.eq(0));
			}
		}
	})
	
	$("#nav li.sub").hover(function(){
		$(this).parent().find('li').removeClass('hover');
		$(this).addClass('hover');
		var i=$("#nav li").index(this)-1;
		if(i>=0){
			$('#sub-nav .sub-nav-item').removeClass("hover");
			$('#sub-nav').addClass('hover');
			//$('#sub-nav .sub-nav-bg').addClass('hover');
			if(i>=0){
				$('#sub-nav div.sub-nav-item:eq('+i+')').addClass("hover");
			};	
		}		
		clearTimeout(timeout);
		hoverOn();
	}, function(){
		$(this).removeClass('hover');
		var i=$("#nav li").index(this)-1;		
		timeout=setTimeout(function(){
			$('#sub-nav div.sub-nav-item:eq('+i+')').removeClass("hover");
			$('#sub-nav').removeClass('hover');
			//$('#sub-nav .sub-nav-bg').removeClass('hover');
		},10);	
		hoverOut();
	})	
	
	$('#sub-nav .sub-nav-item').hover(function(){	
		$('#sub-nav').addClass('hover');
		//$('#sub-nav .sub-nav-bg').addClass('hover');
		var i=$("#sub-nav div.sub-nav-item").index(this)+1;
		$('#nav li').removeClass('hover');
		$('#nav li:eq('+i+')').addClass('hover');
		clearTimeout(timeout);
		hoverOn();
	},function(){
		$('#sub-nav').removeClass('hover');							  
		//$('#sub-nav .sub-nav-bg').removeClass('hover');	
		var i=$("#sub-nav div.sub-nav-item").index(this)+1;
		$('#nav li:eq('+i+')').removeClass('hover');
		timeout=setTimeout(function(){
			$('#sub-nav div.sub-nav-item:eq('+i+')').removeClass("hover");
		},10);	
		hoverOut();			
	})	
	
	
	
	$('#page-top .sub-cate a').hover(function(){
		$(this).parent().find('a').removeClass('hover');	
		$(this).addClass('hover');	
		clearTimeout(timeout);
	},function(){
		if(!$(this).hasClass("current")){
			$(this).removeClass('hover');	
			var timeout=setTimeout(function(){
				$('#page-top .sub-cate a.current').addClass('hover');
			},200);	
		}
	})
	
	$(".member-link").click(function(){
		if(!$("body").hasClass("open")){
			$("body").addClass('open');		
			$(this).addClass('hover');	
		}else{
			$("body").removeClass('open');
			$(this).removeClass('hover');	
		}						   
	})
	
	jQuery(".news-slider").slide({titCell:".hd li",mainCell:".bd ul",effect:"leftLoop",trigger:"click",autoPlay:true,delayTime:700,interTime:6000,easing:"easeInOutExpo"});
	
	$(".index-friendlink .select").each(function(){
		$(this).hoverDelay({
			hoverEvent:function(){
				$(this).find("ul").slideDown(200);	
				$(this).addClass("hover");	
				$(this).find("strong").addClass("hover");	
			},outEvent: function(){
				$(this).find("ul").slideUp(200);	
				$(this).removeClass("hover");	
				$(this).find("strong").removeClass("hover");	
			}
		});
	});

	
	jQuery('.photo-slider ul').bxSlider({
	  slideMargin:20,
	  minSlides: 2,
		maxSlides: 2,
		slideWidth: 210,
	  auto:false,
	  pause:6000
	});
	
	$(".arrow-left").click(function(){
		$(".photo-slider .bx-prev").trigger("click");		  
	})
	$(".arrow-right").click(function(){
		$(".photo-slider .bx-next").trigger("click");		  
	})
	
	
	$("a.tab").click(function () {
		$(this).parent().find("a.current").removeClass("current");
		$(this).addClass("current");
		for(var i=0;i<$(this).parent().find("a").length;i++){
			$("#"+$(this).parent().find("a:eq("+i+")").attr("rel")).hide();
		}
		$("#"+$(this).attr("rel")).show();
		return false;
	});
	$("a.tabs").hover(function () {
		$(this).parent().parent().find("a.current").removeClass("current");
		$(this).addClass("current");
		for(var i=0;i<$(this).parent().parent().find("a").length;i++){
			$("#"+$(this).parent().parent().find("a:eq("+i+")").attr("rel")).hide();
		}
		$("#"+$(this).attr("rel")).show();
		return false;
	});
	var win = $(window);
	(function() {
        var banner = $('#banner'),
            pic_c  = banner.find('.pics'),
            pics   = pic_c.children(),
            idx_c  = banner.find('.idxs'),
            idxs   = idx_c.children(),
            btns   = banner.find('.btns a'),
            prev   = btns.filter('.prev'),
            next   = btns.filter('.next'),

            len    = pics.length,
            idx    = 0,
            prev_i = -1,
            max_i  = len - 1,
            curr_p = pics.eq(idx),
            curr_i = idxs.eq(idx),
            delay  = 5000,
            timeout = -1;

        win.on('load', function() {
            idx_recu(0, 1500/len, function() {
                setTimeout(function() {
                    curr_i.addClass('on');
                    auto();
                }, 300);
                idxs.click(hover);
            });
            banner.hover(function() {
                // prev.stop().fadeIn(300);
                // next.stop().fadeIn(300);
                btns.addClass('on');
            }, function() {
                btns.removeClass('on');
                // prev.stop().fadeOut(300);
                // next.stop().fadeOut(300);
            });
            prev.on('click', function() {fade(idx===0? idx=max_i:--idx)});
            next.on('click', function() {fade(idx===max_i? idx=0:++idx)});
        });

        function fade(idx) {
            clearTimeout(timeout);
            prev_i = idx;
            curr_p.stop(false,true).fadeOut(300);
            curr_p = pics.eq(idx).stop(false,true).fadeIn(300);
            curr_i.removeClass('on');
            curr_i = idxs.eq(idx).addClass('on');
            auto();
        }
        function hover(){
            idx = $(this).index();
            if (idx === prev_i) return;
            fade(idx);
        }
        function idx_recu(idx, delay, func) {
            temp = idxs.eq(idx);
            if (temp.length) {
                temp.css('margin-top',0).fadeIn(500);
                setTimeout(function() {
                    idx_recu(idx+1, delay, func);
                }, delay);
            } else {
                func();
                return;
            }
        }
        function auto() {
            timeout = setTimeout(function() {
                fade(idx===max_i? idx=0: ++idx);
            }, delay);
        }
    }());
	
	$("#follow-btn").css("right",($(window).width()-$(".wrapper").width())/4-30+"px");
	$(".back-top").click(function(){
		$('html,body').animate({scrollTop: '0px'}, 400);
		return false;					   
	})
	$(window).resize(function() {
		$("#follow-btn").css("right",($(window).width()-$(".wrapper").width())/4-30+"px");
	})
});




var tur = true;
function haha(){
	t = $(document).scrollTop();
	if(t > 200){
		$('#follow-btn').css("bottom","120px");
		$('#header').addClass("hover");
		$('#sub-nav').removeClass('hover');
	}else{
		$('#follow-btn').css("bottom","-200px");
		$('#header').removeClass("hover");
	}	
	tur = true;
} 

window.onscroll = function(){ 
	if(tur){
		setTimeout(haha,1); tur = false; 
	}else{
		
	} 
} 


