RegisterNamespaces("API.Slide");

API.Slide = new function()
{
	var objSlide = this;

	this.Init = function(id,uOnChange,uCntValue,uDefault)
	{
		document.ondragstart = new Function( "return false" );
		document.getElementById('img'+id).onmousedown = new Function( "API.Slide.StartMove('"+id+"','"+uOnChange+"',"+uCntValue+");return false" );
		//$('img'+id).onmousedown = new Function( "API.Slide.StartMove('"+id+"','"+uOnChange+"',"+uCntValue+");return false" );
		eval(uOnChange + '("'+id+'",' + uDefault + ')');
	}

	this.StartMove = function( id, uOnChange, uCntValue )
	{
		if(uCntValue>1)
		{
			document.onmousemove = new Function( "e", "API.Slide.Move(e, '"+id+"','"+uOnChange+"',"+uCntValue+");return false" );
			document.onmouseup = new Function( "API.Slide.StopMove('"+id+"');return false" );
		}
	}

	this.StopMove = function( id )
	{
		document.onmousemove = null;
	}

	this.Move = function( e, id, uOnChange, uCntValue )
	{
		try
		{
			e = e||event;
			//var oD=$('d'+id),l=oD.offsetLeft,dx,w,r;
			var oD=document.getElementById('d'+id),l=oD.offsetLeft,dx,w,r;
			while( oD.offsetParent )
			{
				oD = oD.offsetParent
				l += oD.offsetLeft;
			}
			oD=document.getElementById('d'+id);
			//oD=$('d'+id);
			dx = ( oD.offsetWidth-34 ) / uCntValue;

			if( e.clientX >= l+17 && e.clientX <= l+oD.offsetWidth-17 )
			{
				w = e.clientX-17-l;
			}
			else if( e.clientX < l+17 )
			{
				w = l+17;
			}
			else if( e.clientX > l+oD.offsetWidth-17 )
			{
				w = l+oD.offsetWidth-17;
			}
			if( eval(uOnChange + '("'+id+'",' + Math.floor(w/dx) + ')') )
			{
				document.getElementById('img'+id).style.left = w + 'px';
				//$('img'+id).style.left = w + 'px';
			}
		}
		catch(e){}
	}
}
