

$(function(){
		
	new imgChange('.pic_play','4000','slide');	
	new ToSlide('.apps #to_left','.apps #to_right','.apps .mask',125);
	var tempO = true;
	$('#rap_nav_btn,#rap_nav').mouseenter(function(e){		
			showMenu('#rap_nav');		
	})	
	
	$('#rap_nav .toclose').click(function(){hideMenu('#rap_nav');});
	
	$(document).bind('click',function(){		
		hideMenu('#rap_nav');	
	})
	
	$('#rap_nav,#rap_nav_btn').bind('click',function(e){
		e.stopPropagation();	
	})
	
/* 	$('#rap_nav_btn,#rap_nav').mouseleave(function(e){
		//console.log(e.relatedTarget)
		if(!$(e.relatedTarget).is('.header')&&!$(e.relatedTarget).is('#new_nav')){
			hideMenu('#rap_nav')	
		}
				
	}) */

/* 	$('.header').mouseleave(function(e){	
		//console.log(e.relatedTarget)
		hideMenu('#rap_nav')	
	}) */
	
/* 	$('#rap_nav_btn').click(function(){	
		if(!$('#rap_nav').is(':visible')){
			showMenu('#rap_nav');	
		}else{
			hideMenu('#rap_nav');	
		}
		return false;
	})	
 */
	//$('.close').click(function(){hideMenu('.rap_nav');});

 })
 


function  imgChange(w,time,method,addClass,json){
	this.method=method;
	this.addClass = addClass;
	this.timeIn;
	this._oW=$(w);
	this.img_size = this._oW.find('img').size();
	this._sev=time;		
	this.aImg =  this._oW.find('img');	
	this.imgHeight = 202; //this.aImg[0].offsetHeight||
	this.iIndex = 0;	
	this.init();
	this.btnControl();	
}

imgChange.prototype={

	init : function(){
		
		this._oW.css({position:'relative',overflow:'hidden'});
		this.crearBtn(this.img_size);	
		if(this.method=='fade'){			
			this.aImg.css({position:'absolute'});		
			this.aImg.eq(0).show().parent('a').siblings('a').find('img').hide();				
		
		}else if(this.method=='slide'){
			this._oW.children('a').wrapAll('<div class="w_window"><div class="scrollBox"></div></div>');	
			$('.w_window').css({height:'100%',overflow:'hidden'}).scrollTop('0');
		
		}else{
		
			alert('暂无此方法')
		}
		this.start(); //开始自动轮播	
	},
	
	extend :function(destination, source) {
		for (var property in source) {
			destination[property] = source[property];
			
		}
	},
	
	getIndex:function(){
		return this.aImg.index(this.aImg.filter(':visible'))	
	},
	
	options :{
		btnColor:'red',
		ne:'#fdffff'
	},	
	
	crearBtn:function(n){		
		var obtns= $("<div class='icBtns'></div>");
		if(!this.addClass){
			for(var i = 0;i<n; i++){
				obtns.append('<a href="javascript:void(0)">'+(i+1)+'</a>');		
			}
		}else{
			for(var i = 0;i<n; i++){
				obtns.append('<a  class='+this.addClass+(i+1)+'>'+(i+1)+'</a>');		
			}			
		}
		this._oW.append(obtns);
		obtns.css({position:'absolute','z-index':'100'});
		$('.icBtns a').eq(0).addClass('curr');
	},
	
	start:function(){
		var o = this;
		if(this.method=='fade'){		
			this.timeIn=setInterval(function(){o.changeFade(o)}, this._sev);		
		}else if(this.method=='slide'){
			this.timeIn=setInterval(function(){o.changeSlide(o)}, this._sev);		
		}
	},
	
	toSliContinued:function(){
		this.slideContinued = true;
	},
	
	changeSlide:function(o){		
		//document.title=$('.w_window').scrollTop()
		if($('.w_window').scrollTop()<(this.imgHeight*(this.img_size-1)) ){
			
			$('.w_window').animate({'scrollTop':'+='+this.imgHeight},'slow');	
				this.iIndex++;
				$('.icBtns a').eq(this.iIndex).addClass('curr').siblings().removeClass('curr');
					
		}else{			
			$('.w_window').animate({'scrollTop':'0'},'slow');		
			$('.icBtns a').eq(0).addClass('curr').siblings().removeClass('curr');
			this.iIndex = 0;
			
		}
	},
	
	changeFade:function(o){		
	
		var n;		
		if(this.getIndex()<this.aImg.size()-1){	
			this.aImg.filter(':visible').fadeOut('slow').parent('a').next().find('img').fadeIn('slow',function(){			
					n=o.getIndex();
					$('.icBtns a').eq(n).addClass('curr').siblings().removeClass('curr');				
				});			
		}else{
			this.aImg.filter(':visible').fadeOut('slow').end().eq(0).fadeIn('slow',function(){
				n=o.getIndex();
				$('.icBtns a').eq(0).addClass('curr').siblings().removeClass('curr');		
			})	
		}	
	},
	
	btnControl:function(){
	
		var o = this;	
		this._oW.hover(
			function(){clearInterval(o.timeIn)},			
			function(){	
				if(o.method =='fade'){
					o.timeIn=setInterval(function(){o.changeFade(o)}, o._sev);	
				}else if(o.method =='slide'){					
					o.timeIn=setInterval(function(){o.changeSlide(o)}, o._sev);	
				}
			}
		)
		$('.icBtns a').click(function(){
			var ind=$('.icBtns a').index(this);
			if(o.method =='fade'){
				o.aImg .filter(':visible').stop(true,true).fadeOut('slow');
				o.aImg.eq(ind).stop(true,true).fadeIn('slow');
			}else if(o.method =='slide'){				
				$('.w_window').stop(true,true).animate({'scrollTop':ind*o.imgHeight},'slow');	
			
			}
			$('.icBtns a').eq(ind).addClass('curr').siblings().removeClass('curr');
			o.iIndex=ind;
			
		})
	}
}

