var IE = /*@cc_on!@*/false;
var url = "http://"+window.location.hostname+"/wam.php";
$(document).ready( function() {
    $("input:text").focus( function() {
        if ( $(this).val() == $(this).attr('defaultValue') ) {
            $(this).val("");
        }
    });
    $("input:text").blur( function() {
        if ( $(this).val() == "") {
            $(this).val( $(this).attr('defaultValue') );
        }    
    });
    $("#joinList").click( function() {
        var value = $(this).parent().children("input:text").val();
        var mode = "addEmail";
        $("#joinList").replaceWith("<div id='joinListReplaced'>thinking...</div>")
        database(mode,value);
    });
    $("#header li").hover ( function() {
        var left = $(this).offset().left;
        var top = $(this).offset().top + 29;
        if ( $(this).text() == $(this).parent().children("li:first").text() ) {
            var firstLeft = $(this).offset().left + 85; // was 130
            $("#pointReverse").offset({top:top, left:firstLeft}).show();    
        } else {
            $("#point").offset({top:top, left:left}).show();
        }
    }, function() {
        $("#point").offset({top:0,left:0}).hide();
        $("#pointReverse").offset({top:0,left:0}).hide();
    }); 
});
function database(mode,value) {
    var requestString = "&mode="+mode+"&value="+value;
    var contactEmail = "info@wearemanyfestival.com"
    $.ajax({  
        type: "POST",  
        url: url,  
        data: requestString, 
        success: function(text) {
            $("#joinListReplaced").text("added!");
            return true;
        },
        error: function() {
            $("#joinListReplaced").html("<a href='mailto:"+contactEmail+"' title='email us to get on the list!'>failed!</a>");
        }  
    }); 
}
function contact() {
    var valid = true;
    $("#contact input:text").each( function() {
        if ( $(this).val() == $(this).attr('defaultValue') ) { valid = false; }
    });
    if (valid == false) {
        $("#contactMessage").text("Please fill in all fields");
    } else {
        var requestString = $("#contactForm").serialize()+"&mode=send";
        var contactEmail = "info@wearemanyfestival.com"
        $("#contactMessage").text("sending your email...");
        $.ajax({  
            type: "POST",  
            url: url,  
            data: requestString, 
            success: function(text) {
                $("#contactMessage").text(text);
                return true;
            },
            error: function() {
                $("#contactMessage").html("The form did not work; please send your email to <a href='mailto:"+contactEmail+"' title='email us to get on the list!'>"+contactEmail+"</a>.");
                return false;
            }  
        });     
    }
    
}
