// JavaScript Document

//var olr_ad1=new Array()

//olr_ad1[0]='<a target="_parent" href="#"><img src="/clients/268/__Argos.jpg" border="0" style="margin-right:2px;" alt="o" title="o" align="absmiddle"></a>';

//olr_ad1[1]='<a target="_parent" href="#"><img src="/clients/235/_e-resourcing-solutions.jpg" border="0" style="margin-right:2px;" alt="o" title="o" align="absmiddle"></a>';

//olr_ad1[2]='<a target="_parent" href="#"><img src="/clients/230/_Adderley.jpg" border="0" style="margin-right:2px;" alt="o" title="o" align="absmiddle"></a>';


/************************************************/

var totalScrollers=0;


function buildHTML(img, title, id, totaljobs)
{
	//alert(id+" - "+totaljobs);
	if (totaljobs == 0 || totaljobs == null) {
		return '<img src="/clients/'+img+'" border="0" style="margin-right:2px;" alt="'+title+'" title="'+title+'" valign="middle" align="absmiddle">';
	} else {
		return '<a target="_parent" href="#"><img src="/clients/'+img+'" border="0" style="margin-right:2px;" alt="'+title+'" title="'+title+'" valign="middle" align="absmiddle" onclick="Javascript: window.open(\'/minisite/about_us.aspx?ClientID='+id+'\')"></a>';
	}
	
}



function pausescroller(id, content, divId, divClass, delay){

this.id = id
this.content=content //message array content
this.tickerid=divId //ID of ticker div to display information
this.delay=delay //Delay between msg change, in miliseconds.
this.mouseoverBol=0 //Boolean to indicate whether mouse is currently over scroller (and pause it if it is)
this.hiddendivpointer=(id+totalScrollers>ceiling-1)? ((id-1>ceiling-1)? 0 : id-1) : id-1+totalScrollers //index of message 

var ceiling=this.content.length
var current = (id-1>ceiling-1)? 0 : id-1;

document.getElementById("olr_box" + id + "1").innerHTML = buildHTML(content[current][0], content[current][1], content[current][2], content[current][3]);

document.getElementById("olr_box" + id + "2").innerHTML = buildHTML(content[this.hiddendivpointer][0], content[this.hiddendivpointer][1], content[this.hiddendivpointer][2], content[this.hiddendivpointer][3]);

var scrollerinstance=this

if (window.addEventListener) //run onload in DOM2 browsers
	window.addEventListener("load", function(){scrollerinstance.initialize()}, false)
else if (window.attachEvent) //run onload in IE5.5+
	window.attachEvent("onload", function(){scrollerinstance.initialize()})
else if (document.getElementById) //if legacy DOM browsers, just start scroller after 0.5 sec
	setTimeout(function(){scrollerinstance.initialize()}, 500)
}

// -------------------------------------------------------------------
// initialize()- Initialize scroller method.
// -Get div objects, set initial positions, start up down animation
// -------------------------------------------------------------------

pausescroller.prototype.initialize=function(){

	this.tickerdiv=document.getElementById(this.tickerid)
	this.visiblediv=document.getElementById(this.tickerid+"1")
	this.hiddendiv=document.getElementById(this.tickerid+"2")
	//alert("padding:"+parseInt(pausescroller.getCSSpadding(this.tickerdiv)));
	this.visibledivtop=parseInt(pausescroller.getCSSpadding(this.tickerdiv))

	//set width of inner DIVs to outer DIV's width minus padding (padding assumed to be top padding x 2)
	//alert(this.tickerdiv.offsetWidth);
	this.visiblediv.style.width=this.hiddendiv.style.width=this.tickerdiv.offsetWidth-20+"px"
	//alert(this.visiblediv.style.width);
	this.getinline(this.visiblediv, this.hiddendiv)
	this.hiddendiv.style.visibility="visible"
	var scrollerinstance=this

	document.getElementById(this.tickerid).onmouseover=function(){scrollerinstance.mouseoverBol=1}
	document.getElementById(this.tickerid).onmouseout=function(){scrollerinstance.mouseoverBol=0}

	if (window.attachEvent) //Clean up loose references in IE
		window.attachEvent("onunload", function(){scrollerinstance.tickerdiv.onmouseover=scrollerinstance.tickerdiv.onmouseout=null})
	
	setTimeout(function(){scrollerinstance.animateup()}, this.delay)
}


// -------------------------------------------------------------------
// animateup()- Move the two inner divs of the scroller up and in sync
// -------------------------------------------------------------------

pausescroller.prototype.animateup=function(){

	var scrollerinstance=this
	//alert("left:"+parseInt(this.hiddendiv.style.left)+" - "+this.visibledivtop+5);
	if (parseInt(this.hiddendiv.style.left)>(this.visibledivtop+5)){

		this.visiblediv.style.left=parseInt(this.visiblediv.style.left)-5+"px"
		this.hiddendiv.style.left=parseInt(this.hiddendiv.style.left)-5+"px"

		setTimeout(function(){scrollerinstance.animateup()}, 50)

	} else {
	
		this.getinline(this.hiddendiv, this.visiblediv)
		this.swapdivs()

		setTimeout(function(){scrollerinstance.setmessage()}, this.delay)

	}
}

// -------------------------------------------------------------------
// swapdivs()- Swap between which is the visible and which is the hidden div
// -------------------------------------------------------------------

pausescroller.prototype.swapdivs=function(){

	var tempcontainer=this.visiblediv
	this.visiblediv=this.hiddendiv
	this.hiddendiv=tempcontainer
}



pausescroller.prototype.getinline=function(div1, div2){

	div1.style.left=this.visibledivtop+"px"
	//alert(div1.style.left);
	div2.style.left=Math.max(div1.parentNode.offsetWidth, div1.offsetWidth)+"px"
	//alert(div2.style.left);
}


// -------------------------------------------------------------------
// setmessage()- Populate the hidden div with the next message before it's visible
// -------------------------------------------------------------------

pausescroller.prototype.setmessage=function(){

	var scrollerinstance=this

	if (this.mouseoverBol==1) //if mouse is currently over scoller, do nothing (pause it)
		setTimeout(function(){scrollerinstance.setmessage()}, 100)
	else {
		var i=this.hiddendivpointer
		var ceiling=this.content.length
		var id = this.hiddendivpointer
		//alert("idadd4:"+(id+totalScrollers));
		//alert((id+totalScrollers>ceiling-1) ? "bad" : "good");
		this.hiddendivpointer=(id+totalScrollers>ceiling-1) ? ((this.id-1>ceiling-1)? 0 : this.id-1) : id+totalScrollers
		//this.hiddendivpointer=(i+1>ceiling-1)? 0 : i+1
		//this.hiddendiv.innerHTML=this.content[this.hiddendivpointer]
		this.hiddendiv.innerHTML=buildHTML(this.content[this.hiddendivpointer][0], this.content[this.hiddendivpointer][1], this.content[this.hiddendivpointer][2], this.content[this.hiddendivpointer][3]);
		this.animateup()
	}
}

pausescroller.getCSSpadding=function(tickerobj){ //get CSS padding value, if any

if (tickerobj.currentStyle)
		return tickerobj.currentStyle["paddingTop"]
	else if (window.getComputedStyle) //if DOM2
		return window.getComputedStyle(tickerobj, "").getPropertyValue("padding-top")
	else
		return 0
}

function Load_Scrollers(num)
{
	totalScrollers = num;
	for (i=1; i <= num; i++)
	{
		new pausescroller(i, olr_ad2, "olr_box"+i, "microbox", 10000);
	}
}


