(function ($) {
    $.fn.jCarouselLite = function (o) {
        o = $.extend({
            btnPrev: null,
            btnNext: null,
            btnGo: null,
            mouseWheel: false,
            auto: null,
            speed: 200,
            easing: null,
            vertical: false,
            circular: true,
            visible: 3,
            start: 0,
            scroll: 1,
            beforeStart: null,
            afterEnd: null
        }, o || {});
        return this.each(function () {
            var b = false,
                animCss = o.vertical ? "top" : "left",
                sizeCss = o.vertical ? "height" : "width";
            var c = $(this),
                ul = $("ul", c),
                tLi = $("li", ul),
                tl = tLi.size(),
                v = o.visible;
            if (o.circular) {
                ul.prepend(tLi.slice(tl - v - 1 + 1).clone()).append(tLi.slice(0, v).clone());
                o.start += v
            }
            var f = $("li", ul),
                itemLength = f.size(),
                curr = o.start;
            c.css("visibility", "visible");
            f.css({
                overflow: "hidden",
                float: o.vertical ? "none" : "left"
            });
            ul.css({
                margin: "0",
                padding: "0",
                position: "relative",
                "list-style-type": "none",
                "z-index": "1"
            });
            c.css({
                overflow: "hidden",
                position: "relative",
                "z-index": "2",
                left: "0px"
            });
            var g = o.vertical ? height(f) : width(f);
            var h = g * itemLength;
            var j = g * v;
            f.css({
                width: f.width(),
                height: f.height()
            });
            ul.css(sizeCss, h + "px").css(animCss, -(curr * g));
            c.css(sizeCss, j + "px");
            if (o.btnPrev) $(o.btnPrev).click(function () {
                return go(curr - o.scroll)
            });
            if (o.btnNext) $(o.btnNext).click(function () {
                return go(curr + o.scroll)
            });
            if (o.btnGo) $.each(o.btnGo, function (i, a) {
                $(a).click(function () {
                    return go(o.circular ? o.visible + i : i)
                })
            });
            if (o.mouseWheel && c.mousewheel) c.mousewheel(function (e, d) {
                return d > 0 ? go(curr - o.scroll) : go(curr + o.scroll)
            });
            if (o.auto) setInterval(function () {
                go(curr + o.scroll)
            }, o.auto + o.speed);

            function vis() {
                return f.slice(curr).slice(0, v)
            };

            function go(a) {
                if (!b) {
                    if (o.beforeStart) o.beforeStart.call(this, vis());
                    if (o.circular) {
                        if (a <= o.start - v - 1) {
                            ul.css(animCss, -((itemLength - (v * 2)) * g) + "px");
                            curr = a == o.start - v - 1 ? itemLength - (v * 2) - 1 : itemLength - (v * 2) - o.scroll
                        } else if (a >= itemLength - v + 1) {
                            ul.css(animCss, -((v) * g) + "px");
                            curr = a == itemLength - v + 1 ? v + 1 : v + o.scroll
                        } else curr = a
                    } else {
                        if (a < 0 || a > itemLength - v) return;
                        else curr = a
                    }
                    b = true;
                    ul.animate(animCss == "left" ? {
                        left: -(curr * g)
                    } : {
                        top: -(curr * g)
                    }, o.speed, o.easing, function () {
                        if (o.afterEnd) o.afterEnd.call(this, vis());
                        b = false
                    });
                    if (!o.circular) {
                        $(o.btnPrev + "," + o.btnNext).removeClass("disabled");
                        $((curr - o.scroll < 0 && o.btnPrev) || (curr + o.scroll > itemLength - v && o.btnNext) || []).addClass("disabled")
                    }
                }
                return false
            }
        })
    };

    function css(a, b) {
        return parseInt($.css(a[0], b)) || 0
    };

    function width(a) {
        return a[0].offsetWidth + css(a, 'marginLeft') + css(a, 'marginRight')
    };

    function height(a) {
        return a[0].offsetHeight + css(a, 'marginTop') + css(a, 'marginBottom')
    }
})(jQuery);
jQuery.easing = {
    easein: function (x, t, b, c, d) {
        return c * (t /= d) * t + b;
    },
    easeinout: function (x, t, b, c, d) {
        if (t < d / 2) {
            return 2 * c * t * t / (d * d) + b;
        }
        var ts = t - d / 2;
        return -2 * c * ts * ts / (d * d) + 2 * c * ts / d + c / 2 + b;
    },
    easeout: function (x, t, b, c, d) {
        return -c * t * t / (d * d) + 2 * c * t / d + b;
    },
    linear: function (x, t, b, c, d) {
        return c * t / d + b;
    }
};
$(document).ready(function () {
    $(".accordion .children").hide();
    $(".accordion .head").click(function () {
        var idParent = "#" + $(this).parent().parent().parent().attr("id");
        $(idParent + " .children").slideUp("slow");
        if (!$(this).hasClass("on")) {
            $(idParent + " .head").removeClass("on");
            $(this).addClass("on");
            $(idParent + " ." + $(this).attr("title")).slideDown("slow");
        } else {
            $(idParent + " .head").removeClass("on");
        }
    });
});
$(document).ready(function () {
    $(".tabbox .tabcontent").hide();
    $(".tabbox .tabcontent-01").show();
    $(".tabbox .tab-01").addClass("on");
    $(".tab a").click(function () {
        var idParent = "#" + $(this).parent().parent().parent().attr("id");
        $(idParent + " .tab").removeClass("on");
        $(this).parent().addClass("on");
        $(idParent + " .tabcontent").hide();
        $(idParent + " " + $(this).attr("title")).show();
    });
});
var isMenuAnimating = false;
$(document).ready(function () {
    var pxHeight = $("#MembersNav").height();

    function showNav() {
        $("#cwpPlayerDiv").css("visibility", "hidden");
        $("#MembersNav_Shows a").addClass("on");
        $("#MembersNav").show();
        $("select#lstRegion").hide();
    }
    function hideNav() {
        $("#MembersNav_Shows a").removeClass("on");
        $("#MembersNav").stop().hide();
        $("#cwpPlayerDiv").css("visibility", "visible");
        $("select#lstRegion").show();
    }
    $("#MembersNav .tab a").click(function () {
        pxHeight = $("#MembersNav " + $(this).attr("title")).height() + 125;
        $("#MembersNav").stop().height(pxHeight);
    });
    $("#MembersNav_Shows a").click(function () {
        if (!isMenuAnimating) {
            isMenuAnimating = true;
            setTimeout("isMenuAnimating=false", 1000);
            if ($("#MembersNav").css("display") == "none") {
                $("#MembersNav").css("left", (($(window).width() - 959) / 2) + "px");
                showNav();
            } else {
                hideNav();
            }
        }
    });
    $("#MembersNavClose").click(hideNav);
});
$(document).ready(function () {
    var stbInstructions = new Array;
    $("input.SearchTextBox").each(function () {
        stbInstructions[$(this).attr("id")] = $(this).val();
    });
    $("input.SearchTextBox").focus(function () {
        if ($(this).val() == stbInstructions[$(this).attr("id")]) {
            $(this).val("");
        }
    });
    $("input.SearchTextBox").blur(function () {
        if (!$(this).val()) {
            $(this).val(stbInstructions[$(this).attr("id")]);
        }
    });
});
$(document).ready(function () {
    $("#GFooterSliderWrapper #GFooterSliderWindow").jCarouselLite({
        btnNext: "#GFooterSliderWrapper .ScrollBlogNext",
        btnPrev: "#GFooterSliderWrapper .ScrollBlogPrevious",
        speed: 1500,
        easing: "easeinout",
        visible: 4,
        scroll: 4
    });
});
$(document).ready(function () {
    $("#CanadaNetworkContainer select").change(function () {
        document.location = $(this).val();
    });
});
var detectAgent = navigator.userAgent.toLowerCase();
if (detectAgent.indexOf("msie") > -1) {
    var arVersion = navigator.appVersion.split("MSIE");
    var version = parseFloat(arVersion[1]);
    if (version == 7) {
        $(document).ready(function () {
            $("div").each(function () {
                if ($(this).css("float") == "left" && $(this).css("margin-bottom") != "0px") {
                    $(this).css("padding-bottom", $(this).css("margin-bottom"));
                }
            });
        });
    }
}(function ($) {
    var $scrollTo = $.scrollTo = function (target, duration, settings) {
        $(window).scrollTo(target, duration, settings);
    };
    $scrollTo.defaults = {
        axis: "xy",
        duration: parseFloat($.fn.jquery) >= 1.3 ? 0 : 1
    };
    $scrollTo.window = function (scope) {
        return $(window).scrollable();
    };
    $.fn.scrollable = function () {
        return this.map(function () {
            var elem = this,
                isWin = !elem.nodeName || $.inArray(elem.nodeName.toLowerCase(), ["iframe", "#document", "html", "body"]) != -1;
            if (!isWin) {
                return elem;
            }
            var doc = (elem.contentWindow || elem).document || elem.ownerDocument || elem;
            return $.browser.safari || doc.compatMode == "BackCompat" ? doc.body : doc.documentElement;
        });
    };
    $.fn.scrollTo = function (target, duration, settings) {
        if (typeof duration == "object") {
            settings = duration;
            duration = 0;
        }
        if (typeof settings == "function") {
            settings = {
                onAfter: settings
            };
        }
        if (target == "max") {
            target = 9000000000;
        }
        settings = $.extend({}, $scrollTo.defaults, settings);
        duration = duration || settings.speed || settings.duration;
        settings.queue = settings.queue && settings.axis.length > 1;
        if (settings.queue) {
            duration /= 2;
        }
        settings.offset = both(settings.offset);
        settings.over = both(settings.over);
        return this.scrollable().each(function () {
            var elem = this,
                $elem = $(elem),
                targ = target,
                toff, attr = {},
                win = $elem.is("html,body");
            switch (typeof targ) {
            case "number":
            case "string":
                if (/^([+-]=)?\d+(\.\d+)?(px)?$/.test(targ)) {
                    targ = both(targ);
                    break;
                }
                targ = $(targ, this);
            case "object":
                if (targ.is || targ.style) {
                    toff = (targ = $(targ)).offset();
                }
            }
            $.each(settings.axis.split(""), function (i, axis) {
                var Pos = axis == "x" ? "Left" : "Top",
                    pos = Pos.toLowerCase(),
                    key = "scroll" + Pos,
                    old = elem[key],
                    Dim = axis == "x" ? "Width" : "Height";
                if (toff) {
                    attr[key] = toff[pos] + (win ? 0 : old - $elem.offset()[pos]);
                    if (settings.margin) {
                        attr[key] -= parseInt(targ.css("margin" + Pos)) || 0;
                        attr[key] -= parseInt(targ.css("border" + Pos + "Width")) || 0;
                    }
                    attr[key] += settings.offset[pos] || 0;
                    if (settings.over[pos]) {
                        attr[key] += targ[Dim.toLowerCase()]() * settings.over[pos];
                    }
                } else {
                    attr[key] = targ[pos];
                }
                if (/^\d+$/.test(attr[key])) {
                    attr[key] = attr[key] <= 0 ? 0 : Math.min(attr[key], max(Dim));
                }
                if (!i && settings.queue) {
                    if (old != attr[key]) {
                        animate(settings.onAfterFirst);
                    }
                    delete attr[key];
                }
            });
            animate(settings.onAfter);

            function animate(callback) {
                $elem.animate(attr, duration, settings.easing, callback &&
                function () {
                    callback.call(this, target, settings);
                });
            }
            function max(Dim) {
                var scroll = "scroll" + Dim;
                if (!win) {
                    return elem[scroll];
                }
                var size = "client" + Dim,
                    html = elem.ownerDocument.documentElement,
                    body = elem.ownerDocument.body;
                return Math.max(html[scroll], body[scroll]) - Math.min(html[size], body[size]);
            }
        }).end();
    };

    function both(val) {
        return typeof val == "object" ? val : {
            top: val,
            left: val
        };
    }
})(jQuery);

