$(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://'])").live("click", function (e) {
        if ($(this).attr("href").indexOf("https://") > -1) {
            return true;
        }
        e.preventDefault();
        var page = $(this).attr("href");
        if (page == "/") {
            page == "index.php";
        }
        $.History.go(page);
    });
    $.History.bind(function (state) {
        if (state == curPage) {
            return false;
        }
        curPage = state;
        $("a").removeClass("active");
        $(".container").css("height", $(".container").height() + "px");
        $(".leftab").attr("src", "images/LeftClip.png").css({ "top": "256px" });
        $(".rightab").attr("src", "images/RighClip.png").css({ "margin-left": "450px", "top": "257px" });
        $(".moveable").animate({ "top": "-1200px" }, 500, function () {
            loadNew();
        });
        $.ajax({ type: "GET", url: "content/" + state, success: function (data) {
            pageData = data;
            loadComplete = true;
        }
        });
    });
    function loadNew() {
        if (loadComplete == false) {
            setTimeout(loadNew, 50);
        } else {
            loadComplete = false;
            animatePage();
        }
    }
    function animatePage() {
        $(".replace").html(pageData);
        check();
        $(".moveable").animate({ "top": "0px" }, 500, function () {
            $(".leftab").attr("src", "images/lefttabclosed.png").css({ "top": "260px" });
            $(".rightab").attr("src", "images/righttabclosed.png").css({ "margin-left": "385px", "top": "260px" });
        });
        $(".container").animate({ "height": $(".moveable").height() + "px" }, 500, function () {
            $(this).css("height", "auto");
        })

    }
    function check() {
        $(".replace").formControl({
            submitmod: "content/"
        });
        $("a[href=" + curPage + "]").addClass("active");
        $(".accordion").accordion();
    }
    check();
    $(".signup").formControl({
        submitmod: "content/"
    });
    function resize() {
        if ($("iframe").length > 0) {
            $("iframe").css("height", $("iframe").contents().find("html").height());
        }
    }
    setInterval(resize, 300);
});
$(window).load(function () {
   
});
