// Andrew, if you read that code, go easy on me ^^.



//MENU SCRIPT BY MATTHIEU DUFOUR
//OPACITY ON HOVER / TOGGLE RIGHT MENU / AJAX PAGE LOAD / ACCORDION MENU

$(function(){ 
		   
//OPACITY ON HOVER NAV LINKS
	$('ul#nav1 li').animate({ "opacity": .3 },'slow');
			$('ul#nav1 li').hover(function() {
						$(this).stop().animate({ "opacity": 1 },400);
					}, function() {
						$(this).stop().animate({ "opacity": .3 },400);
					});
			
			$('ul#nav2 li').animate({ "opacity": .2 },'slow');
			$('ul#nav2 li').hover(function() {
						$(this).stop().animate({ "opacity": 1 },400);
					}, function() {
						$(this).stop().animate({ "opacity": .3 },400);
					});
			
//OPACITY ON HOVER HOME THUMBNAILS
	
	
			
			
	
//TOGGLE RIGHT MENU
		$("ul#nav2").hide();
		// hide by default.
		// click event on the #works
		$("li#works").click( function () {
			if ($("ul#nav2:visible").length != 0) {						 
			// if show, then hide remove the .open class and add the .closed class
				$("ul#nav2.open").hide("normal", function () { $(this).removeClass("open") }, function () { $(this).addClass("closed") });
			}else {
			// if hidden, then show..
				$("ul#nav2.closed").show("slow", function () { $(this).addClass("open") });
			}
			return false;
			// Not to follow the link
		}); 




//AJAX PAGE LOAD

     var hash = window.location.hash.substr(1);
	 if(window.location.href.indexOf('#') > 0 && window.location.hash != '')
	 {
		 window.location.href = hash;
		 return false;
	 }
	
    $('#menu li a').click(function(event){
		event.preventDefault();
		// Not to follow the link
		
		var toLoad = $(this).attr('href');
		var ref = $(this).attr('href');
		//get the name of the page and the id of the container the data are loaded from
		$('#content').fadeOut('slow',loadContent);
		$('#load').remove();
		//if not removed, every page load adds a loader on the page
		window.location.hash = $(this).attr('href');
		//-4 used for my .php pages instead of -5 for .html extensions
		$('#loader').append('<span id="load"></span>');
		$('#load').fadeIn('normal');
		function loadContent() { 
			$('#content').load(toLoad,{ 'ajax': 1 },showNewContent);
		}
		function showNewContent() {
			$('#content').show('normal',hideLoader);
		}
		function hideLoader() {  
			$('#load').fadeOut('normal');  
		}
    });
	
	
//AJAX PAGE LOAD FOR HOME THUMBNAILS

     var hash = window.location.hash.substr(1);
	 if(window.location.href.indexOf('#') > 0 && window.location.hash != '')
	 {
		 window.location.href = hash;
		 return false;
	 }
	
    $('ul#hometn li a').click(function(event){
		event.preventDefault();
		// Not to follow the link
		
		var toLoad = $(this).attr('href');
		var ref = $(this).attr('href');
		//get the name of the page and the id of the container the data are loaded from
		$('#content').fadeOut('slow',loadContent);
		$('#load').remove();
		//if not removed, every page load adds a loader on the page
		window.location.hash = $(this).attr('href');
		//-4 used for my .php pages instead of -5 for .html extensions
		$('#loader').append('<span id="load"></span>');
		$('#load').fadeIn('normal');
		function loadContent() { 
			$('#content').load(toLoad,{ 'ajax': 1 },showNewContent);
		}
		function showNewContent() {
			$('#content').show('normal',hideLoader);
		}
		function hideLoader() {  
			$('#load').fadeOut('normal');  
		}
    });





//ACCORDION MENU

$(document).ready( function () {
    // On cache les sous-menus :
    $("#nav2 ul.subMenu").hide();
    // On sélectionne tous les items de liste portant la classe "toggleSubMenu"

    // et on remplace l'élément span qu'ils contiennent par un lien :
    $("#nav2 li.toggleSubMenu span").each( function () {
        // On stocke le contenu du span :
        var TexteSpan = $(this).text();
        $(this).replaceWith('<a href="" title="show submenu">' + TexteSpan + '<\/a>') ;
    } ) ;

    // On modifie l'évènement "click" sur les liens dans les items de liste
    // qui portent la classe "toggleSubMenu" :
    $("#nav2 li.toggleSubMenu > a").click( function () {
        // Si le sous-menu était déjà ouvert, on le referme :
        if ($(this).next("ul.subMenu:visible").length != 0) {
            $(this).next("ul.subMenu").slideUp("normal", function () { $(this).parent().removeClass("opens") });
        }
        // Si le sous-menu est caché, on ferme les autres et on l'affiche :
        else {
            $("ul.subMenu").slideUp("normal", function () { $(this).parent().removeClass("opens") });
			$(this).next("ul.subMenu").slideDown("normal", function () { $(this).parent().addClass("opens") });
        }
        // On empêche le navigateur de suivre le lien :
        return false;
    });  
	
	
        // On empêche le navigateur de suivre le lien :
        return false;
    }); 
	

});
//End of document ready...