/****************************
 * Copyright 2009 CDS
 ****************************/

var newsIndex;
var pics;
var texts;
var maxIndex;
var sshowInterval;


function startNewsSlideShow()
{	
  newsIndex=0;
  if(!maxIndex)
  {
    maxIndex=$("#news").children().size();
  }
  displayNews();
  sshowInterval=setInterval("displayNews();",8000);
}


function displayNews()
{
	if($("#newsText").length>0)
	{
		$("#newsText").fadeOut("slow");
		$("#theImg").fadeOut("slow",replaceNewsContent);	
	}
	else replaceNewsContent();
}

function replaceNewsContent()
{
  $("#rightTop").html(newsContent());
  $("img",$("#rightTop")).fadeIn("slow",setNextTimerEvent);
  newsIndex=newsIndex+1;
  if(newsIndex==maxIndex) newsIndex=0;
}


function newsContent()
{
   var newsID="news"+newsIndex;
   var result;

   result=$("#"+newsID).html();
   return result;
}



function setNextTimerEvent()
{
	setTimeout("displayNewsText();",2000);
}


function displayNewsText()
{
	var image=$("img",$("#rightTop"));
	var theTextDiv=	$("div.newsText",$("#rightTop"));

	if(image.hasClass("shouldFade")) image.fadeTo(800,0.33);
	theTextDiv.show('drop',{direction: 'up'},1000);
	image.css("z-index","0");

	newsIndex=newsIndex+1;
	if(newsIndex==maxIndex) newsIndex=0;
}

	
 
function jumpToPage(pageID)
{

  $(".active").removeClass('active');
  $("#L"+pageID).addClass('active');
 	if(pageID=='home') 
	{
          $("#rightTopOut").html('<div id="rightTop"></div>');
	  //if(jQuery.browser.msie) $("#cdslogo").src("img/logo-06LgIE.gif");
	  startNewsSlideShow();
	}
	else
	{
	  clearInterval(sshowInterval);
	  $("#rightTopOut").html($("#"+pageID).html()); //changed to avoid width constrain due to padding for slideshow
	}
 }
 
 
///
//// Auto start of slide show
///


$(document).ready( function() { jumpToPage('home'); } );
