/*** Gestione pannello comandi */
var zen_CommandPanelId = "panelComandi";
aPCtime = "";
function apriPannelloComandi (e, tf) {
  	if(tf)
		Zen.UI.CommandPanel.OnMouseOut(e);
	else
		Zen.UI.CommandPanel.OnMouseOver(e);  
}

function OnPanelDown(e) {
	return Zen.UI.CommandPanel.OnMouseDown(e);
}

function scrollaPannelloComandi() {
	Zen.UI.CommandPanel.OnWindowScroll();
}

function iPannelloComandi() {
  Zen.UI.CommandPanel.Init(zen_CommandPanelId);  
}

onLoad += "iPannelloComandi();window.onscroll = new Function('scrollaPannelloComandi();');document.oncontextmenu=new Function('return false');";

/*** panelComandi open/close fieldset */
function showInfo(fieldsedContent)
{
  fieldset = fieldsedContent.parentNode.parentNode;
  if (fieldset != null)
  {
    n = fieldset.children;
    n[1].style.display = (n[1].style.display == "none")? "block": "none";
    saveCookie(fieldset.id, n[1].style.display, 0);
  }
}

/*************************************************************/
/*  Object   */
/*************************************************************/
Object.extend = function(destination, source) {
  for (property in source) {
    destination[property] = source[property];
  }
  return destination;
}

Object.extend(Array.prototype, {
  shift: function() {
    var result = this[0];
    for (var i = 0; i < this.length - 1; i++)
      this[i] = this[i + 1];
    this.length--;
    return result;
  }
});

Function.prototype.bind = function() {
  var __method = this, args = $A(arguments), object = args.shift();
  return function() {
    return __method.apply(object, args.concat($A(arguments)));
  }
}

var $A = Array.from = function(iterable) {
  if (!iterable) return [];
  else {
    var results = [];
    for (var i = 0; i < iterable.length; i++)
      results.push(iterable[i]);
    return results;
  }
}

var Zen = {
	UI : {	
		GetApplicationPath : function() {
			return !this.ApplicationPath ? "" : this.ApplicationPath == "/" ? this.ApplicationPath : this.ApplicationPath + "/";
		},
		
		GetPaginePath : function() {
			return this.GetApplicationPath() + "pagine/";
		}		
	}
}

/*************************************************************/
/*  Browser   */
/*************************************************************/
Zen.UI.Browser = {
	Init : function() {
		this.Agent = this.Detect();
	},
	IsNetscape : function() {
		return this.Agent == 'NN6' || this.Agent == 'Moz';
	},
	IsOpera : function() {
		return this.Agent == 'Op7';
	},
	IsIE : function() {
		return this.Agent.indexOf("IE") >= 0;
	},
	Detect : function() {
		var csAppName = String(navigator.appName);
		var csAppVer = String(navigator.appVersion);
		var csPlatform = String(navigator.platform);
		var csUserAgent = String(navigator.userAgent);
		var csVendor = String(navigator.vendor);
		var csProduct = String(navigator.product);
		if(csUserAgent.indexOf("Opera/7") > -1 || csUserAgent.indexOf("Opera 7") > -1)
			return "Op7";
		else if(csUserAgent.toLowerCase().indexOf("safari") > -1)
			return "Safari";
		else if(csUserAgent.indexOf("Opera") > -1)
			return "Default";	
		else if(csVendor == "Netscape6")
			return "NN6";
		else if(csProduct == "Gecko")
			return "Moz";
		else if(csAppName == "Netscape")
		{
			if(parseFloat(csAppVer) >= 4.06 && parseFloat(csAppVer) < 5)
				return "NN4";
			else
				return "Default";
		}
		else if(document.all) {
			if(csAppVer.toLowerCase().indexOf("mac")!=-1)
				return "MACIE";
			if(!document.getElementById)
				return "MSIE4";
			if(!window.createPopup)	
				return "MSIE5";		
			return "MSIE55";
		}
		else
			return "Default";
	},
	DocumentElementCount : function() {
		if(document.all && document.all.length >= 0)
			return document.all.length;
		return document.getElementsByTagName('*').length;
	}
}
Zen.UI.Browser.Init();

