// load pages from external links
window.onload = function() 
  { initialiseStateFromURL(); 
    setInterval(pollHash, 500);
  }
  
var recentHash = "";
  
// polling of the hash variable
function pollHash ()
 { if (window.location.hash == recentHash)  { return; }
   else
    { recentHash = window.location.hash;
      initialiseStateFromURL();
    }
 }
  
// function to handle link
function initialiseStateFromURL() 
 { var hash = window.location.hash.substr(1);
   if (hash == '') hash = 'home';
   // select the activated link
   $(".selected").removeClass("selected");
   $("#id_" + hash).addClass("selected");
   // load page
   var toLoad = 'pages/' + hash + '.html';
   $('#main_body').load(toLoad);
   // change banner
   changeClass ('bannerTop','topBanner_'+hash);  
 }
 
$(document).ready(function() 
 {
    /* var hash = window.location.hash.substr(1);
    if (hash == '') hash = 'home';
   
    // handling information links
    var href = $('#information a').each(function()
      { var href = $(this).attr('href');
	if(hash==href.substr(1))
         { var toLoad = 'pages/' + hash + '.html';
	   $('#main_body').load(toLoad)
	 }											
      });
    
    // handling meetings links
    var href = $('#meetings a').each(function()
      { var href = $(this).attr('href');
	    if(hash==href.substr(1))
         { var toLoad = 'pages/' + hash + '.html';
	    $('#main_body').load(toLoad)
	  }											
      });*/

    // action when clicking an information link
    $('#information a').click(function()
     {  
        // select the link to activate
        $(".selected").removeClass("selected");
        $("#id_" + $(this).attr('href').substr(1)).addClass("selected");

        var toLoad = 'pages/' + $(this).attr('href').substr(1) + '.html';
        
        $('#main_body').hide('fast',loadContent);
        window.location.hash = $(this).attr('href').substr(1);
        
 
        // function to load the content
        function loadContent() 
         { $('#main_body').load(toLoad,'',showNewContent()); }
        
        // function to show the new content
        function showNewContent() 
         { $('#main_body').show('fast'); }
		
        return false;
		
	});

    // action when clicking a meetings link
    $('#meetings a').click(function()
     {  // select the link to activate
        $(".selected").removeClass("selected");
        $("#id_" + $(this).attr('href').substr(1)).addClass("selected");
	
        var toLoad = 'pages/' + $(this).attr('href').substr(1) + '.html';
        
        $('#main_body').hide('fast',loadContent);
        window.location.hash = $(this).attr('href').substr(1);
        
        // function to load the content
        function loadContent() 
         { $('#main_body').load(toLoad,'',showNewContent()); }
        
        // function to show the new content
        function showNewContent() 
         { $('#main_body').show('normal'); }
			
        return false;
		
	});

});
