var mySlider = function(myObj,myID,myShow,myStep,myDopFunc) {
	
	this.myObj = myObj; //Объект с блоками
	this.myID = myID; //ID объекта в массиве workObjects
	this.myShow = myShow ? true : false; //Автоматическое слайд-шоу
	this.myStep = myStep ? parseInt(myStep) : 50; // время задержки перед следующими блоками
	this.size = 0 ; //кол-во блоков
	this.width  = 0;
	this.globalWidth = 0;
	this.currentID = 0;
	this.currentWidth = new Array();
	this.maxLeft= 0;
	this.foward = true;
	this.timeID = false;
	this.myDopFunc = myDopFunc ? myDopFunc:false;
	
	
	this.construct = function() {
		if (!this.myObj) return;
		this.size = $(".li",this.myObj).size();
		
		if (!this.size || !this.myObj) return;
		//Ширина рабочего блока
		this.width = parseInt($(this.myObj).width());
		
		//Общая ширина слайдера
		myWidth = 0;  currentWidth = new Array();
		$(".li .item",this.myObj).each(function() {
			//alert($(this).width());
			currentWidth[currentWidth.length] = myWidth; myWidth+=parseInt($(this).width());				
		});
		
		
		
		this.globalWidth = myWidth; this.currentWidth = currentWidth; 	$('.ul',this.myObj).width(this.globalWidth);
		this.maxLeft = this.globalWidth -this.width;
		
		
		
		if (this.myShow) this.timeID = setTimeout('workObjects["'+this.myID+'"].nextShow()',this.myStep);
	}
	
	
	this.nextShow = function(myFunc) {
		var nextID = 0;
		var noAnim = false;
		if (this.foward) {
			nextID = this.currentID + 1;
			if (nextID >= this.size) {
				nextID = 0; 
				noAnim = true;
			}
		}
		else {
			nextID = this.currentID - 1;	
			if (nextID < 0) {
				nextID = this.size - 1;
				noAnim = true;
			}	
		}
		(myFunc) ? myFunc(nextID) : false;
		this.calculate(nextID,noAnim);
	}
	
	this.calculate = function(myNewID,noAnimation) {
		if (this.myDopFunc) this.myDopFunc(myNewID);
		//alert(myNewID);
		clearTimeout(this.timeID);
		if (!myNewID) myNewID = 0; 	var nextMargin = this.currentWidth[myNewID] ? this.currentWidth[myNewID] : 0;
		if (nextMargin > this.maxLeft)	nextMargin = this.maxLeft;		
		nextMargin = 0 - nextMargin; this.currentID = myNewID;
		if (!noAnimation) $('.ul',this.myObj).animate({left:nextMargin},{duration:300,queue:false},false,this.moveNext());
		else  $('.ul',this.myObj).css("left",nextMargin);
	}
	
	this.moveNext = function() {
		if (this.myShow) this.timeID = setTimeout('workObjects["'+this.myID+'"].nextShow()',this.myStep);
	}
	
	this.next = function(myFunc) {
		this.foward = true;
		this.nextShow(myFunc);
	}
	
	this.back = function(myFunc) {
		this.foward = false;
		this.nextShow(myFunc);
	}
	
	
	this.showFoward = function() {
		var nextID = this.currentID + 1;
		if (nextID >= this.size) return (false);
		this.calculate(nextID); 
	}
	
	this.showBack = function() {
		var nextID = this.currentID - 1;
		if (nextID < 0) return (false);
		this.calculate(nextID);
	}
	
	this.show = function(myCurrent,myFunc) {
		myCurrent = parseInt(myCurrent);
		if (! this.currentWidth[myCurrent]) myCurrent = 0;
		(myFunc) ? myFunc(myCurrent) : false;
		this.calculate(myCurrent,true);
	}
	
	
	this.construct();
	
}