/*************************************************************/
/*   Panel   */
/*************************************************************/
Zen.UI.Panel = function(id) {
	this.Id = id;
	this._classes = [];
}

Zen.UI.Panel.prototype = {	
	AddClass : function(clas) {
		this._classes[this._classes.length] = clas;
		return this;
	},
	
	GetClass : function(classId) {
		for(var i = 0; i < this._classes.length; i++)
			if(this._classes[i].Id == classId)
				return this._classes[i];
		return null;		
	}	
}

/*************************************************************/
/*   Class   */
/*************************************************************/
Zen.UI.Class = function(id) {
	this.Id = id;
}

Zen.UI.Class.prototype = {	
	
}

/*************************************************************/
/*   Overflow   */
/*************************************************************/
Zen.UI.Overflow = {
	Hidden : "hidden",
	Scroll : "scroll",
	Auto : "auto" ,
	Empty : ""
}   	

/*************************************************************/
/*   Position   */
/*************************************************************/
Zen.UI.Position = function(x, y) {
	this.X = x;
	this.Y = y;
}

Zen.UI.Position.prototype = {	
	Add : function(position) {
		return new Zen.UI.Position(this.X + position.X, this.Y + position.Y);
	},	
	Sub : function(position) {
		return new Zen.UI.Position(this.X - position.X, this.Y - position.Y);
	},
	ToString : function() {
		return '[X : ' + this.X + ', Y : ' + this.Y + ']';
	}
}

/*************************************************************/
/*   Dimension   */
/*************************************************************/
Zen.UI.Dimension = function(w, h) {
	this.Width = w;
	this.Height = h;
}

Zen.UI.Dimension.prototype = {	
	Add : function(width, height) {
		return new Zen.UI.Dimension(this.Width + width, this.Height + height);
	},	
	ToString : function() {
		return '[Width : ' + this.Width + ', Height : ' + this.Height + ']';
	}
}

/*************************************************************/
/*   Rectangle   */
/*************************************************************/
Zen.UI.Rectangle = function(l, t, w, h) {
	this.Left = l;
	this.Top = t;
	this.Width = w;
	this.Height = h;
}

Zen.UI.Rectangle.prototype = {	
	Right : function() {
		return this.Left + this.Width;
	},	
	Bottom : function() {
		return this.Top + this.Height;
	},	
	ToString : function() {
		return '[Left : ' + this.Left + ', Top : ' + this.Top + ', Width : ' + this.Width + ', Height : ' + this.Height + ']';
	},
	Contains : function(position) {		
		if(position == null) 
			return false;
		if(position.X == -1 && position.Y == -1)	
			return true;
		return this.Left < position.X && position.X < this.Right() &&
			this.Top < position.Y && position.Y < this.Bottom();
	}
}

/*************************************************************/
/*   Window   */
/*************************************************************/
Zen.UI.Window = function(name) {
	this.Name = name;
	this.Url = "";	
}

Zen.UI.Window.prototype = {	
	Open : function() {
		this.Window = window.open(this.Url, this.Name, this.GetFeatures());
		return this.Window;
	},
	
	GetFeatures : function() {
		var result = '';
		if(this.Width > 0)
			result += 'width=' + this.Width + ',';
		if(this.Height > 0)
			result += 'height=' + this.Height + ',';
		if(this.Centered)	 {
			result += 'left=' + (screen.width - this.Width) / 2 + ',';
			result += 'top=' + (screen.height - this.Height) / 2 + ',';
		}			
		return result;
	}	
}

