﻿// Frontpage JScript File

    var data = "";
    var storyLine;
    var displayLength = 0;
    var currentStory = 1;
    var startColor = 255
    var finishColor = 128
    var nowColor = 255


function updateTicker(){

    
    if (storyLine[currentStory].length > 80){
        shortenedLine = storyLine[currentStory].substring(0,80)+ "...";;
    } else {
        shortenedLine = storyLine[currentStory];
    }
    
    toDisplay = "<a href='/news/fullarticle.aspx?id=" + storyLine[currentStory+1] + "' id='newsFeedText'>" + shortenedLine + "</a>";

        if(DOM) {
            document.getElementById("newsFeed").innerHTML = toDisplay;
        }
        else if(IE4){
            document.all["newsFeed"].innerHTML = toDisplay;
        }
        
        updateColor();
        
        fadeInText();
}

function fadeInText(){

    if (nowColor > finishColor){
        nowColor = nowColor -10;
        updateColor();
        setTimeout("fadeInText()", 50);
    } else {
        setTimeout("fadeOutText()", 5000);
    }

}

function fadeOutText(){
    if (nowColor < startColor){
        nowColor = nowColor + 10;
        updateColor();
        setTimeout("fadeOutText()", 50);
    } else {
        nowColor = startColor;
        updateColor();
        currentStory = currentStory + 2;
        if (currentStory >= storyLine.length) currentStory = 1;
        updateTicker();
    }
}

function updateColor(){
    if(DOM) {
        document.getElementById("newsFeedText").style.color = hexColor(nowColor);
    }
    else if(IE4){
        document.getElementById("newsFeedText").style.color = hexColor(nowColor);
    }
}

function hexColor(colorVar){
    singleColor = colorVar.toString(16);
    return "#" + singleColor + singleColor + singleColor;
}

function getNews()
 {

     if (window.XMLHttpRequest)
     {
         // browser has native support for XMLHttpRequest object
         req = new XMLHttpRequest();
     }
     else if (window.ActiveXObject)
     {
         // try XMLHTTP ActiveX (Internet Explorer) version
         req = new ActiveXObject("Microsoft.XMLHTTP");
     }
     
     if(req)
     {
         req.onreadystatechange = detailsResponse;
         req.open("GET", "/news/frontpage_news.aspx", true);
         req.setRequestHeader("content-type","application/x-www-form-urlencoded");
         req.send();
     }
     else
     {
         alert('Your browser does not seem to support XMLHttpRequest.');
     }
}


function detailsResponse(){

	if (req.readyState == 4) {
   		if (req.status == 200) {
   			data = req.responseText;
            storyLine = data.split("##")
            setTimeout("updateTicker()", 250);
		} else {
		    // there was a problem with the request,
		    // for example the response may be a 404 (Not Found)
		    // or 500 (Internal Server Error) response codes
		}
	} else {
   		// still not ready
	}
		
}

function strength_banner(){
	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" ')
	document.write('codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" ')
	document.write('width="200" height="230" id="strength_in_numbers" align="middle">')
	document.write('<param name="allowScriptAccess" value="sameDomain" />')
	document.write('<param name="allowFullScreen" value="false" /><param name="wmode" value="transparent">')
	document.write('<param name="movie" value="/frontpage/strength_in_numbers.swf" />')
	document.write('<param name="quality" value="high" /><param name="bgcolor" value="#ffffff" />')
	document.write('<embed src="/frontpage/strength_in_numbers.swf" quality="high" bgcolor="#ffffff" width="200" height="230" name="strength_in_numbers" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />')
	document.write('</object>')
}

