﻿function fixAcordion() {
  if ($('#MenuLeft ul').hasClass('HotelsMenu') == false) {
    $('#MenuLeft ul.M0 > li').each(function() {
      $(this).css('display', 'block');
      if ($(this).find('ul').length) {
        $(this).find('li').each(function() {
          $(this).parent('ul').css('margin-left','10px');
          $(this).find('a').css({
            'text-transform':'normal',
            'font-weight':'normal'
          });
          $(this).slideDown();
        });
      }
    }); 
    $('#MenuLeft li.L2_Active').css('display', 'block');
  }
} 
function CheckFooterActive() {
  if ($('#FooterLeft .L3_Active')) {
    $('#FooterLeft .L3_Active').children('ul').stop(true,true).slideDown('slow');
    if ($('#FooterLeft .L4_Active')) {
      $('#FooterLeft .L4_Active').children('ul').stop(true,true).slideDown('slow');
     if ($('#FooterLeft .L5_Active')) {
        $('#FooterLeft .L5_Active').children('ul').stop(true,true).slideDown('slow');
      }
    }
  }
}

/* helpdeskStart - nuno.b - 09/01/2012 @ 12:13 (Alterar o tempo de abertura do menu, agora está 1000 milisecs.- estava 250 e 500) #4775 */

function addAcordion() {
  if ($('#topLeft ul.HotelsMenu').length) {
    $('#topLeft ul.HotelsMenu li.L4,#topLeft ul.HotelsMenu li.L4_Active').bind('mouseenter',function(e) {
      $(this).find('ul').stop(true,true).slideDown('slow');
    }).bind('mouseleave', function () {
      $(this).not('.L4_Active').find('ul').delay(1000).slideUp('slow');
    });
  }
  else {
  if ($('#topLeft ul li.L4').length == 0) {
    $('#topLeft li.L3').each(function() {
      $(this).addClass('L5').removeClass('L3');
      $(this).css('margin-left','8px');
    });
    $('#topLeft li.L3_Active').each(function() {
      $(this).addClass('L5_Active').removeClass('L3_Active');
      $(this).css('margin-left','8px');
    });
    $('#topLeft ul li.L2').addClass('L3').removeClass('L2');
    $('#topLeft ul li.L2_Active').addClass('L3_Active').removeClass('L2_Active');
      $('#topLeft ul li.L3').bind('mouseenter',function(e) {
/*          $(this).find('ul').stop(true,true).slideDown('slow');*/
          $(this).find('ul').css('display', 'inline');
      }).bind('mouseleave', function () {
        $(this).find('ul').delay(1000).slideUp('slow');
      });
    }
    else {
      $('#topLeft ul li.L4').addClass('L5').removeClass('L4').css({'margin-left':'10px'});
      $('#topLeft ul li.L4_Active').addClass('L5_Active').removeClass('L4_Active').css({'margin-left':'10px'});
      $('#topLeft ul li.L3').addClass('L4').removeClass('L3');
      $('#topLeft ul li.L3_Active').addClass('L4_Active').removeClass('L3_Active');
      $('#topLeft ul li.L2').addClass('L3').removeClass('L2');
      $('#topLeft ul li.L2_Active').addClass('L3_Active').removeClass('L2_Active');
    /*  $('#topLeft ul.M3').each(function() {
        $(this).css({
          'height': $(this).height() + 'px'
        });
      });*/
      if ($('#FooterLeft').length) {
        $('#topLeft ul.M0 li').bind('mouseenter',function(e) {
          $(this).children('ul').stop(true,true).slideDown('slow');
        }).bind('mouseleave', function () {
          $(this).find('ul').not('.M0').delay(1000).slideUp('slow');
          CheckFooterActive();
        });
        $('#topLeft ul.M0 li').not('.L4_active').trigger('mouseleave');
      }
      else {
        $('#topLeft ul li.L4').bind('mouseenter',function(e) {
          $(this).find('ul').stop(true,true).slideDown('slow', function() {
            $(this).height((parseInt($(this).find('li').size()) * 21));
          });
        }).bind('mouseleave', function () {
          $(this).find('ul').not('.M2').delay(1000).slideUp('slow');
        });
      }
    }
  }
  if ($('#topLeft ul li.L2').length || $('#topLeft ul li.L2_Active').length) {
    if ($('#topLeft ul .L5').length == 0) {
      $('#topLeft ul li.L2,#topLeft ul li.L2_Active').bind('mouseenter',function(e) {
        $(this).find('ul').stop(true,true).slideDown('slow');
      }).bind('mouseleave', function () {
        $(this).not('.L2_Active').find('ul').not('.M2').delay(1000).slideUp('slow');
      });
    }
  }
  if ($('.HotelsHighMenu').length) {
    $('.HotelsMenu li').css('display', 'block');
    $('.HotelsHighMenu li').hover(
      function () {
        $(this).delay(1000).find('ul').slideDown('slow');
      }, 
      function () {
        $(this).find('ul').not('ul.HotelsHighMenu, .L2_Active ul').slideUp('slow');
      }
    );
    $('.HotelsHighMenu .HotelsMenu').css('display','none');
  }
  if ($('#LeftMenuContentor ul')) {
    $('#LeftMenuContentor ul').trigger('mouseleave');
  }
}
$(function() {
  if ($(".PortugalAcordion .ChildrenAcordion").length) {
    $('.ChildrenAcordion li').bind('mouseenter',function(e) {
      var containerToSlide = $(this).find('table.Slider');   
      $('.ChildrenAcordion table.Slider').not(containerToSlide).stop(true,true).animate({
        "opacity":"hide"
      },{ queue:false, duration:1000 });
      containerToSlide.delay(1000).animate({
        "opacity":"show"
        },{ queue:false, duration:1000 });
      }).bind('mouseleave', function () {
        var containerToSlide = $(this).find('table.Slider'); 
        containerToSlide.stop(true,true).animate({
         "opacity":"hide"
       },{ queue:true, duration:1000 });
    });
    $('.ChildrenAcordion li').each(function() {
      $(this).trigger('mouseenter').trigger('mouseleave');
    });
  }
});
/* helpdeskEnd */

