

var changeTo =  function(to){
	if(to.length == 0) return;

    var load = $.overlay.show('<div id="load" />');
		
	$('#content').load(to.attr('href') + ' #content > *', function(data){	
	    $('.selected').removeClass('selected');
	    $("#nav a[href='" + to.attr('href') + "']").addClass('selected');
	    	
		eval($(data).find('script').text());
			
	    document.title = 'AmperSoft ~ ' + to.attr('alt');

        load.hide();
	});

    return false;
};

var init = function(){
    var seccion = (document.location.hash == "" )? "" : document.location.hash;
    changeTo($("#nav a[href='" + seccion.substr(1) +"']"));
    
	$('#footer > *').css('opacity', 0.6);
    
    $('#nav a:not(.selected)').live('click', function(e){
        var link = $(e.target);
        document.location.hash = link.attr('href');
        changeTo(link);
        
        return false;
    });
};

$(document).ready(init);
