/* Copyright 2006 Kalifiye.net */
	var page = {
		getSize : function(){
			var _window = {'width' : 0, 'height' : 0};

			if(self.innerHeight){
				_window.width	= self.innerWidth;
				_window.height	= self.innerHeight;
			}
			else if(document.documentElement && document.documentElement.clientHeight){
				_window.width	= document.documentElement.clientWidth;
				_window.height	= document.documentElement.clientHeight;
			}
			else if(document.body){
				_window.width	= document.body.clientWidth;
				_window.height	= document.body.clientHeight;
			}

			return _window;
		},

		getScroll : function(){
			var _window = {'X' : 0, 'Y' : 0};
			
			if (typeof window.pageYOffset == "number"){
				_window.X = window.pageXOffset;
				_window.Y = window.pageYOffset;
			}
			else if(document.documentElement && document.documentElement.scrollTop){
				_window.X = document.documentElement.scrollLeft;
				_window.Y = document.documentElement.scrollTop;
			}
			else if(document.body && document.body.scrollTop){
				_window.X = document.body.scrollLeft;
				_window.Y = document.body.scrollTop;
			}
			else if(window.scrollY){
				_window.X = window.scrollX;
				_window.Y = window.scrollY;
			}
			
			return _window;
		}
	};
	
	var ToolTip = {
		tooltip 	: null,
		timer 		: null,
		offX  		: 0,
		offY 		: 0,
		params		: {},
		
		create 			: function(){
			this.tooltip 				= document.createElement('DIV');
			this.tooltip.id 			= 'fafi_tooltip';
			this.tooltip.style.position	= 'absolute';
			
			document.body.appendChild(this.tooltip);
		},
		
		show 			: function(e, options){
				if(!this.tooltip) this.create();
				
				this.params = options;
				if(this.params){				
					if(this.tooltip.onmouseout == null) this.tooltip.onmouseout = this.mouseOutCheck;
					if(this.tooltip.onmouseover == null) this.tooltip.onmouseover = this.clearTimer;

					if(typeof this.params.page != 'undefined')
						this.xhr();
					else
						this.tooltip.innerHTML = this.params.content;

					this.position(e);
				}
		},
		
		hide 			: function(){	
				this.clearTimer();
			
				if(this.tooltip){
					this.timer = setTimeout("ToolTip.tooltip.style.display = 'none'", 300);
				}
		},
		
		position 		: function(e){
			if (!e) var e = window.event;
			
			var x = e.pageX ? e.pageX : e.clientX + page.getScroll().X;
			var y = e.pageY ? e.pageY : e.clientY + page.getScroll().Y;
				x += this.offX;
				y += this.offY;
	
			this.tooltip.style.left = x +'px';
			this.tooltip.style.top 	= y +'px';
			
			this.timer = setTimeout("ToolTip.tooltip.style.display = 'block'", 300);
		},
		
		mouseOutCheck 	: function(e){
			if (!e) var e = window.event;
			
			var reltg = (e.relatedTarget) ? e.relatedTarget : e.toElement;
			if((this.tooltip != reltg) && !ToolTip.contained(reltg)) ToolTip.hide();
		},
		
		contained 		: function(Node){
			if(!Node) return;
			
			while(Node = Node.parentNode){
				if(Node == ToolTip.tooltip) return true;
			}
			
			return false;
		},
		
		clearTimer		: function(){
			if(ToolTip.timer) clearTimeout(ToolTip.timer);
		},
		
		xhr : function(){
			ToolTip.tooltip.innerHTML = '';
			
			if(!_indicator){
				var _indicator = document.createElement('DIV');
					_indicator.id = 'fafi_tooltip_indicator';
					_indicator.style.display = 'none';
					_indicator.innerHTML = '<img src="images/indicator.gif" align="absmiddle">&nbsp;';
					_indicator.innerHTML += '<strong style="color:#666;font-size:10px">Veriler Yükleniyor. Lütfen Bekleyiniz...</strong>';
					
				ToolTip.tooltip.appendChild(_indicator);
			}
				
			Ajax.Responders.register({
				onCreate 	: function(){
					_indicator.style.display = 'block';
				},
				
				onComplete 	: function(){
					_indicator.style.display = 'none';
				}
			});
			
			new Ajax.Request(ToolTip.params.page, {
				method : 'get',
				asynchronous : true,
				evalScripts: true,
				onSuccess : function(res){
					ToolTip.tooltip.innerHTML = decodeURIComponent(res.responseText);
				},
				
				onFailure : function(res){
					ToolTip.tooltip.innerHTML = '<span style="color:#f00">Error ' + res.status + ' -- ' + res.statusText +'<\/span>';
				}
			});
		}
	};