/***********************************************
* 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 = 240; // width of the "neutral" area in the center of the gallery in px
var maxspeed = 5; // top scroll speed in pixels. Script auto creates a range from 0 to top speed.

var photo_txt = {
	monster	: "One of our friendly staff members will meet you at the door.",
	chair	: "The dental clinic. See the comfortable blue chair that you sit in while the dentist checks your teeth.",
	chair2	: "Dr Richard and Nurse Vicki with a friend in the dental chair.",
	chair3	: "Dr Richard and Nurse Vicki are each wearing a special mask and clean gloves to look at Zac's teeth.",
	glasses	: "Dr Richard needs a very bright light to see in your mouth. You can choose which sunglasses you would like to wear.",
	jets	: "We use tooth dryers, water sprayers and tooth cleaners to see your teeth properly. Sometimes they tickle - but not too much laughing!",
	tappo	: "Andrew, our friendly tappopotomus loves helping children.",
	xray	: "A special tooth picture (dental x-ray) can show all your new teeth. If Dr Richard gets a special picture of your teeth, ask for a copy to take to school for news.",
	table	: "This is the dentists' table. They put their little mirror there after they have checked your teeth.",
	juliette: "This is Dr Juliette Scott our Dental Consultant.",
	desk	: "Dr Richard and Nurse Vicki say hello at the front desk.",
	tiger	: "Zac is ready for his dental visit. Teeth clean, fur brushed and nose shiny.",
	horse	: "George comes to see us every 6 months, because horses need good teeth to eat their apples.",
	heidi	: "This is Heidi, one of our senior dental nurses that you will meet at your visit. She never forgets anyone, and she will know your name as soon as you come to the dental clinic.",
	shoes	: "If you come and see us in December, make sure you dress up and wear your red and green shoes like we do.",
	brush	: "Toothbrushes should be clean, soft and not shaggy.",
	nicole  : "This is Nurse Nicole, she loves to see all your smiling faces."
}

function change_photo(id) {
	document.images["photo"].src = "photos/" + id + ".jpg";
	document.getElementById("tag").innerHTML = photo_txt[id];
	return false;
}

////NO NEED TO EDIT BELOW THIS LINE////////////

var iedom = document.all || document.getElementById;
var scrollspeed = 0;
var movestate = "";
var actualwidth = "";
var cross_scroll, ns_scroll, cross_pos;
var loadedyes = 0;

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;
}

function moveleft() {
	if (loadedyes) {
		movestate = "left";
		if (iedom && parseInt(cross_scroll.style.left) > (menuwidth - actualwidth)) {
			cross_pos -= scrollspeed;
			cross_scroll.style.left = cross_pos + "px";
		}
	}
	lefttime = setTimeout("moveleft()",10);
}

function moveright() {
	if (loadedyes) {
		movestate = "right";
		if (iedom && parseInt(cross_scroll.style.left) < 0) {
			cross_pos += scrollspeed;
			cross_scroll.style.left = cross_pos + "px";
		}
	}
	righttime = setTimeout("moveright()",10);
}

function motionengine(e) {
	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 - dsocx;
	var leftbound = (menuwidth - restarea) / 2;
	var rightbound = (menuwidth + restarea) / 2;
	if (curposy > rightbound) {
		scrollspeed = (curposy - rightbound) / ((menuwidth - restarea) / 2) * maxspeed;
		if (window.righttime) { clearTimeout(righttime); }
		if (movestate != "left") { moveleft(); }
	} else if (curposy < leftbound) {
		scrollspeed = (leftbound - curposy) / ((menuwidth - restarea) / 2) * maxspeed;
		if (window.lefttime) { clearTimeout(lefttime); }
		if (movestate != "right") { moveright(); }
	} else {
		scrollspeed = 0;
	}
}

function contains_ns6(a, b) {
	while (b.parentNode) {
		if ((b = b.parentNode) == a) {
			return true;
		}
	}
	return false;
}

function stopmotion(e) {
	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 = "";
	}
}

function fillup() {
	if (iedom) {
		crossmain = document.getElementById ? document.getElementById("motioncontainer") : document.all.motioncontainer;
		menuwidth = parseInt(crossmain.style.width);
		mainobjoffset = getposOffset(crossmain, "left");
		cross_scroll = document.getElementById ? document.getElementById("motiongallery") : document.all.motiongallery;
		cross_pos = parseInt(cross_scroll.style.left);
		actualwidth = document.all ? cross_scroll.offsetWidth : document.getElementById("trueContainer").offsetWidth;
		actualwidth += 8;
		crossmain.onmousemove = function(e) {
			motionengine(e);
		}
		crossmain.onmouseout = function(e) {
			stopmotion(e);
		}
	}
	loadedyes = 1;
}

//window.onload = fillup;
