var blank = {
  config:
  {
    wrapperId: '#wrapper'
  },
  init: function()
  {
    if(!$(this.config.wrapperId).length) return false;
  }
}

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

//find max value in array
var max = function(array)
{
  var mxm = array[0];
  for (i = 0; i < array.length; i++) 
  {
    if (array[i] > mxm) 
    {
      mxm = array[i];
    }
  }
  return mxm;
 };

//preloader of images
var preloader = {
  load: function(source)
  {
    var key = this.images.length;
    this.images[key] = new Image();
    this.images[key].src = source;
  },
  images: new Array()
}

//auto rollovers
var imageHover = {
  elementsFilter: '*[src*=but_]',
  replaceSrcNormal: '.png',
  replaceSrcHover:  '_hover.png',
  init: function()
  {
    if(!$(this.elementsFilter).length) return false;
    $(this.elementsFilter).each(function(key){
      imageHover.images[key] = new Image();
      imageHover.images[key].src = $(this).attr('src').replace(imageHover.replaceSrcNormal,imageHover.replaceSrcHover);
      if(imageHover.isLoaded(imageHover.images[key]))
      {
        $(this).hover(
          function(){ $(this).attr('src',$(this).attr('src').replace(imageHover.replaceSrcNormal,imageHover.replaceSrcHover)); },
          function(){ $(this).attr('src',$(this).attr('src').replace(imageHover.replaceSrcHover,imageHover.replaceSrcNormal)); }
        );
      }
    });
  },
  isLoaded: function(el)
  {
     if (!el.complete) {
        return false;
     }
     if (typeof el.naturalWidth != "undefined" && el.naturalWidth == 0) {
        return false;
     }
     return true;
  },
  images: new Array()
}

var autoTableHover = {
  config:
  {
    table: '.autoHover',
		hoverClass: 'hover'
  },
	settings:
	{
		rowClick: false
	},
  init: function(settings)
  {
    if(!$(this.config.table).length) return false;
		this.settings = settings;
		$(this.config.table+' tr').hover(function(){ $(this).addClass(autoTableHover.config.hoverClass); },function(){ $(this).removeClass(autoTableHover.config.hoverClass); })
		if(this.settings.rowClick)
			$(this.config.table+' tr').each(function(){ $(this).children().css('cursor','pointer').click(function(){ window.location = $(this).parent().find('a').get(0).href }) })
  }
}

// pridat stranku do zaloziek
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;
}
/*
<a href="#" onclick="return AddFavorite(this,'http://<?=$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].($_GET['lang']?'?lang='.$_GET['lang']:'')?>','Energy 21 - <?=$title?>');">Přidat do oblíbených</a>
*/

var customLightbox = {
  config: 
  { 
    overlayBgColor:'#000',
    imageLoading:'/images/lightbox-ico-loading.gif',
    imageBtnPrev:'/images/lightbox-btn-prev.gif',
    imageBtnNext:'/images/lightbox-btn-next.gif',
    imageBtnClose:'/images/lightbox-btn-close.gif',
    imageBlank:'/images/lightbox-blank.gif',
    txtImage:'Obrázek:<br />',
    txtOf:'z'
  },
  init: function()
  {
    $('a[rel=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
  }
}

//--------------------------------------------------------------------------

$(document).ready(function() {     

  customLightbox.init();
  
})
