﻿// sIFR replaces headings

var candice = {
    src: '../scripts/sifr/candice.swf'
};

sIFR.activate(candice);


sIFR.replace(candice, {selector: 'div#header ul li',
                       wmode: 'transparent',
                       css: {
                                '.sIFR-root': { 'leading': -4 },
                                'a, a:hover': { 'color': '#FFFFFF', 'text-align': 'center', 'text-decoration': 'none', 'line-height': '-50px' },
                                'a:hover, a.selected, a.selected:hover': {'color': '#FFCC66'}
                             }
                        });

sIFR.replace(candice, {selector: 'h1, h2.replace', wmode: 'transparent', css: {'.sIFR-root': { 'color': '#503314', 'letter-spacing': -0.5 } }});
sIFR.replace(candice, {selector: 'h2.normal', wmode: 'transparent', css: {'.sIFR-root': { 'color': '#503314', 'letter-spacing': -0.5 } }});

$(document).ready(function(){
   
    /* Register form */
    if($("#register").html()) {
        $(" #content-inner a[@href='terms.aspx']").click(function() {
            window.open($(this).attr("href"));
            return false;
        });
    }    
    
    $("#getstarted, #frmRegister, #frmLogin, #uploadForm, #languageChoice, #forgottenPasswordForm, .uploadForm").corner();
    
    if($("body#home").html()){
        if(!$("body").attr("class").match("country-NL")){
            $("#ctl00_content_popularVideo, #offer, #prizes").corner();
        }else{
            $("#offer").corner();
            $("#prizes h2").removeClass("replace");
            $("#prizes h2").css("text-indent", "-10000em");
            $("#prizes .button").removeClass("button");
            $("#ctl00_content_prizes a").removeClass("button");
        }
        
        if ($("body").attr("class").match("country-ES")) {
            $("#ctl00_content_zona40ES").corner();
            $("#ctl00_content_spidermanES").corner();
        }
    }
    
    if($("body#upload").html()){
        $("#aspnetForm").corner();
    }
    
    if($("body#forgotpassword").html()){
        $("#aspnetForm").corner();
    }
    
    if($("body#sendtofriend").html()){
        $("#aspnetForm").corner();
    }

    if($("body#contact").html()){
        $("#aspnetForm").corner();
    }
        
    // set class for JavaScript-only tasks
    $("body").addClass("hasJS"); 
    
    /* 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 */

    // add anchor using title text of content (keeps translated text in the HTML)
    $("p#uploadFormats1").append("<a href=\"#\" id=\"uploadFormatsToggle\">" + $("p#ctl00_content_uploadFormats2").attr("title") + "</a>");
    
    $("#uploadFormatsToggle").click(function(){
        window.location.href = "upload.aspx?show=true";
        //return false;
    });
    
    // remove the title attribute
    $("p#ctl00_content_uploadFormats2").removeAttr("title");
    
    // add click handler to "learn more" text
    
    /* 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?");        
    });

    $("#whatyoucanwin").css("padding-top", 0);
        
    $(".button").each(function(){
        $(this).wrap("<span class='button-outer'></span>");
        var classes = $(this).attr("class");
        var type = $(this).attr("type");
        
        $(this).parents("span.button-outer").addClass(classes);
        $(this).parents("span.button-outer").removeClass("button");
        
        if(type == "submit") $(this).parents("span.button-outer").addClass("submit");
        
        // If this is safari we can't style the buttons, so add an inline to the button-outer to remove the background
        if($.browser.safari) $(this).parent("span.button-outer").css("background", "none");
        
    });
    
    // We need to apply class names to the nav elements
    
    $("#header ul li a").each(function(){
        $(this).parent("li").addClass($(this).attr("class"));
        if($(this).attr("class").match($("body").attr("id"))){
            $(this).addClass("selected");
        }
    });
    
    $("#offer div").each(function(){

    });

});
function setNavState(element, text, onOff) {
    $(element).css("background-image", "url(main-nav.aspx?type=" + onOff + "&msg=" + text + ")");
}

function setUploadLoader(theForm) {
    $("#loadingLabel").addClass("loadingLabelShow");
    $("#loadingLabel").css("background-image", "url(../images/ajax-loader-white.gif)");
    $(".uploadButton").hide();
    return true;
}
