$(document).ready(function(){

  $("#datepicker").datepicker();


  if ( $(".lightbox").length )
  {
    $(".lightbox").lightbox({fitToScreen: false});
  }

  /*
  alert( $('#center').css('padding-top').substring(0,2) );
  alert ( $('#columns').outerHeight() + ' ' + $('#left').outerHeight() + ' ' + $('#center').outerHeight() + ' ' + $('#right').outerHeight() );
  alert ( $('#columns').outerHeight() + ' ' + $('#left').innerHeight() + ' ' + $('#center').innerHeight() + ' ' + $('#right').innerHeight() );
  alert ( $('#columns').outerHeight() + ' ' + $('#left').height() + ' ' + $('#center').height() + ' ' + $('#right').height() );
  height = Math.max( $('#left').outerHeight(), $('#center').outerHeight(), $('#right').outerHeight() );
  */
  
  height = $('#columns').outerHeight();
  $('#left').css('height', height);
  $('#right').css('height', height);

  /* TODO: why it does not work with $('#center').bind */
  $(window).bind('resize', function(e){
      height = $('#columns').outerHeight();
      $('#left').css('height', height);
      $('#right').css('height', height);
  });

  /*
  Per ora non serve il center.
  $('#center').css('height', height - $('#center').css('padding-top').substring(0,2) - $('#center').css('padding-bottom').substring(0,2) ); 
  */


   /* IE CSS FIX CON JS */
   if( $.browser.msie )
   {
     $('p + p').css( 'margin-top', '5px' );
     $('table + p').css( 'margin-top', '5px' );
   }


    if ($(".cerca_e_prenota_news .class_event.view_line").length > 0)
    {

        var newsitems;
        var curritem=0;
        var iPause=0;
        var tickerSelector = ".cerca_e_prenota_news .class_event.view_line";

        function ticknews() {
            if (iPause==0){
                $(".class_event.view_line:eq("+curritem+")").fadeOut("slow");
                curritem = ++curritem%newsitems;
                delay = 500;
                var start = new Date().getTime();
                while (new Date().getTime() < start + delay);
                $(".class_event.view_line:eq("+curritem+")").fadeIn("slow");
            }
        }

        newsitems = $(tickerSelector).hide().hover(
            function(){
                $(this).addClass("hovered");
                iPause=1;
            },
            function(){
                $(this).removeClass("hovered");
                iPause=0;
            }
        ).filter(":eq(0)").show().add(tickerSelector).size();

        setInterval(ticknews,5000); //time in milliseconds
    }

});
