/*
	slideris.js
*/
/*
var arg = {
	frame: 'title_news',
	content: 'title_news_cont',
	step: 600,
	speed: 300,
	navleft: 'titleSliderBack',
	navright: 'titleSliderNext',
	removeempty: false,
	loop: flase,
	autolength: null
}
*/
function horizontalSlider(args){
	this.frame = args.frame;
	this.content = args.content;
	this.navleft = args.navleft;
	this.navright = args.navright;
	this.step = args.step;
	this.speed = args.speed;
	this.totalwidth = 0;
	this.currentpos = 0;
	this.unlock = true;
	this.removeempty = (args.removeempty);
	this.loop = (args.loop);
	this.autolength = args.autolength;
	this.timmer = null;
	var self = this;
	
	this.init = function(){
		if(document.getElementById(this.content) && document.getElementById(this.frame)){
			if(!this.step || this.step<1){
				this.step = $('#'+this.frame).innerWidth();
			}
			if(!this.speed || this.speed<1){
				this.speed = 300;
			}
			this.totalwidth = $('#'+this.content).innerWidth();
			if(!this.autolength || this.autolength<1000){
				this.autolength = 0;
			}
			if(document.getElementById(this.navleft) && document.getElementById(this.navright)){
				if(this.totalwidth > $('#'+this.frame).innerWidth() && this.totalwidth>this.step){
				$('#'+this.navright).click(function(){
					$(this).blur();
					if(self.unlock){
						self.pauseAutoSlide();
						var np = self.currentpos + (-1*self.step);
						if(Math.abs(np) < self.totalwidth){
							self.unlock = false;
							$('#'+self.content).animate({'left': np}, self.speed, function(){
								self.unlock = true;
								self.currentpos = np;
							});
						}
						else if(self.loop){
							self.toStart();
						}
						if(self.autolength>0 && arguments[1]){
							self.autoSlide();
						}
					}
				});
				$('#'+this.navleft).click(function(){
					$(this).blur();
					if(self.unlock){
						self.pauseAutoSlide();
						var np = self.currentpos + (1*self.step);
						if(np < 1){
							self.unlock = false;
							$('#'+self.content).animate({'left': np}, self.speed, function(){
								self.unlock = true;
								self.currentpos = np;
							});
						}
						else if(self.loop){
							self.toEnd();
						}
					}
				});
				
				if(this.autolength>0){
					$('#'+this.frame).mouseover(function(){
						self.pauseAutoSlide();
					});
					$('#'+this.frame).mouseout(function(){
						self.autoSlide();
					});
					this.autoSlide();
				}
				}
				else{
					if(this.removeempty){
						document.getElementById(this.navright).style.display = 'none';
						document.getElementById(this.navleft).style.display = 'none';
					}
				}
			}
			
		}
	};
	
	this.toStart = function(){
		self.unlock = false;
		$('#'+self.content).animate({'left': 0}, self.speed, function(){
			self.unlock = true;
			self.currentpos = 0;
		});
	};
	this.toEnd = function(){
		self.unlock = false;
		var np = -1 * Math.floor(self.totalwidth / self.step) * self.step;
		$('#'+self.content).animate({'left': np}, self.speed, function(){
			self.unlock = true;
			self.currentpos = np;
		});
	};
	
	this.autoSlide = function(){
		this.timmer = setTimeout(function(){$('#'+this.navright).trigger('click', true);}, this.autolength);
	};
	
	this.pauseAutoSlide = function(){
		if(this.timmer){
			clearTimeout(this.timmer);
		}
	};
	
	this.init();
}



