// ----- POPUP START ---------------------------------------------------

// Prehod jQuery do nekonfliktniho rezimu, aby mohl byt spolu s jinymi frameworky
jQuery.noConflict();

/**
 * Ajax popup/splash engine
 */
function popupX (code, cname, expires, setconclick, callback)
{
  var self = this;

  // Requirements check
  if(setconclick && typeof(jQuery.cookie) != 'function')
  {
    if(typeof(console)=='object')
    {
      console.error('popupX: Cannot find jQuery.cookie plugin!');
    }
    return false;
  }

  /**
   * Constructor
   */
  self.init = function(code, cname, expires, setconclick, callback){

    self.expires = expires;
    self.setconclick = setconclick;
    self.cname = cname;
    self.data = jQuery(code);
    // wait for document ready
    jQuery(document).ready(function() {
        //rozbal_bnp();
      // append popup
      jQuery('body').append(self.data);
      // store placeholder
      self.placeholder = jQuery('#popPlaceholder');//self.data;
      // bind actions
      self.placeholder.find('a').click(function(){
        self.hide();
        if(jQuery(this).attr('href')=='#')
        {
          return false;
        }
        else
        {
          return true;
        }
      });
      self.show();
      // call callback
      if(typeof callback == 'function')
      {
        callback();
      }

    });
  };

  /**
   * Set cookie to displayed state
   */
  self.setDisplayedCookie = function()
  {
    if(self.setconclick)
    {
      jQuery.cookie(self.cname, true, {path:'/', expires: self.expires });
    }
  };

  /**
   * Show popup
   */
  self.show = function()
  {
    self.ie6fix();
    //self.placeholder.show();
  };

  /**
   * Hide popup
   */
  self.hide = function()
  {
    self.ie6unfix();
    self.setDisplayedCookie();
    self.placeholder.hide();
  };

  /**
   * Remove popup
   */
  self.remove = function()
  {
    var self = this;
    self.placeholder.remove();
    self.placeholder = false;
  };

  /**
   * Fix for IE6 - hide selects
   */
  self.ie6fix = function()
  {
    /*
    if(! (jQuery.browser.msie && parseInt(jQuery.browser.version) <= 6 )) return false;
    self.fixedSelects = jQuery('select:visible');
    self.fixedSelects.css('visibility', 'hidden');
    */
  };

  /**
   * Unfix for IE6
   */
  self.ie6unfix = function()
  {
    /*
    if(typeof(self.fixedSelects)!=='object') return false;
    self.fixedSelects.css('visibility', 'visible');
    */
  };

  // Initialize
  self.init(code, cname, expires, setconclick, callback);
};

// ----- POPUP END ----------------------------------------------------
