/*
	vScroll - Javascript Vertical Scroller
	
	Based on the "Cross Browser Marquee II" script at Dynamic Drive
	
	Modifications made by: Kevin Southworth <southwo8@msu.edu> http://portal.ksouthworth.net
	Changes:
		2004-07-16:
			- Moved/converted the scroller functions into a Class
			- Added ability to specify CSS classes for the 
			  outer DIV (container) and the inner DIV (scrolled content)
			- Added some setter functions to set things like width, height, speed, content, etc.

	USAGE:
		// include the JS file either in your <HEAD> or <BODY>
		<script src="vscroll.js" type="text/javascript"></script>
		// Create a new scroller object
		// specify the name of the variable you're creating (e.g. 'scroll1', it MUST be unique)
		// the name of the DIV to scroll ->
		// (this is the name vScroll will use to create your scroller, it MUST be unique)
		var scroll1 = new vScroll('scroll1','kigBoxDiv');
		// Set the width and height (optional)
		scroll1.setWidth("150px");	// CSS style syntax, px or %
		scroll1.setHeight("200px");
		// Set whatever content you want to be scrolled...
		scroll1.setContent('Here is come test content.<br>You can use any HTML content, like images<br><img src="img1.gif">');
		// Write the DIVs to the page and start the scroller
		scroll1.writeDiv('outerClass','innerClass');
		// (the CSS classes are optional)
		scroll1.writeDiv();		
*/

/*
Cross browser Marquee II-  Dynamic Drive (www.dynamicdrive.com)
For full source code, 100's more DHTML scripts, and TOS, visit http://www.dynamicdrive.com
Credit MUST stay intact
*/

// constructor
function vScroll( p_objName, p_divName )
{
	/* Properties */
	this.objName = p_objName;
	this.divName = p_divName;
	this.marqueewidth = "";
	this.marqueeheight = "";
	this.marqueespeed = 1;
	this.pauseit = 1;
	this.marqueecontent = "";
	
	this.marqueespeed = (document.all)? this.marqueespeed : Math.max(1, this.marqueespeed-1); //slow speed down by 1 for NS
	this.copyspeed = this.marqueespeed;
	this.pausespeed = (this.pauseit==0)? this.copyspeed: 0;
	this.iedom = document.all||document.getElementById;
	this.actualheight = '';
	this.cross_marquee = '';
	this.ns_marquee = '';
	
	/* Public Methods */
	this.scroll = vs_scrollmarquee;
	this.setContent = vs_setcontent;
	this.setSpeed = vs_setcopyspeed;
	this.setWidth = vs_setwidth;
	this.setHeight = vs_setheight;
	this.writeDiv = vs_writediv;
	
	/* Private Methods */
	this._getDiv = vs_getdiv;
	this._populate = vs_populate;
}

/* Class Methods */

function vs_setcontent( p_content )
{
	this.marqueecontent = p_content;
}

function vs_setcopyspeed( p_speed )
{
	this.copyspeed = p_speed;
}

function vs_setwidth( p_w )
{
	this.marqueewidth = p_w;
}

function vs_setheight( p_h )
{
	this.marqueeheight = p_h;
}

function vs_writediv( p_outerCSS, p_innerCSS )
{
	document.write( this._getDiv(p_outerCSS,p_innerCSS) );
	this._populate();
}

function vs_getdiv( p_outerCSS, p_innerCSS )
{
	var outerClass = '';
	var innerClass = '';
	if( p_outerCSS )
		outerClass = "class='" + p_outerCSS + "'";
	if( p_innerCSS )
		innerClass = "class='" + p_innerCSS + "'";
	
	var mouseover = this.objName + ".setSpeed('" + this.pausespeed + "')";
	var mouseout = this.objName + ".setSpeed('" + this.marqueespeed + "')";
	var outerDiv = "<div "+outerClass+" style=\"position:relative; width:"+this.marqueewidth+"; height:"+this.marqueeheight+"; overflow:hidden;\" onmouseover=\""+mouseover+"\" onmouseout=\""+mouseout+"\">";
	var innerDiv = "<div id=\"" + this.divName + "\" "+innerClass+" style=\"position:absolute; left:0px; top:0px; width: 100%;\"></div>";
	outerDiv += (innerDiv + "</div>");
	
	return outerDiv;
}

function vs_populate(){
	if(this.iedom)
	{
		if( document.getElementById )
		{
			this.cross_marquee = document.getElementById(this.divName);
		}
		else
		{
			//alert('document.all');
			this.cross_marquee = eval('document.all.'+this.divName);
		}
		this.cross_marquee.style.top = parseInt(this.marqueeheight)+8+"px";
		this.cross_marquee.innerHTML = this.marqueecontent;
		this.actualheight = this.cross_marquee.offsetHeight;
	}
	else if(document.layers)
	{
		this.ns_marquee = document.ns_marquee.document.ns_marquee2;
		this.ns_marquee.top = parseInt(this.marqueeheight)+8;
		this.ns_marquee.document.write(this.marqueecontent);
		this.ns_marquee.document.close();
		this.actualheight = this.ns_marquee.document.height;
	}
	lefttime=setInterval(this.objName+".scroll()",20)
}

function vs_scrollmarquee(){
	if (this.iedom)
	{
		if (parseInt(this.cross_marquee.style.top)>(this.actualheight*(-1)+8))
			this.cross_marquee.style.top = parseInt(this.cross_marquee.style.top)-this.copyspeed+"px";
		else
			this.cross_marquee.style.top = parseInt(this.marqueeheight)+8+"px";
	}
	else if (document.layers){
		if(this.ns_marquee.top > (this.actualheight*(-1)+8))
			this.ns_marquee.top -= this.copyspeed;
		else
			this.ns_marquee.top = parseInt(this.marqueeheight)+8;
	}
}

/*if (iedom||document.layers){
with (document){
if (iedom){
write('<div style="position:relative;width:'+marqueewidth+';height:'+marqueeheight+';overflow:hidden" onmouseover="copyspeed=pausespeed" onmouseout="copyspeed=marqueespeed">')
write('<div id="iemarquee" style="position:absolute;left:0px;top:0px;width:100%;">')
write('</div></div>')
}
}
}*/
