function start() {
    $("#content").hide();
    $("#footer").hide();
    $("#menu").hide();
    $("#fader").css("visibility","visible");
    $("#header").css("width", "0px");
    loadPage();
    $("#menu > a").hover( function() {
        $(this).animate({
            color:"#f5f5f5"
        }, 500);
    }, function() {
        $(this).animate({
            color:"#666"
        }, 500);
    });
    $("#menu > a").click( function() {
        var page = $(this).attr("href");
        if (page != "artisti.php")
            $("#artist_submenu").slideUp(400);
        var hashPage = "";
        switch(page) {
        case "index.php":
            hashPage = "#home";
            break;
        case "pelati.php":
            hashPage = "#pelati";
            break;
        case "artisti.php":
            $("#artist_submenu").slideToggle(400);
            return false;
            hashPage = "#artisti";
            break;
        case "esposizioni.php":
            hashPage = "#esposizioni";
            break;
        case "proposte.php":
            hashPage = "#proposte";
            break;
        case "contatti.php":
            hashPage = "#contatti";
            break;
        case "mappa.php":
            hashPage = "#mappa";
            break;
        }
        window.location.hash=hashPage;
        $("#content,#footer").fadeOut(500, function() {
            $("#content").empty();
            $("#content").load("./pages/"+page, function() {
                $("#content,#footer").fadeIn(500);
            });
        });
        return false;
    });
    $("#artist_submenu > ul > li > a").hover( function() {
        $(this).animate({
            color:"#f5f5f5"
        }, 200);
    }, function() {
        $(this).animate({
            color:"#666"
        }, 200);
    });
    $("#artist_submenu > ul > li > a").click( function() {
        $("#artist_submenu").fadeOut(200);
        var artist = $(this).attr("rel");
        window.location.hash = "#artisti_"+artist;
        $("#content,#footer").fadeOut(500, function() {
            $("#content").empty();
            $("#content").load("./pages/artisti.php",
                "p="+artist, function() {
                $("#content,#footer").fadeIn(500);
            });
        });
        return false;
    });
}

function appear() {
    $("#header").animate({
        width:"100%"
    }, 1000, "linear", function() {
        $("#menu").fadeIn(1000);
        $("#fader").fadeOut(1000, function() {
            $("#content,#footer").fadeIn(1000);
        });
    });
}

function appearCredits() {
    $("#content").empty().load("./pages/dissolvenza.php", function() {
        $("#slider").css("width","0px");
        $("#header").animate({
            width:"100%"
        }, 1000, "linear", function() {
            $("#fader").fadeOut(1000, function() {
                $("#content").fadeIn(1000, function() {
                    $("#slider").animate({
                        width:"100%"
                    }, 5000, "linear");
                });
                $("#content").delay(5000);
                $("#content").fadeOut(500, function() {
                    $("#content").empty();
                    $("#content").load("./pages/index.php", function() {
                        $("#content,#footer").fadeIn(500);
                        $("#menu").fadeIn(500);
                    });
                });
            });
        });
    });
}

function loadPage() {
    var ajaxPage;
    if (window.location.hash) {
        var strArray = window.location.hash.split("_");
        switch (strArray[0]) {
    	case "#home":
    		ajaxPage = "index.php";
    		break;
        case "#pelati":
    		ajaxPage = "pelati.php";
    		break;
    	case "#artisti":
    		ajaxPage = "artisti.php";
    		break;
    	case "#esposizioni":
    		ajaxPage = "esposizioni.php";
    		break;
    	case "#proposte":
    		ajaxPage = "proposte.php";
    		break;
    	case "#contatti":
    		ajaxPage = "contatti.php";
    		break;
    	case "#mappa":
    		ajaxPage = "mappa.php";
    		break;
        default:
            ajaxPage = "index.php";
            break;
        }
    } else {
        ajaxPage = "index.php";
    }
    if (ajaxPage == "index.php") {
        appearCredits();
    } else if (ajaxPage == "artisti.php" && strArray.length == 2) {
        $("#content").empty();
        $("#content").load("./pages/artisti.php", "p="+strArray[1], appear);
    } else {
        $("#content").empty();
        $("#content").load("./pages/"+ajaxPage, appear);
    }
    return true;
}
