var $ = function(elmId)
{
	return document.getElementById(elmId);
}

function jsComSlide()
{
	var obj =
	{
	   nodeWidth : 0,
	   areaWidth : 0,
		childsWidth : 0,
	   childs : {},
	   areaId : '',
	   slideName : '',
	   timeout : null,

		toLeft : function(inc, speed)
		{
		   speed = !speed ? 5 : speed;
		   inc = !inc ? -2 : inc;
		
			this.incPosition('left', inc);
			this.timeout = window.setTimeout(this.slideName+".toLeft("+inc+", "+speed+")", speed);
		},

		toRight : function(inc, speed)
		{
			speed = !speed ? 5 : speed;
			inc = !inc ? 2 : inc;
		
			this.incPosition('left', inc);
			this.timeout = window.setTimeout(this.slideName+".toRight("+inc+", "+speed+")", speed);
		},

		incPosition : function(side, inc)
		{
			var idx;
			
			switch(side)
			{
			   case 'left':
			   {
			      var l = parseInt(this.childs[0].style.left);

					if(l < -this.childsWidth) this.reset('left', l + this.childsWidth);
					
					if(l > 0) this.reset('left', -this.childsWidth + l);
			   }
			}
		
			for(idx = 0; idx < this.childs.length; idx++)
		   {
		      switch(side)
		      {
		         case 'left'		: this.childs[idx].style.left 	= (parseInt(this.childs[idx].style.left) + inc) + 'px'; break;
		         case 'right'	: this.childs[idx].style.right 	= (parseInt(this.childs[idx].style.right) + inc) + 'px'; break;
		         case 'top'		: this.childs[idx].style.top 		= (parseInt(this.childs[idx].style.top) + inc) + 'px'; break;
		         case 'bottom'	: this.childs[idx].style.bottom 	= (parseInt(this.childs[idx].style.bottom) + inc) + 'px'; break;
				}
		   }
		},

		init : function()
		{
			var i;
			var clone;
			
			var itemCount = $(this.areaId).childNodes.length;
			this.maxVisible = Math.floor(this.areaWidth / this.nodeWidth);
			
			this.childs = $(this.areaId).childNodes;

			for(i = 0; i < itemCount; i++)
			{
			   this.childs[i].style.position = 'relative';
			   this.childs[i].style.left = 0;
			   
			   clone = this.childs[i].cloneNode(true);
			   $(this.areaId).appendChild(clone);
			}
			
			this.childsWidth = this.nodeWidth * itemCount;
		},
		
		reset : function(side, correction)
		{
			var idx;
		
		   for(idx = 0; idx < this.childs.length; idx++)
		   {
		      switch(side)
		      {
		         case 'left' : this.childs[idx].style.left = correction + 'px'; break;
		         case 'right' : this.childs[idx].style.right = correction + 'px'; break;
		         case 'top' : this.childs[idx].style.top = correction + 'px'; break;
		         case 'bottom': this.childs[idx].style.bottom = correction + 'px'; break;
		      }
		   }
		},
		
		stop : function()
		{
		   window.clearTimeout(this.timeout);
		}
	};
	
	return obj;
}


