var maxspeed=10; //Speed 
var maxwidth=620; // Set Width
var neutral=50; // Set Neutral Area
var startwhere=0; // Right-1, Left-0, Center-2

// Everything else should be good!!


var iedom=document.all||document.getElementById, scrollspeed=0, movestate='', actualwidth='', cross_scroll, ns_scroll, statusdiv, loadedyes=0, lefttime, righttime;

function ietruebody(){
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
}

function positiondiv(){
	var mainobjoffset=getposOffset(crossmain, "left"),
	menuheight=parseInt(crossmain.offsetHeight),
	mainobjoffsetH=getposOffset(crossmain, "top");
}


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 moveleft(){
	if (loadedyes){
		movestate="left";
		if (iedom&&parseInt(cross_scroll.style.left)>(menuwidth-actualwidth)){
			cross_scroll.style.left=parseInt(cross_scroll.style.left)-scrollspeed+"px";
			document.getElementById("right-arrow").style.visibility = "visible";
			document.getElementById("left-arrow").style.visibility = "visible";
			
		}
		else {
			document.getElementById("right-arrow").style.visibility = "hidden";
			document.getElementById("left-arrow").style.visibility = "visible";
		}
	}
	lefttime=setTimeout("moveleft()",10);
}

function moveright(){
	if (loadedyes){
		movestate="right";
		if (iedom&&parseInt(cross_scroll.style.left)<0){
			cross_scroll.style.left=parseInt(cross_scroll.style.left)+scrollspeed+"px";
			document.getElementById("left-arrow").style.visibility = "visible";
			document.getElementById("right-arrow").style.visibility = "visible";
		}
		else {
			document.getElementById("left-arrow").style.visibility = "hidden";
			document.getElementById("right-arrow").style.visibility = "visible";
		}
	}
	righttime=setTimeout("moveright()",10);
}

// The Engine that moves the images nicely!!!
// Borrowed from Dynamic Drive

function motionengine(e){
	var mainobjoffset=getposOffset(crossmain, "left"),
		dsocx=(window.pageXOffset)? pageXOffset: ietruebody().scrollLeft,
		dsocy=(window.pageYOffset)? pageYOffset : ietruebody().scrollTop,
		curposy=window.event? event.clientX : e.clientX? e.clientX: "";
		curposy-=mainobjoffset-dsocx;		
	var leftbound=(menuwidth-neutral)/2;
	var rightbound=(menuwidth+neutral)/2;
	if (curposy>rightbound){
		scrollspeed=(curposy-rightbound)/((menuwidth-neutral)/2) * maxspeed;
		clearTimeout(righttime);
		if (movestate!="left") moveleft();
	}
	else if (curposy<leftbound){
		scrollspeed=(leftbound-curposy)/((menuwidth-neutral)/2) * maxspeed;
		clearTimeout(lefttime);
		if (movestate!="right") {
			moveright();
		}
	}
	else {
		scrollspeed=0;
	}
}


function contains_ns6(a, b) {
	if (b!==null)
	while (b.parentNode)
	if ((b = b.parentNode) == a)
	return true;
	return false;
}

function stopmotion(e){
	if (!window.opera||(window.opera&&e.relatedTarget!==null))
	if ((window.event&&!crossmain.contains(event.toElement)) || (e && e.currentTarget && e.currentTarget!= e.relatedTarget && !contains_ns6(e.currentTarget, e.relatedTarget))){
		clearTimeout(lefttime);
		clearTimeout(righttime);
		movestate="";
	}
}

function fillup(){
	if (iedom){
		crossmain=document.getElementById? document.getElementById("gallery") : document.all.gallery;
		if(typeof crossmain.style.maxWidth!=='undefined')
			crossmain.style.maxWidth=maxwidth+'px';
		menuwidth=crossmain.offsetWidth;
		cross_scroll=document.getElementById? document.getElementById("gallery-inner") : document.all.gallery-inner;
		actualwidth=document.getElementById? document.getElementById("gallery-images").offsetWidth : document.all['gallery-images'].offsetWidth;
		if (startwhere)
			cross_scroll.style.left=(menuwidth-actualwidth)/startwhere+'px';
		
		crossmain.onmousemove=function(e){
			motionengine(e);
		}

		crossmain.onmouseout=function(e){
			stopmotion(e);
		}
	}
		loadedyes=1
	if (document.body.filters)
		onresize();
	}

	onresize=function(){
		if (typeof gallery!=='undefined'&&gallery.filters){
			gallery.style.width="0";
			gallery.style.width="";
			gallery.style.width=Math.min(gallery.offsetWidth, maxwidth)+'px';
		}
			menuwidth=crossmain.offsetWidth;
			cross_scroll.style.left=startwhere? (menuwidth-actualwidth)/startwhere+'px' : 0;
}
