/*
	scripts.js

	Javascript function file for use by the 
	Study At The OU (SAOU) Website.

	Function :	$(document).ready(function(){
	Notes	 :	Handles the switching of a 'tabbed'
			(constructed using CSS) menu.

*/

$(document).ready(function(){
  
    // This code is responsible for setting the correct tab on first display of the menu structure.  
	if (jsCurrentTab=='U') {
	    // Hide the Postgrad list from view
        $("div#subjects-postgraduate").hide()
	    $("div.subjects-links h3").hide()
	    $("li#toggle-undergraduate").addClass("selected")
	    // DIP - Added to prevent <a> appearing on selected tab.
        $("li#toggle-undergraduate a").hide()
        $("li#toggle-undergraduate").text("Undergraduate")   
	} else {
	    // Hide the Undergrad list from view
        $("div#subjects-undergraduate").hide()
	    $("div.subjects-links h3").hide()
	    $("li#toggle-postgraduate").addClass("selected")
	    // DIP - Added to prevent <a> appearing on selected tab.
	    $("li#toggle-postgraduate a").hide()
        $("li#toggle-postgraduate").text("Postgraduate")   
	};
	
	// Assign the function code that sets the menu list up for display of the postgraduate branch.
	var showPostGraduate = function(event) {
	  $("li#toggle-postgraduate").addClass("selected"); 
	  $("li#toggle-undergraduate").removeClass("selected"); 
	  $("div#subjects-postgraduate").show();
	  $("div#subjects-undergraduate").hide();
	  
      // We'd removed the <a> link from the undergraduate tab -reinstate it here.
      $("li#toggle-undergraduate").html("<a href='#subjects-undergraduate'>Undergraduate</a>");
      
      // Rebind the reinstated <a> link to the function code for undergraduate processing.
      $('li#toggle-undergraduate a').bind('click', showUnderGraduate);
      
      // Hide the postgraduate <a>
      $("li#toggle-postgraduate a").hide();
      $("li#toggle-postgraduate").text("Postgraduate");
	  
	  return false;
	};
	
    // Bind the above function code to the click of the postgraduate <a>.			
	$('li#toggle-postgraduate a').bind('click', showPostGraduate);
	
	// Assign the function code that sets the menu list up for display of the undergraduate branch.
	var showUnderGraduate = function(event) {
	  $("li#toggle-undergraduate").addClass("selected"); 
	  $("li#toggle-postgraduate").removeClass("selected"); 
	  $("div#subjects-postgraduate").hide();
	  $("div#subjects-undergraduate").show();
	  
      // We'd removed the <a> link from the postgraduate tab -reinstate it here.
      $("li#toggle-postgraduate").html("<a href='#subjects-postgraduate'>Postgraduate</a>");
      
      // Rebind the reinstated <a> link to the function code for postgraduate processing.
      $('li#toggle-postgraduate a').bind('click', showPostGraduate);
      
      // Hide the undergraduate <a>
      $("li#toggle-undergraduate a").hide();
      $("li#toggle-undergraduate").text("Undergraduate");
      
      return false;
    };
	
	// Bind the above function code to the click of the undergraduate <a>.			
	$('li#toggle-undergraduate a').bind('click', showUnderGraduate);
	
});
