/* Global Javascript Functions

*/

//start the jQuery functions
$(document).ready(function() {

/*
//make lists of stuff for copy and paste into php/SQL
$("form input, form textarea").each(function(){
	var theID = $(this).attr("id")
	$("#map").append(theID + ', &nbsp;  ');
});
*/
// hide email addresses
$(".emaillink").attr("href", "mailto:will" + "@" + "luktown.org");
$(".contributeemail").attr("href", "mailto:recordings" + "@" + "soundofthatday.com");


//insert the style switch
if(document.body.className == 'addrecordingpage'){
	$("#header").prepend('<a class="styletoggle" href="">Go Small</a>');
}

	//change style via body class on click
	$(".styletoggle").click(function(){

			$("#content").hide();

			if(document.body.className == 'addrecordingpage'){
					$('body').addClass('smaller');
					$(this).text("Go Big!")
				}
				else {
					$('body').removeClass('smaller');
					$(this).text("Go Small!")
				}

			$("#content").fadeIn("200");

	return false

	});

$("#uploadform").submit(function(){
	if ($("#soundfile").val() == ""){

		$("#soundfile").focus().addClass("error");
		$("#soundfile").after("<label class='error' for='soundile'>Don't forget to add a file.</label>");
		 return false;
	}
      else	if($("#geotag").val() == ""){
		$("#address1").focus().addClass("error");
			if ($("label.maperror").length>0){
				$("label.maperror").html("Almost.  Try adding or removing some info.")
			}
			else {
				$("#address1").after("<label class='error clear maperror' for='address1'>We need to find you on the map first.  Please try a different address.</label>");
			}
		 return false;
	}

	else {$("button#submit").html("uploading now...").addClass("foundit")}
});



$("#hi").keyup(function(){

	if($("#hi").length>5){
		//console.log("hi");
	}
})//keyup
/*
$(document).keyup(function(event){
    if (event.keyCode == 27) {
        alert('escaped!');
    }
});
*/



// hide the sign up form
//$("#notifysignup").hide();

// hide the send to friend form.  revealed on successful submission of sign up form.
//$("#spreadtheword").hide();


/*
// show the sign up form.
$("a.notifysignup").click(function(){
	$("#spreadtheword").hide();
	$("#notifysignup2").show();
});

$("a.spreadtheword").click(function(){
	$("#spreadtheword").show();
	$("#notifysignup2").hide();
});

// hide the sign up form when the 'cancel' button is clicked
$("a.hidenotify").click(function(){
	$("#notifysignup").hide();
});

// validate and submit the signup form
$("#notifysignup2 form").submit(function(event){
	if($("#notifysignup2 #email").val().length == 0 && $("#notifysignup2 #phone").val().length == 0)	{
			$("#notifysignup2 legend").after("<br /><label class='error'>Enter something!</label>");
			//$("#notifysignup2 input").addClass("error");
		}
	else {
			var theEmail = $("#notifysignup2 #email").val();
			var thePhone = $("#notifysignup2 #phone").val();
			$.post("notifylist.php",{
		       email: $("#email").val(),
		       phone: $("#phone").val()
		     }, function() {
					//$("#notifysignup2").addClass("success").html("<h4>Thank You!</h4><p>We'll let you know as soon as we know. </p> <p>You entered: <em> " + theEmail + "  " + thePhone + " </em></p><p class='clear'><a href='#spread'>Spread the word.</a></p><p class='clear'><a class='hidenotify' href='##'>Close this window.</a></p>")
					//$("a.hidenotify").click(function(){	$("#notifysignup2").hide();});
					$("#notifysignup2").hide();
					$("#spreadtheword").show();
					$("#spreadtheword").prepend(
						"<h2>Thank you!</h2><p>We'll let you know as soon as we know.</p><p id='entered'>You entered: <em> " + theEmail + "  " + thePhone + " </em></p>")

				}); //post
			}// else
	return false;
	event.preventDefault();
});
*/
	/*apply to the header search input - add as needed*/
	$("#friendemail").inputClear();

	$("#sendtofriend a").click(function(){
		var theEmail = $("#friendemail").val();
		//var theLink = "mailto:" + theEmail + "?subject=Record Your Slice of Earth&body=http://soundofthatday.com/"
		var theLink = "mailto:" + theEmail + "?body=%20http://soundofthatday.com/"
		console.log(theLink);
		$(this).attr("href",theLink)
		//return false;
	});

	/*add class to drop downs for IE <6*/


	    $("p.getnotified").hover(
	            function() {$(this).addClass("over");}
				,
	            function() {$(this).removeClass("over");}
	    ); // getnotified hover


// close notify form with esc key
$(document).keydown( function( e ) {
	if( e.which == 27) {  // escape, close box
		if($("#notifysignup").length>0) { $(".#notifysignup").hide(); }
	}
});


});// document ready / end jquery functions



	/*clear search field on click - made into plugin so it can easily be used more than once.*/
	jQuery.fn.inputClear = function() {
		return this.focus(function() {
			if( this.value == this.defaultValue ) {
				this.value = "";
			}
		}).blur(function() {
			if( !this.value.length ) {
				this.value = this.defaultValue;
			}
		});
	};