Zen.UI.Window.Self = {
	GetRectangle : function(element) {
		return new Zen.UI.Rectangle(this.GetLeft(), this.GetTop(), this.GetWidth(), this.GetHeight());
	/*
		if(Zen.UI.Browser.IsNetscape())
			return this.GetNetscapeRectangle(element);
		if(Zen.UI.Browser.IsOpera())
			return this.GetOperaRectangle(element);	
		return this.GetGenericRectangle(element);
	*/	
	},
	
	GetLeft : function() {
		return this.Filter(
			window.pageXOffset ? window.pageXOffset : 0,
			document.documentElement ? document.documentElement.scrollLeft : 0,
			document.body ? document.body.scrollLeft : 0);
	},
	
	GetTop : function() {
		return this.Filter(
			window.pageYOffset ? window.pageYOffset : 0,
			document.documentElement ? document.documentElement.scrollTop : 0,
			document.body ? document.body.scrollTop : 0);
	},
	
	GetWidth : function() {
		return this.Filter(
			window.innerWidth ? window.innerWidth : 0,
			document.documentElement ? document.documentElement.clientWidth : 0,
			document.body ? document.body.clientWidth : 0);
	},
	
	GetHeight : function() {
		return this.Filter(
			window.innerHeight ? window.innerHeight : 0,
			document.documentElement ? document.documentElement.clientHeight : 0,
			document.body ? document.body.clientHeight : 0);
	},
	
	Filter : function(n_win, n_docel, n_body) {
		var n_result = n_win ? n_win : 0;
		if (n_docel && (!n_result || (n_result > n_docel)))
			n_result = n_docel;
		return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
	},
	
	GetGenericRectangle : function(){
		var doc = window.document;
		var db = doc.body;
		if(doc.all && doc.compatMode == "CSS1Compat")
			db = doc.documentElement;	
		if(!db)	
			return new Zen.UI.Rectangle(0, 0, 0, 0);
		return new Zen.UI.Rectangle(db.scrollLeft, db.scrollTop, db.clientWidth, db.clientHeight);
	},
	
	GetNetscapeRectangle : function(element) {
		var win = self;
		var _w = win.innerWidth;
		var _dw = typeof(win.document.documentElement.offsetWidth) == 'number' ? win.document.documentElement.offsetWidth : _w + 1;
		var _h = win.innerHeight;
		var _dh = typeof(win.document.documentElement.offsetHeight) == 'number' ? win.document.documentElement.offsetHeight : _h + 1;
		
		var widthAdjusted = false;
		if(_dh > _h || element && element.Bottom() > _h) {
			_w = _w - 16;
			widthAdjusted = true;
		}		
		if(_dw > _w  || element && element.Right() > _w) {
			_h = _h - 16;		
			if(!widthAdjusted && element && element.Bottom() > _h) {			
				_w = _w - 16;
			}	
		}			
		return new Zen.UI.Rectangle(win.scrollX, win.scrollY, _w, _h);
	}, 
	
	GetOperaRectangle : function(win) {
		var win = self;
		return new Zen.UI.Rectangle(win.document.body.scrollLeft, win.document.body.scrollTop, win.innerWidth, win.innerHeight);
	}
}

/*************************************************************/
/*   MouseEvent   */
/*************************************************************/
Zen.UI.MouseEvent = function(evt) {
	this._e = evt || window.event;
}

Zen.UI.MouseEvent.prototype = {	
	GetPosition : function() {
		if(this._e.pageX != null)
			return new Zen.UI.Position(this._e.pageX, this._e.pageY);
		return new Zen.UI.Position(this._e.clientX + document.body.scrollLeft, this._e.clientY + document.body.scrollTop);
	},
	Cancel : function() {
		if(document.all) {
			if(this._e) {
				this._e.cancelBubble = true;
				this._e.keyCode = 0;
			}
		}	
		else 
		if(this._e) {
			this._e.preventDefault();
			this._e.stopPropagation();
		}
		return false;
	}
}

/*************************************************************/
/*   Element   */
/*************************************************************/
Zen.UI.Element = function(id) {
	this.Id = id;
	this.HtmlElement = document.getElementById(id);
	this.IsNull = this.HtmlElement == null;
}

