// JavaScript Document Tooltip by Portable
$(document).ready(HC_init);

function HC_init(){
	   $("a.hcTip")
	   .hover(function(){HC_show(this,this.id)},function(){$('#HC').remove()})
           //.click(function(){return false});	   
}

function HC_show(whoIS,linkId){
var url='';
var title= false
var mustramelo=whoIS.rel
var myString = new String('red,green,blue');
var myArray = mustramelo.split(';'); 
var ancho=myArray[0];
var tioTulio=myArray[1];
mustramelo= myArray[2];
	if(tioTulio == 'sin_titulo')tioTulio="&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 queryString = url.replace(/^[^\?]+\??/,'');
	var params = parseQuery( queryString );
	if(params['width'] === undefined){params['width'] = 250};
	//alert(whoIS.ancho)
	params['width'] =ancho;
	if(params['link'] !== undefined){
	//$('#' + linkId).bind('click',function(){window.location = params['link']});
	$('#' + linkId).css('cursor','pointer');
	}
	
	if(hasArea>((params['width']*1)+75)){//style='width:"+params['width']*1+"px'
		$("body").append("<div id='HC' ><div id='HC_arrow_left'></div><div id='HC_close_left'><span>"+tioTulio+"</span><br /><span id='HC_copy'></span></div>");//right side
		var arrowOffset = getElementWidth(linkId) + 11;
		var clickElementx = getAbsoluteLeft(linkId) + arrowOffset; //set x position
	}else{ //style='width:"+params['width']*1+"px'
		$("body").append("<div id='HC'><div id='HC_arrow_right' style='left:"+((params['width']*1)+1)+"px'></div><div id='HC_close_right'><span>"+tioTulio+"</span><br /><span id='HC_copy'></span></div>");//left side
		var clickElementx = getAbsoluteLeft(linkId) - ((params['width']*1) + 15); //set x position
	}
	
	$('#HC').css({left: clickElementx+"px", top: clickElementy+"px"});
	$('#HC').show();
	//var mustramelo=whoIS.rel
	$('#HC_copy').html(mustramelo)
	
	//$('#HC_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
	//alert(objectId)
	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-60
}

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 140
}

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;
              }
}
