var w3c=(document.getElementById)?true:false;
var ie4=(document.all && !w3c)?true:false;
var ie5=(document.all && w3c)?true:false;
var ns6=(w3c && navigator.appName.indexOf("Netscape")>=0)?true:false;

var onPause = false;

function getElHeight(el)
{
  if(ie4||ie5)
	return (el.style.height)? el.style.height : el.clientHeight;
  else 
	return (el.style.height)? parseInt(el.style.height):parseInt(el.offsetHeight);
}

function getPageLeft(el)
{
  var x;
  if(ie4||w3c)
  {
    x = 0;
    while(el.offsetParent!=null)
    {
		x+=el.offsetLeft;
		el=el.offsetParent;
	}
	
	x+=el.offsetLeft;
	return x;
  }
}

function getPageTop(el)
{
	var y;
	if(ie4||w3c)
	{
		y=0;
		
		while(el.offsetParent!=null)
		{
			y+=el.offsetTop;
			el=el.offsetParent;
		}	
		y+=el.offsetTop;
		return y;
	}	
}

function getDiv(name)
{
	return (ie4 || ie5 )?document.all[name]:document.getElementById(name);
}

function RollingInfo(objname)
{
  this.name = objname;

  /* Constants */
  this.boxwidth=290;         // BACKGROUND BOX WIDTH IN PIXELS. 
  this.boxheight=90;         // BACKGROUND BOX HEIGHT IN PIXELS.
  this.speed=50;             // SPEED OF SCROLL IN MILLISECONDS (1 SECOND=1000 MILLISECONDS)..
  this.pixelstep=1;          // PIXELS "STEPS" PER REPITITION.
  this.godown=false;         // TOP TO BOTTOM=TRUE , BOTTOM TO TOP=FALSE
 
  /* DIV object names */
  this.divOuterName; 
  this.divInnerName;
  this.divRefName;
  
  /* DIV Objects */
  this.outer; //Outer div
  this.inne; //Inner div
  this.ref = null; //Ref div
 
 
  this.elementheight; 
  
  this.Init = function(width, height, divOuterName, divInnerName, divRefName)
  {
	this.boxwidth = width;
	this.boxheight = height;
	
	this.divOuterName = divOuterName;
	this.divInnerName = divInnerName;
	this.divRefName = divRefName;	
	
	//Adding itself to central repository (weak dependency)
	objRollingInfoCollection.AddObject(this, this.name);
  }
  
  this.Load = function()
  {
  	this.outer=getDiv(this.divOuterName);
	this.inner=getDiv(this.divInnerName);
	
	if ( this.divRefName != null)
		this.ref=getDiv(this.divRefName);
		
	this.elementheight=getElHeight(this.inner);
	
	if ( this.ref != null)
	{
		this.outer.style.left=getPageLeft(this.ref)+'px';
		this.outer.style.top=getPageTop(this.ref)+'px';
	}
	
	this.outer.style.height = this.boxheight + 'px';
	this.outer.style.width =  this.boxwidth + 'px';
	
	this.inner.style.top=((this.godown)? - this.elementheight : this.boxheight) + 'px';
	this.inner.style.clip='rect(0px, '+(this.boxwidth-4)+'px, '+(this.elementheight)+'px, 0px)';
	
	this.inner.style.visibility="visible";
	this.outer.style.visibility="visible";	
	
	setInterval("objRollingInfoCollection.Run(\"" + this.name + "\")", this.speed);
  }


  this.OnResize = function()
  {
    if ( this.ref != null)
    {
		this.outer.style.left=getPageLeft(this.ref)+'px';
		this.outer.style.top=getPageTop(this.ref)+'px';	
	}
  }
  
  
  this.Scrollbox = function()
  {
	this.inner.style.top = parseInt(this.inner.style.top)
		+ ((this.godown)? this.pixelstep: - this.pixelstep)
		+'px';
	
	if(this.godown)
	{	
		if( parseInt(this.inner.style.top) > this.boxheight )
			this.inner.style.top= - this.elementheight + 'px';
	}
	else
	{
		if( parseInt(this.inner.style.top) < 2 - this.elementheight ) 
			this.inner.style.top = this.boxheight + 2 + 'px';
	}
  }
}


function RollingInfoCollection()
{
	//PRIVATE:
	this.objects = new Array();
	this.names = new Array();
	
	//PUBLIC:
	this.AddObject = function(obj, name)
	{
		this.objects[this.objects.length] = obj;
		this.names[this.names.length] = name;
	}
		
	this.GetObjectByName = function(name)
	{
		var i;
		for ( i = 0; i < this.names.length; i ++ )
		{
			if (this.names[i] == name)
			{
				return this.objects[i];
			}
		}
		return null;
	}
	
	this.Run = function(name)
	{
		var obj = this.GetObjectByName(name);
		if ( obj != null && onPause == false) 
			obj.Scrollbox();
			
	}
	
	this.NotifyOnLoad = function()
	{
		var i;
		for ( i = 0; i < this.objects.length; i++)
			this.objects[i].Load();
	}
	
	this.NotifyOnResize = function()
	{
		var i; 
		for ( i = 0; i < this.objects.length; i++)
			this.objects[i].OnResize();
	}
}

var objRollingInfoCollection = new RollingInfoCollection();
window.onresize=function()
{
	objRollingInfoCollection.NotifyOnResize();
}

window.onload=function()
{
	objRollingInfoCollection.NotifyOnLoad();
}
