var AdFactory = {
    adurl: "/adultswimdynamic/js.ng/site=toonswim&toonswim_pos=${width}x${height}_${or}&toonswim_rollup=shows&toonswimstatus=test",
    parser: new RegExp(/document\.write\('(.*)'\);/),
    loadAd: function(A, C, B){
        try {
            B += "?" + Show.configuration.ids.adId
        } 
        catch (D) {
        }
        return '<iframe frameborder="no" scrolling="no" style="border:none;width:' + A + "px;height:" + C + 'px" src="' + B + '" />'
    },
    errorAd: function(A, B){
        return '<div style="background:#C2C2C2;color:#FFF;line-height:' + B + "px;width:" + A + 'px;text-align:center;">adspace</div>'
    },
    loadBillboard: function(A){
        A(AdFactory.loadAd(300, 250, root_path + "global/html/templates/billboard.html"))
    },
    loadSponsorshipBadge: function(A){
        A(AdFactory.loadAd(125, 125, root_path + "global/html/templates/sponsorshipbadge.html"))
    },
    loadLeaderboard: function(A){
        A(AdFactory.loadAd(728, 90, root_path + "global/html/templates/leaderboard.html"))
    }
};
var Navs = {
    init: function(){
        dboard.init();
        $(window).bind("resize", Navs.resizeNav);
        if (typeof Show !== "undefined") {
            Navs.buildShowMenu();
            $("#lnkShowMenu a").click(Navs.showShowMenu);
            $("#lnkMainMenu").click(Navs.showAsMenu)
        }
        else {
            $("#lnkMainMenu").hide();
            $("#lnkSchedule").hide();
            $("#asMenu").show();
			$("#lnkGames").show()
        }
        if (dboard.isLoggedIn()) {
            var A = $("#lnkLogin");
            A.html("Log out").click(function(){
                if (dboard.isLoggedIn()) {
                    dboard.logOut();
                    $(this).html("Log in");
                    return false
                }
            })
        }
        Navs.resizeNav()
    },
    hideAsMenu: function(){
        var A = $("#asMenu").width();
        $("#asMenu").animate({
            width: 0
        }, "slow", "easeOutBounce", function(){
            $("#asMenu").hide();
            $("#asMenu").width(A);
            $("#lnkMainMenu").fadeIn(200);
			$("#lnkAllShows").fadeIn(200)
        });
        return false
    },
    showShowMenu: function(){
        Navs.hideAsMenu();
        Navs.hideLogin();
        $("#lnkShowMenu").fadeOut(200);
        $("#showMenu").fadeIn(600);
        return false
    },
    hideShowMenu: function(){
        var A = $("#showMenu").css("left");
        $("#showMenu").animate({
            left: $(window).width()
        }, "slow", "easeOutBounce", function(){
            $("#showMenu").hide();
            $("#showMenu").css("left", A)
        });
        return false
    },
    showAsMenu: function(){
        Navs.hideShowMenu();
        $("#lnkMainMenu").fadeOut(200);
		$("#lnkAllShows").fadeOut(200);
        $("#lnkShowMenu").fadeIn(600);
        $("#asMenu").fadeIn(600);
        return false
    },
    buildShowMenu: function(){
        $.each(Show.configuration.menuSetup, function(A){
            if (Show.configuration.menuSetup[A]) {
                if (A + 1 != Show.configuration.menuSetup.length) {
                    divider = ""
                }
                else {
                    divider = ""
                }
                newlink = $("<li/>").attr("id", Show.configuration.menuSetup[A].anchor + "link").append('<a class="hist" href="indexpage.html#' + Show.configuration.menuSetup[A].anchor + '">' + Show.configuration.menuSetup[A].menuName + divider + "</a>").appendTo("#showMenu ul")
            }
        })
    },
    resizeNav: function(){
        var A = $(window).innerWidth() - $("#asLogo").outerWidth();
        A -= $("#lnkShowMenu").length > 0 ? $("#lnkShowMenu").outerWidth() : 0;
        $("#asMenu").width(A - 70)
    },
    showLogin: function(){
        Navs.hideShowMenu();
        $("#loginBox").fadeIn(600);
        $("#asMenu").fadeOut(200);
        return false
    },
    hideLogin: function(){
        $("#asMenu").fadeIn(600);
        $("#loginBox").fadeOut(200);
        return false
    }
};
var Tracker = {
    PAGENAME_PREFIX: "",
    track: function(A, B){
        window.setTimeout(function(){
            try {
				var showName = A.split(" - ");
				function subSectionStr() {
					if (showName[0] == "Index") {
						return " : Home";
					}
					else {
						return " : " + showName[0];
					}
				}
                s.pageName = B + " : " + Tracker.PAGENAME_PREFIX + A;
                s.server = B;
                s.channel = B + subSectionStr();
                s.pageType = "";
                var C = s.t();
                if (C) {
                    document.write(C)
                }
            } 
            catch (D) {
                if (typeof(console) != "undefined") {
                    console.log("{track} pageName: " + A + ", channel: " + B + ", error: " + D)
                }
            }
        }, 0)
    }
};
var PROXY_PREFIX = "/adultswimdynamic";
var isie = (navigator.appVersion.indexOf("MSIE") != -1) ? (navigator.appVersion.indexOf("Mac") != -1) ? false : true : false;
if (isie) {
    document.execCommand("BackgroundImageCache", false, true)
}
function extend(D, B){
    var C = new B();
    for (var A in C) {
        if (typeof(D[A]) != "function") {
            D[A] = C[A]
        }
    }
}

function fixpng(B){
    if (!$.browser.msie) {
        return
    }
    for (var A = 0; A < B.length; A++) {
        if (B[A].complete) {
            $(B[A]).ifixpng()
        }
        else {
            $(B[A]).load(function(){
                $(this).ifixpng()
            })
        }
    }
}

$(document).ready(function(){
    $.ifixpng(root_path + "global/imgs/pixel.gif");
    fixpng($("img[@src$=.png], .pngfix"));
    $("#loading").ajaxStart(function(){
        $(this).show()
    });
    $("#loading").ajaxStop(function(){
        $(this).hide()
    });
    if (typeof(window.__firebug__) != "undefined") {
        $("#firebug").show()
    }
});
