﻿var MaxBoxHeight = 0;

$(document).ready(function() {
    if ($("#HeaderImages img").length > 0) {
        window.setInterval("SwapImage()", 7000);
        $("#HeaderImages li").wrapInner("<div></div>")
        $("#HeaderImages li:not(:first)").hide().css("width","0");
    }
    $("#info").before('<div id="toggleinfo"><a href="#">Artists and programme notes</a></div>').hide();
    $("#toggleinfo a").click(function(e) {
        $("#info").slideToggle();
        e.preventDefault();
    });
    $("#vidcarousel").jCarouselLite({
        btnNext: "#next",
        btnPrev: "#prev",
        visible: 4
    });
    $("#acarousel").jCarouselLite({
        btnNext: "#anext",
        btnPrev: "#aprev",
        visible: 4
    });
    $("#ytcarousel").jCarouselLite({
        btnNext: "#ynext",
        btnPrev: "#yprev",
        visible: 4
    });

    $(".togglevisible").add($(".togglevisible").nextAll()).wrapAll('<div class="togglewrapper"></div>');
    $(".togglewrapper").before('<a class="togglelnk" href="#">more</a>').hide();
    $(".togglelnk").click(function(e) {
        $(this).next().slideToggle();
        e.preventDefault();
    });

    $(".home .rightcol .box").each(function(){
        if ($(this).height() > MaxBoxHeight)
            MaxBoxHeight = $(this).height();
    }).css("height",MaxBoxHeight);
    if ($(".home .rightcol").height() > $(".home .leftcol").height()) {
        $(".home .leftcol").css("height",$(".home .rightcol").height());
    } else {
        $(".home .rightcol").css("height",$(".home .leftcol").height());
    }
});

function SwapImage() {
    if ($("#HeaderImages img:visible").next("img").length > 0) {
        $("#HeaderImages img:visible").fadeOut(2500).next("img").fadeIn(2500);
    } else {
        $("#HeaderImages img:visible").fadeOut(2500);
        $("#HeaderImages img:first").fadeIn(2500);
    }
    SwapMessage();
}

var nxt;
function SwapMessage() {
    if ($("#HeaderImages li:visible").next("li").length > 0) {
        nxt = $("#HeaderImages li:visible").next("li");
    } else {
        nxt = $("#HeaderImages li:first");
    }
    $("#HeaderImages li:visible").fadeOut("fast", function(){
        nxt.css("width","0").show().animate({width: '790'},2500);
    });
}