/***********************************************
* 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=3 //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.

////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
var loadedyes=0

function ietruebody(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function creatediv(){
statusdiv=document.createElement("div")
statusdiv.setAttribute("id","statusdiv")
document.body.appendChild(statusdiv)
statusdiv=document.getElementById("statusdiv")
statusdiv.innerHTML=endofgallerymsg
}

function positiondiv(){
menuheight=parseInt(crossmain.offsetHeight)
mainobjoffsetH=getposOffset(crossmain, "top")
statusdiv.style.left=mainobjoffset+(menuwidth/2)-(statusdiv.offsetWidth/2)+"px"
statusdiv.style.top=menuheight+mainobjoffsetH+"px"
}

function showhidediv(what){
if (endofgallerymsg!="")
statusdiv.style.visibility=what
}

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"
showhidediv("hidden")
}
else
showhidediv("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-1)+"px"
showhidediv("hidden")
}
else
showhidediv("visible")
}
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(sOuterContainer, sContainer, sGallery)
{
	crossmain = document.getElementById(sOuterContainer)
		
	if(crossmain != null)
	{
		menuwidth=parseInt(crossmain.style.width)
		mainobjoffset=getposOffset(crossmain, "left")
		cross_scroll = document.getElementById(sContainer)
		actualwidth = document.getElementById(sGallery).offsetWidth
		
		crossmain.onmousemove=function(e){
		motionengine(e)
		}
		
		crossmain.onmouseout=function(e){
		stopmotion(e)
		showhidediv("hidden")
		}

		loadedyes=1
	
		if (endofgallerymsg!="")
		{
			creatediv()
			positiondiv()
		}
	}
}

function initialisePage()
{
	fillup("motioncontainer", "motiongallery", "trueContainer");
	fillup2("motioncontainer2", "motiongallery2", "trueContainer2");
}

//gallery2, added by Kate, 17/05/06

var restarea2=6 //1) width of the "neutral" area in the center of the gallery in px
var maxspeed2=7 //2) top scroll speed in pixels. Script auto creates a range from 0 to top speed.
var endofgallerymsg2="" //3) message to show at end of gallery. Enter "" to disable message.

////NO NEED TO EDIT BELOW THIS LINE////////////

var iedom2=document.all||document.getElementById
var scrollspeed2=0
var movestate2=""

var actualwidth2=''
var cross_scroll2, ns_scroll2
var loadedyes2=0

function ietruebody2(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function creatediv2(){
statusdiv2=document.createElement("div")
statusdiv2.setAttribute("id","statusdiv2")
document.body.appendChild(statusdiv2)
statusdiv2=document.getElementById("statusdiv2")
statusdiv2.innerHTML=endofgallerymsg2
}

function positiondiv2(){
menuheight2=parseInt(crossmain2.offsetHeight)
mainobjoffsetH2=getposOffset2(crossmain2, "top")
statusdiv2.style.left=mainobjoffset2+(menuwidth2/2)-(statusdiv2.offsetWidth/2)+"px"
statusdiv2.style.top=menuheight2+mainobjoffsetH2+"px"
}

function showhidediv2(what){
if (endofgallerymsg2!="")
statusdiv2.style.visibility=what
}

function getposOffset2(what, offsettype){
var totaloffset2=(offsettype=="left")? what.offsetLeft: what.offsetTop;
var parentEl2=what.offsetParent;
while (parentEl2!=null){
totaloffset2=(offsettype=="left")? totaloffset2+parentEl2.offsetLeft : totaloffset2+parentEl2.offsetTop;
parentEl2=parentEl2.offsetParent;
}
return totaloffset2;
}


function moveleft2(){
if (loadedyes2){
movestate2="left"
if (iedom2&&parseInt(cross_scroll2.style.left)>(menuwidth2-actualwidth2)){
cross_scroll2.style.left=parseInt(cross_scroll2.style.left)-scrollspeed2+"px"
showhidediv2("hidden")
}
else
showhidediv2("visible")
}
lefttime=setTimeout("moveleft2()",10)
}

function moveright2(){
if (loadedyes2){
movestate2="right"
if (iedom2&&parseInt(cross_scroll2.style.left)<0){
cross_scroll2.style.left=parseInt(cross_scroll2.style.left)+scrollspeed2+"px"
showhidediv2("hidden")
}
else
showhidediv2("visible")
}
righttime=setTimeout("moveright2()",10)
}

function motionengine2(e){
var dsocx2=(window.pageXOffset)? pageXOffset2: ietruebody2().scrollLeft;
var dsocy2=(window.pageYOffset)? pageYOffset2 : ietruebody2().scrollTop;
var curposy2=window.event? event.clientX : e.clientX? e.clientX: ""
curposy2-=mainobjoffset2-dsocx2
var leftbound2=(menuwidth2-restarea2)/2
var rightbound2=(menuwidth2+restarea2)/2
if (curposy2>rightbound2){
scrollspeed2=(curposy2-rightbound2)/((menuwidth2-restarea2)/2) * maxspeed2
if (window.righttime) clearTimeout(righttime)
if (movestate2!="left") moveleft2()
}
else if (curposy2<leftbound2){
scrollspeed2=(leftbound2-curposy2)/((menuwidth2-restarea2)/2) * maxspeed2
if (window.lefttime) clearTimeout(lefttime)
if (movestate2!="right") moveright2()
}
else
scrollspeed2=0
}

function contains_ns6(a, b) {
while (b.parentNode)
if ((b = b.parentNode) == a)
return true;
return false;
}

function stopmotion2(e){
if ((window.event&&!crossmain2.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)
	movestate2=""
}
}


function fillup2(sOuterContainer, sContainer, sGallery)
{
	
crossmain2 = document.getElementById(sOuterContainer)
		
	if(crossmain2 != null)
	{
		menuwidth2=parseInt(crossmain2.style.width)
		mainobjoffset2=getposOffset2(crossmain2, "left")
		cross_scroll2 = document.getElementById(sContainer)
		actualwidth2 = document.getElementById(sGallery).offsetWidth
		
		
		crossmain2.onmousemove=function(e){
		motionengine2(e)
		}
		
		crossmain2.onmouseout=function(e){
		stopmotion2(e)
		showhidediv2("hidden")
		}

		loadedyes2=1
	
		if (endofgallerymsg2!="")
		{
			creatediv2()
			positiondiv2()
		}
	}
}

// end gallery2

window.onload=initialisePage