function addProjectEvents() {
    var subcontent = $('#subcontent');
    subcontent.find('img[@src$=.png]').pngfix();

    $('.info-box').cornerz({background: '#f5f5f5'});

    $('#subnavigation li').hover(function() {
	$(this).addClass('subnavigation-hover');
    }, function() {
	$(this).removeClass('subnavigation-hover');
    });

    var $lastLink = null;
    var $el = null;
    $('#subnavigation').localScroll({
	target:subcontent,
	axis:'x',
	duration:600,
	onBefore:function( e, el, $target ){
	    $el = $(el);
	    $target.queue('fx',[]).stop();
	    $lastLink = $(this);
	    $lastLink[0].blur();
	},
	onAfter:function(){
	    subcontent.animate({"height": $el.height() + 20 + "px"}, "slow");
	}
    });

}

function loadProject(url) {
    var extraBox = $('#extra-bg');

    extraBox.slideUp('fast', function() {
	$.get(url+'?ajax=true&ms=' + new Date().getTime(), callback=function(data){
	    extraBox.css({"height": 0}).show();
	    $("#extra").html(data);

	    var contentHeight = $('#project-information').height();
	    $('#subcontent').css({"height": contentHeight + 20 + "px"});
	    extraBox.animate({"height": contentHeight + 70 + "px"}, 1000, 
			     callback=function() {
				 extraBox.css('height', 'auto');
			     });

	    addProjectEvents();
	});	
    });
}


$(function() {
    $("#loading").ajaxStart(function(){
	$(this).show();
    });

    $("#loading").ajaxStop(function(){
	$(this).hide();
    });

    /*$(".project-link").click(function() {
	var url = $(this).attr('href');
	loadProject(url);
	return false;
    });*/

    addProjectEvents();
});
