 /*
   Cross browser Marquee script- © Dynamic Drive (www.dynamicdrive.com)
   For full source code, 100's more DHTML scripts, and Terms Of Use, visit http://www.dynamicdrive.com
   Credit MUST stay intact
 */

/* Based on http://www.dynamicdrive.com/dynamicindex2/cmarquee.htm
 * 
 * You can use defaults and not specify any parameters, but you must
 * have the following CSS IDs and properties set:
 * 
 * <script type="text/javascript" src="marquee.js"></script>
 * <div id="marquee_container" style="width: X; height: Y; overflow:hidden;">
 * <script type="text/javascript">
 * putMarquee('your banner');
 * </script>													
 * </div>
 * 
 */

var marqueespeed, pauseit, copyspeed, pausespeed, marquee;
var actualwidth='';
var marqueewidth = "600px"; //set this to something reasonable as a default

//Specify the marquee's marquee speed (larger is faster 1-10)
//Pause marquee onMousever (0=no. 1=yes)?
//set the defaults
this.setSpeedAndPause(2, 1);

function setSpeedAndPause(speed, pause)
{
	this.pauseit = pause;
	this.marqueespeed = (document.all) ? speed : Math.max(1, speed-1); //slow speed down by 1 for NS
	this.copyspeed = this.marqueespeed;
	this.pausespeed = (pauseit==0) ? copyspeed : 0;
}

function populate(contents)
{
	//IE will not calculate the width of the text (will get "0") unless it's written with JavaScript!
	//Also put the contents wayyy off screen (left: -9000px;) so there's no chance the contents
	//themselves will create a horizontal scrollbar
	document.write('<span id="marquee_contents" style="visibility: hidden; position: absolute; top:0px; left:-9000px;">'+contents+'</span>');
	this.actualwidth = getObjectById("marquee_contents").offsetWidth;
	this.marquee = getObjectById("marquee");
	this.marquee.innerHTML = contents;
	//alert("marqueewidth: " + this.marqueewidth);
	this.marquee.style.left = parseInt(this.marqueewidth) + "px";
	//alert("banner width: " + this.actualwidth);
	//alert("start: " + this.marquee.style.left);
	//be careful, the ending point switch acts differently if
	//the marquee_contents is wider or narrower than the marquee_container
	//when wider 0px is full left, when narrower 0px is center
	//I assume it's wider so the marquee will always leave the screen
	//(but if it's narrower, it will take longer to start again)
	//alert("end point: " + (-1 * ((parseInt(this.marqueewidth) / 2) + parseInt(this.actualwidth))));
	setInterval("scrollMarquee()",20);
}

function getObjectById(obj_id)
{
	return document.all ? document.all[obj_id] : document.getElementById(obj_id);
}

function scrollMarquee()
{
	//if (parseInt(this.marquee.style.left) > (actualwidth * (-1) + 8))
	if (parseInt(this.marquee.style.left) > (-1 * ((parseInt(this.marqueewidth) / 2) + parseInt(this.actualwidth))))
		this.marquee.style.left = parseInt(this.marquee.style.left) - this.copyspeed + "px";
	else
		this.marquee.style.left = parseInt(this.marqueewidth) + "px";
	//(parseInt(this.marqueewidth)/2)+this.actualwidth+"px";
	//if(parseInt(this.marquee.style.left) % 1000 == 0)
	//	alert(this.marquee.style.left);
}

function putMarquee(contents, container_id, fudge_px)
{
	var container;
	if(container_id)
		container = this.getObjectById(container_id);
	else
		container = this.getObjectById("marquee_container");
	this.marqueewidth = container.offsetWidth;

	document.write('<div id="marquee_background" style="position:relative; overflow:hidden" onMouseover="copyspeed=pausespeed" onMouseout="copyspeed=marqueespeed">');
	document.write('<div id="marquee" style="position:relative;left:0px;top:0px"></div>');
	document.write('</div>');

	var background = this.getObjectById("marquee_background");

	//fudge_factor is for IE wanting to draw the marquee background larger
	//than the container
	var fudge_factor = 3;
	if(fudge_px)
		fudge_factor = fudge_px
	background.style.width = this.marqueewidth - fudge_factor + "px";
	background.style.height = container.offsetHeight + "px";

	this.populate(contents);
}


