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: 'icon iExternal',
    titleAppend:   ' [odkaz na jiný web]'
  },
  init: function()
  {
    $('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()
  {
    $('a[href^="http"]:not([href*='+window.location.host+'])').each(
      function()
      {
        $(this).click(
          function()
          {
            // ulozime do GA
            if(typeof(pageTracker)=='object')
            {
              pageTracker._trackPageview($(this).attr('href').replace(/(http|https):\/\//, '\/out\/' ) );
            }
          }
        );
      }
    );
  }
};

var filter = {
  init: function()
  {
    $('#filter select').change(
      function()
      {
        $(this).parent().parent().submit();
      }
    );
  }
};

var filled = {
  init: function()
  {
    $('.checkFill input.empty').focus(
      function()
      {
        $(this).removeClass('empty');
      }
    );
    $('.checkFill input.text').blur(
      function()
      {
        if ( !$(this).attr('value') )
        {
          $(this).addClass('empty');
        }
      }
    );
  }
};

var ffound = {
  config: {
    id: '#fundFounding',
    items: '.items',
    item: '.item',
    clickable: '.stepCount',
    content: '.content',
    contentDest: '#ffText',
    selectedClass: 'selected'
  },
  
  init: function(){
    if(!$(ffound.config.id).length) return false;
    $(ffound.config.id).find(ffound.config.clickable).click(function(){
      ffound.select($(this));
      return false;
    });
    ffound.select( $(ffound.config.id).find(ffound.config.clickable).eq(0).click() );
  },
  
  select: function(el)
  {
    var item = el.parents(ffound.config.item);
    var items = $(ffound.config.item);
    var contentSource = item.find(ffound.config.content);
    var contentDest = $(ffound.config.id).find(ffound.config.contentDest);
    items.removeClass(ffound.config.selectedClass);
    item.addClass(ffound.config.selectedClass);
    contentDest.html(contentSource.html());
  }
}

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

  $('#page').prepend('<a href="#content" accesskey="0" class="forBlind">Přejít na obsah<'+'/a>');
  Cufon.replace('.cufon, #homepage .wsw h2' );
  inputValue.init();
  customLightbox.init();
  externalLinks.init();
  trackLinks.init();
  filter.init();
  filled.init();

  // tabs
  $('ul.tabs' ).tabs('.tab' ).history();

  $('table tr:odd').addClass('odd');
  $('table tr:even').addClass('even');

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

});

