/**
 * Created by JetBrains PhpStorm.
 * User: Dmitriy
 * Date: 25.08.11
 * Time: 21:16
 * To change this template use File | Settings | File Templates.
 */
function staticHover()
{
	this.position="top_left";
	this.hover=false;
	this.hideOut=false;
	this.inited=false;

	var self=this;

	this.uninit=function(jq)
	{
		this.hover.unbind("mouseenter");
		this.hover.unbind("mouseleave");
		jq.die("mouseenter");
		jq.die("mouseleave");
		this.inited=false;
	};
	this.init=function(jq)
	{
		if(!$("#staticHover").length)
			$("body").append('<div id="staticHover" class="dn pa"></div>');

		this.hover=$("#staticHover");

		this.hover.mouseenter(function(){
			self.hmEnter();
		});
		this.hover.mouseleave(function(){
			self.hmLeave();
		});

		jq.live("mouseenter",function(){
			self.mEnter($(this));
		});
		jq.live("mouseleave",function(){
			self.mLeave($(this));
		});
		this.inited=true;
	};
	this.toggle=function(jq)
	{
		if(this.inited)
			this.uninit(jq);
		else
			this.init(jq);
	};
	this.lockIt=function(jq)
	{
		var off=jq.offset();
		switch(this.position)
		{
			case "bottom_left":
				this.hover.css({
					left:off.left,
					top:off.top+jq.height()+parseInt(jq.css("padding-top"))+parseInt(jq.css("padding-bottom")),
					display:"block"
				});
			break;
			case "top_left":
				//alert($("body").height()-off.top);
				this.hover.css({
					left:off.left,
					bottom:($("body").height()-off.top),
					display:"block"
				});
				//alert(this.hover.attr("style"));
			break;
		}
	};
	this.unlockIt=function()
	{
		this.hover.html("").attr("style","");
	};
	this.clearTm=function()
	{
		if(this.hideOut)
		{
			clearTimeout(this.hideOut);
			this.hideOut=false;
		}
	};
	this.hmEnter=function()
	{
		this.clearTm();
	};
	this.hmLeave=function()
	{
		this.hideOut=setTimeout(function(){
			self.unlockIt();
		},10);
	};
	this.mEnter=function(jq)
	{
		this.clearTm();
		this.lockIt(jq);
		//this.hover.html(jq.find(".staticHover").html());
		var c=jq.find(".staticHover").clone();
		c.removeClass("dn");
		this.hover.html("").append(c);
		//.appendTo(this.hover);
	};
	this.mLeave=function(jq)
	{
		this.hideOut=setTimeout(function(){
			self.unlockIt();
		},10);
	};
}

$(function(){
	/*var sh=new staticHover();
	sh.init($(".blogItem "));*/
});
