var tmpIdLieu;
var tmpIdLieuOut;
var timerLieu = null;
var timerLieuClosing = null;
jQuery(document).ready(function(){
    $(".map").hide();
    $("#programme-pager").PDPager();
    $("#archives-pager").PDPager({selectedClass:'archives-menu-select'});
    prepareProg();
    selectBestDate();
    
    $(".lieu-detail").hide();
    
    if (showAffiche)
    {
      $("#affiche").PDWindow();
    }
    $(window).resize();
    
    /*$("#agenda li img").mouseenter(
      function () {
        $(this).animate({width: $(this).width() + 40}, 100);
      }
    );
    $("#agenda li img").mouseout(
      function () {
        $(this).animate({width: $(this).width() - 40}, 100);
      }
    );*/
    
    $("#background-image").bind('load', function () {
        $(window).resize();
        $(this).fadeIn(4000);
    })
    
    $("#background-image").hide().attr('src', backgroundSrc);
    
    $("#background-image").PDBackgroundImage();
    $(".lieu, li[lieu-id]").hover(
        function () {
        var lieuId = tmpIdLieu = $(this).attr("lieu-id");
        if (tmpIdLieu == tmpIdLieuOut)
            clearTimeout(timerLieuClosing);
        clearTimeout(timerLieu);
        timerLieu = setTimeout(function () {
            $("#contenu-infos li[lieu-id="+lieuId+"] .lieu-container").animate({'opacity': '0.8', 'backgroundColor':'#FFFFFF'}, 400);
            $("#contenu-infos li[lieu-id="+lieuId+"] .lieu-detail").slideDown();
        }, 300);
        //$("#contenu-infos li[lieu-id!="+lieuId+"]").fadeTo('fast', 0.6);
        },
        function () {
        var lieuIdClosing = tmpIdLieuOut = $(this).attr("lieu-id");
        if (tmpIdLieu == tmpIdLieuOut)
            clearTimeout(timerLieu);
        //clearTimeout(timerLieuClosing);
        timerLieuClosing = setTimeout(function () {
            $("#contenu-infos li[lieu-id="+lieuIdClosing+"] .lieu-detail").slideUp();
            $("#contenu-infos li[lieu-id="+lieuIdClosing+"] .lieu-container").animate({'opacity': '1', 'backgroundColor':'#E5DFE1'}, 400);
        }, 310);
        //hideLieu(lieuId);
        
        }
    );
  }
);

function showLieu() {
    
}

function hideLieu() {
}

function selectBestDate()
{
  $('#agenda > li.current-date-marker').click();
}

function prepareProg(){
  $("#agenda > li").click(agendaJourneeClick);
  
  $("#programme-pager li.lieu > h1, #archives-pager li.lieu > h1").click(function () {
   var cMap = $(this).next();
   if (cMap.is(":visible"))
   {
     cMap.slideUp();
   }
   else
   {
        $(cMap).css('width', $(cMap).prev().width() + 33);
        var h = $(cMap).parent().height() - $(cMap).prev().height();
        if ( h > 150)
            h = 150;
        $(cMap).css('height', h);
        $(".map:visible").slideUp();
     cMap.slideDown(
       function ()
       {
         if (map[$(cMap).attr("id")] == null)
           newGMap($(cMap).attr("id"), $(cMap).attr("map-address"))
       }
     );
   }
 });
  
}
function agendaJourneeClick()
{
    $("#agenda > li > img.img-deselect").fadeTo('fast', '1');
    $("#agenda > li.pager-menu-item-selected > img.img-deselect").fadeTo('fast', '0');
    
  /*$("#agenda > li").fadeTo('fast', 0.8);
  $("#agenda > li.pager-menu-item-selected").fadeTo('fast', 1);*/
}



