$(function() {
   $(".hover").hover(function() {
        var src = $(this).attr("src").replace(/\./, '_on.');
        $(this).attr("src", src);
    },function() {
        var src = $(this).attr("src").replace(/_on\./, '.');
        $(this).attr("src", src);
    });
});

var pos = 0;
function slideshow(move) {
    pos = pos + move;
    if (pos < 0) {
        pos = images.length - 1;
    }
    if (pos >= images.length) {
        pos = 0;
    }
    $("#slideshow td.image img").attr("src", images[pos].src);
    $("#slideshow td.text").text(images[pos].caption);
}
function slideshow_init() {
    slideshow(0);
    $("#slideshow a.prev").click(function() {
        slideshow(-1);
        return false;
    });
    $("#slideshow a.next").click(function() {
        slideshow(1);
        return false;
    });
}
function validate(form) {
    var valid = true;
    $("dd.mandatory").remove();
    $("#" + form + " :input.required").each(function() {
        if ($(this).val() === "") {
            if (valid) {
                // Give focus to the first invalid item
                $(this).focus();
            }
            $(this).parents("dd").after("<dd class='mandatory'>This is a required field</dd>");
            valid = false;
        }
    });
    $("#" + form + " :input.email").each(function() {
        if ($(this).val() !== "") {
            var isEmail = /^[_a-z0-9-]+(\.[_a-z0-9-]+)*(\+[_a-z0-9-]+)?@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,6})$/i.test($(this).val());
            if (!isEmail) {
                if (valid) {
                    // Give focus to the first invalid item
                    $(this).focus();
                }
                $(this).parents("dd").after("<dd class='mandatory'>Please input a valid e-mail address</dd>");
                valid = false;
            }
        }
    });
    $("dd.mandatory+dd.mandatory").remove();
    return valid;
}
