$(document).ready(function () {
    $("ul.video-list li a:first").hide();

    $("ul.video-list li a").click(function () {
        // work out our video image source
        var strVideoHRef = $(this).attr("href");
        var intVideoIdEndChar = strVideoHRef.indexOf('&') > 0 ? strVideoHRef.indexOf("&") : strVideoHRef.length;
        var strVideoId = strVideoHRef.substring(strVideoHRef.indexOf('=') + 1, intVideoIdEndChar);
        var strImageSource = "http://img.youtube.com/vi/" + strVideoId + "/0.jpg";

        $("ul.video-list li a").each(function () {
            $(this).show();
        });
        $(this).hide();

        $("div#youtube-content div.selected img").attr("src", strImageSource);

        // work out the anchor source
        //var strBoltonSchoolHRef = $("div#youtube-content div.selected a").attr("href");
        //var strBoltonSchoolTVPath = strBoltonSchoolHRef.substring(0, strBoltonSchoolHRef.lastIndexOf('/')+1);
        //alert(strBoltonSchoolTVPath);
        $("div#youtube-content div.selected a").attr("href", strVideoHRef);
        $("div#youtube-content div.selected a").attr("title", $(this).attr("title"));

        // check to see if we are a division home or the home page. If home (first if statement) then update the description rather than the heading!
        if ($("div.division div#youtube-content div.selected .youtube-selected").length)
            $("div.division div.selected h3.youtube-selected").text($(this).text());
        else if ($("div#youtube-content div.selected p.youtube-description").length)
            $("div#youtube-content div.selected p.youtube-description").text($(this).text());

        return false;
    });
});