function ToSlide(oL,oR,slideDiv,w){

	this.oS= $(slideDiv);
	this.bL = true;
	this.bR= false;
	this.l = $(oL);
	this.r = $(oR);
	this.w=w;
	_this=this;
	this._init();

}

ToSlide.prototype = {
	_init:function(){
	
		var chilredSize = this.oS.find('li').size();	
		var initedW=chilredSize*this.w;	
		this.oS.children().eq(0).width(initedW);
		
		this.oS.scrollLeft(0);
		this.disable(this.r);
	
		this.l.bind('click',function(){_this.toLeft(_this.w)})
		this.r.bind('click',function(){_this.toRight(_this.w)})
		
	},

	toLeft:function(w){
		_this.oS.stop(true,true).animate({'scrollLeft':'+='+w+'px'},'slow',function(){
			_this.bL=(_this.oS.scrollLeft()<(_this.oS.find('li').size()-7)*_this.w)?true:false;
			_this.bR=(_this.oS.scrollLeft()>0)?true:false;
			_this.changeAble();
		});	
		
	},
	
	toRight:function(w){		
		_this.oS.stop(true,true).animate({'scrollLeft':'-='+w+'px'},'slow',function(){
			_this.bL=(_this.oS.scrollLeft()<(_this.oS.find('li').size()-7)*_this.w)?true:false;
			_this.bR=(_this.oS.scrollLeft()>0)?true:false;
			_this.changeAble();
		});
	},
	
	disable:function(o){
		o.addClass('gray');
		o.css({cursor:'default'})	
	},
	
	enalbe:function(o){
		o.removeClass('gray');
		o.css({cursor:'pointer'})	
	},
	
	changeAble:function(){
		if(this.bL){
			this.enalbe(this.l);			
		}else{
			this.disable(this.l);
		}
		
		if(this.bR){
			this.enalbe(this.r);			
		}else{
			this.disable(this.r);
		}	
	}
	
}
/*快速导航*/
function showMenu(o){
	var obj = $(o)
	var iH = obj.outerHeight()-5;
	obj.show();
	obj.stop(true).animate({bottom:-iH +'px'},'normal');
}

function  hideMenu(o){
	var obj = $(o)
	var iH = obj.outerHeight();	
	obj.stop(true).animate({bottom:'0'},'normal',function(){	
		obj.hide();
	}); 
}






