
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);   
   } 
   
  
  /* 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();
    	show_flashs();
  }
  
  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=jQuery('<img class="excelsos_overlay" style="position:absolute;top:0;left:0;width:100%;height:200%;" src="excelsos_box_overlay.png"/>');
        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();
               });
        jQuery(overlay).bind("click",function() {
	        	jQuery("[class='excelsos_overlay']").remove();
	        	jQuery("[class='excelsos_box']").remove();
	        	show_flashs();
        });
        
        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() {
        excelsosBox('a[xplugin="excelsos_box"]');
   }
   
   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();
        }        
    }
 
 
   $(document).ready(function() {  
   	activate_excelsos_box(); 
   })