$(document).ready(function () {

    var loadComplete = false;
    var pageData = "";
    var curPage = window.location.pathname;
    curPage = curPage.substring(curPage.lastIndexOf('/') + 1);
    if (curPage == "") {
        curPage = "index.php";
    }
    /*$("a:not([href*='http://']):not([href*='mailto:']):not([href*='blog'])").live("click", function (e) {
        e.preventDefault();
        var page = $(this).attr("href");
        if (page == "/") {
            page == "index.php";
        }
        $.History.go(page);
    });
    $.History.bind(function (state) {
        if (curPage == state) { return false };
        curPage = state;
        $(".fadecover").css("display", "block").fadeTo(200, 1, function () {
            $(".main").css("height", $(".main").height() + "px").children("*:not('.fadecover')").remove();
            loadNew();
        });
        $.ajax({ type: "GET", url: state, success: function (data) {
            pageData = data;
            loadComplete = true;
        }
        });
    });
    */
    function loadNew() {
        if (loadComplete == false) {
            setTimeout(loadNew, 50);
        } else {
            loadComplete = false;
            animatePage();
        }
    }
    function animatePage() {
        $(".main").append(pageData).css("height", "");
        $(".fadecover").fadeTo(200, 0, function () {
            $(this).css("display", "none");
        });
        check();
    }
    function check() {
        $(".slidenext").bind("click", function () {
            $(".slides>*").stop(true, true).last().fadeTo(300, 0, function () {
                $(this).prependTo(".slides").fadeTo(0, 1);
            });
        });
        $(".slideprev").bind("click", function () {
            $(".slides>*").stop(true, true).first().fadeTo(0, 0, function () {
                $(this).appendTo(".slides").fadeTo(300, 1);
            });
        });
    }
    check();
});
