Indexpage = {
    currentSection: "",
    loadedSections: [],
    sectionsList: null,
    init: function(){
        this.currentSection = (location.hash.substring(1) != "") ? location.hash.substring(1) : Show.configuration.menuSetup[0].anchor;
        var A = {};
        $.each(Show.configuration.menuSetup, function(B){
            var C = $('<div id="' + Show.configuration.menuSetup[B].anchor + 'div" class="onePane" style="left:' + (B * 2000) + 'px"><div class="paneContent"><div class="indextitle"><img class="showtitle" src="imgs/showGlobal/showtitle.png"/><img class="sectiontitle" src="' + Show.configuration.menuSetup[B].sectionImageFile + '"/></div></div></div>').appendTo("#showContainer");
            A[Show.configuration.menuSetup[B].anchor] = B;
            fixpng(C.find(".showtitle, .sectiontitle"))
        });
        this.sectionsList = A;
        window.setInterval(this.checkAnchor, 100);
        this.loadBgImage();
        this.goSection(false)
    },
    checkAnchor: function(){
        var A = location.hash.substring(1);
        if (A == "") {
            location.hash = Indexpage.currentSection
        }
        else {
            if (A != Indexpage.currentSection) {
                Indexpage.currentSection = A;
                Indexpage.goSection(true)
            }
        }
    },
    goSection: function(A){
        animateSpeed = A ? 1000 : 0;
        paneLocation = Indexpage.sectionsList[Indexpage.currentSection] * 2000;
        var B = Indexpage.currentSection;
        if (B == "video" || B == "downloads" || B == "characters" || B == "episodes" || B == "extras" || B == "store" || B == "smallshow") {
            $("#" + Indexpage.currentSection + "div .indextitle").width(SlotGrid.calcWidth($(window).innerWidth()))
        }
        $("#showContainer").animate({
            left: paneLocation * -1
        }, animateSpeed, "easeInOutCirc", function(){
            $("#globalNavs a.active").removeClass("active");
            $("a", "#" + Indexpage.currentSection + "link").addClass("active");
            Indexpage.loadSection(Indexpage.currentSection)
        })
    },
    loadSection: function(C){	
        Tracker.track(Show.configuration.showName + " - " + Indexpage.currentSection, "Shows");
        if (Indexpage.loadedSections[C]) {
            return
        }
        Indexpage.loadedSections[C] = true;
        switch (Indexpage.currentSection) {
            case "video":
                var B = new SlotGrid(new VideosFeed());
                B.appendTo($("#videodiv .paneContent"));
                break;
            case "downloads":
                var B = new SlotGrid(new DownloadsFeed());
                B.appendTo($("#downloadsdiv .paneContent"));
                break;
            case "characters":
            case "episodes":
            case "extras":
                var B = new SlotGrid(new GenericFeed(Indexpage.currentSection));
                B.appendTo($("#" + Indexpage.currentSection + "div .paneContent"));
                break;
            case "store":
                var B = new SlotGrid(new StoreFeed("Robot Chicken"));
                B.appendTo($("#storediv .paneContent"));
                break;
            case "smallshow":
                var B = new SlotGrid(new SmallshowFeed());
                B.appendTo($("#smallshowdiv .paneContent"));
                break;
            case "boards":
                var A = new Boards();
                A.appendTo($("#boardsdiv .paneContent"));
                break
        }
    },
    loadBgImage: function(){
        if (Show.configuration.stretchBgImage == "true") {
            $("<img />").attr({
                src: "imgs/showGlobal/showBgImage.jpg",
                id: "showBgImg"
            }).appendTo("#showFrame");
            $(window).bind("resize", this.resizeBgImage);
            $("#showBgImg").bind("load", this.resizeBgImage)
        }
        else {
            $("body").css("background-image", "url(imgs/showGlobal/showBgImage.jpg)")
        }
    },
    resizeBgImage: function(){
        $("#showBgImg").css("width", "100%");
        imageHeight = $("#showBgImg").height();
        windowHeight = $(window).height();
        diff = windowHeight - imageHeight;
        diff = (diff * 5 / 3);
        if (diff > 0) {
            $("#showBgImg").width($("#showBgImg").width() + diff)
        }
        else {
            $("#showBgImg").css("width", "100%")
        }
        $(".paneContent").css("height", $(window).innerHeight() - 156)
    }
};
$(document).ready(function(){
    Show.init();
    Navs.init();
    Indexpage.init()
});
$(function(){
    $.ajaxHistory.initialize();
    $(".hist").history()
});
