window.onload = init; 

function init () {
	startShow();
	startTicker();
	if (document.getElementById('boxtit1')) { toggleDIV('boxtit1','boxcont1'); }
}

function brokenLink(artid){
	document.getElementById('brokenLink').innerHTML = '<br /><br/><iframe src="jsna_broken_link.php?id='+artid+'" width="400" height="30" scrolling="no" frameborder="0"></iframe>';
}



function hideLayers()
{
	var mapobjects = new Array("pb","ed","eb","so","hg","nf","yl","hh","sc","lw");
	for (var i=0; i<mapobjects.length; i++) { document.getElementById(mapobjects[i]).style.display='none'; }
}
function showLayer(id)
{
	hideLayers();
	document.getElementById(id).style.display='block';
}
	

var curr_id = 1;
var next_id = 2;
var swp_time = 10000;
var chg_speed = 2;
var curr_opacity = 100;
var len = im_array.length;
var num = Math.floor(Math.random() * (len - 1));
var pLoad = new Array()
var isOpera = (navigator.userAgent.indexOf('Opera')>=0) ? true : false;

function startShow() {
	if (im_array.length > 1)
	{
		document.images.h_image1.src=im_array[num++];
		for (i = 0; i < len; i++){
		   pLoad[i] = new Image();
		   pLoad[i].src = im_array[i];
		}
		showImage();
	}
}

var curr_d = null;
var curr_l = null;

function toggleDIV(d,l)
{
	if(!document.getElementById) return;

	if (document.getElementById(l).style.display == "block") {
		hideDIV(d,l);
	} else {
		showDIV(d,l);
	}
}

function showDIV(d,l) {
	if(!document.getElementById) return;

	if (curr_d!=null && curr_l!=null) {
		hideDIV(curr_d,curr_l);
	}

	document.getElementById(d).style.backgroundImage = "url(/_images/cms_tabs/tabup.gif)";
	document.getElementById(d).style.backgroundColor = "#D9EDF7";
	document.getElementById(l).style.display = "block";
	curr_d = d;
	curr_l = l;
}

function hideDIV(d,l) {
	if(!document.getElementById) return;
	
	document.getElementById(d).style.backgroundImage = "url(/_images/cms_tabs/tabdown.gif)";
	document.getElementById(d).style.backgroundColor = "#FFFFFF";
	document.getElementById(l).style.display = "none";
}


function showImage() {
	curr_opacity=100;
	document.getElementById('h_image'+curr_id).style.visibility = 'visible';
	if (isOpera) {
		document.getElementById('h_image'+curr_id).style.display = 'inline';
	}

	if (!isOpera) {
		document.getElementById('h_image'+next_id).style.visibility = 'visible';
	}

	if (document.all) {
		document.getElementById('h_image'+curr_id).style.filter = 'alpha(opacity=100)';
		document.getElementById('h_image'+next_id).style.filter = 'alpha(opacity=1)';
	} else {
		document.getElementById('h_image'+curr_id).style.opacity = 0.99;
		document.getElementById('h_image'+next_id).style.opacity = 0.01;
	}		
	document.getElementById('h_image'+next_id).src=pLoad[num++].src;

	if (num > (len-1)) {
		num=0;
	}
	setTimeout('swpImage()',swp_time);		
}

function swpImage() {
	curr_opacity--;
	if(document.all){
		document.getElementById('h_image'+curr_id).style.filter = 'alpha(opacity='+curr_opacity+')';
		document.getElementById('h_image'+next_id).style.filter = 'alpha(opacity='+(100-curr_opacity)+')';
	}
	else{
		document.getElementById('h_image'+curr_id).style.opacity = Math.max(0.01,curr_opacity/100);
		document.getElementById('h_image'+next_id).style.opacity = Math.min(0.99,(1 - (curr_opacity/100)));
	}
	if(curr_opacity>0){
		setTimeout('swpImage()',chg_speed);
	} else {
		document.getElementById('h_image'+curr_id).style.visibility = 'hidden';	
		if (isOpera) {
			document.getElementById('h_image'+curr_id).style.display = 'none';
		}

		if (curr_id==1) {
			curr_id = 2;
			next_id = 1;
		} else {
			curr_id = 1;
			next_id = 2;
		}
		showImage();
	}
}





// Ticker startup
function startTicker()
{
	if (document.getElementById("tickertape")) {
		// Define run time values
		theCurrentStory     = -1;
		theCurrentLength    = 0;
		// Locate base objects
		if (document.getElementById) {	
				theAnchorObject     = document.getElementById("tickertape");
				//setTimeout("runTheTicker()", ini_ticker_timeout);
				runTheTicker();   	
			 }
		else {
				document.write("<style>.ticki{display:none;}.ticko{border:0px; padding:0px;}</style>");
				return true;
		}
	}
}
// Ticker main run loop
function runTheTicker()
{
	var myTimeout;  
	// Go for the next story data block
	if(theCurrentLength == 0)
	{
		theCurrentStory++;
		theCurrentStory      = theCurrentStory % theItemCount;
		theStorySummary      = theSummaries[theCurrentStory].replace(/&quot;/g,'"');
		theStorySummary      = theStorySummary.replace(/&#39;/g,"'");	
		theTargetLink        = theSiteLinks[theCurrentStory];
		theAnchorObject.href = theTargetLink;
		//thePrefix 	     = "<span style='color:#000;text-decoration:none'>" + theLeadString + "</span>";
		thePrefix 	     = "<span>" + theLeadString + "</span>";
	}
	// Stuff the current ticker text into the anchor
	theAnchorObject.innerHTML = thePrefix + 
	theStorySummary.substring(0,theCurrentLength) + whatWidget();
	// Modify the length for the substring and define the timer
	
	if(theCurrentLength != theStorySummary.length)
	{
		theCurrentLength++;
		myTimeout = theCharacterTimeout;
	}
	else
	{
		theCurrentLength = 0;
		myTimeout = theStoryTimeout;
	}
	// Call up the next cycle of the ticker
	setTimeout("runTheTicker()", myTimeout);
}
// Widget generator
function whatWidget()
{
	if(theCurrentLength == theStorySummary.length)
	{
		return theWidgetNone;
	}

	if((theCurrentLength % 2) == 1)
	{
		return theWidgetOne;
	}
	else
	{
		return theWidgetTwo;
	}
}

	var theCharacterTimeout = 30;
	var theStoryTimeout     = 5000;
	var theWidgetOne        = "-";
	var theWidgetTwo        = "_";
	var theWidgetNone       = "";
	var theLeadString       = "Newsflash: ";
	
