var Popup = Class.create();
Popup.prototype = {
	initialize: function(element, div, tmpBase) {
		this.element      = $(element);
		this.div     = $(div);
		this.tmpBase = tmpBase;

		this.show_timer = null;

		// hide the tool-tip by default
		this.div.hide();

		this.eventMouseOver = this.showPopup.bindAsEventListener(this);
		this.eventMouseOut   = this.hidePopup.bindAsEventListener(this);

		this.registerEvents();
	},

	destroy: function() {
		Event.stopObserving(this.element, "mouseover", this.eventMouseOver);
		Event.stopObserving(this.div, "mouseout", this.eventMouseOut);
	},

	registerEvents: function() {
		Event.observe(this.element, "mouseover", this.start_show_timer.bindAsEventListener(this));
		Event.observe(this.element, "mouseout",this.start_hide_timer.bindAsEventListener(this));
		Event.observe(this.element, "mouseout",this.stop_show_timer.bindAsEventListener(this));
		Event.observe(this.div, "mouseover", this.stop_hide_timer.bindAsEventListener(this));
		Event.observe(this.div, "mouseout",this.start_hide_timer.bindAsEventListener(this));
	},

	showPopup: function(event){
		//Event.stop(event);
		this.stop_hide_timer(event);

		//Element.setStyle(this.element.childElements()[0], {background:'url(images/header_tab_hover.jpg)'});
		Element.setStyle(this.element.childElements()[0], {color:'#FFF'});
		new Element.show(this.div);

	},



	hidePopup: function(event){
		
		
		//Element.setStyle(this.element.childElements()[0], {background:'url(images/header_tab.jpg)'});
		Element.setStyle(this.element.childElements()[0], {color:'#000'});
		
		new Element.hide(this.div);
	},

	start_show_timer: function(event) {
		this.show_timer = setTimeout(this.showPopup.bind(this, event), 200);
		
	},

	stop_show_timer: function(event) {
		if (this.show_timer) {
			clearTimeout(this.show_timer);
			this.show_timer = null;
		}
	},start_hide_timer: function(event) {
		this.stop_hide_timer(event);
		this.hide_timer = setTimeout(this.hidePopup.bind(this, event), 200);
	},

	stop_hide_timer: function(event) {
		if (this.hide_timer) {
			clearTimeout(this.hide_timer);
			this.hide_timer = null;
		}
	}

}

