                /* $Id: jquery.popup.js 67 2008-01-22 08:54:37Z Bolik@xjgc.com $ NS. Pauli Edition*/

(function($)
    
 {
  function Popupper(el, content) {
    this.input = $(el);
    this.popupContent = content;

    this.bindMethodsToObj("show", "hide", "hideIfClickOutside", "hideIfFocusOutside");
    this.build();
    this.show();
  };
  
  Popupper.prototype = {
    build: function() {       
        
      this.popupController = $('<div class="popupController"></div>').append(this.ClearController); 
      this.popupContent = $('<div class="popupContent"></div>').append(this.popupContent); 
     
      this.popupPanel = this.rootLayers = $('<div class="popupperPanel"></div>')
        .css({ display: "none", position: "absolute", zIndex: 100 })
        .append(this.popupController, this.popupContent)
        .appendTo(document.body);
      
      if ($.browser.msie && $.browser.version < 7) {
        this.ieframe = $('<iframe class="popupPanel_ieframe" frameborder="0" src="#"></iframe>')
          .css({ position: "absolute", display: "none", zIndex: 100 })
          .insertBefore(this.popupPanel);
        this.rootLayers = this.rootLayers.add(this.ieframe);
      };
      
      $("a", this.popupContent).click(this.bindToObj(function(event) {  
        if($(event.target).attr("href") != "")
            window.open($(event.target).attr("href"));
        this.hide();
        return false;
      }));
    },

    show: function(event) {
      this.setPosition();
      this.rootLayers.css("display", "block");
      this.input.unbind("focus", this.show);
      $(document.body).click(this.hideIfClickOutside);
      this.input.focus(this.hideIfFocusOutside);        
    },

   hideFormElements: function()
   {
        var drInfants = document.getElementById('divInfantsSelect');
        drInfants.style.visibility="hidden";
   },
   
   showFormElements: function()
   { 
        var drInfants = document.getElementById('divInfantsSelect');            
        drInfants.style.visibility = "visible";
   },
   checkBrws: function()
    {    
                var ie = navigator.appVersion;
        	     
                if (ie.indexOf("MSIE 6") != -1 || ie.indexOf("MSIE 5") != -1 || ie.indexOf("MSIE 4") != -1){
	                 return true;
	            } else {
	                return false;
	            }
   },
    
    hide: function() {
      this.rootLayers.css("display", "none");      
      $(document.body).unbind("click", this.hideIfClickOutside);            
//      this.unbind("focus", this.hideIfFocusOutside);
//      this.focus(this.show);
    },
    
    hideIfClickOutside: function(event) {
      if (event.target != this.input[0] && !this.insideSelector(event)) {
        this.hide();        
      };
    }, 
    
    hideIfFocusOutside: function(event) {
      if (event.target != this && !this.insideSelector(event)) {
        this.hide();
      };
    }, 
     
    setPosition: function() {
      var offset = this.input.offset();
      this.rootLayers.css({
        top: offset.top + this.input.outerHeight(),
        left: offset.left
      });
      
      if (this.ieframe) {
        this.ieframe.css({
          width: this.popupPanel.outerWidth(),
          height: this.popupPanel.outerHeight()
        });
      };
    },  
     
    insideSelector: function(event) {
      var offset = this.popupPanel.offset();
      offset.right = offset.left + this.popupPanel.outerWidth();
      offset.bottom = offset.top + this.popupPanel.outerHeight();
      
      return event.pageY < offset.bottom &&
             event.pageY > offset.top &&
             event.pageX < offset.right &&
             event.pageX > offset.left;
    },
    
    
    bindToObj: function(fn) {
      var self = this;
      return function() { return fn.apply(self, arguments) };
    },
    
    bindMethodsToObj: function() {
      for (var i = 0; i < arguments.length; i++) {
        this[arguments[i]] = this.bindToObj(this[arguments[i]]);
      };
    } 
    
  };

  $.fn.popupper = function(content) {
    return this.each(function() { 
      new Popupper(this, content); 
    });
  };
})(jQuery);