Zen.UI.Element.prototype = {	
	GetPosition : function() {
		var result = new Zen.UI.Position(0, 0);
		var element = this.HtmlElement;
		while(element != null)
		{
			result = result.Add(new Zen.UI.Position(element.offsetLeft, element.offsetTop));
			element = element.offsetParent;
		}
		return result;
	}, 
	SetPosition : function(position) {
		//alert(position.ToString());
		if(position.X != null)
			this.HtmlElement.style.left = position.X + "px";
		if(position.Y != null)
			this.HtmlElement.style.top = position.Y + "px";
	},
	SetVisibility : function(visible) {
		this.HtmlElement.style.visibility = visible ? 'visible' : 'hidden';
	},
	MoveTo : function(x, y) {
		this.SetPosition(new Zen.UI.Position(x, y));
	},	
	GetDimension : function() {
		return new Zen.UI.Dimension(this.HtmlElement.offsetWidth, this.HtmlElement.offsetHeight);
	},
	KeepDimension  : function() {
		this._dimension = this.GetDimension();
	},
	RestoreDimension : function() {
		//alert(this._dimension.ToString());
		if(Zen.UI.Browser.IsNetscape())
			this.SetDimension(this._dimension.Add(-14, -14));
		else
			this.SetDimension(this._dimension);
		//alert(this.GetDimension().ToString());
	},
	SetDimension : function(dimension) {
		if(dimension.Width != null)
			this.HtmlElement.style.width = dimension.Width + "px";
		if(dimension.Height != null)
			this.HtmlElement.style.height = dimension.Height + "px";	
	},
	SetOverflow : function(overflow) {
		this.HtmlElement.style.overflow = overflow;
	},
	GetRectangle : function() {
		var position = this.GetPosition();
		var dimension = this.GetDimension();
		return new Zen.UI.Rectangle(position.X, position.Y, dimension.Width, dimension.Height);
	}, 
	Right : function() {
		return this.GetPosition().X + this.GetDimension().Width;
	},
	Bottom : function() {
		return this.GetPosition().Y + this.GetDimension().Height;
	}
}

/*************************************************************/
/*   Drag   */
/*************************************************************/
Zen.UI.Drag =  {
	Start : function(element, mousePosition, offsetPosition, moveCallback, dropCallback) {
		if(this._element && this._element.Id == element.Id)
			return;
		this._element = element;
		this._moveCallback = moveCallback;
		this._dropCallback = dropCallback;
		this._startOffset = mousePosition.Sub(this._element.GetPosition());
		this._moved = false;
		if(offsetPosition != null)
			this._startOffset = this._startOffset.Sub(offsetPosition);
		this._onmousemove = document.onmousemove;
		document.onmousemove = ZenUIDragMove;
		this._onmouseup = document.onmouseup;
		document.onmouseup = ZenUIDragDrop;
		this._onselectstart = document.onselectstart;
		document.onselectstart = new Function ("return false");
		this._ondragstart = document.ondragstart;
		document.ondragstart = new Function ("return false");
	}, 
	Move : function(evt) {				
		var mouseEvent = new Zen.UI.MouseEvent(evt);
		var currentPosition = mouseEvent.GetPosition().Sub(this._startOffset);		
		this._element.SetPosition(currentPosition);
		this._moved = true;
		if(this._moveCallback)
			this._moveCallback(evt, currentPosition);
		return mouseEvent.Cancel();	
	},
	Drop : function(evt) {
		var mouseEvent = new Zen.UI.MouseEvent(evt);
		if(this._dropCallback)
			this._dropCallback(evt, this._moved);
		this._element = null;	
		document.onmousemove = this._onmousemove;
		document.onmouseup = this._onmouseup;
		document.onselectstart = this._onselectstart;
		document.ondragstart = this._ondragstart;
		return mouseEvent.Cancel();	
	}
};

function ZenUIDragMove(evt) {
	Zen.UI.Drag.Move(evt);
}

function ZenUIDragDrop(evt) {
	Zen.UI.Drag.Drop(evt);
}

