
	var excelsos_mouseX=0;
	var excelsos_mouseY=0;
	 
	jQuery(document).ready(function(){
	   jQuery().mousemove(function(e){
	        excelsos_mouseX=e.pageX;
	        excelsos_mouseY=e.pageY;      
	   });    
	})

function center(container,content) {
     var left= (screen.width - $(content).attr("width")) / 2;
     var top = (screen.height - $(content).attr("height")) / 2;
     $(container).css("left",left);
     $(container).css("top",top);   
   } 
 
 function center_alone(content) {
  var left= (screen.width-300) / 2;
  var top = (screen.height-300) / 2;
  
  $(content).css("left",left);
  $(content).css("top",top);   
} 
  
  /* NO FUNCIONA EN IE.
   * experimental! detecta si estamos en un frame o no.
   */ 
  function isInsideFrame() {
    return window.parent.innerWidth!=window.innerWidth;
  }
 
 
  function excelsosBoxHide() {    
    window.parent.excelsosBoxHideDirect();
 }
 
 
 
 function show_flashs() {
    var IE=(typeof window.ActiveXObject != 'undefined');
    if (IE) {
          jQuery("object").show();
    } else {
          jQuery("embed").show();
    }
}

function hide_flashs() {
    var IE=(typeof window.ActiveXObject != 'undefined');
    if (IE) {
          jQuery("object").hide();
    } else {
          jQuery("embed").hide();
    }
}

 
/**
 * atencion, solo se llama al hacer apretar la cruz.
 */  
  function excelsosBoxHideDirect() {      		
    	jQuery("body").find("[class='excelsos_overlay']").remove();
    	jQuery("body").find("[class='excelsos_box']").remove();    	
    	jQuery("body").find("#excelsos_box_light").hide();
    	
    	show_flashs();
  }
  
  function excelsos_box_message(message) {
  		window.parent.excelsos_box_light_show_direct(message);
  }
  
  function excelsos_box_light_show_direct(message) {  
      var box=$("#excelsos_box_light");      

		if ($(message).size()>0) {
      	$(box).find("#excelsos_box_light_text").html(message);
     	} else {
     		$(box).find("#excelsos_box_light_text").text(message);
     	}
      
      
      $("body").append(create_overlay());
      
      var box=$(box).remove().clone();
      $("body").append(box);
      $(box).show();
      center_alone(box);           
  }
    
 function create_overlay() {
 		var overlay=jQuery('<img class="excelsos_overlay" style="position:absolute;top:0;left:0;width:100%;height:200%;" src="excelsos_box_overlay.png"/>');

       jQuery(overlay).bind("click",function() {
	        	jQuery("[class='excelsos_overlay']").remove();
	        	jQuery("[class='excelsos_box']").remove();
	        	jQuery("body").find("#excelsos_box_light").hide();
	        	show_flashs();
        });
        
		return overlay;
 }
    
  function excelsos_box_show_direct(url,width,height) {        
		var rootdoc=parent.document.body;

        //quitamos todos los boxes que hayan    
      	jQuery("body").find("[class='excelsos_overlay']").remove();
    	jQuery("body").find("[class='excelsos_box']").remove();
   	      	  
   	    //agregamos el box
        
        var overlay=create_overlay();
        newFrameStyle="position:absolute;";
        
        var newFrame=jQuery('<div class="excelsos_box" style="'+newFrameStyle+'"><center><img style="position:relative;" class="loading" src="excelsos_box_loading.gif" alt="loading"/></center><iframe style="background-color: transparent;" src="'+url+'" frameborder="0" allowtransparency="true" transparency="true" marginheight="0" marginwidth="0"></iframe><br/></div>');		
        jQuery(newFrame).find("iframe").attr("width",width);
        jQuery(newFrame).find("iframe").attr("height",height);
        
        var extras="";
        var IE=(typeof window.ActiveXObject != 'undefined');
        
        
        jQuery(newFrame).prepend('<img class="excelsos_box_close" style="position:relative;'+extras+'display:none;cursor:pointer;" src="excelsos_box_close.gif" alt="close" onclick="excelsosBoxHide();"></img><br/>');
        
        center(jQuery(newFrame),jQuery(newFrame).find("iframe"));        
                
        jQuery(newFrame).find("iframe")
            .bind("load",function(){                
                jQuery(this).parent().find("[class='loading']").remove();
                jQuery(this).parent().find("[class='excelsos_box]").show();
                jQuery(this).parent().find("[class='excelsos_box_close']").show();
               });
                
        /*$(newFrame).css("top","0px");
        $(newFrame).css("left","0px");*/
        
        hide_flashs();
	    jQuery("body").append(overlay);        
        jQuery("body").append(newFrame);            						        
        
  }
  
  
    function excelsos_box_show(url,width,height) {        
         if (!isInsideFrame()) {                        
            window.parent.excelsos_box_show_direct(url,width,height);
        } else {        
            window.parent.excelsos_box_show_direct(url,width,height);
        }
    }
    
    
    function excelsosBoxClick(e) {        
        var xwidth=jQuery(e).attr("xwidth");
        var xheight=jQuery(e).attr("xheight")
        var xurl=jQuery(e).attr("xurl");                    
        
        if (!isInsideFrame()) {
            window.parent.excelsos_box_show_direct(xurl,xwidth,xheight); 
        } else {        
            window.parent.excelsos_box_show_direct(xurl,xwidth,xheight);
        }
    }
    
    function excelsosBox(e) {        
        jQuery(e).each(function() {        
            if ($(this).attr("xplugged")!="true") {
                $(this).get(0).onclick=function(){excelsosBoxClick(this);};
                $(this).attr("xplugged","true");
            }
         });
    }
  
   function activate_excelsos_box() {
   		$("body").append('<div id="excelsos_box_light"><table id="excelsos_box_light_table"><tr><td><span id="excelsos_box_light_text">esto es un mensaje</span></td></tr></table></div>');
        excelsosBox('a[xplugin="excelsos_box"]');
   }
   
   function excelsos_box_enter_loading() {
   	var loading=jQuery('<div style="position:absolute;"  class="loading"><center><img src="excelsos_box_loading.gif" alt="loading"/></center></div>');		
   	jQuery("body").append(loading);
   	center_alone(loading);    
   	$(loading).show(); 
   }
   
   function excelsos_box_leave_loading() {
   	jQuery("body").find("[class='loading']").remove();
   }
   
   function reload_iframe(selector) {           
        if ($(selector).get(0).contentDocument!=null) {
            $(selector).get(0).contentDocument.location.href=$(selector).get(0).contentDocument.location.href;
        } else {
            $(selector).get(0).contentWindow.location.reload();
        }        
    }
 
   jQuery(document).ready(function() {  
    	activate_excelsos_box();     
   })
