/*
 * MappaTo JavaScript Library v1.0.0
 * http://www.comune.torino.it/
 * Copyright (c) 2009 Comune di Torino
 * Module licensed under GNU Affero GPL licenses.
 * http://www.gnu.org/licenses/agpl.html
 * Date: 2009
 */
function CalendarAction()
{
	this.containerCanali = null;
	this.currentIconMenuActions = null;
	this.currentIconMenuActionsRow = null;
	this.eventi = null;
	this.timer = 20;
	this.show = function(ev, obj)
	{
		//objLibs.printMsgBox("***********************");
		//objLibs.printMsgBox("clickH3 - start");
		
		if(!objLibs.isObj(obj)) obj = this;
		if(objLibs.isObj(obj))
		{
			//objLibs.printMsgBox('showIcon: '+obj.id);
			objCalendarAction.currentIconMenuActionsRow = document.getElementById(obj.id.replace("modifica","menumodifica"));
			if(objLibs.isObj(objCalendarAction.currentIconMenuActionsRow))
			{
				//if(objLibs.isObj(objFade))
					//objFade.runFadeIn(objCalendarAction.currentIconMenuActionsRow);
				//else
					objCalendarAction.currentIconMenuActionsRow.style.display = "block";
			}
		}
		//objLibs.printMsgBox("clickH3 - end");
		return false;
	};
	this.hidden = function(ev, obj)
	{
		//objLibs.printMsgBox("***********************");
		//objLibs.printMsgBox("clickH3 - start");
		if(objLibs.isObj(objCalendarAction.currentIconMenuActionsRow))
		{
			//if(objLibs.isObj(objFade))
				//objFade.runFadeOut(objCalendarAction.currentIconMenuActionsRow);
			//else
				objCalendarAction.currentIconMenuActionsRow.style.display = "none";
		}
		objCalendarAction.currentIconMenuActionsRow = null;
		//objLibs.printMsgBox("clickH3 - end");
		return false;
	};
	this.showIcon = function(ev, obj)
	{
		if(!objLibs.isObj(obj)) obj = this;
		if(objLibs.isObj(obj))
		{
			objCalendarAction.hiddenAll();
			//objLibs.printMsgBox('showIcon: '+obj.id);
			if(obj.id.indexOf('checkContainer') >= 0)
				objCalendarAction.currentIconMenuActions = document.getElementById(obj.id.replace("checkContainer","modifica"));
			else
				objCalendarAction.currentIconMenuActions = document.getElementById(obj.id.replace("linkChannel","modifica"));
			//objLibs.printMsgBox('objCalendarAction.currentIconMenuActions.id: '+objCalendarAction.currentIconMenuActions.id);
			objCalendarAction.currentIconMenuActions.onmouseover = objCalendarAction.show;
			if(objLibs.isObj(objCalendarAction.currentIconMenuActions))
			{
				//if(objLibs.isObj(objFade))
					//objFade.runFadeIn(objCalendarAction.currentIconMenuActions);
				//else
					objCalendarAction.currentIconMenuActions.style.display = "block";
			}
			else
				objCalendarAction.currentIconMenuActions = null;
		}
		//objLibs.printMsgBox("clickH3 - end");
		return false;
	};
	this.hiddenIcon = function(ev, obj)
	{
		if(objLibs.isObj(objCalendarAction.currentIconMenuActions))
		{
			//if(objLibs.isObj(objFade))
				//objFade.runFadeOut(objCalendarAction.currentIconMenuActions);
			//else
				objCalendarAction.currentIconMenuActions.style.display = "none";
		}
		objCalendarAction.currentIconMenuActions = null;
		return false;
	};
	this.hiddenAll = function()
	{
		if(objLibs.isObj(objCalendarAction.currentIconMenuActionsRow))
			objCalendarAction.hidden(null,null);
		if(objLibs.isObj(objCalendarAction.currentIconMenuActions))
			objCalendarAction.hiddenIcon(null, null);
	};
	this.initEvents = function()
	{
		if(objLibs.isObj(objCalendarAction.eventi))
		{
			objCalendarAction.eventi.onmouseover = objCalendarAction.hiddenAll;
			objCalendarAction.eventi.onfocus = objCalendarAction.hiddenAll;
		}
		if(objLibs.isObj(objCalendarAction.containerCanali))
		{
			//objCalendarAction.containerCanali.onmouseout = objCalendarAction.hidden
			var allChilds = objCalendarAction.containerCanali.getElementsByTagName("div");
			for (var i=0; i < allChilds.length; i++)
			{
				var currChild = allChilds.item(i);
				if(currChild.className == 'menumodificaSJ')
				{
					currChild.className = 'menumodifica';
					currChild.style.display = 'none';
				}
			}
			var allChilds = objCalendarAction.containerCanali.getElementsByTagName("a");
			for (var i=0; i < allChilds.length; i++)
			{
				var currChild = allChilds.item(i);
				if(currChild.id.indexOf('linkChannel') >= 0)
				{
					currChild.onmouseover = objCalendarAction.showIcon;
					currChild.onfocus = objCalendarAction.showIcon;
					objCalendarAction.currentIconMenuActions = document.getElementById(currChild.id.replace("linkChannel","modifica"));
					objCalendarAction.hiddenIcon(null, null);
				}
			}
			var allChilds = objCalendarAction.containerCanali.getElementsByTagName("span");
			for (var i=0; i < allChilds.length; i++)
			{
				var currChild = allChilds.item(i);
				if(currChild.id.indexOf('checkContainer') >= 0)
				{
					currChild.onmouseover = objCalendarAction.showIcon;
					currChild.onfocus = objCalendarAction.showIcon;
					objCalendarAction.currentIconMenuActions = document.getElementById(currChild.id.replace("checkContainer","modifica"));
					objCalendarAction.hiddenIcon(null, null);
				}
			}
		}
	};
	this.init = function()
	{
		this.containerCanali = document.getElementById("containerCanali");
		this.eventi = document.getElementById("eventi");
		this.initEvents();
	};
}

/* Initialize CalendarAction sigleton */
function initCalendarAction()
{
	objCalendarAction = new CalendarAction();
	objCalendarAction.init();
}

function initCalendarActionOnLoad()
{
	if (typeof oldOnLoadCalendarAction == 'function') oldOnLoadCalendarAction();
	initCalendarAction();
}

/* Var sigleton instance*/
var objCalendarAction;

/* Event initialize */
var oldOnLoadCalendarAction;
if (typeof window.onload == 'function') 
	oldOnLoadCalendarAction = window.onload;
window.onload = initCalendarActionOnLoad;
