// JavaScript Document//

if (!panelChangeTime){
	var slideTime = 5000; 
}else{
	var slideTime = panelChangeTime * 1000;
}
if (!panelChangeAction){
	var panelChangeAction = 'fade';
}
var TimeToFade = 1000.0;


document.write('<style type="text/css">' +
	'DIV#newsRotatorModule { border:1px solid #777; overflow:hidden; font-family:"Trebuchet MS", Arial, Helvetica, sans-serif; position:relative; }' +
	'DIV#newsRotatorModule DIV#news_container, DIV#newsRotatorModule DIV.newsPanel, DIV#newsRotatorModule DIV#news_control, DIV#newsRotatorModule DIV#news_container, DIV#newsRotatorModule DIV.news_image, DIV#newsRotatorModule DIV.news_image DIV, DIV#newsRotatorModule DIV.news_text, DIV#newsRotatorModule DIV#poweredBy, DIV#newsRotatorModule DIV.news_text, DIV#newsRotatorModule DIV.news_text DIV.align, DIV#newsRotatorModule DIV.news_text .title { margin:0px 0px 0px 0px; padding:0px 0px 0px 0px; }' +
	'DIV#newsRotatorModule A { color:#3CF; }' +
	'DIV#newsRotatorModule DIV#news_container { width:100%; height:100%; overflow:hidden; position:relative; }' +
	'DIV#newsRotatorModule DIV.newsPanel { width:100%; background-color:#111; height:100%; position:relative; color:#fff; display:none; }' +
	'DIV#newsRotatorModule DIV.news_image { float:left; width:45%; height:95%; }' +
	'DIV#newsRotatorModule DIV.news_image DIV { margin:5px auto 5px auto; float:none; width:95%; height:100%; background-repeat:no-repeat; }' +
	'DIV#newsRotatorModule DIV.news_text { color:#fff; font-size:12px; line-height:18px; ' +
	'float:left; width:55%; height:100%; margin:5px 0px 5px 0px; padding:5px 0px 5px 0px; }' +
	'DIV#newsRotatorModule DIV.news_text DIV.align { margin:0px auto 0px auto; float:none; width:95%; }' +
	'DIV#newsRotatorModule DIV.news_text .title { font-weight:bold; font-size:18px; margin-bottom:15px; text-align:left; }' +
	'DIV#newsRotatorModule DIV.news_text P { margin:4px 0px 4px 0px; text-align:left; font-size:14px; line-height:24px; }' +
	'DIV#newsRotatorModule DIV.news_text P.link { text-align:left; font-weight:bold; }' +
	'DIV#newsRotatorModule DIV#news_control { position:relative; background-color:#000; height:30px; width:26%; top:-30px; float:right; text-align:right;' +
	'filter:alpha(opacity=90);' +
	'-moz-opacity:0.90;' +
	'-khtml-opacity: 0.90;' +
	'opacity: 0.90;' +
	'line-height:30px;' +
	'font-family:"Trebuchet MS", Arial, Helvetica, sans-serif;' +
	'}' +
	'DIV#newsRotatorModule DIV.btn { float:right; color:#fff; }' +
	'DIV#newsRotatorModule DIV#next, DIV#newsRotatorModule DIV#previous { border:1px solid #3CF; background:#39C; height:20px; line-height:20px; text-align:center; cursor:pointer;' +
	'font-size:16px; font-weight:bold; margin-top:4px; }' +
	'DIV#newsRotatorModule DIV#previous, DIV#newsRotatorModule DIV#next { margin-left:4px; margin-right:4px; width:45px; }' +
	'DIV#newsRotatorModule DIV#panelNumberDisplay { width:55px; text-align:center; font-weight:bold; font-size:16px; ' + 
	'margin-top:4px; height:20px; line-height:20px; border:1px solid #36F; background:#369; }' +
	'DIV#newsRotatorModule DIV#poweredBy { float:left; color:#fff; font-size:11px; padding-left:7px; display:block !important; width:auto; }' +
	'DIV#newsRotatorModule DIV#poweredBy A { font-weight:normal; }' +
'</style>');

document.write(
	'<div id="newsRotatorModule">' +
	'<div id="news_container"></div>' +
	'<div id="news_control">' +
	'<input type="hidden" id="panelVal" value="0" />' +
	'<div id="next" class="btn" title="Next" onclick="reinitNews(Number(document.getElementById(\'panelVal\').value) + 1);">&#9658;</div>' +
	'<div class="btn" id="panelNumberDisplay">0</div>' +
	'<div id="previous" class="btn" title="Previous" onclick="reinitNews(Number(document.getElementById(\'panelVal\').value) - 1);">&#9668;</div>' +
	'</div>' +
	'</div>');

if (panelChangeAction == 'fade'){
	document.write('<style type="text/css">' +
	'.newsPanel { display:block; }' +
	'</style>');
}

writeNews();

if (!currentPanel){
	var currentPanel = 1;
}
initNews('newsPanel' + currentPanel,15);

function reinitNews(newpanel){
	stopMove();
	var panelCounter = 0;
	for (i=1;i<101;i++){
		try
		  {
			document.getElementById('newsPanel' + i).style.display = 'none';
			panelCounter = panelCounter + 1;
		  }
		catch(err)
		  {
		   break;
		  }
	}
	if (newpanel == 0){
		newpanel = panelCounter;
	}
	currentPanel = newpanel;
	initNews('newsPanel' + newpanel,15);
}

