id = 0;
movestate = "";
tmMover = "";
scrollspeed = 0;

function getposOffset(what, offsettype){
var totaloffset=(offsettype=="left")? what.offsetLeft: what.offsetTop;
var parentEl=what.offsetParent;
while (parentEl!=null){
totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
parentEl=parentEl.offsetParent;
}
return totaloffset;
}

function mousemove(arg1,e){
	id = arg1;
	
	oContainer = document.getElementById("motioncontainer"+arg1);
	oGallery = document.getElementById("motiongallery"+arg1);
	
	cWidth = parseInt(oContainer.style.width);// + getposOffset(oContainer, "left");
	
	curposc = window.event? event.clientX : e.clientX? e.clientX: "";
	curposy = curposc - getposOffset(oContainer, "left");

	middle = (cWidth/2);
	
	rightbound = parseInt(oContainer.style.width)+3/2;
	leftbound = parseInt(oContainer.style.width)-3/2;  
	
	//alert(curposy + ' ' + middle);
	
	if(curposy < middle){
		scrollspeed = ((curposy-rightbound)/(parseInt(oContainer.style.width)-5)/2) * 5;
		moveleft();
	}else{
		scrollspeed = ((leftbound-curposc)/(parseInt(oContainer.style.width)-5)/2) * 5;
		moveright();
	}
	
}


function moveright(){

gLeft = parseInt(oGallery.style.left);

	if(parseInt(oGallery.offsetWidth-(gLeft*-1)) > parseInt(oContainer.style.width)+2){

		clearTimeout(tmMover);
		oGallery.style.left = parseInt(oGallery.style.left)+ scrollspeed + "px";

		tmMover = setTimeout('moveright()',7);
		
	}else{
		scrollspeed = 0;
	}
}

function moveleft(){

	
	gLeft = parseInt(oGallery.style.left)
	
	if(gLeft <= 0){
			
		clearTimeout(tmMover);
		oGallery.style.left = parseInt(oGallery.style.left)- scrollspeed + "px";
	
		tmMover = setTimeout('moveleft()',5);
	
	}else{
		scrollspeed = 0;
	}

}

function stop(){
	clearTimeout(tmMover);
	id = 0;
}
