function setupDimmer()
{
    // Get the width of the presentation area
    var presentation_area = $('.site_full');
    var presentation_area_width = presentation_area.width();
    
    // Store where the content (comments, etc) begins
    var site_container = $('.site_container');
    var content_begin = site_container.position().top;
    
    

    $(".v_watch").css("zIndex", 99);
    // Set the presentation area to an absolute position, and set z-index
    // so that it stays above dimmer
    presentation_area.css("position", "absolute");
    presentation_area.css("top", "0");
    presentation_area.css("width", presentation_area_width + "px");
    
    // Set the position of the bottom content area
    $('.v_watch .presentation_area .iframe_container').css("width", presentation_area_width + "px");
    site_container.css("paddingTop", (0 + content_begin) + "px");

    var $btn = $('.button_lights').createButton(siteRoot + "/Content/img/sunoff.png", siteRoot + "/Content/img/sunon.png", $(".site_full:first"));
    $btn.addOff(function() {
            $(".v_watch").css("zIndex", 98);
        });
    $btn.addOn(function() {
            $(".v_watch").css("zIndex", 101);
        });
}
    
function startEvent()
{
    var rand = (new Date()).getTime();
    $(".text_container").hide();
    $(".iframe_container").show();
    var randStr = "?";
    if (iframe_url.indexOf('?') != -1) randStr = "&";
    $("#mediaframe").attr("src", iframe_url + randStr + "rand=" + rand);
}
    

function checkEventStart()
{
    if (type == "Live")
    {
        $.post(siteRoot + "/" + communityId + "/Ajax/EventStarted.aspx", { id: presentation_id }, 
            function(data) {
                if (data == "True")
                    startEvent();
                else
                {
                    $(".not_yet_started").show();
                    setTimeout(
                        function() {
                            checkEventStart();
                        }, 5000);
                }
            });
    }
    else
    {
        startEvent();
        
        
    }
}

$(document).ready(function() {
    setupDimmer();
    $(".iframe_container").hide();
    $(".text_container").show();
    
    // If a password is required...
    if ($(".presentation_area .not_logged_in").size())
    {
        
    }
    else if ($(".presentation_area .password_required").size())
    {
        $("#eventPasswordForm").validate({
            messages: {
                "eventPassword": {
                    required: "Password is required."
                }
            },
            errorLabelContainer: ".eventPasswordError"
        });
        $("#eventPasswordForm").submit(function() {
            $.post(siteRoot + "/" + communityId + "/Ajax/EventLogin.aspx", { password: $(this).find("#eventPassword").val(), id: presentation_id, type: type }, 
                function(data) { 
                    if (data == "True")
                    {
                        // Verified
                        $(".presentation_area .password_required").hide();
                        checkEventStart();
                    }
                }); 
            
            return false;
        });
    }
    else
    {
        checkEventStart();    
    }
});

