var autoswitch_interval;
function switchMainBox(num, dontclear) {
    if ((typeof(dontclear) == "undefined") || (dontclear != 1)) {
        clearInterval(autoswitch_interval);
    }

    image_id = 'mainbox_image' + num;
    text_id = 'mainbox_text' + num;
    num_id = 'num' + num
    $('span.topic.highlighted').removeClass("highlighted");
    $('#'+num_id).addClass("highlighted");
    $('.mainbox_part:visible').fadeOut("slow", function() {
        $('#'+image_id).fadeIn("slow");
        $('#'+text_id).fadeIn("slow");
    })
}


/* Fade in first mainbox */
$(document).ready(function() {
    $('img.mainbox_part:first').fadeIn("slow");
    $('div.mainbox_part:first').fadeIn("slow");
    $('#num1').addClass("highlighted");

})


/* AUTOSWITCH */
$(document).ready(function() {
    var seconds = 10;

    current = 1;
    autoswitch_interval = setInterval(function() {
	current++;
	if (current > 7)
	    current = 1;
	switchMainBox(current, 1);
    }, seconds * 1000)

})


/* Email watermark thing */
$(document).ready(function() {

    // Define what happens when the textbox comes under focus
    // Remove the watermark class and clear the box
    $("#emailsubscribe").focus(function() {

        $(this).filter(function() {

            // We only want this to apply if there's not
            // something actually entered
            return $(this).val() == "" || $(this).val() == "Your email address"

        }).removeClass("watermarkOn").val("");

    });

    // Define what happens when the textbox loses focus
    // Add the watermark class and default text
    $("#emailsubscribe").blur(function() {

        $(this).filter(function() {

            // We only want this to apply if there's not
            // something actually entered
            return $(this).val() == ""

        }).addClass("watermarkOn").val("Your email address");

    });

});
