var t = count = n = 0;
$(function(){
	$(".big_img a:not(:first)").hide();
	$(".link_nav a:not(:first)").hide();
	$num_nav = $(".num_nav span");
	$big_img = $(".big_img a");
	count = $big_img.length;
	t = setInterval("showAuto()", 3000);  
	
	$num_nav.click(function(){
		var num_nav = $(".num_nav span").index(this);
		$(this).addClass("selected").siblings().removeClass("selected");
		$big_img.filter(":visible").fadeOut(500).parent().children().eq(num_nav).fadeIn(1000); 
		$(".link_nav a").filter(":visible").fadeOut(500).parent().children().eq(num_nav).fadeIn(1000); 
	});
	$(".img_nav").hover(function(){clearInterval(t)}, function(){t = setInterval("showAuto()", 3000);}); 
})

function showAuto()   
{   
	n = n >= 2 ? 0 : (n + 1);   
	$num_nav.eq(n).trigger('click');   
}


$.fn.SerachEffect=function(c){
	function rgbTOhsl(rgb){
		if(rgb.match(/#/)) return rgb;
		var s='#',colorArr=rgb.match(/\d+/g);
			s+=(parseInt(colorArr[0],10)).toString(16);
			s+=(parseInt(colorArr[1],10)).toString(16);
			s+=(parseInt(colorArr[2],10)).toString(16);
		return s;
	}
	var $this=$(this),
		sColor=rgbTOhsl($this.css('color')),
		sText=$(this).val(),
		cc=c||'#000';
		$this.focus(function(){		
			if(sColor==rgbTOhsl($this.css('color'))&&sText==$this.val()){
				$this.css('color',cc).val('');
			}
		}).blur(function(){
			if($this.val().match(/^\s*$/)){
				$this.css('color',sColor).val(sText);
			}
		});
}
$.fn.accordion=function(o){
	var o=o||{},t=o.time||300,c=o.cla||'',sh=o.sh||0,coll=o.collapsible||false;
 
 	var $ts=$(this).children().children(':first-child').click(function(event){
	
		var $t=$(this);	 
		if(coll){
			$ts.next().eq(sh).slideUp(t);
		}
		if($t.next().is(':hidden')){		 
			$ts.next().eq(sh).slideUp(t);
			$t.next().slideDown(t);
			$ts.parent().eq(sh).removeClass(c);
			$t.parent().addClass(c);
		}
		
		sh=$ts.next().index($t.next());
		 
	});
	 
	$ts.next().hide();
	if(sh>=0) $ts.next().eq(sh).show().parent().addClass(c);	 
 }
$.fn.Slide=function(o){

	var o=o||{},sn=o.show||2,t=o.time||300,r=o.rounds||false,a=o.auto||false;
		$this=$(this),
		$pointL=$this.children('a').eq(0),
		$pointR=$this.children('a').eq(1),
		$slideWraper=$this.children('div.slideWraper'),
		$slideWrap=$slideWraper.children('ul.slideWrap');
		slideListWidth=parseInt($slideWrap.children().outerWidth(true),10);

	var	listLen=$slideWrap.children().length;
      if(o.two){
            listLen=Math.ceil(listLen/2);
            $slideWrap.width(listLen*slideListWidth);
        }
	var	hideNum=listLen-sn,
		hideNumL=0,hideNumR=hideNum;



		if(r){
			$slideWrap.clone().css('left',listLen*slideListWidth).appendTo($slideWraper);
			$slideWrap.clone().css('left',-listLen*slideListWidth).prependTo($slideWraper);
			hideNum+=2*listLen;
			hideNumL=listLen;
			hideNumR+=listLen;
		}

		$pointL.click(function(){
			 	if(!r&&hideNumR>=hideNum) return;
				if(!$slideWraper.children().is(':animated')){
				hideNumL--;hideNumR++;
				if(r&&hideNumL<=0){
					$slideWraper.children().eq(2).css('left',-(listLen+1)*slideListWidth).prependTo($slideWraper);
					hideNumR=listLen+listLen-sn;
					hideNumL=listLen;
				}

				$slideWraper.children().animate({'left':'+='+slideListWidth},t);
				}

		});
		$pointR.click(function(){


			if(!r&&hideNumL>=hideNum) return;
			if(!$slideWraper.children().is(':animated')){
			hideNumL++;hideNumR--;
			if(r&&hideNumR<=0){

				$slideWraper.children().eq(0).css('left',(sn+1)*slideListWidth).appendTo($slideWraper);
				hideNumL=listLen+listLen-sn;
				hideNumR=listLen;
			}

			$slideWraper.children().animate({'left':'-='+slideListWidth},t);
			}
		});
		if(a){
		$this.mouseover(function(){
				clearInterval(Timer);
			}).mouseout(function(){
				set();
			});
		var Timer;
		(set=function(){
			Timer=setInterval(function(){$pointL.click();},t*3);
		})();
		}
}
 
$(function(){
var $ta=$('a.ta').click(function(){
	var $this=$(this);
	var t=[1974,2001,2003,2007,2009];
	var i=$ta.index($this);
	$this.parents('.main_t').children().removeClass().addClass("t"+t[i]);
	var id="x"+(i+1);
	$this.prevAll('div').children().attr('id',id);
	 swfobject.embedSWF("/swf/"+id+".swf", id, '250', '347', "9.0.0", "expressInstall.swf", {}, { wmode: 'transparent' });
	  
	return false;
}); 


});

function logs(){
		var s='';	 
		for(var i=0,aLen=arguments.length;i<aLen;i++){
			s+=arguments[i]+' ';
		}
		s=s.slice(0,-1);
		if(!window.console) alert(s);
		else
		console.log(s);
}
window.onload=function(f){
setTimeout(function(){
	if($(window).width()-1150>0){
		w=($(window).width()-1150)/2;
		$('div.header').width(1150);
		$('<div/>').addClass('headhelp').css({ "width":w}).prependTo('body');
		$('<div/>').addClass('headhelp headhelpr').css({ "width":w,left:w+1149}).prependTo('body');
	}
	$('input.btn').hover(function(){
		$(this).toggleClass('o');
	
	})
	 
	
} ,300);	
};

(function($) {

    $.fn.Slide = function(options) {
        var opt = $.extend({}, $.fn.Slide.settings, options);
        return this.each(function() {
            var $this = $(this);
            var slide = new Slide(opt);
            slide.init($this);

        });
    }
    var Slide = function(options) {
        this.o = options;
        this.$slide = null;
        this.show = this.o.show;
        this.time = this.o.time;
        this.rounds = this.o.rounds;
        this.auto = this.o.auto;
        this.two=this.o.two;
        this.autoTime = this.o.autoTime;
        this.moveNums = this.moveNum = this.o.moveNum;
        this.easing = this.o.easing;
        this.start = this.o.start;
        this.complete = this.o.complete;
    }
    Slide.prototype = {
        init:function(obj) {
            var _this = this;
            this.$slide = obj;
            this.$slideWraper = this.$slide.find('div.slideWraper'),
                    this.$slideWrap = this.$slide.find('ul.slideWrap');
            var $slideList = this.$slide.find('li.slideList');

            this.slideListWidth = parseInt($slideList.eq(0).outerWidth(true), 10);
            this.listLen = $slideList.length;
            if(this.two){
                this.listLen=Math.ceil(this.listLen/2);
                this.$slideWrap.width(this.listLen*this.slideListWidth);
            }

            this.lNum = 0;
            this.rNum = this.listLen - this.show;
            this.timer = 0;
            //如果循环，就添加2个UL
           if (this.rounds) {
                this.$slideWrap.clone().css({
                    "left":this.listLen * this.slideListWidth
                }).appendTo(this.$slideWraper);
                this.$slideWrap.clone().css({
                    "left": -this.listLen * this.slideListWidth
                }).prependTo(this.$slideWraper);
                this.lNum = this.listLen;
                this.rNum = this.listLen - this.show + this.listLen;
            }

            this.$slide.find('a.pL').bind('click', function(event) {
                var t=_this.start(_this.$slide) || 0;
                setTimeout(function(){
                    _this.moveL();
                },t);
                 setTimeout(function(){
                     _this.complete(_this.$slide);
                 }, _this.time+t);
            });
            this.$pointR=this.$slide.find('a.pR').bind('click', function(event) {
                var t=_this.start(_this.$slide) || 0;
                setTimeout(function(){
                    _this.moveR();
                },t);
                setTimeout(function(){
                     _this.complete(_this.$slide);
                 }, _this.time+t);
            });
            //自动运行
            if(this.auto){
              this.autoPlay();
              this.$slide.bind('mouseenter',function(){
                  clearInterval(_this.timer);
              });
              this.$slide.bind('mouseleave',function(){
                  _this.autoPlay();
              });
            }

        },
        autoPlay:function(){
            var _this=this;
            _this.timer=setInterval(function(){
                _this.$pointR.click();

            },_this.autoTime);

        },
        /**
         * @describe
         * 根据隐藏的数量是否等于零判断
         */
        isLimitL:function() {
            if (this.rounds) {
                if (this.lNum - this.moveNum <= 0) {
                    this.$slideWraper.children().eq(2).css({
                        "left": -(this.listLen + this.lNum) * this.slideListWidth
                    }).prependTo(this.$slideWraper);
                    this.lNum += this.listLen;
                    this.rNum -= this.listLen;
                }
            } else {
                if (this.lNum <= 0)
                    return false;
                if (this.lNum - this.moveNum <= 0)
                    this.moveNums = this.lNum;
                else
                    this.moveNums = this.moveNum;
            }
            this.lNum -= this.moveNums;
            this.rNum += this.moveNums;
            return true;
        },
        isLimitR:function(){
            if(this.rounds){
                 if (this.rNum - this.moveNum <= 0) {
                        this.$slideWraper.children().eq(0).css({
                            "left": (this.show + this.rNum) * this.slideListWidth
                        }).appendTo(this.$slideWraper);
                        this.lNum -= this.listLen;
                        this.rNum += this.listLen;
                    }
            }else{
                if (this.rNum <= 0)
                        return false;
                    if (this.rNum - this.moveNum <= 0)
                        this.moveNums = this.rNum;
                    else
                        this.moveNums = this.moveNum;
            }
            this.lNum += this.moveNums;
            this.rNum -= this.moveNums;
            return true;
        },
        moveL:function() {
             if (!this.$slideWraper.children().is(':animated')&&this.isLimitL() ) {
                this.$slideWraper.children().animate({
                    'left':'+=' + this.slideListWidth * this.moveNums
                }, this.time, this.easing);
            }


        },
        moveR:function() {
             if (!this.$slideWraper.children().is(':animated')&&this.isLimitR() ) {
                this.$slideWraper.children().animate({
                    'left':'-=' + this.slideListWidth * this.moveNums
                }, this.time, this.easing);
             }
        }

    }


    $.fn.Slide.settings = {
        show:2,
        time:300,
        rounds:false,
        auto:false,
        moveNum:1,
        autoTime:1000,
        easing:"swing",
        two:false,
        start:function($slide) {
        },
        complete:function($slide) {
        }
    }
})(jQuery);
