var margin = 5; // margin around the items.
var speed = 25; // milliseconds it will take for items to move 1 pixel.
var stopspeed = 2000; // milliseconds that the news item will stop for, example: 2000 : 2seconds.
var scroller;
var scrollers = new Array ();
var margins = new Array ();



function begin(name, id) {
    //scroller = document.getElementById("scroller"); 
	
	scrollers[id] = document.getElementById(name); 
	margins[id] = margin;

	//scroller = document.getElementById(id); 
    if(scrollers[id].hasChildNodes()) {
        for(var i = 0; i < scrollers[id].childNodes.length; i++) {
            if(scrollers[id].childNodes[i].nodeType == 1) {
                scrollers[id].childNodes[i].style.margin = margins[id]  + 'px';
            } else if(scrollers[id].childNodes[i].nodeType == 3) {
                scrollers[id].removeChild(scrollers[id].childNodes[i]);
                i--;
            }
        }
        setTimeout("count(" + margins[id] + ","+ id +")", stopspeed);
    }
}
function beginWide() {
    scroller = document.getElementById("scrollerWide"); 
    if(scroller.hasChildNodes()) {
        for(var i = 0; i < scroller.childNodes.length; i++) {
            if(scroller.childNodes[i].nodeType == 1) {
                scroller.childNodes[i].style.margin = margin + 'px';
            } else if(scroller.childNodes[i].nodeType == 3) {
                scroller.removeChild(scroller.childNodes[i]);
                i--;
            }
        }
        setTimeout("count(" + margins[id] + ","+ id +")", stopspeed);
    }
}
    
function count(counter, id) {
    counter--;

    setTimeout("move(" + counter + ","+ id +")", speed);
}

function move(counter, id) {

    scrollers[id].firstChild.style.marginTop = counter + 'px';
	//scrollers[id].firstChild.style.marginLeft = counter + 'px';
    //if(counter > -(scrollers[id].firstChild.offsetHeight)) {
	if(counter > -(scrollers[id].firstChild.offsetHeight)) {
        count(counter, id);
    } else {
        setTimeout("stack(" + counter + ","+ id +")", stopspeed);
    }
}

function stack(counter, id) {
    var thischild = scrollers[id].firstChild;
    scrollers[id].removeChild(thischild);
    scrollers[id].appendChild(thischild);
    scrollers[id].lastChild.style.margin = margins[id] + 'px';
    count(margins[id], id);
}


function blendimage(divid, imageid, imagefile, millisec) { 
    var speed = Math.round(millisec / 100); 
    var timer = 0; 
    
	if (navigator.appVersion.indexOf("MSIE")!=-1)
		document.getElementById(divid).style.backgroundImage = "url(" + document.getElementById(imageid).src + ")";

    //make image transparent 
    changeOpac(0, imageid); 

	//make new image 
    document.getElementById(imageid).src = imagefile; 
	
    //fade in image 
    for(i = 0; i <= 100; i++) { 
        setTimeout("changeOpac(" + i + ",'" + imageid + "')",(timer * speed));
        timer++; 
    } 
}




//Roller
function opacity(id, opacStart, opacEnd, millisec) { 
    //speed for each frame 
    var speed = Math.round(millisec / 100); 
    var timer = 0; 

    //determine the direction for the blending, if start and end are the same nothing happens 
    if(opacStart > opacEnd) { 
        for(i = opacStart; i >= opacEnd; i--) { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } else if(opacStart < opacEnd) { 
        for(i = opacStart; i <= opacEnd; i++) 
            { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } 
} 
//change the opacity for different browsers 
function changeOpac(opacity, id) { 
    var object = document.getElementById(id).style; 
    object.opacity = (opacity / 101); 
    object.MozOpacity = (opacity / 101); 
    object.KhtmlOpacity = (opacity / 101); 
    object.filter = "alpha(opacity=" + opacity + ")"; 
} 
function shiftOpacity(id, millisec) { 
    //if an element is invisible, make it visible, else make it ivisible 
    if(document.getElementById(id).style.opacity == 0) { 
        opacity(id, 0, 100, millisec); 
    } else { 
        opacity(id, 100, 0, millisec); 
    } 
}

var secs
var timerID = null
var timerRunning = false
var delay = 500
var delayShow = 20000 

var msg=new Array()
var messageCount =-1;
var show=1;

function InitializeTimer()
{
    // Set the length of the timer, in seconds
    secs = 1
    StopTheClock()
    StartTheTimer()
	if(navigator.appName =="Microsoft Internet Explorer")
	{
		show=0;
	}
	
}

function StopTheClock()
{
    if(timerRunning)
        clearTimeout(timerID)
    timerRunning = false
}

function StartTheTimer()
{
	
    if (secs==0)
    {

        //StopTheClock()
        // Here's where you put something useful that's
        // supposed to happen after the allotted time.
        // For example, you could display a message:
		secs=1
		if(show==1) 
		{   
			//alert(msg.length+ " "+messageCount)
			
			messageCount++
			if(messageCount>=msg.length)
				messageCount =0
			document.getElementById("FrontpageRotate").innerHTML = msg[messageCount];

			show=0
			timerID = self.setTimeout("StartTheTimer()", delayShow)
		}
		else
		{
			
			show=1
			timerID = self.setTimeout("StartTheTimer()", delay)
		}

		shiftOpacity('FrontpageRotate',500);
		
		
    }
    else
    {
        self.status = secs
        secs = secs - 1
        timerRunning = true
        timerID = self.setTimeout("StartTheTimer()", delay)
    }
}