var main = {
  soundBlocked: 0,

  event_listeners: function() {
    // dropdown-menu
    jQuery("#dropdown-menu div.menu-title").bind('mouseenter', function() {
      jQuery("#dropdown-menu div.menu-title").removeClass('current');
      jQuery("#dropdown-menu div.menu-container").css('display','none');
      jQuery(this).addClass('current');
      container = '#'+jQuery(this).attr('id')+'-container';
      jQuery(container).css('display','block');
    });
    jQuery("#dropdown-menu").bind('mouseleave', function() {
      jQuery("#dropdown-menu div.menu-title").removeClass('current');
      jQuery("#dropdown-menu div.menu-container").css('display','none');
    });
    
    jQuery("#menulauncher-1").click(function() { document.location.href = "http://markeding.at/"; });
    jQuery("#menulauncher-2").click(function() { document.location.href = "http://markeding-wels.at/"; });
    jQuery("#menulauncher-3").click(function() { document.location.href = "http://markeding-wien.at/"; });
    jQuery("#menulauncher-4").click(function() { document.location.href = "http://markeding-award.at/"; });
    
    // metanavigation menu
    jQuery("#metanavigation-menu div.menu-item").bind('mouseenter', function() {
      id = jQuery(this).attr("id")+"-background";
      jQuery("#"+id).not('.current').css("zIndex", "-6");
    });
    jQuery("#metanavigation-menu div.menu-item").bind('mouseleave', function() {
      id = jQuery(this).attr("id")+"-background";
      jQuery("#"+id).not('.current').css("zIndex", "-10");
    });

  },

  // Launcher
  launch: function() {
    main.event_listeners();
    soundManager.url = '/fileadmin/template/js/soundmanager/swf/';
    soundManager.useHTML5Audio = true;
    soundManager.preferFlash = true;
    soundManager.onready(function() {
      soundManager.createSound({
        id: 'audioLogo',
        url: '/fileadmin/template/js/soundmanager/sounds/audiologo.mp3',
        autoLoad: true,
        autoPlay: false,
        volume: 50,
        onfinish: function() {
          main.soundBlocked = 0;
        }
      });
      soundManager.createSound({
        id: 'audioFred',
        url: '/fileadmin/template/js/soundmanager/sounds/fred.mp3',
        autoLoad: true,
        autoPlay: false,
        volume: 50,
        onfinish: function() {
          main.soundBlocked = 0;
        }
      });
    });
    jQuery('#logo').bind('mouseover', function() {
      if(main.soundBlocked) {
        return;
      }
      main.soundBlocked = 1;
      soundManager.play('audioLogo');
    });
    jQuery('#fred-sound').bind('click', function() {
      if(main.soundBlocked) {
        return false;
      }
      main.soundBlocked = 1;
      soundManager.play('audioFred');
      return false;
    });
  }
};

// Bind launcher to onload event
jQuery(window).load(function () {
  main.launch();
});
