// JavaScript Document

	var interval 	= 20000; // 20 seconds
	var num_indices = 5; // 6

	function getIndex(val){

		var loader = document.getElementById("loader");
		loader.style.display = "block";

		if (val == "rand"){

			val = randomXToY(0,num_indices - 1);

		} else {

			// this means the index was explictly requested
			var but = document.getElementById("but");
			but.innerHTML = "<a href='#' onclick='butSetInterval();'>Start Slideshow</a>";

			clearInterval(siv);

		}

		var src = "/wp-content/themes/bizcast v2.0/iframes/index_" + val + ".php";

		var indices = document.getElementById("indices");
		indices.options[val].selected = true;

		var target = document.getElementById("target");
		target.style.display = "none";
		target.setAttribute("src",src);

	}

	function randomXToY(minVal,maxVal,floatVal){

		var randVal = minVal+(Math.random()*(maxVal-minVal));

		return typeof floatVal=='undefined'?Math.round(randVal):randVal.toFixed(floatVal);

	}

	function startSetInterval(){

		siv = window.setInterval("getIndex('rand')", interval);

	}

	function startSetTimeout(){
		
		// Go the first one
		getIndex("rand");

		// Wait for the given delay and then start the loop.
	 	siv = window.setTimeout("startSetInterval()", interval);

	}

	function butClearInterval(){

		var but = document.getElementById("but");
		but.innerHTML = "<a href='#' onclick='butSetInterval();'>Start Slideshow</a>";

		clearInterval(siv);
//		alert("Slideshow Stopped");

	}
	
	function butSetInterval(){

		// Go the first one
		getIndex("rand");

		var but = document.getElementById("but");
		but.innerHTML = "<a href='#' onclick='butClearInterval();'>Stop Slideshow</a>";

		siv = window.setInterval("getIndex('rand')", interval);
//		alert("Slideshow Started");

	}








