﻿$(document).ready(function(){


    // set class for JavaScript-only tasks
    $("body").addClass("hasJS"); 
        
    /* MAIN NAV */

    /* Hide Text */
    $("div#header ul li a").each(function(i){    
        $(this).parent("li").css("background-image", "url(main-nav.aspx?type=off&msg=" + $(this).attr("class") + ")");
        $(this).html("<span>" + $(this).text() + "</span>");
    });

/*
    $("div#header ul li a").each(function(i){
        // add a <span> to each so we can hide the text using visibility:hidden
        // to maintain accessibility
        
        
        // get the class attribute for this link
        var thisClass = $(this).attr("class");
        
        // if the class is the same as the "nav-" class on the <body>, set it to be selected
        var initialState = "off"
        if ($("body").attr("class").indexOf("nav-" + thisClass) != -1) {
            initialState = "on";
        };
        setNavState(this, thisClass, initialState);
        
        // create a <span> to preload the background image
        $(this).append("<span class=\"cache\"></span>");
        setNavState($(this).find("span.cache"), thisClass, "on");
        
        // if is NOT selected, add mouse events
        if (initialState == "off") {
            // mouseover 
            $(this).mouseover(function(){
                setNavState(this, thisClass, "on");
            });
            
            // mouseout
            $(this).mouseout(function(){
                setNavState(this, thisClass, "off");
            });
        }        
    });
    */
    /* 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;
    });
    
    $("#downloads ul li ul li a").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 setNavState(element, text, onOff) {
    $(element).css("background-image", "url(main-nav.aspx?type=" + onOff + "&msg=" + text + ")");    
    $(element).parent("li").css("background-image", "url(main-nav.aspx?type=off&msg=" + text + ")");
}

function setUploadLoader(theForm) {
    $("#loadingLabel").addClass("loadingLabelShow");
    $("#loadingLabel").css("background-image", "url(../images/ajax-loader-white.gif)");
    $(".uploadButton").hide();
    return true;
}

// sIFR replaces headings
sIFR.activate();
sIFR.replace({selector: 'h1, h2.replace', wmode: 'transparent', src: '../scripts/impact.swf', css: {'.sIFR-root': { 'color': '#ffc916', 'letter-spacing': -0.5, 'text-transform': 'uppercase', 'font-style': 'italic' }, 'a': { 'color': '#ffc916'}, 'a:hover': { 'color': '#ffc916'} }});
sIFR.replace({selector: 'h2.normal', wmode: 'transparent', src: '../scripts/impact.swf', css: {'.sIFR-root': { 'color': '#ffc916', 'letter-spacing': -0.5, 'font-style': 'italic' } }});