/**
 * Handels the rondel on the home.
 *
 * @copyright	Daniel Lehmann, DreamMedia, Berlin, Germany (www.dreammedia-bny.com)
 * @author		Daniel Lehmann <code@dreammedia-bny.com>
 * @version		1.0
 * @date        07.06.2011
 */

(function() {
	
	var rondel;
	var overlay = new Array();
	
	new StartUp(init);
	
	/**
	 * Initialises the rondel.
	 **/
	function init() {
		
		var rondel_div = document.getElementById("rondel");
		rondel_div.onmouseover = onMouseOver;
		rondel_div.onmouseout = onMouseOut;
		
		document.getElementById("window1").onclick = onClick;
		document.getElementById("window2").onclick = onClick;
		document.getElementById("window3").onclick = onClick;
		document.getElementById("overlay").onclick = onClick;
		
		var slots = new Array();
		slots.push(document.getElementById("window1"));
		slots.push(document.getElementById("window2"));
		slots.push(document.getElementById("window3"));
		
		rondel = new SlotMachine(slots);
		rondel.chance = 100;			// the chance to win. in this case always
		rondel.min_rotations = 2;		// the minimum on rotations until the slot stops
		rondel.max_rotations = 5;		// the maximum on rotations until the slot stops
		
		// the groups of images
		rondel.addGroup(group("gfx/home/badewannen_1.jpg", "gfx/home/badewannen_2.jpg", "gfx/home/badewannen_3.jpg"));
		rondel.addGroup(group("gfx/home/heizkoerper_1.jpg", "gfx/home/heizkoerper_2.jpg", "gfx/home/heizkoerper_3.jpg"));
		rondel.addGroup(group("gfx/home/tapete_1.jpg", "gfx/home/tapete_2.jpg", "gfx/home/tapete_3.jpg"));
		rondel.addGroup(group("gfx/home/naturstein_1.jpg", "gfx/home/naturstein_2.jpg", "gfx/home/naturstein_3.jpg"));
		rondel.addGroup(group("gfx/home/stuff_1.jpg", "gfx/home/stuff_2.jpg", "gfx/home/stuff_3.jpg"));
		
		defineOverlay('braun fehrentz besitzt über 8 Jahre Erfahrung und einen exzellenten Ruf im Bäderbau.');
		defineOverlay('Profitieren Sie von unseren Konzepten und Produkten zum Leben und Wohnen.');
		defineOverlay('Freuen Sie sich auf schönste Materialien und Gestaltungslust von Meisterhand.');
		
		rondel.init(onImagesLoaded);
		setOverlay(0);
		
	}
	
	/**
	 * Creates a image group for the rondel.
	 *
	 * @param	path_1		the path to the first image
	 * @param	path_2		the path to the second image
	 * @param	path_3		the path to the third image
	 * @return	array
	 **/
	function group(path_1, path_2, path_3) {
		
		var image_1 = new Image();
		image_1.src = path_1;
		
		var image_2 = new Image();
		image_2.src = path_2;
		
		var image_3 = new Image();
		image_3.src = path_3;
		
		var group = new Array();
		group.push(image_1);
		group.push(image_2);
		group.push(image_3);
		
		return group;
		
	}
	
	/**
	 * Defines the content of an overlay.
	 * The order of the defined overlays has to be the same as the defined groups of the rondel.
	 *
	 * @param	text	the text of the overlay
	 **/
	function defineOverlay(text) {
		
		var new_overlay = new Array();
		new_overlay["text"] = text;
		
		overlay.push(new_overlay);
		
	}
	
	/**
	 * Sets the content of an overlay.
	 *
	 * @param	index	the index of the defined overlay (its order number starting at 0)
	 **/
	function setOverlay(index) {
		
		if (index <= overlay.length) document.getElementById("overlaybody").innerHTML = overlay[index]["text"];
		
	}
	
	/**
	 * All images got loaded and the rondel got initialised.
	 **/
	function onImagesLoaded(rondel) {
		
		rondel.start(onRondelFinished);
		
	}
	
	/**
	 * The rondel finished rotating.
	 **/
	function onRondelFinished(rondel) {
		
		setOverlay(rondel.getPositions()[0]);
		
	}
	
	/**
	 * Mouse hovers over the rondel.
	 **/
	function onMouseOver() {
		
		document.getElementById("overlay").style.visibility = "visible";
		
	}
	
	/**
	 * Mouse left the rondel area.
	 **/
	function onMouseOut() {
		
		document.getElementById("overlay").style.visibility = "hidden";		
		
	}
	
	/**
	 * The rondel got clicked.
	 **/
	function onClick() {
		rondel.start(onRondelFinished);
	}
	
})();