/*************************************************************/
/* CommandPanel */
/*************************************************************/
Zen.UI.CommandPanel = {
	PanelDockFloat : {
		ProcessOver : function (panelElement) {			
		}, 
		Expand : function(panelElement) {
			panelElement.SetOverflow(Zen.UI.Overflow.Empty);			
			//panelElement.RestoreDimension();						
			Zen.UI.CommandPanel.ResetPanelHeight(panelElement.Id);
		},
		Collapse : function(panelElement) {
			panelElement.SetOverflow(Zen.UI.Overflow.Hidden);			
			var height = document.getElementById('ZenLogo') ? document.getElementById('ZenLogo').offsetHeight + (Zen.UI.Browser.IsIE() ? 12 : 0) : 10;
			panelElement.SetDimension(new Zen.UI.Dimension(null, height));						
		},
		ProcessOut : function(panelElement) {			
		},
		ProcessClick : function(panelElement, expand) {
			if(expand) 
				this.Expand(panelElement);
			else	
				this.Collapse(panelElement);
		},
		Init : function(panelElement, expand, position) {
			panelElement.MoveTo(position.X, position.Y);
			this.ProcessClick(panelElement, expand);
		},	
		ProcessWindowScroll : function(panelElement) {}
	},	
	PanelDockRight : {
		ProcessOver : function (panelElement) {
			var xMax = Zen.UI.Window.Self.GetRectangle(panelElement).Right() - panelElement.GetDimension().Width;
			var sxPC = panelElement.GetPosition().X;
			if (sxPC>xMax)
				panelElement.MoveTo(xMax);
		}, 
		ProcessOut : function(panelElement) {
			//if(panelElement.GetPosition().X == -850)
			panelElement.MoveTo(Zen.UI.Window.Self.GetRectangle(panelElement).Right() - 10);			
			panelElement.MoveTo(Zen.UI.Window.Self.GetRectangle(panelElement).Right() - 10);						
		},
		ProcessWindowScroll : function(panelElement) {
			this.ProcessOut(panelElement);
		},
		ProcessClick : function(panelElement, expand) {},
		Init : function(panelElement) {
			this.ProcessOut(panelElement);
		}
	},	
	PanelDockLeft : {
		ProcessOver : function (panelElement) {
			var xMax = Zen.UI.Window.Self.GetRectangle().Left;
			var sxPC = panelElement.GetPosition().X;
			if (sxPC < xMax)
				panelElement.MoveTo(xMax);
		}, 
		ProcessOut : function(panelElement) {
			panelElement.MoveTo(Zen.UI.Window.Self.GetRectangle().Left - panelElement.GetDimension().Width + 10);			
		},
		ProcessWindowScroll : function(panelElement) {
			this.ProcessOut(panelElement);
		},
		ProcessClick : function(panelElement, expand) {},
		Init : function(panelElement) {
			this.ProcessOut(panelElement);
		}
	},	
	Init : function (panelName) {
		this._expand = true;
		this._dock = this.PanelDockRight;
		//this._dock = this.PanelDockLeft;
		this._panelElement = new Zen.UI.Element(panelName);
		if(this._panelElement.IsNull)
			return;
		this._panelElement.KeepDimension();		
		//this._panelElement.SetVisibility(true);
		this._stateContainer = document.forms[0][panelName + "_SS"];
		this.LoadState();
		this._timerState = new Zen.UI.TimerState({Interval : 30, Action : this.ProcessOver.bind(this)}, {Interval : 500, Action : this.ProcessOut.bind(this)});		
		this._dock.Init(this._panelElement, this._expand, this._currentPosition);		
	},		
	ResetPanelHeight : function (panelName) {	    		
		/*
		var totalHeight = 0;
		for (var i = 0; i < el.childNodes.length; ++i) {
			var child = el.childNodes[i];
			if (typeof(child.offsetHeight) != 'undefined')
			{
				totalHeight += child.offsetHeight;
			}
		}		
		el.style.height = totalHeight;
		*/
		if(!this._expand)
		    return;
		if(panelName == null)		
		    panelName = this._panelElement.Id;
		var el = document.getElementById(panelName);
		if(document.getElementById(panelName + "_tab"))
		    el.style.height = document.getElementById(panelName + "_tab").offsetHeight + "px";
	    setTimeout("Zen.UI.CommandPanel.ResetPanelHeight('" + panelName + "')", 300);
	},		
	OnMouseOver : function (evt) {
		if(this._timerState)
			this._timerState.OnOver(evt);
	},	
	OnMouseOut : function(evt) {
		if(this._timerState)
			this._timerState.OnOut(evt);
	}, 	
	OnWindowScroll : function() {
		if(this._panelElement.IsNull)
			return;
		this._dock.ProcessWindowScroll(this._panelElement);
	},
	ProcessOver : function() {
		this._dock.ProcessOver(this._panelElement);
	},	
	ProcessOut : function() {
		if(!Zen.UI.Browser.IsIE() || (this._timerState.MousePosition && this._timerState.MousePosition.X != -1 && this._timerState.MousePosition.Y != -1)) // dropdows
			this._dock.ProcessOut(this._panelElement);
	}, 
	OnMouseDown : function(evt) {	
		this._mouseEvent = new Zen.UI.MouseEvent(evt);
		this._mousePosition = this._mouseEvent.GetPosition();
		var shiftX = this._dock == this.PanelDockRight ? -14 : this._dock == this.PanelDockLeft ? 14 : 0;		
		Zen.UI.Drag.Start(this._panelElement, this._mousePosition, new Zen.UI.Position(shiftX, 0), this.OnPanelMove.bind(this), this.OnMouseClick.bind(this));	
		return this._mouseEvent.Cancel();	
	},
	OnMouseClick : function(evt, moved) {
		if(moved)
			return;
		this._expand = !this._expand;
		this._dock.ProcessClick(this._panelElement, this._expand);
		this.SaveState();
	},
	/*
	StartDrag : function() {
		clearInterval(this._dragTimer);	
		if(document.onmousemove == muovi)
			return;		
		var shiftX = this._dock == this.PanelDockRight ? -12 : this._dock == this.PanelDockLeft ? 12 : 0;
		this._dock = this.PanelDockFloat;
		Zen.UI.Drag.Start(this._panelElement, this._mousePosition, new Zen.UI.Position(shiftX, 0), this.OnPanelMove.bind(this));	
	},	
	*/
	OnPanelMove : function(evt, currentPosition) {
		this._dock = this.PanelDockFloat;
		if(currentPosition.X < Zen.UI.Window.Self.GetRectangle().Left + 12) {
			//Zen.UI.Drag.Drop(evt);
			this.ExpandPanel();			
			this._dock = this.PanelDockLeft;
			this._panelElement.MoveTo(Zen.UI.Window.Self.GetRectangle().Left, currentPosition.Y);
		}
		else
		if(currentPosition.X + this._panelElement.GetDimension().Width > Zen.UI.Window.Self.GetRectangle(this._panelElement).Right() - 12){
			//Zen.UI.Drag.Drop(evt);
			this.ExpandPanel();			
			this._dock = this.PanelDockRight;
			this._panelElement.MoveTo(Zen.UI.Window.Self.GetRectangle().Right(this._panelElement) - this._panelElement.GetDimension().Width, currentPosition.Y);
		}
		this._currentPosition = currentPosition;
		this.SaveState();
	}, 
	ExpandPanel : function() {
		if(this._expand)
			return;
		this._expand	= true;
		this._dock.ProcessClick(this._panelElement, true);
	},
	SaveState : function() {
		//if(!this._stateContainer)
		//	return;
		var dock = this._dock == this.PanelDockLeft ? "Left" : this._dock == this.PanelDockRight ? "Right" : "Float";
		var state = dock + ";" + (this._currentPosition ? this._currentPosition.X : "0") + ";" + (this._currentPosition ? this._currentPosition.Y : "0")+ ";" + (this._expand ? "1" : "0");
		this.SaveStateInCookie(state);
		//this._stateContainer.value = state;		
	},
	SaveStateInCookie : function(state) {
		var today = new Date();
		var expires = new Date();
		expires.setTime(today.getTime() + 1000*60*60*24*365);
		document.cookie = "Zen.CommandPanel=" + escape(state) + "; expires=" + expires.toGMTString();
	},
	LoadState : function() {
		//var state = this._stateContainer ? this._stateContainer.value : null;
		var state = this.LoadStateFromCookie(); 
		if(state == null)
			return;
		//alert(state);
		var stateArr = state.split(';');
		if(stateArr.length > 0)	 {
			this._dock = stateArr[0] == "Float" ? this.PanelDockFloat : stateArr[0] == "Left" ? this.PanelDockLeft : this.PanelDockRight;
			if(stateArr.length >= 3) 
				this._currentPosition = new Zen.UI.Position(parseInt(stateArr[1]), parseInt(stateArr[2]));						
			if(stateArr.length >= 4)	
				this._expand = stateArr[3] == "1" ? true : false;
		}
	}, 
	LoadStateFromCookie : function() {
		var search = "Zen.CommandPanel=";
		if (document.cookie.length > 0) {
			offset = document.cookie.indexOf(search);
			if (offset != -1) { 
				offset += search.length;
				end = document.cookie.indexOf(";", offset);
				if (end == -1) 
					end = document.cookie.length;
				return unescape(document.cookie.substring(offset, end));
			} 
		}
	}
}

