// newsContainer[0] = Array('title','description','img_src','url')
 // newsContainer comes from page home_news.tpl
  //var autoSlideMode = false;
  var newsIdx = 0;
  var fadeSpeed = 0.8;
  var defaultBgImage = '/extension/ccifc/design/ccifc/images/pic_banner2.jpg';
  var timeoutID ;
  var autoNewsNextDelay = 8 ;//time interval between the 2 news show in secondes

 
  function showNewsByIdx(idx)
  {
   	var objNewsTile = document.getElementById('show_news_title');
	var objNewsDescription = document.getElementById('show_news_description');
	var objNewsImage = document.getElementById('show_news_img');
	var objNewsUrl = document.getElementById('show_news_url');
	var objNewsViewMore = document.getElementById('img_btn_view_more');

	if(newsContainer[idx][2] != '')
	{
		objNewsImage.src = newsContainer[idx][2];
	}else{
		objNewsImage.src = defaultBgImage;
	}
  	
 	objNewsTile.innerHTML = newsContainer[idx][0];
	objNewsDescription.innerHTML = newsContainer[idx][1];
	objNewsUrl.href = newsContainer[idx][3];

	var iii = 0;
	//while(iii < 10000){iii++} //used to delay some time

	//objNewsImage.style.display = 'block'; //the fading js will set this to none, so when show the image, need to set it to display
	
	Effect.Appear('show_news_img', { duration: fadeSpeed   });
	
	objNewsViewMore.style.display = 'block';
  }
  
  

	

  
  //this is the function called after the fade effect finished, and the obj is the object that controls the fading action
  function showNextNews(obj)
  {
  	var objectId = obj.element.id;
   	newsIdx += 1;
	if(newsIdx > (newsContainer.length - 1) ) newsIdx = 0;
  	showNewsByIdx(newsIdx)
  }
  
  
  //this is the function called after the fade effect finished, and the obj is the object that controls the fading action
  function showPreviousNews(obj)
  {
  	var objectId = obj.element.id;
   	newsIdx -= 1;
	if(newsIdx < 0 ) newsIdx = newsContainer.length - 1;
  	showNewsByIdx(newsIdx)
  }
  
    
  
  function autoShowNextNews(objectId,direction)
  {

		document.getElementById('img_btn_view_more').style.display = 'none';
	  
		if(direction > 0)
		{
			//move forward
			Effect.Fade(objectId, { duration: fadeSpeed , afterFinish: showNextNews   });
		}else{
			//move backward
			Effect.Fade(objectId, { duration: fadeSpeed , afterFinish: showPreviousNews   });
		}
		return false;
 }
 
 
  

 //click the show next news button by hand
 function loopShowNews(objectId,direction)
 {

 	autoShowNextNews(objectId,direction);
	
 	//when the user click on the next news button, unset (stop) the interval id, and start a new interval id
 	clearInterval(timeoutID);  
 	jsTimer(autoNewsNextDelay);

 }
 
 
 
 
 
//function timerAction()
 
 
function jsTimer(delayInSeconds)
{ 
	//autoSlideMode = true
    var executeCode = "autoShowNextNews('show_news_img',1)"; 
    timeoutID = window.setInterval(executeCode, delayInSeconds*1000); 
} 


//start the timer, in seconds, autoload the next news
 jsTimer(autoNewsNextDelay);
 
 
 
 
 
 
 
 