function observe_menus() {
    $('ul.menu li.main').not('li.main.selected').hover(
		function() {
		    $('a', this).animate({
		        backgroundPosition: "0 0"
		    }, 0);

		    $('a.main', this).animate({ 
                    height: "56px"
                  }, 250 );
		    $('ul', this).css('display', 'block');
		},
		function() {
		    $('a', this).animate({
		        backgroundPosition: "-131px 0"
		    }, 0);
		    
		    $('a.main', this).animate({ 
                    height: "38px"
                  }, 250 );
		    $('ul', this).css('display', 'none');
		}
	);

	// hack : if ie6, move the background of selected main menu
	// cause it strangely doesn't work in CSS
	if ($.browser.msie && $.browser.version.substr(0,1)<7) {
    	$('ul.menu li.main.selected a').animate({
    	    backgroundPosition: "0 0"
    	}, 0);	    
	}
}

function toggle_news() {
    // there is a bug in FF PC that cause some zone to flicker if the sliding 
    // div has overflow set to auto, so I set the overflow property at the end
    // of the animation
    if ($("#news-zone").is(':hidden'))
         setTimeout(function() { $("#news-zone").toggleClass("visible"); }, 500);
     else
         $("#news-zone").toggleClass("visible");

     $("#news-zone").toggle("slide", { direction: "up"}, 500);
     $(".a-news").toggle(200);
     
     // the #news-zone return false strangly disable click on links -> re-activate it
     $("#news-zone .extended a:not('.external')").click(function() {
        var href = $(this).attr('href');
        document.location.href = href;
     });
}

function observe_news() {
    $('h1.news a').click(function() {
       $(this).toggleClass("selected");

       toggle_news();
       
       return false;
    });
    
    // close news zone if clicked anywhere but in the news zone
    $(document).click(function() {
        if ($("#news-zone").is(':visible'))
            toggle_news();
    });
    $("#news-zone").click(function() {
        return false;
    });    
        
    $('.a-news h4 a').not('.a-news h4 a#view-archives').click(function() {
        // get the parent div
        var clickedTitle    = $(this).parent();
        var clickedNewsDiv  = $(this).parent().parent(".a-news");

        $(clickedTitle).toggleClass("selected");
        //$('p.intro', clickedNewsDiv).toggle();
        $('p.extended', clickedNewsDiv).toggle("slide", { direction: "up" }, 500);

        return false;
    });
    
    $('#view-archives').click(function() {
        $('#view-archives-block h4').toggleClass("selected");
        $('#view-archives').toggleClass("selected");
        $('#view-archives').text($('#view-archives').text() == 'View archives' ? 'Hide archives' : 'View archives');
        $('.archives').toggle("slide", { direction: "up" }, 500);
    });
}

function observe_portfolio_nav() {
    $(".portfolio-nav li").mouseover(function() {
        $(this).addClass("hover");
    }).mouseout(function() {
        $(this).removeClass("hover");
    });
    
    $(".portfolio-nav li").click(function() {
        var href = $('a.name', this).attr("href");
        document.location.href = href;
        return false;
    });
}

function observe_external_links() {
    // open pdfs and googlemaps in new window
    // $("a[href$='.pdf'],a[href^='http://maps.google.be'],a[href^='http']").click(function(){
    $('a.external').click(function() {
        window.open(this.href);
        return false;
    });
}

$(document).ready(function(){
    observe_menus();
    observe_news();
    observe_portfolio_nav();
    observe_external_links();
});


