var Motion = {
	_bool : false,
	_type : '',
	left : null,
	right : null,
	gallery : null,
	width : null,
	minleft: 0,
	
	construct : function(idl, idr, idg, ewidth, count, default_position)
	{
		this.left = document.getElementById(idl);
		this.right = document.getElementById(idr);
		this.gallery = document.getElementById(idg);
		this.width = ewidth * count;
		
		this.minleft = -1 * (this.width - (ewidth * 3));
		
		if ( count > 3 )
		{
			this.left.onmousedown = function()
			{
				Motion._bool = true;
				Motion._type = 'left';
				Motion.move();
			};
			
			this.right.onmousedown = function()
			{
				Motion._bool = true;
				Motion._type = 'right';
				Motion.move();
			};
			
			this.left.onmouseup = function()
			{
				Motion._bool = false;
			};
			
			this.right.onmouseup = function()
			{
				Motion._bool = false;
			};
			
			if ( default_position > 2 )
			{
				//alert(default_position);
				this.gallery.style.left = 
					default_position == count ? this.minleft : -1 * (ewidth * (default_position - 2));
			}
		}
	},
	
	move : function()
	{
		var iLeft = parseInt(this.gallery.style.left);
		document.getElementById('test').innerHTML = this.width + ' | ' + iLeft;
		switch ( this._type )
		{
			case 'left':
				this.gallery.style.left = iLeft <= this.minleft ? this.minleft+'px' : (iLeft - 20) + 'px';
				break;
			
			case 'right':
				this.gallery.style.left = iLeft >= 0 ? '0px' : (iLeft + 20) + 'px';
				break;
				
			default:
				break;
		}
		
		if ( this._bool )
		{
			setTimeout('Motion.move()', 100);
		}
	}
};