/**
 * This script contains the functions to rotate header on a page (sort like a slideshow of headers)
 */

var slideshows = new Object();

function runHeader() {
	startSlideshow(document.getElementById('headerslides'));
}

function runSlogans() {
	startSlideshow(document.getElementById('contentRight'));
}

// Returns the height of the intro
function startSlideshow( el ) {

	// Get all H! headers in element
	var headers = el.getElementsByTagName( 'h1' );

	// Save slideshow to global array
	elid = el.id;
	slideshows.elid = 0;

	// hide all elements to start with
	hideElements ( headers );

	// Show first slide
	slideGo( el , 0 );

	// Interval to show next
	if( headers.length > 1 ) setInterval( "slideNext('" + el.id + "')" , 5000 );
}

// Loop throug all elements and set them to display none
function hideElements ( el ) {
	for ( var i=0; i < el.length; i++ ) el[i].style.display = 'none';
}

// Function to go to any element of slideshow
function slideGo( el , i ) {
	var headers = el.getElementsByTagName( 'h1' );
	var total = headers.length;
	slideshows.elid = i % total;
	hideElements( headers );
	headers[slideshows.elid].style.display = 'block';
}

// Function to go to next element of slideshow
function slideNext( elid ) {
	slideGo( document.getElementById(elid) , slideshows.elid+1 );
}

// Function to go to previous element of slideshow
function slidePrevious( el ) {
	slideshows[el.id] = slideshows[el.id]-1;
}