/*************************************************************/
/*   TimerState   */
/*************************************************************/
Zen.UI.TimerState = function(over, out) {
	this._state = new Zen.UI.TimerState.Init(over, out, this.OnTimer.bind(this));
}

Zen.UI.TimerState.prototype = {	
	OnOver : function(evt) {
		this.MousePosition = new Zen.UI.MouseEvent(evt).GetPosition();
		this._state = this._state.OnOver();
	},	
	OnOut : function(evt) {
		this.MousePosition = new Zen.UI.MouseEvent(evt).GetPosition();
		this._state = this._state.OnOut();
	},	
	OnTimer : function() {
		this._state = this._state.OnTimer();
	}
}

Zen.UI.TimerState.Init = function(over, out, onTimer) {
	this._over = over;
	this._out = out;
	this._onTimer = onTimer;
}
Zen.UI.TimerState.Init.prototype = {
	OnOver : function() {
		return new Zen.UI.TimerState.WaitOver(this._over, this._out, this._onTimer); 
	},	
	OnOut : function() {
		return this;
	},
	OnTimer : function() {
		return this;
	}
}

Zen.UI.TimerState.WaitOver = function(over, out, onTimer) {
	this._over = over;
	this._out = out;
	this._onTimer = onTimer;
	this._timer = setInterval(onTimer, this._over.Interval);
}
Zen.UI.TimerState.WaitOver.prototype = {
	OnOver : function() {
		return this;
	},	
	OnOut : function() {
		clearInterval(this._timer);
		return new Zen.UI.TimerState.Init(this._over, this._out, this._onTimer);
	},	
	OnTimer : function() {
		clearInterval(this._timer);
		this._over.Action();
		return new Zen.UI.TimerState.Over(this._over, this._out, this._onTimer);
	}
}

Zen.UI.TimerState.Over = function(over, out, onTimer) {
	this._over = over;
	this._out = out;
	this._onTimer = onTimer;
}
Zen.UI.TimerState.Over.prototype = {
	OnOver : function() {
		return this;
	},	
	OnOut : function() {
		return new Zen.UI.TimerState.WaitOut(this._over, this._out, this._onTimer); 
	},	
	OnTimer : function() {		
		return this;
	}
}

Zen.UI.TimerState.WaitOut = function(over, out, onTimer) {
	this._over = over;
	this._out = out;
	this._onTimer = onTimer;
	this._timer = setInterval(onTimer, this._out.Interval);
}
Zen.UI.TimerState.WaitOut.prototype = {
	OnOver : function() {
		clearInterval(this._timer);
		return new Zen.UI.TimerState.Over(this._over, this._out, this._onTimer);		
	},	
	OnOut : function() {
		return this;		
	},	
	OnTimer : function() {
		clearInterval(this._timer);
		this._out.Action();
		return new Zen.UI.TimerState.Init(this._over, this._out, this._onTimer);
	}
}

