/***********************************************
* CMotion Image Gallery- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* Visit http://www.dynamicDrive.com for source code
* Last updated Mar 15th, 04'. Added "End of Gallery" message.
* This copyright notice must stay intact for legal use
***********************************************/

var restarea=6 //1) width of the "neutral" area in the center of the gallery in px
var maxspeed=4 //2) top scroll speed in pixels. Script auto creates a range from 0 to top speed.
var endofgallerymsg="" //3) message to show at end of gallery. Enter "" to disable message.

function enlargeimage(path, optWidth, optHeight){ //function to enlarge image. Change as desired.
//var actwidth=typeof optWidth!="undefined" ? optWidth : "600px" //set 600px to default width
//var actualHeight=typeof optHeight!="undefined" ? optHeight : "500px" //set 500px to  default height
//var winattributes="width="+actwidth+",height="+actualHeight+",resizable=yes"
//window.open(path,"", winattributes)
}

////NO NEED TO EDIT BELOW THIS LINE////////////

var iedom=document.all||document.getElementById

var scrollspeed = new Array()
for (i=1; i<=10; i++) {		scrollspeed[i] = 0; }
var movestate = new Array()
for (i=1; i<=10; i++) {		movestate[i] = 0; }
var actwidth = new Array()
for (i=1; i<=10; i++) {		actwidth[i] = 0; }
var loadedyes = new Array()
for (i=1; i<=10; i++) {		loadedyes[i] = 0; }
var mainobjoffset = new Array()
for (i=1; i<=10; i++) {		mainobjoffset[i] = 0; }
var menuwidth = new Array()
for (i=1; i<=10; i++) {		menuwidth[i] = 0; }

var cross_scroll, ns_scroll

function ietruebody(){
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

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;
}

// MOVE LEFT
function moveleft(i){
	if (loadedyes[i]) {
		movestate[i] = "left";
		if (iedom && (parseInt(cross_scroll.style.left) > parseInt(menuwidth[i]-actwidth))){
			cross_scroll.style.left=parseInt(cross_scroll.style.left) - scrollspeed[i]+"px"
		}
	}
	lefttime=setTimeout("moveleft(" + i + ")",10)
}

// MOVE RIGHT
function moveright(i){
	if (loadedyes[i]){
		movestate[i]="right"
		if (iedom && parseInt(cross_scroll.style.left)<0){
			cross_scroll.style.left=parseInt(cross_scroll.style.left) + scrollspeed[i]+"px"
		}
	}
	righttime = setTimeout("moveright(" + i + ")",10)
}

function motionengine(e, i){
	getobjects(i)
	var dsocx=(window.pageXOffset)? pageXOffset: ietruebody().scrollLeft;
	var dsocy=(window.pageYOffset)? pageYOffset : ietruebody().scrollTop;
	var curposy=window.event ? event.clientX : e.clientX? e.clientX: ""

	curposy -= mainobjoffset[i] - dsocx

	var leftbound 		= (menuwidth[i] - restarea) / 2
	var rightbound	= (menuwidth[i] + restarea) / 2
	if (curposy > rightbound) {
		scrollspeed[i] = (curposy-rightbound) / ((menuwidth[i]-restarea)/2) * maxspeed
		if (window.righttime) clearTimeout(righttime)
		if (movestate[i] != "left") moveleft(i)
	}
	else if (curposy<leftbound) {
		scrollspeed[i]=(leftbound-curposy)/((menuwidth[i]-restarea)/2) * maxspeed
		if (window.lefttime) clearTimeout(lefttime)
		if (movestate[i] != "right") moveright(i)
	}
	else {
		scrollspeed[i] = 0
	}
}

function contains_ns6(a, b) {
while (b.parentNode)
if ((b = b.parentNode) == a)
return true;
return false;
}

function stopmotion(e, i){
	getobjects(i);
	if ((window.event && ! crossmain.contains(event.toElement)) || (e && e.currentTarget && e.currentTarget!= e.relatedTarget && !contains_ns6(e.currentTarget, e.relatedTarget))){
		if (window.lefttime) clearTimeout(lefttime)
		if (window.righttime) clearTimeout(righttime)
		movestate[i] = ""
	}
}

