/**
 * Stavební poradna
 *
 * @vesrion SVN:$Id$
 * @author Mishal.cz <mishal at mishal dot cz>
 * 
 */


var jsEnabled = document.getElementsByTagName && document.createElement && document.createTextNode && document.documentElement && document.getElementById;

if(jsEnabled) {
  // Global Killswitch on the <html> element
  $(document.documentElement).addClass('js');
}

$(document).ready(function() {
  
  /*
  var sidebarHeight = $('#sidebar-wrapper').outerHeight();
  var contentHeight = $('#content-wrapper').outerHeight();


  if(contentHeight < sidebarHeight)
  {

    setTimeout(function()
    {
      $('#content').height(sidebarHeight + 25);
    }, 100);
  }  
  */
 
  var currentImage = 0;
  var imageCount = $("#reference ul li").each(function()
  {
    var that = $(this);
    that.hide();
    var img  = that.find('img');    
    var alt = img.attr('alt');
    if(alt)
    {
      that.append(alt);
    }
  }).size();

  $("#reference ul li:eq("+currentImage+")").show();

  setInterval(rotate, 3500); // time in milliseconds
  
  function rotate()
  {    
    var old_image = currentImage%imageCount;
    var new_image = ++currentImage%imageCount;
    $("#reference ul li:eq(" + old_image + ")").fadeOut("slow", function() {
      $("#reference ul li:eq(" + new_image + ")").fadeIn("slow");
    });    
  }

  $('a[rel^="photo"]').prettyPhoto(
    { theme: 'light_square', showTitle: $(this).hasClass('title') ? true : false, opacity: 0.60 }
  );

  // hover over certificates
  $('ul.certifikaty li a').hover(function()
  {
    var href = $(this).attr('href');    
    $('p.certifikaty a[href='+ href+'] img').addClass('over');
  },
  function()
  {
    var href = $(this).attr('href');
    $('p.certifikaty a[href='+ href+'] img').removeClass('over');
  });

});
