function log(e)
{
  //return false;
  if(typeof(console)=='object') console.log(e);
  //else alert(e);
};

function AddFavorite(linkObj,addUrl3,addTitle3)
{
  if (document.all && !window.opera)
  {
    window.external.AddFavorite(addUrl3,addTitle3);
    return false;
  }
  else if (window.opera && window.print)
  {
    linkObj.title = addTitle3;
    return true;
  }
  else if ((typeof window.sidebar == 'object') && (typeof window.sidebar.addPanel == 'function'))
  {
    window.sidebar.addPanel(addTitle3,addUrl3,'');
    return false;
  }
  window.alert('Po potvrzení stiskněte CTRL-D,\nstránka bude přidána k Vašim oblíbeným odkazům.');
  return false;
}

var customLightbox = {
  config:
  {
    overlayBgColor:'#000',
    overlayOpacity:0.8,
    fixedNavigation:false,
    imageLoading:'/images/lightbox-ico-loading.gif',
    imageBtnPrev:'/images/lightbox-btn-prev.png',
    imageBtnNext:'/images/lightbox-btn-next.png',
    imageBtnClose:'/images/lightbox-btn-close.png',
    imageBlank:'/images/transparent.png',
    containerResizeSpeed:200,
    txtImage:'Obrázek:<br />',
    txtOf:'z',
    keyToClose:'c',
    keyToPrev:'p',
    keyToNext:'n',
    imageArray:[],
    activeImage:0
  },
  init: function()
  {
    $('a[rel=lightbox],a.lightbox').lightBox(customLightbox.config); //only rel="lightbox"

    var lbRels = new Array();  var thisRel = ''; var trIsIn = false;
    $('a[rel*="lightbox["]').each(function(){ //each rel="lightbox[..."
        thisRel = $(this).attr('rel').replace('lightbox[','').replace(']',''); //curren rel
        for(i=0; i<lbRels.length; i++) { //find if is not yet in array of rels
          if(thisRel == lbRels[i]) trIsIn = true;
          else trIsIn = false;
        }
        if(!trIsIn) lbRels[lbRels.length] = $(this).attr('rel').replace('lightbox[','').replace(']',''); //not i array of rels => store rel
    });
    for(i=0; i<lbRels.length; i++) { $('a[rel="lightbox['+lbRels[i]+']"]').lightBox(customLightbox.config); } //each unique rel => apply lightbox
  }
};

var inputValue = {
  config:
  {
    rememberEl: '.rememberValue',
    values:     new Array()
  },
  init: function()
  {
    $(inputValue.config.rememberEl).focus(
      function()
      {
        inputValue.name = $(this).attr('name');
        if ( inputValue.config.values[inputValue.name] == null || $(this).val() == inputValue.config.values[inputValue.name] )
        {
          inputValue.config.values[inputValue.name] = $(this).val();
          $(this).val('').addClass('filled');
        }
      }
    ),
    $(inputValue.config.rememberEl).blur(
      function()
      {
        inputValue.name = $(this).attr('name');
        if( $(this).val() == '' )
        {
          $(this).val(inputValue.config.values[inputValue.name] ).removeClass('filled');
        }
      }
    )
  }
};

var externalLinks = {
  config:
  {
    externalClass: 'external',
    titleAppend:   ' [odkaz na jiný web]'
  },
  init: function()
  {
    $('#main a[href^="http"]:not([href*='+window.location.host+']), #menu a[href^="http"]:not([href*='+window.location.host+'])').each(
      function()
      {
        $(this).addClass(externalLinks.config.externalClass ).attr('title', $(this).attr('title') + externalLinks.config.titleAppend );
      }
    );
  }
};

var trackLinks = {
    init: function(){
        if (typeof(t) == 'object') {
            pageTracker = t;
        }
        if (typeof(pageTracker) == 'object') {
            $('a[href^="http"]:not([href*=' + window.location.host + '])').each(function(){
                $(this).click(function(){
                    pageTracker._trackPageview($(this).attr('href').replace(/(http|https):\/\//, '\/out\/'));
                });
            });
        }
    }
};

var language = {
    init: function(){
      $('#language .hide').hide();
      $('#language').hover(
        function()
        {
          $(this).children('.hide').fadeIn();
        },
        function()
        {
          $(this).children('.hide').fadeOut();
        }
      )
    }
};

/**
 * Ajax popup/splash engine
 */
function popupX (code, cname, expires, setconclick, callback)
{
  var self = this;
   
  // Requirements check  
  if(setconclick && typeof($.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 = $(code);
    
    // wait for document ready
    $(document).ready(function() {
      
      // append popup
      $('body').append(self.data);
      // store placeholder        
      self.placeholder = self.data;
      // bind actions
      self.placeholder.find('a').click(function(){
        self.hide();
        if($(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)
    {
      $.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(! ($.browser.msie && parseInt($.browser.version) <= 6 )) return false;
    self.fixedSelects = $('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);
};


/*******************************************
 *
 *  on DOM ready
 *
 ********************************************/
$(document).ready(function() {

  $('#page').prepend('<a href="#content" accesskey="0" class="forBlind">Přejít na obsah<'+'/a>');
//   Cufon.replace('.cufon' );
  Cufon.replace('.cufon, .wsw h2, .wsw h3, .wsw h4, .wsw h5', { hover: true });

  inputValue.init();
  customLightbox.init();
  externalLinks.init();
  trackLinks.init();
  language.init();

  // scroll
  $('div.scrollable').before('<a class="prevPage browse png"><!-- --></a>').after('<a class="nextPage browse png"><!-- --></a>')
  .scrollable({
      size: 1,
      speed: 500
  })
  .circular()
  //.mousewheel({speed: 100 } )
  .autoscroll({
      interval: 5000,
      steps: 1,
      autoplay: true,
      autopause: true
  });

  try
  {
    DD_belatedPNG.fix('.png');
  }
  catch(e){}

});

