/* Begin Main story module */
var currPic=0;
var timePlay=10000;
var timer1, timer2;
var paused = true;
var opacity = 100;
var msDivs = new Array(6);
var msButtons = new Array(6); 
var msWrap;
var button;
var position;
var currPosition;

function initPageComponents() {
 /*  Used to load all components on the page */
 msDivs[0] = document.getElementById('Story1');
 msDivs[1] = document.getElementById('Story2');
 msDivs[2] = document.getElementById('Story3');
 msDivs[3] = document.getElementById('Story4');
 msDivs[4] = document.getElementById('Story5');
 msDivs[5] = document.getElementById('Story6');
 
 msButtons[0] = document.getElementById('a1'); 
 msButtons[1] = document.getElementById('a2');
 msButtons[2] = document.getElementById('a3');
 msButtons[3] = document.getElementById('a4');
 msButtons[4] = document.getElementById('a5'); 
 msButtons[5] = document.getElementById('a6'); 
 
 msWrap = document.getElementById('pic-show');
 initPausePlayEvents();
 var breakingNews = document.getElementById('breakingNewsImg'); 
 if (breakingNews == null)
 {
  paused = false;
//  timer1=setTimeout('timedStory()',timePlay); //set for start play
 }
}

function initPausePlayEvents() {
 /* add Event Handlers for the Photo Module */
 if (!document.getElementById || !document.getElementsByTagName) {
  return true;
 }
 /* checks for Javascript operability  */ 

 /*  get all the links in the photo module  */
 var topStories = document.getElementById('morePic');
 var links = topStories.getElementsByTagName('a');

 for (i=0;i < links.length; i++) {
  if (links.item(i).id.substring(0,1) == 'a'){  
   //filter the links for those that have a class name beginnig with 'a'
   //add the doNumber event handler for the number links
   links.item(i).href='javascript:{}';
   tii_addEventHandler (links [i], 'click', function (event)
   {
    doNumber (event);
   }, false);
  }
 }
 
 var playLink = document.getElementById('playLink');
  
 //add the doButton event handler for the play pause button 
 tii_addEventHandler ( playLink , 'click', function (event)
 {
  doButton (event);
 }, false);
}

/* helper function to deal specifically with images and the cross-browser differences in opacity handling */
function fader(opac) {
 if (msWrap.style.MozOpacity!=null) {  
  /* Mozilla's pre-CSS3 proprietary rule */ 
  msWrap.style.MozOpacity = (opac/100) - .001;
 } else if (msWrap.style.opac!=null) {
  /* CSS3 compatible */
  msWrap.style.opacity = (opac/100) - .001;
 } else if (msWrap.style.filters!=null) {
  /* IE's proprietary filter */ 
 if (opac==100){
  msWrap.filters.alpha.opacity=100;
 } else {
//  msWrap.style.filter = "alpha(opacity="+opac+");";
  msWrap.filters.alpha.opacity=opac;
  }
 }
}


/* change picture, wait 5 seconds, repeat */
function timedStory() {
 if (currPic<4){
 currPic++;
 change(currPic, 1);
// timer1=setTimeout('timedStory()',timePlay);
 }else{
	currPic=0;
//	clearTimeout(timer1); //remark this for disable loop
	change(currPic,1);
//	timer1=setTimeout('timedStory()',timePlay); //remark this for disable loop
	paused = true; //default "true"
 }
}

/* executed when the play pause button is selected */
function doButton(event) {
 paused = !paused;
 if (paused) {
  /* stop the image loop */
  clearTimeout(timer1);
 }
 else { 
  /* restart the image loop */
  timedStory();
 }
}  

/*executed when a number link is selected */
function doNumber (event) {
 var eventSource = typeof event.target != 'undefined' ? event.target : window.event.srcElement;
 /*  get the number portion of the class name of the event source */ 
 currPic = eventSource.id.substring(1,2)-1;
 paused = true;
 clearTimeout(timer1);
 clearTimeout(timer2);
 change(currPic, 1);
} 

/* Initialization and Unobtrusive Javascript Calls */
tii_callFunctionOnElementLoad('morePic', initPageComponents);