function removeLinks(target, onlyTxt, onlyImg, imgSize) {
    $.ajax({
        type: "GET",
        url: "/_data/Shows.xml",
        dataType: "xml",
        success: function (data) {
            var validShows = new Array();
            $(data).find("item").each(function () {
                validShows.push([$(this).find("id").text(), $(this).find("url").text(), $(this).find("image").text()]);
            });
            $(target).each(function () {
                var showValid = false;
                var show = !onlyImg ? $(this).text() : $(this).find("img").attr("alt");
                for (i = 0; i < validShows.length; i++) {
                    if (show.toLowerCase() == validShows[i][0].toLowerCase()) {
                        showValid = true;
                        $(this).attr("href", validShows[i][1]);
                        if (!onlyImg && !onlyTxt) {
                            $(this).prepend("<br />");
                        }
                        if (onlyImg) {
                            $(this).html("");
                        }
                        if (!onlyTxt) {
                            if (imgSize) {
                                $("<img/>", {
                                    src: validShows[i][2] + "?size=130x91",
                                    width: 130,
                                    height: 91,
                                    alt: validShows[i][0],
                                    title: validShows[i][0]
                                }).prependTo(this);
                            } else {
                                $("<img/>", {
                                    src: validShows[i][2] + "?size=70x49",
                                    width: 70,
                                    height: 49,
                                    alt: validShows[i][0],
                                    title: validShows[i][0]
                                }).prependTo(this);
                            }
                        }
                    }
                }
                if (!showValid) {
                    if (!onlyImg && !onlyTxt) {
                        $(this).parent().addClass("linkRemoved").html($(this).text());
                    }
                    if (onlyImg) {
                        $(this).find("img").unwrap();
                    }
                    if (onlyTxt) {
                        $(this).parent().html($(this).text());
                    }
                }
            });
        }
    });
}
function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(";");
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == " ") {
            c = c.substring(1, c.length);
        }
        if (c.indexOf(nameEQ) == 0) {
            return c.substring(nameEQ.length, c.length);
        }
    }
    return null;
}
