$(function () {
    
    // Fix transparency in IE6
    $('body').supersleight({shim: '/display_images/youngpeople/x.gif'});
    
    // Make any links to the mixer game open using thickbox
    var game_links = $("a[href*=projecttwo.html]").addClass("thickbox").each(function () {
        this.href += (this.href.match(/\?/)) ? "&" : "?";
		this.href += "KeepThis=true&TB_iframe=true&height=570&width=770";
    });
    tb_init(game_links);

    // Initialise Spotify form
    $(".feelgood_tunes .feelgood-form").hide();
    $(".feelgood_tunes .form_control").click(function () {
        $(this).siblings(".feelgood-form:hidden").slideDown();
        $(this).siblings(".feelgood-form:visible").hide();
        return false;
    }); 
    
    // Initialise sliding feedback form
    $('a.pageslide').pageSlide({
        width: "360px",
        bodyclickclose: false,
        loaded: function () {
            $('#feedbackform').attr("onsubmit", "").submit(function () {
                if (($('#yourthoughts').val() === "" || $('#yourthoughts').val() === "I think...") && ($('#wouldlike').val() === "" || $('#wouldlike').val() === "I would like to see...")) {
                    alert('Please tell us your thoughts, or what you\'d like to see');
                    return false;
                }
                if ($('#details_name').val() === "" || $('#details_name').val() === "Name") {
                    alert('Please enter your name');
                    $('#details_name').focus();
                    return false;
                }
                if ($('#details_email').val() === "" || $('#details_email').val() === "Email" || !(/^([a-zA-Z0-9-_\+\']+\.)*[a-zA-Z0-9-_\+\']+@([a-zA-Z0-9\-]+\.)+[a-zA-Z0-9]+$/).test($('#details_email').val())) {
                    alert('Please enter your valid email address');
                    $('#details_email').focus();
                    return false;
                }
                if ($('#age').val() === "") {
                    alert('Please choose your age');
                    $('#age').focus();
                    return false;
                }
        
                //more validation here
        
                return true;
            });

			$("#feedback_container a.new_window").attr({ target: "_blank", title: "opens in new window" });
        }
    });
    
    /* Cufon font replacement */
    
    if (Cufon) {
        // Aaaiight font doesn't have apostrophes, so we're using commas with negative top margins.
        $(".body_text h2, .callout, .related_links_title, .intro strong, .body_text strong, .speech li div").each(function() {
            $(this).html( $(this).html().replace(/'/g,"<span class=\"apostrophe\">,</span>") );
        });
        Cufon.replace(".body_text h2, .callout, .related_links_title, .intro strong, .body_text strong, .speech li div", { fontFamily: 'Aaaiight' });
        Cufon.replace(".listing h3", { fontFamily: 'Aaaiight', hover: true });
    }
    
    /* Sidebar callouts: alternate colours */
    $("#right-col div.callout:even").addClass("leftbubble");
    $("#right-col div.callout:odd").addClass("rightbubble");
    
    /* Resource browser */
    $("#other_uthink_resources ul li").not(":first").hide();
    var yp_current_resource = 1;
    $("#other_uthink_resources a.next").click(function() {
        if ($("#other_uthink_resources ul li:last").is(":not(:visible)")) {
            $("#other_uthink_resources ul li:visible").hide().next().fadeIn("fast");
            $("#yp_current_resource").text(++yp_current_resource);
        }
		return false;
    });
    $("#other_uthink_resources a.prev").click(function() {
        if ($("#other_uthink_resources ul li:first").is(":not(:visible)")) {
            $("#other_uthink_resources ul li:visible").hide().prev().fadeIn("fast");
            $("#yp_current_resource").text(--yp_current_resource);
        }
		return false;
    });
    
});

