$(function() {
    $("#next").click(slideshow_move(1));
    $("#prev").click(slideshow_move(-1));

    if ($("#slideshow img").size() > 1) {
        window.setTimeout(slideshow_autorun, 10000);
    }	
});

function slideshow_move(direction) {
    return function() {
        var size = $("#slideshow img").size();
        if (direction < 0) direction = size + direction;
        var current_idx;
        $("#slideshow img").each(function(idx) {
            if ($(this).css("display") != "none") {
                current_idx = idx;
                return false;
            }
        });
        var next_idx = (current_idx + direction) % size;
        $("#slideshow img:eq(" + current_idx + ")").fadeOut("normal", function() {
            $("#slideshow img:eq(" + next_idx + ")").fadeIn("normal");
        });
        return false;
    }
}

function slideshow_autorun() {
    slideshow_move(1)();
    window.setTimeout(slideshow_autorun, 10000);
}

function echeck(str) {
    var at="@"
    var dot="."
    var lat=str.indexOf(at)
    var lstr=str.length
    var ldot=str.indexOf(dot)
    if (str.indexOf(at)==-1){
        alert("You entered an invalid email address")
        return false
    }

    if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
        alert("You entered an invalid email address")
        return false
    }

    if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
        alert("You entered an invalid email address")
        return false
    }

    if (str.indexOf(at,(lat+1))!=-1){
        alert("You entered an invalid email address")
        return false
    }

    if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
        alert("You entered an invalid email address")
        return false
    }

    if (str.indexOf(dot,(lat+2))==-1){
        alert("You entered an invalid email address")
        return false
    }

    if (str.indexOf(" ")!=-1){
        alert("You entered an invalid email address")
        return false
    }

    return true;
}

function mailing() {
    if(echeck(document.getElementById("mailingEmailEmail").value))
        return true;
    else
        return false;
}