 jQuery(function($) {
   $(document).ready(buttonTip_init);
   
   
function buttonTip_init(){
    $("a.buttonPopup")
    .click(function(){buttonTip_show(this.href,this.id,this.name); return false;},function(){$('#buttonTip').remove();});
}

function buttonTip_show(url,linkId,title){
    if (document.getElementById("buttonTip")) {
		return false;
	}
  
	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 queryString = url.replace(/^[^\?]+\??/,'');
	var params = parseQuery( queryString );
	
	
	
	if(params['width'] === undefined){params['width'] = 400};
	if(params['link'] !== undefined)
	{
	    $('#' + linkId).bind('click',function(){window.location = params['link']});
	    $('#' + linkId).css('cursor','pointer');
	}
		
	var clickElementy = getAbsoluteTop('contentColumn') + 12; //set y position
	var clickElementx = getAbsoluteLeft('contentColumn') + 20; //set x position
	
	var strCloseLink = "<div style='float:right;'><a class='buttonTip_close_right' href='#' onclick=" + "$('#buttonTip').remove()" 
	                        + "; return false;'><img src='images/close_grey.gif' border='0'/></a></div>"
	
	var strBody =  "<div id='buttonTip' style='width:"
	                    + params['width']*1+"px'><div id='buttonTip_arrow_right' style='left:" 
	                        + 397 +"px'></div><div id='buttonTip_close_right'><div style='float:left; padding-top: 9px; padding-left: 5px; color: #bc34b8;'>" + title  + "</div>"
	                            + strCloseLink + "</div><div id='buttonTip_copy'><div class='buttonTip_loader'><div></div></div>";
	
	$("body").append(strBody);
	$('#buttonTip').hide();	
	$('#buttonTip').css({left: clickElementx+"px", top: clickElementy+"px"});
	$('#buttonTip').show();
	$('#buttonTip_copy').load(url);
}

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
}

function parseQuery ( query ) {
   var Params = new Object ();
   if ( ! query ) return Params; // return empty object
   var Pairs = query.split(/[;&]/);
   for ( var i = 0; i < Pairs.length; i++ ) {
      var KeyVal = Pairs[i].split('=');
      if ( ! KeyVal || KeyVal.length != 2 ) continue;
      var key = unescape( KeyVal[0] );
      var val = unescape( KeyVal[1] );
      val = val.replace(/\+/g, ' ');
      Params[key] = val;
   }
   return Params;
}

function blockEvents(evt) {
              if(evt.target){
              evt.preventDefault();
              }else{
              evt.returnValue = false;
              }
}
 });
