/* Parts of the code by Codylindley.com 2006© */
/* requires span class=helpbubble elements with css: position: absolute; display: none; background-color: insertsomecolorhere;*/
/*call this at the start of the script $(document).ready(pb_init);*/
$(document).ready(pb_init);
function pb_init(){
	   $("span.helpbubble")
	   .hover(function(){pb_show(this.id,this.name)},function(){pb_hide(this.id,this.name)})
           .click(function(){return false});	   
}
function pb_show(linkId,title){
	if(title == false)title="&nbsp;";
	var de = document.documentElement;
	var w = self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
	var hasArea = w - getAbsoluteLeft(linkId);
	var clickElementy = getAbsoluteTop(linkId) - 3; //set y position
	
	var newid = 'pb_' + linkId;

	
	$('#' + newid).css('cursor','pointer');
	
	if(hasArea>((240*1)+75)){
		var arrowOffset = getElementWidth(linkId) + 11;
		var clickElementx = getAbsoluteLeft(linkId) + arrowOffset; //set x position
	}else{

		var clickElementx = getAbsoluteLeft(linkId) - ((240*1) + 15); //set x position
	}	
	/*alert('left: ' + clickElementx + ' top: ' + clickElementy + ' on id #' +newid);*/
	var elemheight = $('#'+newid).height() + 20;
	$('#'+newid).css({left: clickElementx+"px", top: clickElementy+"px"});
	$('#frhideselect').css({left: clickElementx+"px", top: clickElementy+"px", height: elemheight+"px"}); 
	$('#frhideselect').show();
	$('#'+newid).show();

}
function pb_hide(linkId,title){
	var newid = 'pb_' + linkId;
	$('#'+newid).hide();
	$('#frhideselect').hide();
}
function getElementWidth(objectId) {
	x = document.getElementById(objectId);
	return x.offsetWidth;
}

function getAbsoluteLeft(objectId) {
	// Get an object left position from the upper left viewport corner
	o = document.getElementById(objectId)
	oLeft = o.offsetLeft            // Get left position from the parent object
	while(o.offsetParent!=null) {   // Parse the parent hierarchy up to the document element
		oParent = o.offsetParent    // Get parent object reference
		oLeft += oParent.offsetLeft // Add parent left position
		o = oParent
	}
	return oLeft
}

function getAbsoluteTop(objectId) {
	// Get an object top position from the upper left viewport corner
	o = document.getElementById(objectId)
	oTop = o.offsetTop            // Get top position from the parent object
	while(o.offsetParent!=null) { // Parse the parent hierarchy up to the document element
		oParent = o.offsetParent  // Get parent object reference
		oTop += oParent.offsetTop // Add parent top position
		o = oParent
	}
	return oTop
}
