
$(document).ready(function(){

/* 
 * UI-Elements
 */
 
  $('#content .fg-button')
  .hover(
      function(){ 
	$(this).addClass("ui-state-hover"); 
      },
      function(){ 
	$(this).removeClass("ui-state-hover"); 
      }
  );
  
  $("#tabs").tabs({ selected: -1 });


/*
 *   OPTION Bottom Menu
 */
  $(".bottom_menu_element .fg-button").unbind('hover');
  $('.bottom_menu_element .menu_header').each(function() {$(this).show("slow"); });
  $('.bottom_menu_element .menu_content').fadeIn("slow"); // 'scale', {percent:100, origin:['left', 'top']}, 200, function() {}
  
/*
  $(".bottom_menu_element").hover(function () {
      $(this).find('.fg-button').addClass("ui-state-hover"); 
      $(this).find('.fg-button span').addClass("ui-icon-triangle-1-se").removeClass("ui-icon-triangle-1-e");
  }, function() {
      $(this).find('.fg-button').removeClass("ui-state-hover"); 
      $(this).find('.fg-button span').addClass("ui-icon-triangle-1-e").removeClass("ui-icon-triangle-1-se");
      $(this).find('.menu_content').hide(); // 'scale', {origin:['left', 'top']}, 200, function() {}
  });
*/  
  

  
/*
 *   OPTION Top Menu
 */

  $('#top_dropdown .headlink').mouseenter(function() {
    if($(this).find('ul').length > 0) {
      $('#top_menu_sub').html($(this).find('ul').html());  
    }
  });
  
  $('#top_dropdown .headlink').mouseleave(function() {
    $('#top_menu_sub li').animate({opacity:0},{duration:500});
  });
  
  $('#top_menu_sub').mouseenter(function() {
    $('#top_menu_sub li').stop().animate({opacity:1},{duration:0});
  });
  $('#top_menu_sub').mouseleave(function() {
    $('#top_menu_sub li').animate({opacity:0},{duration:500});
  });
  
  $('#top_dropdown .headlink a').click(function() {
    if($(this).parent().find('ul').length > 0) {
      return false;
    }  
  });

  $('#top_dropdown .headlink.active')
    .mouseenter()
    .unbind('mouseleave');
  $('#top_menu_sub li.active').parents().unbind('mouseleave');

/*
 *   Preload
 */

   vCycleImages = setInterval(function() {
      var bImgLoaded = true;
      var images = $("img");

      for (var i = 0; i < images.length; i++) {
         var img = images[i];
         if (img.complete == false)
            bImgLoaded = false;
      }


      if (bImgLoaded) {
        clearInterval(vCycleImages);
        if( $('#bottom_menu_wrapper').position().top + $('#bottom_menu_wrapper').outerHeight() < $(window).height() ) {
          $('#bottom_menu_wrapper').css('margin-top', ($(window).height() - $('#bottom_menu_wrapper').outerHeight() - $('#bottom_menu_wrapper').position().top ) + 'px');
        }
        $('#bottom_menu_wrapper').removeClass("hidden");
        $('#loading').remove(); 
        $('#content').css('visibility','visible'); 
      }
   }, 500);


   $('#loading').click(function() {$(this).remove();})
});


