$(document).ready(function(){

  $('#banner-links a').css('opacity', 0.01);
  
  $('#vypis_bytu tr').mouseover(function() {
    if ($(this).hasClass("even") || $(this).hasClass("odd"))
      $(this).addClass("hover");
  }, function(){
    $(this).removeClass("hover");
  });  
  
  $('#vypis_bytu tr').mouseout(function() {
    $(this).removeClass("hover");
  });  
  
//   $("#vypis_bytu tr").hover(function(){
//     if ($(this).hasClass("even") || $(this).hasClass("odd"))
//       $(this).addClass("hover");
//   }, function(){
//     $(this).removeClass("hover");
//   });

  $("#start-tabs").tabs();
  $("#startovaci-byty tbody tr:odd").addClass('odd');
  $("#startovaci-byty tbody tr td").click(function() { 
    var href = $(this).parent().children('td:last-child').children('a').attr('href'); 
    window.location.href = href; 
  });

  //$("#startovaci-byty tbody tr td").parent().children('td:last-child').children('a').attr('href');
  
  $("#vypis_bytu tr").click(function(){
    if (typeof($(this).children("td:first").children("a:first").attr("href")) != 'undefined')
      location.href = $(this).children("td:first").children("a:first").attr("href");
  });
  
  //alert('wtf');
  $(".polaroid img").css({ opacity: 0.7 });
  $(".polaroid a").hover(function() {
    $(this).children('img').css({ opacity: 1.0 });
  }, function() {
    $(this).children('img').css({ opacity: 0.7 });
  });
  
  $('.novinka-front').click(function () {
    var url = $(this).children("div").children("div.right").children("a").attr("href");
//    alert (url);
    if (url) {
      $(this).css('cursor', 'pointer');
      window.location = url;
    }
  });
  
  /* bubble banners on homepage */
  if ($('#bubble-banner').length){

    $('#bubble-banners-cover').find('div:first-child').show();

    /*$('#bubble-banners-cover').cycle({
        speed:  2000,
        pager:  '#bubble-banners-slider-cover',
    });*/

    var cycleInterval;
    var changeHandler = function(e){
      
      clearInterval(cycleInterval);
      if (!$(this).hasClass('active')){
        e.preventDefault(e);
      }

      $('#bubble-banners-cover div').removeClass('active').fadeOut(1500);
      $('#bubble-banners-slider-cover a').removeClass('active');
      
      var bubbleId = $(this).attr('class');
      $('#'+bubbleId).addClass('active').fadeIn(1500);
      $(this).addClass('active').fadeIn(1500);

    }

    var actives = {
      activeBubble : $('#bubble-banners-cover div.active'),
      activeTab : $('#bubble-banners-slider-cover a.active')
    }

    var nextBubble = function() {
      $.each(actives, function(key, val) {
        val.removeClass('active');
        var next = val.next();

        if (!next.length) {
          next = val.siblings().first();
        }
        
        next.addClass('active').fadeIn(1500);
        actives[key] = next;

      });
    }

    $('#bubble-banners-slider a').click(changeHandler);
    cycleInterval = setInterval(nextBubble, 5500);

  }
  
  
});


$(function() {
	$('.fotolightbox, a.lightbox, .kontakt-mapa').lightBox({
   fixedNavigation:true,
   imageLoading: 'http://www.geosan-development.cz/js/lightbox-jquery/images/lightbox-ico-loading.gif',
   imageBtnClose: 'http://www.geosan-development.cz/js/lightbox-jquery/images/lightbox-btn-close.gif',
   imageBtnPrev: 'http://www.geosan-development.cz/js/lightbox-jquery/images/lightbox-btn-prev.gif',
   imageBtnNext: 'http://www.geosan-development.cz/js/lightbox-jquery/images/lightbox-btn-next.gif'
  });
});

$(document).ready(function(){
  $('#newsCycle').cycle('fade');
});
