/***********************************************

* 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

* Modified here for continuous looping motion by jscheuer1

* as first seen in http://www.dynamicdrive.com/forums

***********************************************/

var defaultspeed=2;

var iedom=document.all||document.getElementById;

var scrollspeed=0;

var movestate="";

var actualwidth='';

var motionScroller_0, motionScroller_1;

var loadedyes=0;

function moveleft(){

	if (iedom&&loadedyes){

		if (window.righttime) clearTimeout(righttime)

		if (window.lefttime) clearTimeout(lefttime)

		movestate="left";

		if (parseInt(motionScroller_0.style.left)<(-actualwidth))

		motionScroller_0.style.left=parseInt(motionScroller_1.style.left)+actualwidth+"px";



		if (parseInt(motionScroller_1.style.left)<(-actualwidth))

		motionScroller_1.style.left=parseInt(motionScroller_0.style.left)+actualwidth+"px";

		motionScroller_0.style.left=parseInt(motionScroller_0.style.left)-scrollspeed+"px";

		motionScroller_1.style.left=parseInt(motionScroller_1.style.left)-scrollspeed+"px";

	}

	lefttime=setTimeout("moveleft()",40);

}

function moveright(){

	if (iedom&&loadedyes){

		if (window.righttime) clearTimeout(righttime)

		if (window.lefttime) clearTimeout(lefttime)

		movestate="right";

		if (parseInt(motionScroller_0.style.left)>0)

		motionScroller_1.style.left=parseInt(motionScroller_0.style.left)-actualwidth+"px";

		if (parseInt(motionScroller_1.style.left)>0)

		motionScroller_0.style.left=parseInt(motionScroller_1.style.left)-actualwidth+"px";



		motionScroller_0.style.left=parseInt(motionScroller_0.style.left)+scrollspeed+"px";

		motionScroller_1.style.left=parseInt(motionScroller_1.style.left)+scrollspeed+"px";

	}

	righttime=setTimeout("moveright()",40);

}



function setup(){

	fillup();

	scrollspeed=1;moveright();

}



function fillup(){

	if (iedom){

		//get motioncontainer

		motionContainer = document.getElementById? document.getElementById("motioncontainer") : document.all.motioncontainer;

		//get width

		menuwidth=parseInt(motionContainer.style.width);

		//get totaloffset position

		mainobjoffset=getposOffset(motionContainer, "left");

		//get motionscroller_0

		motionScroller_0 = document.getElementById? document.getElementById("motionscroller_0") : document.all.motionscroller_0;

		//create div

		motionScroller_1=document.createElement('div');

		motionScroller_1.style.position='absolute';

		motionScroller_1.style.whiteSpace='nowrap';

		//create nobr

		extra=document.createElement('nobr');

		//get trueContainer innerHTML

		extra.innerHTML=document.all? document.all['imagecontainer'].innerHTML : document.getElementById("imagecontainer").innerHTML

		//append extra

		motionScroller_1.appendChild(extra);

		//append to motioncontainer

		motionContainer.appendChild(motionScroller_1);

		//get the width of crross_scroll

		actualwidth=document.all? motionScroller_0.offsetWidth : document.getElementById("imagecontainer").offsetWidth;

		motionScroller_1.style.left=actualwidth+'px';

	}

//set some defaults

	loadedyes=1;

}

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;

}

//Remove window onload

//Attach onload event to window

if (typeof(window.addEventListener) != "undefined")

	window.addEventListener("load", setup, false);

else if (typeof(window.attachEvent) != "undefined")

   window.attachEvent("onload", setup);

else {

  if (window.onload != null ) {

		var oldOnload = window.onload;

    window.onload = function (e) {

    	oldOnload(e);

     	setup();

    }

 	}

  else

  	window.onload = setup;

}

