var Hover = function(config){
	this.events = new EventManager();
	this.cb = new ContentBuffer();
	this.serializer = new Serializer();
}

Hover.prototype.Init = function(config){
	this.Purge();
	this.config = config;
	
	this.container = Element.create('div', {id:'hover', style:'height:'+(config.height)+'px'}, null);
	//this.titleBar = Element.create('div', {id:'hoverTitleBar'}, config.titleContent, this.container);
	this.inner = Element.create('div', {id:'hoverInner'}, null, this.container);
	this.content = Element.create('div', {id:'hoverContent'}, config.content, this.inner);
	
	if(config.position == 'top'){
		this.pointer = Element.create('div', {id:'hoverGapTop'}, null, this.container);
	}else if(config.position == 'right'){
		this.container.style.padding = '0px';
		this.pointer = Element.create('div', {id:'hoverGapTop'}, null, this.container);
	}
	
	this.mouseout = this.events.add({element:this.container, type:'mouseout', handler:this.Hide, context:this});
	this.mouseover = this.events.add({element:this.container, type:'mouseover', handler:this.Over, context:this});
}

Hover.prototype.Purge = function(){
	if(this.container){
		this.Destroy();
	}
}

Hover.prototype.Show = function(e, el){
	var pos = Element.getXY(el);
	var originalPos = Element.getXY(el);
	var size = Element.getSize(el);
	
	if(this.config.position == 'top'){
		pos.y = pos.y  - this.config.height;
		
		if(pos.x + (this.config.width / 2) + 5 >= document.body.clientWidth){
			if(window.event){
				pos.x = document.body.clientWidth - (this.config.width + 5);
			}else{
				pos.x = document.body.clientWidth - (this.config.width + 5);
			}
			
		}else{
			pos.x = Math.round((pos.x + (size.width / 2)) - (this.config.width / 2));
		}
	}else if(this.config.position == 'right'){
		pos.x = pos.x + size.width;
	}
	
	this.content.style.height = config.height - 10 + 'px';
	
	this.pointer.style.width = '13px';
	this.pointer.style.position = 'absolute';
	this.pointer.style.left = ((originalPos.x - 18)) + 'px';
	//this.pointer.style.marginTop = '-1px';
	
	this.container.style.zIndex = 9999999999;
	this.container.style.display = 'block';
	this.container.style.width = d.yX + 'px';
	
	document.body.appendChild(this.container);
}

Hover.prototype.Hide = function(e, el){
	this.timeout =  window.setTimeout('h.Destroy()', 500);
}

Hover.prototype.Destroy = function(e, el){
	Element.removeChildNodes(this.container);
	Element.remove(this.container);
	
	this.mouseout.removeAllElements();
	this.mouseover.removeAllElements();
	
	this.container = false;
	
	window.clearTimeout(this.timeout);
	this.timeout = false;
	
	toolbox.enableInfoDiv = true;
}

Hover.prototype.Over = function(e, el){
	window.clearTimeout(this.timeout);
	this.timeout  = false;
}

var h = new Hover();

function HideHover(e, el){
	h.Hide(e, el);
}

function CreateHover2(e, el, content, width, height, timeout, searchTerm, numItems){
	config = {};
	config.elSize = Element.getSize(el);
	config.elPos = Element.getXY(el);
	//config.titleContent = numItems + ' Stor' + ((numItems > 1) ? 'ies' : 'y');
	config.width = 684;
	config.height = 90;
	config.position = 'top';
	
	content = unescape(content + '<div class="clear"></div>');
	config.content = content;
	
	h.Init(config);
	h.Show(e, el);
	toolbox.infoDiv.style.visibility = 'hidden';
	toolbox.enableInfoDiv = false;
}