var hash = window.location.hash;
if (hash.length > 0) {
    var link = hash.substr(1) + ".php";
    window.location.href = hash;
    $(document).ready(function(){
        $("#wrapper").empty();
        $.ajax({
            type: "POST",
            url: link,
            success: function(msg) {
                $("#wrapper").append(msg);
            }
        });
    });
}

$(document).ready(function(){

    //When mouse rolls over
    $("#mainnav li a").mouseover(function(){
        $(this).stop().animate({
            fontSize: "22px"
            }, 200 );
    });
    //When mouse rolls over
    $("#mainnav li a").mouseout (function(){
        $(this).stop().animate({
            fontSize: "14px"
            }, 200 );
    });

    // Load pages via Ajax on mouseclicks.
    $("li.home a").click (function() {       
        ajax_load("index.php",this);
        return false;
    });

    $(".envelope").live("click",function() {
        ajax_load("contact.php",this);
        return false;
    });

    $("li.location a").click (function() {
        ajax_load("location.php",this);
        return false;
    });
    $("li.community a").click (function() {
        ajax_load("community.php",this);
        return false;
    });
    $("li.floorplans a").click (function() {
        ajax_load("floorplans.php",this);
        return false;
    });
    $("li.features a").click (function() {
        ajax_load("features.php",this);
        return false;
    });
    $("li.gallery a").click (function() {
        ajax_load("gallery.php",this);
        return false;
    });
    $("li.application a").click (function() {
        ajax_load("application.php",this);
        return false;
    });

    $("li.contact a").click (function() {
        ajax_load("contact.php",this);
        return false;
    });

});

function ajax_load(page,element) {    
    $('#mainnav').find('li.active').removeClass('active');
    $(element).parent().addClass('active');
    $("#wrapper").empty();
    $("#wrapper").css({'display' : 'none'})
    $.ajax({
        type: "POST",
        url: page,
        success: function(msg){            
            $("#wrapper").append(msg);
            $("#wrapper").fadeIn();
            pageTracker._trackPageview(page);
        }
    });
    var strLen = page.length;
    page = page.slice(0,strLen-4);
    window.location.hash = page;
}