/**
*Anonymous function, 
*/
(function() {
	var DOM = YAHOO.util.Dom;
	var Event = YAHOO.util.Event;
	var Anim =YAHOO.util.Animation;
	YAHOO.namespace('gaia.app');

	YAHOO.gaia.app.games = function() {
	

	var elf_content= function() {

		YAHOO.gaia.app.games.showChat("elf","elf_info");
	}

	var pinball_content= function() {

		YAHOO.gaia.app.games.showChat("pinball","pinball_info");
	}
	var jigsaw_content= function() {

		YAHOO.gaia.app.games.showChat("jigsaw","jigsaw_info");
	}
	var rally_content= function() {

		YAHOO.gaia.app.games.showChat("rally","rally_info");
	}
	var slots_content= function() {

		YAHOO.gaia.app.games.showChat("slots","slots_info");
	}
	var cards_content= function() {

		YAHOO.gaia.app.games.showChat("cards","cards_info");
	}
	var word_bump_content= function() {

		YAHOO.gaia.app.games.showChat("word_bump","word_bump_info");
	}
	var fishing_content= function() {

		YAHOO.gaia.app.games.showChat("fishing","fishing_info");
	}
	var moregames_content= function() {

		YAHOO.gaia.app.games.showChat("moregames","moregames_info");
	}
	var zomg_content= function() {

		YAHOO.gaia.app.games.showChat("zomg","zomg_info");
	}
	
	/**
	* fires on mouseout,  hides the pannel and the arrow and the contents
	*/
	var games_content_out= function() {
		
		var chatBox = document.getElementById("chatBox");
		if (chatBox) chatBox.style.visibility="visible";
		var arrow = document.getElementById("arrow");
		if (arrow) {
			arrow.style.visibility="hidden";
			arrow.style.visibility="hidden";
			arrow.style.overflow="hidden";
		}
		YAHOO.gaia.app.games.destroy_pannel();
	}

	var pinball_info="pinball_info";
	var jigsaw_info="jigsaw_info";
	// Add listeners to all the list and calls the finction to disply the respective data
	Event.addListener("elf","mouseover",elf_content);
	Event.addListener("elf","mouseout",games_content_out);
	Event.addListener("pinball","mouseover",pinball_content);
	Event.addListener("pinball","mouseout",games_content_out);
	Event.addListener("jigsaw","mouseover",jigsaw_content);
	Event.addListener("jigsaw","mouseout",games_content_out);
	Event.addListener("rally","mouseover",rally_content);
	Event.addListener("rally","mouseout",games_content_out);
	Event.addListener("slots","mouseover",slots_content);
	Event.addListener("slots","mouseout",games_content_out);
	Event.addListener("cards","mouseover",cards_content);
	Event.addListener("cards","mouseout",games_content_out);
	Event.addListener("word_bump","mouseover",word_bump_content);
	Event.addListener("word_bump","mouseout",games_content_out);
	Event.addListener("fishing","mouseover",fishing_content);
	Event.addListener("fishing","mouseout",games_content_out);
	Event.addListener("moregames","mouseover",moregames_content);
	Event.addListener("moregames","mouseout",games_content_out);
	Event.addListener("zomg","mouseover",zomg_content);
	Event.addListener("zomg","mouseout",games_content_out);
	// define myPanel as a global variable, to be able to destoy the pannel created on mouseover
	var myPanel;
	return {
		// defines the panel, its configuration properties and the contents 
		init: function(append_to,default_dialog) { 	
			myPanel = new YAHOO.widget.Panel("chatBox", { width:"360px", visible:true, draggable:false, close:false, underlay:'none'});
			myPanel.setBody("<div id='dialog_active_content'></div>");
			myPanel.setFooter("<div id='arrow'><span>&nbsp;</span></div>");
			myPanel.render(append_to);
			myPanel.show;
		},
		// Displays the panel on mouseover, appends to respective div and defines it's respective contents
		showChat:function(game,temp_div){
			var pinball_info=YAHOO.util.Dom.get(temp_div).innerHTML;
			YAHOO.gaia.app.games.init(game,temp_div);
			document.getElementById("dialog_active_content").innerHTML=DOM.get(temp_div).innerHTML;
			document.getElementById("chatBox").style.visibility="visible";
			document.getElementById("arrow").style.visibility="visible";
		},
		// destroy the pannel created, to avoid the copy of the pannel being generated
		destroy_pannel:function(){
			myPanel.destroy();
		}

		};
	}();
})();
