/**
 * $Header: //depot/Projects/CIMIT/website/web/lib/rotatingStories.js#7 $
 *
 * COPYRIGHT:
 *
 * This software is Copyright (c) 2006-2008 Marc Davignon
 *                         <mpdavig@users.sourceforge.net>
 *
 * LICENSE:
 *
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of Version 2 of the GNU General Public License as published by the
 * Free Software Foundation.
 *
 * Code used and modified from interactive/rotating_stories.html
 */

var stor = -1;
/* Maximum number of stories to rotate through */
var maxstor = 3;
var timeout = 0;
var revocur = 0;

/* CHANGE ME: Number of story revolutions, starts counting from 0 */
var revomax = 2;

function autorot() {
	showNext();
	/* CHANGE ME: Time in milliseconds between story rotation . Change the
	   last value here to increase or decrease the timeout value.
	   20000 seems like a good amount of time */
	if (revocur <= revomax) {
		timeout = setTimeout('autorot();', 5000);
	}
}



function rotateDiv(stor){
  divArray = new Array();
  var divs = document.getElementById("storyContainer").getElementsByTagName("div");

  // Reduce the div array to elements with "id" values
  for (var i=0; i < divs.length; i++ )
    if ( (divs[i].id != "") ) divArray[divArray.length] = divs[i];
  divs = divArray;

  for (var i=0; i < divs.length; i++ ) {
    var div = divs[i];
    if ( (div.id != "") ) {
	if(i != stor){
        	div.style.display = "none";
	}
	else{
		div.style.display = "block";
	}
    }
  }

  var spans = document.getElementById("nav").getElementsByTagName("span");
  for (var i=0; i < spans.length; i++ ) {
    var span = spans[i];
    if ( (span.id != "")) {
	if(i != stor)
        	span.className = "none";
	else
		span.className = "selStory";
    }
  }
}


function stoprot() {
	clearTimeout(timeout);
}


function showNext(){
	if(stor < maxstor) {
		stor++;
	} else {
		stor=0;
		/* Count the number of resets back to the first story */
		revocur++;
	}

	rotateDiv(stor);
}

function showPrev(){
	if(stor > 0)
		stor--;
	else
		stor=maxstor;

	rotateDiv(stor);
}

function showStoryOne(){
	stor=0;
	rotateDiv(stor);
}

function showStoryTwo(){
	stor=1;
	rotateDiv(stor);
}

function showStoryThree(){
	stor=2;
	rotateDiv(stor);
}

function showStoryFour(){
	stor=3;
	rotateDiv(stor);
}