function getobjects(id) {
	if (id == 1) {
		crossmain 			= document.getElementById? document.getElementById("motioncontainer1") : document.all.motioncontainer1;
		cross_scroll	=	 document.getElementById? document.getElementById("motiongallery1") : document.all.motiongallery1;
		actwidth 			= document.all ? cross_scroll.offsetWidth : document.getElementById("trueContainer1").offsetWidth;
	} else if (id == 2) {
		crossmain 			= document.getElementById? document.getElementById("motioncontainer2") : document.all.motioncontainer2;
		cross_scroll	=	 document.getElementById? document.getElementById("motiongallery2") : document.all.motiongallery2;
		actwidth 			= document.all ? cross_scroll.offsetWidth : document.getElementById("trueContainer2").offsetWidth;
	} else if (id == 3) {
		crossmain 			= document.getElementById? document.getElementById("motioncontainer3") : document.all.motioncontainer3;
		cross_scroll	=	 document.getElementById? document.getElementById("motiongallery3") : document.all.motiongallery3;
		actwidth 			= document.all ? cross_scroll.offsetWidth : document.getElementById("trueContainer3").offsetWidth;
	} else if (id == 4) {
		crossmain 			= document.getElementById? document.getElementById("motioncontainer4") : document.all.motioncontainer4;
		cross_scroll	=	 document.getElementById? document.getElementById("motiongallery4") : document.all.motiongallery4;
		actwidth 			= document.all ? cross_scroll.offsetWidth : document.getElementById("trueContainer4").offsetWidth;
	} else if (id == 5) {
		crossmain 			= document.getElementById? document.getElementById("motioncontainer5") : document.all.motioncontaine5;
		cross_scroll	=	 document.getElementById? document.getElementById("motiongallery5") : document.all.motiongallery5;
		actwidth 			= document.all ? cross_scroll.offsetWidth : document.getElementById("trueContainer5").offsetWidth;
	} else if (id == 6) {
		crossmain 			= document.getElementById? document.getElementById("motioncontainer6") : document.all.motioncontainer6;
		cross_scroll	=	 document.getElementById? document.getElementById("motiongallery6") : document.all.motiongallery6;
		actwidth 			= document.all ? cross_scroll.offsetWidth : document.getElementById("trueContainer6").offsetWidth;
	} else if (id == 7) {
		crossmain 			= document.getElementById? document.getElementById("motioncontainer7") : document.all.motioncontainer7;
		cross_scroll	=	 document.getElementById? document.getElementById("motiongallery7") : document.all.motiongallery7;
		actwidth 			= document.all ? cross_scroll.offsetWidth : document.getElementById("trueContainer7").offsetWidth;
	} else if (id == 8) {
		crossmain 			= document.getElementById? document.getElementById("motioncontainer8") : document.all.motioncontainer8;
		cross_scroll	=	 document.getElementById? document.getElementById("motiongallery8") : document.all.motiongallery8;
		actwidth 			= document.all ? cross_scroll.offsetWidth : document.getElementById("trueContainer8").offsetWidth;
	} else if (id == 9) {
		crossmain 			= document.getElementById? document.getElementById("motioncontainer9") : document.all.motioncontainer9;
		cross_scroll	=	 document.getElementById? document.getElementById("motiongallery9") : document.all.motiongallery9;
		actwidth 			= document.all ? cross_scroll.offsetWidth : document.getElementById("trueContainer9").offsetWidth;
	} else if (id == 10) {
		crossmain			= document.getElementById? document.getElementById("motioncontainer10") : document.all.motioncontainer10;
		cross_scroll	=	 document.getElementById? document.getElementById("motiongallery10") : document.all.motiongallery10;
		actwidth 			= document.all ? cross_scroll.offsetWidth : document.getElementById("trueContainer10").offsetWidth;
	}
}

function fillup_object(o, i) {
		if (o) {
			menuwidth[i] = parseInt(o.style.width);
			mainobjoffset[i] = getposOffset(o, "left");
			getobjects(i);
			o.onmousemove=function(e) {
				motionengine(e, i);
			}
			o.onmouseout=function(e){
				stopmotion(e, i);
			}
			loadedyes[i] = 1
		}
}

function fillup() {
	if (iedom) {
		crossmain1 = document.getElementById? document.getElementById("motioncontainer1") : document.all.motioncontainer1
		crossmain2 = document.getElementById? document.getElementById("motioncontainer2") : document.all.motioncontainer2
		crossmain3 = document.getElementById? document.getElementById("motioncontainer3") : document.all.motioncontainer3
		crossmain4 = document.getElementById? document.getElementById("motioncontainer4") : document.all.motioncontainer4
		crossmain5 = document.getElementById? document.getElementById("motioncontainer5") : document.all.motioncontainer5
		crossmain6 = document.getElementById? document.getElementById("motioncontainer6") : document.all.motioncontainer6
		crossmain7 = document.getElementById? document.getElementById("motioncontainer7") : document.all.motioncontainer7
		crossmain8 = document.getElementById? document.getElementById("motioncontainer8") : document.all.motioncontainer8
		crossmain9 = document.getElementById? document.getElementById("motioncontainer9") : document.all.motioncontainer9
		crossmain10 = document.getElementById? document.getElementById("motioncontainer10") : document.all.motioncontainer10

		fillup_object(crossmain1, 1);
		fillup_object(crossmain2, 2);
		fillup_object(crossmain3, 3);
		fillup_object(crossmain4, 4);
		fillup_object(crossmain5, 5);
		fillup_object(crossmain6, 6);
		fillup_object(crossmain7, 7);
		fillup_object(crossmain8, 8);
		fillup_object(crossmain9, 9);
		fillup_object(crossmain10, 10);
	}
}