var ai;

function fadeContent(target) {
  var content = $("#main_content"+target+" .fade_in:hidden");
  if(content.length > 0) {
    $(content).eq(0).fadeIn(500);
  } else {
    clearInterval(ai);
    
    if(target) {
      setTimeout(function(){ checkHeights(target) }, 300);
    } else {
      checkHeights();
    }
  }
}



$(document).ready(function(){
  
  // Fade content
  $("#main_content img").hide();
  $("#main_content img").fadeIn(500);
  
  //ai = setInterval("fadeContent(' .first')", 200);
  //ai = setTimeout(function(){ setInterval("fadeContent(' .second')", 200) }, 150);
  //ai = setTimeout(function(){ setInterval("fadeContent(' .third')", 200) }, 300);
  
  
  $('.fadeThis').append('<span class="hover"></span>').each(function () {
	  var $span = $('> span.hover', this).css('opacity', 0);
	  $(this).hover(function () {
	    $span.stop().fadeTo(400, 1);
	  }, function () {
	    $span.stop().fadeTo(400, 0);
	  });
  });
  
  $('#showBrowsers').click(function() {
    $(this).parent().animate({height: "110px"}, 500);
    $('#floatingMenu').animate({marginTop: "10px"}, 500);
  });
  
  $("#main_content .txt a").mouseover(function(){
    $(this).stop().animate({color: "#b51800"}, 300);
  }).mouseout(function(){
	$(this).stop().animate({color: "#8a8c8e"}, 300);
  });
  
  
});

function checkHeights(target) {

  if(target == 2) {
    var first_height = $('#main_content .first').height();
    var second_height = $('#main_content .second').height();
    
    if(first_height > second_height) {
      $('#main_content .second').height(first_height);
    } else if(second_height > first_height) {
      $('#main_content .first').height(second_height);
    }
  } else if(target == 3) {
    var first_height = $('#main_content .first').height();
    var second_height = $('#main_content .second').height();
    var third_height = $('#main_content .third').height();
    
    if(first_height > second_height && first_height > third_height) {
      $('#main_content .second').height(first_height);
      $('#main_content .third').height(first_height);
    } else if(second_height > first_height && second_height > third_height) {
      $('#main_content .first').height(second_height);
      $('#main_content .third').height(second_height);
    } else if(third_height > first_height && third_height > second_height) {
      $('#main_content .third').height(third_height);
      $('#main_content .second').height(third_height);
    }
  } else {
    $('#main_content .alinea_txt').each(function(){
      var txt_height       = $(this).height();
      var img_height       = $(this).next('.img').height();
      var slideshow_height = $(this).next('.slideshow').height();
      
      if(slideshow_height > txt_height) {
        $(this).height(slideshow_height);
      } else if(txt_height < img_height) {
        $(this).height(img_height);
      }
      
    });
  }
	
}