﻿$(document).ready(function(){

  // on load make sure to load the very first page
  $("#contentfetcher").load("subpages/willkommen.html?r=" + Math.floor(Math.random()*1000));
  g_mainMenuEntrySelected = "#m_willkommen";
    
  // register the click handlers of the main menu
  RegisterMainMenu( );
  
  // hide the submenus
  TurnOffSubMenu( );
  
  ShowSubmenu( );

});

function RegisterMainMenu( )
{
  //register the click handlers
  $("#m_kontakt").click( function(){
    // Kontakt
    $("#datawrapper").show( );
    $("#contentfetcher").load("subpages/kontakt.html?r=" + Math.floor(Math.random()*1000));
    g_mainMenuEntrySelected = "#m_kontakt";
    g_currentImage = -1;
    SwitchGraphics( );
    ShowSubmenu( );
  });
  
  $("#m_gaestebuch").click( function(){
    $("#datawrapper").show( );
    $("#contentfetcher").load("subpages/fotos.html?r=" + Math.floor(Math.random()*1000));
    g_mainMenuEntrySelected = "#m_gaestebuch";
    g_currentImage = -1;
    SwitchGraphics( );
    ShowSubmenu( );
  });
  
  $("#m_wettbewerb").click( function(){
    $("#datawrapper").show( );
    $("#contentfetcher").load("subpages/lw.html?r=" + Math.floor(Math.random()*1000));
    g_mainMenuEntrySelected = "#m_wettbewerb";
    g_currentImage = -1;
    SwitchGraphics( );
    ShowSubmenu( );
  });
  
  $("#m_umzug").click( function(){
    $("#datawrapper").show( );
    $("#contentfetcher").load("subpages/umzug.html?r=" + Math.floor(Math.random()*1000));
    g_mainMenuEntrySelected = "#m_umzug";
    g_currentImage = -1;
    SwitchGraphics( );
    ShowSubmenu( );
  });
  
  $("#m_willkommen").click( function(){
    $("#datawrapper").show( );
    $("#contentfetcher").load("subpages/willkommen.html?r=" + Math.floor(Math.random()*1000));
    g_mainMenuEntrySelected = "#m_willkommen";
    g_currentImage = -1;
    SwitchGraphics( );
    ShowSubmenu( );
  });
  
  $("#m_programm").click( function(){
    $("#datawrapper").show( );
    $("#contentfetcher").load("subpages/programm.html?r=" + Math.floor(Math.random()*1000));
    g_mainMenuEntrySelected = "#m_programm";
    g_currentImage = -1;
    SwitchGraphics( );
    ShowSubmenu( );
  });
  
  $("#m_jugendschutz").click( function(){
    $("#datawrapper").show( );
    $("#contentfetcher").load("subpages/jugendschutz.html?r=" + Math.floor(Math.random()*1000));
    g_mainMenuEntrySelected = "#m_jugendschutz";
    g_currentImage = -1;
    SwitchGraphics( );
    ShowSubmenu( );
  });
  
  $("#m_anreise").click( function(){
    $("#datawrapper").show( );
    $("#contentfetcher").load("subpages/anreise.html?r=" + Math.floor(Math.random()*1000));
    g_mainMenuEntrySelected = "#m_anreise";
    g_currentImage = -1;
    SwitchGraphics( );
    ShowSubmenu( );
  });
  
  $("#m_fahne").click( function(){
    $("#datawrapper").show( );
    $("#contentfetcher").load("subpages/fahne.html?r=" + Math.floor(Math.random()*1000));
    g_mainMenuEntrySelected = "#m_fahne";
    g_currentImage = -1;
    SwitchGraphics( );
    ShowSubmenu( );
  });
  
  $("#m_sponsoren").click( function(){
    $("#datawrapper").show( );
    $("#contentfetcher").load("subpages/sponsoren.html?r=" + Math.floor(Math.random()*1000));
    g_mainMenuEntrySelected = "#m_sponsoren";
    g_currentImage = -1;
    SwitchGraphics( );
    ShowSubmenu( );
  });
  
  $("#m10").click( function(){
    //$("#datawrapper").show( );
   // $("#contentfetcher").load("subpages/kurz.html");
    //g_mainMenuEntrySelected = "#m10";
    //g_currentImage = -1;
    //SwitchGraphics( );
    //ShowSubmenu( );
  });
  
  $("#m11").click( function(){
    //$("#datawrapper").show( );
   // $("#contentfetcher").load("subpages/kurz.html");
   // g_mainMenuEntrySelected = "#m11";
    //g_currentImage = -1;
    //SwitchGraphics( );
   // ShowSubmenu( );
  });
  
  $("#m12").click( function(){
    //$("#datawrapper").show( );
   // $("#contentfetcher").load("subpages/kurz.html");
    //g_mainMenuEntrySelected = "#m12";
    //g_currentImage = -1;
    //SwitchGraphics( );
    //ShowSubmenu( );
  });
  
  $("#m13").click( function(){
    //$("#datawrapper").show( );
   // $("#contentfetcher").load("subpages/kurz.html");
    //g_mainMenuEntrySelected = "#m13";
    //g_currentImage = -1;
    //SwitchGraphics( );
    ///ShowSubmenu( );
  });

  $("#m14").click( function(){
    //$("#datawrapper").show( );
   // $("#contentfetcher").load("subpages/kurz.html");
    //g_mainMenuEntrySelected = "#m14";
    //g_currentImage = -1;
    //SwitchGraphics( );
    ////ShowSubmenu( );
  });  
  
  $("#m15").click( function(){
    //$("#datawrapper").show( );
   // $("#contentfetcher").load("subpages/kurz.html");
    //g_mainMenuEntrySelected = "#m15";
    //g_currentImage = -1;
    //SwitchGraphics( );
    //ShowSubmenu( );
  });
}