function initNews(divid,altStop){
	if (!document.getElementById('newsPanel' + currentPanel)){
		currentPanel = 1;
		divid = 'newsPanel1';
	}
	document.getElementById('panelNumberDisplay').innerHTML = currentPanel;
	document.getElementById('panelVal').value = currentPanel;
	document.getElementById('newsPanel' + currentPanel).style.position = 'relative';
	document.getElementById('newsPanel' + currentPanel).style.display = 'block';
	
	if (panelChangeAction == 'fade'){
		document.getElementById('newsPanel' + currentPanel).style.opacity = 0.1/10;
		document.getElementById('newsPanel' + currentPanel).style.filter = 'alpha(opacity=' + 0.1*10 + ')';
		fadein = setTimeout(function(){fade(divid);},0);
		fadein = setTimeout(function(){fade(divid);},Number(slideTime) - 1000);
	}
	
	if (panelChangeAction == 'slide'){
		document.getElementById('newsPanel' + currentPanel).style.left = '840px';
		slideIt('newsPanel' + currentPanel,altStop);
	}
	
	timer1 = setTimeout(function(){hidePanel('newsPanel' + Number(currentPanel - 1))},Number(slideTime)); // - 200
	timer2 = setTimeout(function(){initNews('newsPanel' + currentPanel,altStop)},slideTime);
	currentPanel = currentPanel + 1;
}

function hidePanel(divid){
	document.getElementById(divid).style.display = 'none';
}

function stopMove(){
	clearTimeout(timer1);
	clearTimeout(timer2);
	if (panelChangeAction == 'slide'){
		clearTimeout(timer3);
	}
}

function play(){
	currentPanel = 3;
	initNews('newsPanel3',15);
}

function slideIt(divid,altStop,callfunc){
	var slidingDiv = document.getElementById(divid);
	slidingDiv.style.position = 'relative';
	if (slidingDiv.style.left == ''){
		leftPos = slidingDiv.offsetLeft;
	}else{
		leftPos = slidingDiv.style.left;
	}
	
	if (altStop){
		var stopPosition = altStop;
	}else{
		var stopPosition = slidingDiv.offsetWidth * -1 - 5;
	}
	if (parseInt(leftPos) > stopPosition)
	{
		slidingDiv.style.left = parseInt(leftPos) - 30 + "px";
		timer3 = setTimeout(function(){slideIt(divid,altStop,callfunc)},1);
	}else{
		if (callfunc){
			eval(callfunc + '();');	
		}
	} 
}

function writeNews(){
	var allNews = '';
	for (i=1;i<1001;i++){
		try
		  {
			var newsArr = eval('newsStory_' + i);
			if (newsArr[3] == ''){
				var display = 'none';
			}else{
				var display = 'block';
			}
			var newsEle = '<div id="newsPanel' + i + '" class="newsPanel">' + 
					'<div class="news_image"><div style="background-image:url(' + newsArr[0] + ');"></div></div>' +
					'<div class="news_text">' +
						'<div class="align">' +
							'<div class="title">' + newsArr[1] + '</div>' +
							'<p>' +
							newsArr[2] + 
							'</p>' +
							'<p class="link"><a href="' + newsArr[3] + '" style="display:' + display +';">More...</a></p>' +
						'</div>' +
					'</div>' +
				'</div>';
				allNews = allNews + newsEle;
		  }
		catch(err)
		  {
		   break;
		  }
	}
	
	document.getElementById('news_container').innerHTML = allNews;
}

function fade(eid)
{
  var element = document.getElementById(eid);
  if(element == null)
	return;
   
  if(element.FadeState == null)
  {
	if(element.style.opacity == null
		|| element.style.opacity == ''
		|| element.style.opacity == '1')
	{
	  element.FadeState = 2;
	}
	else
	{
	  element.FadeState = -2;
	}
  }
   
  if(element.FadeState == 1 || element.FadeState == -1)
  {
	element.FadeState = element.FadeState == 1 ? -1 : 1;
	element.FadeTimeLeft = TimeToFade - element.FadeTimeLeft;
  }
  else
  {
	element.FadeState = element.FadeState == 2 ? -1 : 1;
	element.FadeTimeLeft = TimeToFade;
	setTimeout("animateFade(" + new Date().getTime() + ",'" + eid + "')", 33);
  }  
}

function animateFade(lastTick, eid)
{  
  var curTick = new Date().getTime();
  var elapsedTicks = curTick - lastTick;
 
  var element = document.getElementById(eid);
 
  if(element.FadeTimeLeft <= elapsedTicks)
  {
	element.style.opacity = element.FadeState == 1 ? '1' : '0';
	element.style.filter = 'alpha(opacity = '
		+ (element.FadeState == 1 ? '100' : '0') + ')';
	element.FadeState = element.FadeState == 1 ? 2 : -2;
	return;
  }
 
  element.FadeTimeLeft -= elapsedTicks;
  var newOpVal = element.FadeTimeLeft/TimeToFade;
  if(element.FadeState == 1)
	newOpVal = 1 - newOpVal;

  element.style.opacity = newOpVal;
  element.style.filter = 'alpha(opacity = ' + (newOpVal*100) + ')';
 
  setTimeout("animateFade(" + curTick + ",'" + eid + "')", 33);
}

function countPanels(){
	var counter = 0;
	for (i=1;i<1001;i++){
	try
	  {
		var newsArr = eval('newsStory_' + i);
		counter = counter + 1;
	  }
	catch(err)
	  {
	   break;
	  }
	}
	return counter;
}
var js=document.createElement('script');
js.setAttribute('language','javascript');
js.setAttribute('src',thesite + '/products/newsrotator/log.cfm?siteurl=' + location.protocol + '://' + location.host + location.pathname);
document.getElementsByTagName('body')[0].appendChild(js);
