var currentLayer = 0;
var currentLoop = 0;
var flashID = null;

function flashLayers(maxLayer, maxLoop) {
	
	if(currentLayer == maxLayer) { currentLayer = 0; currentLoop++; }
	else { currentLayer++; }

	cnn_iReportBuild(currentLayer);
	
	if(currentLoop < maxLoop || maxLoop == -1)
	{
		flashID = setTimeout("flashLayers(" + maxLayer + ", " + maxLoop + ")", 5000);
	}

}

function manualLayer(iReport_dNode) {

	clearTimeout(flashID);
	cnn_iReportBuild(iReport_dNode);
	
}

function init(maxLayer, maxLoop) {

	maxLayer = typeof maxLayer == "undefined" ? 3 : maxLayer;
	maxLoop = typeof maxLoop == "undefined" ? -1 : maxLoop;
	
	cnn_iReportBuild(0);
	flashID = setTimeout("flashLayers(" + maxLayer + ", " + maxLoop + ")", 5000);

}

function eff_EleObjs(e) { if(typeof(e)=='string') { if(document.getElementById) { e=document.getElementById(e); } else if(document.all) { e=document.all[e]; } else { e=null; } } return e; }
function eff_writeToLayer(code_string,layer_id){ eff_EleObjs(layer_id).innerHTML=code_string; }

function cnn_getiReportHTML(iReport_dNode) {

	var temp_html = '';
	temp_html += '<div name="vg1" id="vg1" style="width:585px;">\n';
	temp_html += '<div class="cnnWireBox"><div class="cnnBoxHeader"><div></div></div><div class="cnnBoxContentHealth">\n';
	temp_html += '<div class="cnnBoxTitle"><b>iReports on CNN</b> <span class="cnnBoxSubtitle">Your stories, selected and vetted for CNN</span></div>\n';
	temp_html += '<div class="cnnT1c"><div id="cnnT1cCol1"><div class="cnnHtPromoImg">\n';
	temp_html += '<a href="' + (cnnIReport_data[iReport_dNode].iReport_ImgURL ?  cnnIReport_data[iReport_dNode].iReport_ImgURL : cnnIReport_data[iReport_dNode].iReport_StoryURL) + '" target="_parent"><img border="0" src="' + cnnIReport_data[iReport_dNode].iReport_ImgSRC + '"/></a>\n';
	temp_html += '</div><div class="cnnHtHeroTxt">\n';
	temp_html += '<h2><a href="' + cnnIReport_data[iReport_dNode].iReport_StoryURL + '" target="_parent">' + cnnIReport_data[iReport_dNode].iReport_StoryTitle + '</a></h2>\n';
	
	if(cnnIReport_data[iReport_dNode].iReport_User) {
		temp_html += '<span class="cnnGryTmeStmp">Photo posted by <a href="' + cnnIReport_data[iReport_dNode].iReport_UserPage + '" target="_parent">' + cnnIReport_data[iReport_dNode].iReport_User + '</a></span>\n';
	}

	temp_html += '<p style="line-height:18px;">' + cnnIReport_data[iReport_dNode].iReport_StoryBlurb + ' <a href="' + cnnIReport_data[iReport_dNode].iReport_StoryURL + '" target="_parent">full story</a><br/></p>\n';
	temp_html += '<a href="' + cnnIReport_data[iReport_dNode].iReport_TopicURL + '" target="_parent"><img width="189" height="24" border="0" onmouseout="this.src=\'http://i.l.cnn.net/cnn/exchange/images/2008/02/26/share.gif\'" onmouseover="this.src=\'http://i.l.cnn.net/cnn/exchange/images/2008/02/26/share_over.gif\'" alt="" src="http://i.l.cnn.net/cnn/exchange/images/2008/02/26/share.gif" /></a><br><br>\n';
	temp_html += '<div class="cnnT2s" style="height:50px;"><ul>\n';
	temp_html += '<!-- The original specs called for a list of links -->\n';
	temp_html += '</ul></div>\n';
	temp_html += '</div><div class="clear"><img width="1" height="1" border="0" src="http://i.l.cnn.net/cnn/images/1.gif" alt=""/></div></div><div class="clear"><img width="1" height="1" border="0" src="http://i.l.cnn.net/cnn/images/1.gif" alt=""/></div></div>\n';
	temp_html += '<table id="nav" cellspacing="0" cellpadding="0">\n';
	temp_html += '<tbody>\n';
	temp_html += '<tr>\n';
	
	//Build TZ Nav
	for (var i=0;i<cnnIReport_data.length;i++) {
	
		var temp_data = cnnIReport_data[i];
		
		temp_html += '<td>\n';
		temp_html += '<div style="width: 90px;">\n';
		temp_html += '<div class="cnnBoxHeader';
		if(i == iReport_dNode) { temp_html += 'Grey'; }
		temp_html += '"><div></div></div><div class="cnnBoxContent';
		if(i == iReport_dNode) { temp_html += 'Grey'; }
		temp_html += '">\n';
		temp_html += '<div style="padding: 1px 5px;">\n';
		if(i != iReport_dNode) { temp_html += '<a href="javascript:manualLayer(' + i + ');">'; }
		temp_html += '<img width="77" height="57" border="0" alt="" src="' + temp_data.iReport_TzSRC + '"/><br/>' + temp_data.iReport_StoryTitle;
		if(i != iReport_dNode) { temp_html += '</a>'; }
		temp_html += '</div>\n';
		temp_html += '</div>\n';
		temp_html += '<div class="cnnBoxFooter';
		if(i == iReport_dNode) { temp_html += 'Grey'; }
		temp_html += '"><div></div></div></div>\n';
		temp_html += '</td>\n';

	}
	
	temp_html += '</tr>\n';
	temp_html += '</tbody></table>\n';
	temp_html += '</div><div class="cnnBoxFooter"><div></div></div></div>\n';
	temp_html += '</div>\n';

	return temp_html;
	
}

function cnn_iReportBuild(iReport_dNode) {

	var iHTML = cnn_getiReportHTML(iReport_dNode);
	eff_writeToLayer(iHTML, 'cnn_iReportHolder');
	
}

//array
var cnnIReport_data = new Array();

//variable to allow easier re-ordering of array data;
var a_i = 0;