function TurnOffSubMenu( )
{
  var index = 0;
  for ( index = 0; index < 16; ++index )
  {
    var submenuName = "#s" + index;
    
    // first get rid of the click handler
    $( submenuName ).unbind( "click" );
    
    // now hide the element
    $( submenuName ).hide( );
  }
  
  // now remove the menu highlighting from each entry
  HighlightMenu( "" );
  
  // make sure to set the image visibility time to the default here
  g_imagesVisible = 5;
  
};

function HighlightMenu( entry )
{
  $( ".menuitem" ).removeClass( "activemenuitem" ); 

  if ( 0 != entry.length )
  {
    $( entry ).addClass( "activemenuitem" );
  }
  
  $( g_mainMenuEntrySelected ).addClass( "activemenuitem" );
};

function ShowSubmenu( )
{
  TurnOffSubMenu( );
  
  HighlightMenu( g_mainMenuEntrySelected );

  if ( "#m_kontakt" == g_mainMenuEntrySelected )
  {
    // Kontakt
  }
  else if ( "#m_gaestebuch" == g_mainMenuEntrySelected )
  { 
    // Fotos
  }
  else if ( "#m_wettbewerb" == g_mainMenuEntrySelected )
  {
    // landeswertungsspiele
  }
  else if ( "#m_umzug" == g_mainMenuEntrySelected )
  {
    // umzug
  }  
  else if ( "#m_willkommen" == g_mainMenuEntrySelected )
  {
    // willkommen
    $( "#s9" ).html( "Impressum" );
    
    $("#s9").bind( "click", function() { HighlightMenu( "#s9" ); $("#contentfetcher").load("subpages/impressum.html?r=" + Math.floor(Math.random()*1000));} );
    
    $( "#s9" ).show( );
  }
  else if ( "#m_programm" == g_mainMenuEntrySelected )
  {
    // programm
    $( "#s7" ).html( "Donnerstag" );
    $( "#s6" ).html( "Freitag" );
    $( "#s5" ).html( "Samstag" );
    $( "#s4" ).html( "Sonntag" );
    
    $("#s7").bind( "click", function() { HighlightMenu( "#s7" ); $("#contentfetcher").load("subpages/donnerstag.html?r=" + Math.floor(Math.random()*1000));} );
    $("#s6").bind( "click", function() { HighlightMenu( "#s6" ); $("#contentfetcher").load("subpages/freitag.html?r=" + Math.floor(Math.random()*1000));} );
    $("#s5").bind( "click", function() { HighlightMenu( "#s5" ); $("#contentfetcher").load("subpages/samstag.html?r=" + Math.floor(Math.random()*1000));} );
    $("#s4").bind( "click", function() { HighlightMenu( "#s4" ); $("#contentfetcher").load("subpages/sonntag.html?r=" + Math.floor(Math.random()*1000));} );
    
    $( "#s7" ).show( );
    $( "#s6" ).show( );
    $( "#s5" ).show( );
    $( "#s4" ).show( ); 
  }
  else if ( "#m_jugendschutz" == g_mainMenuEntrySelected )
  {
    // jugendschutz
    $( "#s4" ).html( "Sicherheit" );
    $( "#s3" ).html( "Alkoholausschank" );
    
    $("#s4").bind( "click", function() { HighlightMenu( "#s4" ); $("#contentfetcher").load("subpages/sicherheit.html?r=" + Math.floor(Math.random()*1000));} );
    $("#s3").bind( "click", function() { HighlightMenu( "#s3" ); $("#contentfetcher").load("subpages/alkohol.html?r=" + Math.floor(Math.random()*1000));} );
    
    $( "#s4" ).show( );
    $( "#s3" ).show( );  
  }
  else if ( "#m_anreise" == g_mainMenuEntrySelected )
  {
    // anreise
    $( "#s3" ).html( "Donnerstag" );
    $( "#s2" ).html( "Freitag" );
    $( "#s1" ).html( "Samstag" );
    $( "#s0" ).html( "Sonntag" );
    
    $("#s3").bind( "click", function() { HighlightMenu( "#s3" ); $("#contentfetcher").load("subpages/anr_donnerstag.html?r=" + Math.floor(Math.random()*1000));} );
    $("#s2").bind( "click", function() { HighlightMenu( "#s2" ); $("#contentfetcher").load("subpages/anr_freitag.html?r=" + Math.floor(Math.random()*1000));} );
    $("#s1").bind( "click", function() { HighlightMenu( "#s1" ); $("#contentfetcher").load("subpages/anr_samstag.html?r=" + Math.floor(Math.random()*1000));} );
    $("#s0").bind( "click", function() { HighlightMenu( "#s0" ); $("#contentfetcher").load("subpages/anr_sonntag.html?r=" + Math.floor(Math.random()*1000));} );
    
    $( "#s3" ).show( );
    $( "#s2" ).show( );
    $( "#s1" ).show( );
    $( "#s0" ).show( ); 
  }
  else if ( "#m_sponsoren" == g_mainMenuEntrySelected )
  {
    // sponsoren
    // make sure we display the images faster than usual
    g_imagesVisible = 1;
  }
  else if ( "#m_fahne" == g_mainMenuEntrySelected )
  {
    // fahne
    $( "#s5" ).html( "Sponsoren" );
    
    $("#s5").bind( "click", function() { HighlightMenu( "#s5" ); $("#contentfetcher").load("subpages/fahnensponsoren.html?r=" + Math.floor(Math.random()*1000));} );
    
    $( "#s5" ).show( );
  }
  else
  {
    alert( "ShowSubmenu menueintrag wird nicht verwendet" ) ;
  }
}

