$(function(){
    
    // show and center sub nav    
    $("#main-nav li").hover(function(){
        var thisWidth = $(this).width();
        var subWidth = $("ul",$(this)).width();
        var margLeft =  (thisWidth - subWidth) / 2
        $("ul",$(this)).css("margin-left", margLeft).show();
    },function(){
        $("ul",$(this)).hide();
    })
    
    // check if #carousel exists
    if ($("#carousel").length > 0) {
        $("#carousel").after('<div id="carousel-pager">').cycle({ 
            fx: "scrollHorz", 
            speed: 400, 
            timeout: 3000, 
            pager:  "#carousel-pager",
            pause: true,
            pagerAnchorBuilder: function() {
                return "<div></div>"
            },
            next: "#next-slide",
            prev: "#prev-slide"
        });
    }
    
    // video player
    $("#video-feed").widget({
        profile: "chicagothemusical",
        playlist: "uploads",
        max: "10"
    });
    
    setTimeout("videoload()", 2000);
    
    // get/set text fields onfocus/blur
    (function() {
        for (var b = document.getElementsByTagName("input"), a = 0; a < b.length; a++) if (b[a].type == "text") b[a].setAttribute("rel", b[a].defaultValue), b[a].onfocus = function() {
            if (this.value == this.getAttribute("rel")) this.value = "";
            else return false
        }, b[a].onblur = function() {
            if (this.value == "") this.value = this.getAttribute("rel");
            else return false
        }
    })();
})

