/**
 * @author orange
 */
var Help=Class.create();
Help.current=null;
Help.showHelp=function(id){
	
};
Help.init=function(){
	helpLinks=$$(".help[rel]");
	
	
	for(var i=0, len=helpLinks.length; i<len; i++){
		new Help(helpLinks[i]);
	}
}

Help.prototype={
	id:null,
	cache:null,
	box:null,
	initialize:function(element){
		element.observe("mouseover", this.showHelp.bindAsEventListener(this));
		this.element=element;
		this.id=element.rel;
	},
	showHelp:function(){
		
		if(this.cache==null){
			new Ajax.Request('/ajax.php?op=get_help', { onComplete: this.helpResult.bind(this), parameters:"id="+this.id });
		}
		else{
			this.showBox(this.cache);
		}
	},
	helpResult:function(result){
		if(result.responseText){
			object=eval(result.responseText);
			this.cache=object;
			this.showBox(this.cache);
		}
	},
	showBox:function(text){
		if(Help.current){
			Help.current.hideHelp();
		}
		Help.current=this;
		this.box=new Element("div", {className:"help_box"});
		this.box.update(text);
		this.element.parentNode.insertBefore(this.box, this.element);
		document.observe("click", this.hideHelp.bindAsEventListener(this));
		this.timer=setTimeout(this.hideHelp.bind(this),10000);
	},
	hideHelp:function(){
		clearTimeout(this.timer);
		document.stopObserving("click");
		this.box.hide();
		id=0;
		Help.current=null;
	}
}
document.observe('dom:loaded', Help.init)
