﻿
img = new Image();
img.src = 'images/cu_logo_over.jpg';

img2 = new Image();
img2.src = 'images/wif_btn_over.jpg';

$(document).ready(function()
{
    $(".dialog").dialog({
        bgiframe: true,
        autoOpen: false,
        modal: true,
        show: 'fold',
        hide: 'fold',
        buttons: {
            'New Email': function()
            {
                var to = $("#" + $(this).attr("id") + "_to").val();
                var subject = $("#" + $(this).attr("id") + "_subject").val();
                var body = $("#" + $(this).attr("id") + "_body").val();

                var win = window.open("mailto:" + to + "?subject=" + subject + "&body=" + body);
                if (win && win.open && !win.closed)
                    win.close();
            },
            Cancel: function()
            {
                $(this).dialog('close');
            }
        }
    });

    $("#youtube_upload").dialog({
        bgiframe: true,
        autoOpen: false,
        modal: true,
        show: 'fold',
        hide: 'fold',
        title: 'Video Upload',
        open: function(event, ui)
        {
            $('#youtube_forms').show();
            $('#youtube_progress').hide();
            $('#errorzone').hide();
            $('#validation').hide();
            $('.ui-dialog-buttonpane').show();
            $('.ui-dialog-titlebar-close').show();
        },
        buttons: {
            'Upload': function()
            {
                if ($('#youtube_title').val().length > 0 && $('#youtube_desc').val().length > 0 && $('#youtube_file').val().length > 0)
                {
                    $('#youtube_forms').hide();
                    $('#youtube_progress').show();
                    $('.ui-dialog-buttonpane').hide();
                    $('.ui-dialog-titlebar-close').hide();

                    $.ajax({
                        type: "POST",
                        url: "youtube_upload.php",
                        dataType: "json",
                        data: { 'title': $('#youtube_title').val(), 'desc': $('#youtube_desc').val() },
                        timeout: 30000,
                        error: function(xhr, status, error)
                        {
                            $('#youtube_progress').hide();
                            $('.ui-dialog-titlebar-close').show();

                            $('#errorzone').text("An error has occurred, please try again.").show();
                        },
                        success: function(data, status)
                        {
                            $('#youtube_upload_file_token').val(data.token);
                            $('#youtube_upload_file_form').attr('action', data.url + '?nexturl=' + window.location.href);
                            $('#youtube_upload_file_form').submit();
                        }
                    });
                }
                else
                {
                    $("#validation").show();
                }
            },
            Cancel: function()
            {
                $(this).dialog('close');
            }
        }
    });
});

function showPhotoForm()
{
    $('#photo_dialog').dialog('option', 'width', 450).dialog('option', 'height', 320).dialog('open');
}

function showContestForm()
{
    $('#contest_dialog').dialog('option', 'width', 600).dialog('option', 'height', 500).dialog('open');
}

function showYouTubeForm()
{
    $('#youtube_upload').dialog('option', 'width', 450).dialog('option', 'height', 375).dialog('open');
}

function showNewsVideo(flashPlayerUrl)
{
    $('#press_list').hide();
    $('#press_video').show();

    var flashUrl = flashPlayerUrl + "&rel=0";
    var playerHtml = '<object width="293" height="190"><param name="movie" value="' + flashUrl + '"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><param name="wmode" value="transparent"></param><embed src="' + flashUrl + '" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="293" height="190" wmode="transparent"></embed></object>';
    $('#press_player').html(playerHtml);
}

function hideNewsVideo()
{
    $('#press_video').hide();
    $('#press_list').show();
    
    $('#press_player').html('');
}

function showUploadedVideo(flashPlayerUrl)
{
    $('#uploaded_list').hide();
    $('#uploaded_video').show();

    var flashUrl = flashPlayerUrl + "&rel=0";
    var playerHtml = '<object width="293" height="190"><param name="movie" value="' + flashUrl + '"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><param name="wmode" value="transparent"></param><embed src="' + flashUrl + '" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="293" height="190" wmode="transparent"></embed></object>';
    $('#uploaded_player').html(playerHtml);
}

function hideUploadedVideo()
{
    $('#uploaded_video').hide();
    $('#uploaded_list').show();
    
    $('#uploaded_player').html('');
}
