﻿$(document).ready(function(){
    // set class for JavaScript-only tasks
    $("body").addClass("hasJS");         
    /* MAIN NAV */
    /* Register form */
    if($("#register").html()) {
        $(" #content-inner a[@href='terms.aspx']").click(function() {
            window.open($(this).attr("href"));
            return false;
        });
    }        
    $("#test").keydown(function() {
        if(event.which || event.keyCode){
            if ((event.which == 13) || (event.keyCode == 13)) {
                document.getElementById('"+Button1.UniqueID+"').click();
                return false;
            }
        }
        else
        {
            return true;
        };
    });

    /* VIEW VIDEO */

    // Set up rating stars on view video page
    $(".ratingform").rating("rating.aspx", {radio: "rating", hidden: "rating"});
        
    /* GALLERY sort form */

    // hide submit button
    $("form#frmGallery input").hide();
    // add event to select list
    $("form#frmGallery select").change(function() {
        $("form#frmGallery").submit();
    });


    /* UPLOAD form */

    // hide 'extra info' panel
    $("p#uploadFormats2").hide();

    // add anchor using title text of content (keeps translated text in the HTML)
    $("p#uploadFormats1").append("<a href=\"#\" id=\"uploadFormatsToggle\">" + $("p#uploadFormats2").attr("title") + "</a>");

    // remove the title attribute
    $("p#uploadFormats2").removeAttr("title");

    // add click handler to "learn more" text
    $("p#uploadFormats1").find("a#uploadFormatsToggle").click(function() {
        $("p#uploadFormats2").toggle();
        return false;
    });

    /* EXTERNAL LINKS */
    $("a[@rel='external']").click(function() {
        window.open($(this).attr("href"));
        return false;
    });
    
    /* 'BACK' LINKS */
    $("a[@class='back']").click(function() {
        window.history.go(-1);
        return false;
    });

    /* ADMIN */
    $("a.delete").click(function(){
        return confirm("Delete?");        
    });
});

function setUploadLoader(theForm) {
    $("#loadingLabel").addClass("loadingLabelShow");
    $("#loadingLabel").css("background-image", "url(images/ajax-loader.gif)");
    $(".uploadButton").hide();
    return true;
}

// sIFR replaces headings
sIFR.activate();
sIFR.replace({selector: 'h2.white', wmode: 'transparent', src: 'scripts/myriad.swf', css: {'.sIFR-root': { 'color': '#ffffff', 'letter-spacing': 0, 'font-weight': 'bold'} }});
sIFR.replace({selector: 'h2.form', wmode: 'transparent', src: 'scripts/myriad.swf', css: {'.sIFR-root': { 'color': '#ffc916', 'letter-spacing': 0, 'text-transform': 'uppercase', 'font-weight': 'bold' }}});
sIFR.replace({selector: '#howtoenter h2', wmode: 'transparent', src: 'scripts/myriad.swf', css: {'.sIFR-root': { 'color': '#fff31b', 'letter-spacing': 0, 'font-weight': 'bold' } }});
