$(window).load(function() {
    $('#header_slideshow').cycle({ fx: 'fade', speed: 1000, timeout: 5000 });   
});

$(document).ready(function(){
  
  if($('.submenu').length > 0){
    $('.submenu').each(function(){
      if($('ul', $(this)).length < 1){
        $(this).css('height','0px');
        $(this).css('line-height','0px');
        $(this).css('font-size','0px');
        $(this).css('overflow','hidden');
      }
    });
  }
  
  $('#header #multi-ddm').dropDownMenu({timer: 500, parentMO: 'multi-ddm-hover', childMO: 'multi-ddm-child-hover'});
  
  if($(".PlaceYouTubeMovie").is(':empty')) {
    $(".PlaceYouTubeMovie").hide();   
  }
});

function MenuSwitch(ClickedElement){
  var ContentDivElement    = $('.item-content');
  var Url = ClickedElement.attr('href');
  
  if(ClickedElement.hasClass('MoveMenuSub')){
    window.location.href = Url;
  } else {
    ContentDivElement.slideUp('slow', function(){
      
      window.location = Url;
    });
  }
  return false;
}

$(window).load(function() {
  if($('.item-content').length > 0){
    $('a.MoveMenu').each(function(){
      $(this).click(function(){
        return MenuSwitch($(this));
      });
    });
      
    setTimeout(function(){
      if(!bDontFold){
        CheckActiveMenu();
      }
    }, 500);
  }  
});

function CheckActiveMenu(){
  var ContentDivElement    = $('.item-content');
  var ContentElementHeight = ContentDivElement[0].scrollHeight;  
  
  if(ContentDivElement.find(".nav-item").length == 0) {
    ContentDivElement.animate({'height': ContentElementHeight + 'px',paddingTop: '10px'});                      
  } else {
     ContentDivElement.animate({'height': ContentElementHeight + 'px'});     
  }
  return true;  
}

function FetchYouTubeFile(YouTubeUrl, DivForYouTube){
  if(YouTubeUrl != ''){
    var VideoID;
    var UrlCheckResult;

    UrlCheckResult = YouTubeUrl.match("[\\?&]v=([^&#]*)");

    VideoID = ( UrlCheckResult === null ) ? YouTubeUrl : UrlCheckResult[1];
    var CorrectUrl = "http://www.youtube.com/v/"+VideoID+""; 
    
    DivForYouTube.append('<object width="450" height="300"> \
                                  <param name="movie" value="' + CorrectUrl + '"></param> \
                                  <param name="wmode" value="transparent"></param> \
                                  <embed src="' + CorrectUrl + '" type="application/x-shockwave-flash" wmode="transparent" width="180" height="300"></embed> \
                                </object> \
                                ');
  }
}
