
var speed;						//
var width;						//To be defined by user
var height;						//
var content;						//
var contentHeight;					//

var contentWidth;					//For use later
var move=true;						//

var iedom=document.all||document.getElementById		//Constant for compatibility


//Function should be called by user to insert the scroller into the document
//Ensures that init() will be run after loading and inserts an empty framework of two containers
function insert(){

	window.onload=init;

	with (document){
		if (iedom){

			write('<div style="position:absolute;visibility:hidden" id=widther name=widther></div>');
			document.all.widther.innerHTML=content;

			write('<div style="width:'+this.width+';height:'+this.height+';overflow:hidden;">');
			write('<div id="content1" style="position:relative;left:0px;top:0px;width:'+document.all.widther.offsetWidth+'" onMouseover="move=false" onMouseout="move=true"></div>');
			write('<div id="content2" style="position:relative;left:0px;width:'+document.all.widther.offsetWidth+';top:-'+contentHeight+';" onMouseover="move=false" onMouseout="move=true"></div></div>');

		}else if (document.layers){
	
			write('<layer name="content1" left=0 top=0 onMouseover="speed=0" onMouseout="speed=speed"></layer>');
			write('<layer name="content2" left=0 top=0 onMouseover="speed=0" onMouseout="speed=speed"></layer>');
		
		}
	
	}

}


//Function called after loading to insert content and begin scrolling
//Inserts the content into both containers, gets the content width, positions the frames next to each other and initiates loop
function init(){

	if (iedom){

		document.all.content1.innerHTML=content;
		document.all.content2.innerHTML=content;

		contentWidth=document.all.widther.offsetWidth;

		document.all.content2.style.left=contentWidth+"px";

	}else if (document.layers){

		document.content1.document.write(content);
		document.content1.document.close();
		document.content2.document.write(content);
		document.content2.document.close();

		contentWidth=document.content1.document.width;

		document.content2.style.left=contentWidth;


	}

	var timer=setInterval("shift()",30);

}


//Function called from the init() timer repeatedly to scroll the pictures
//It detects if we are in a moving state, scrolls the pictures across (by 'speed' pixels) and if neccessary cycles the containers
function shift(){

	if(move){

		if (iedom){

			if (parseInt(document.all.content1.style.left)>(contentWidth*-1))
				document.all.content1.style.left=parseInt(document.all.content1.style.left)-speed+"px";

			else
				document.all.content1.style.left=parseInt(document.all.content2.style.left)+contentWidth-speed+"px";

			if (parseInt(document.all.content2.style.left+100)>(contentWidth*-1))
				document.all.content2.style.left=parseInt(document.all.content2.style.left)-speed+"px";
			
			else
				document.all.content2.style.left=parseInt(document.all.content1.style.left)+contentWidth-speed+"px";

		}else if (document.layers){

			if (document.content1.left>(contentWidth*-1))
				document.content1.left-=speed;

			else
				document.content1.left=document.content2.left+contentWidth-speed;

			if (ns_slide2.left>(contentWidth*-1))
				document.content2.left-=speed;

			else
				document.content2.left=document.content1.left+contentWidth-speed;
		
		}

	}

}


