/* JQUERY SCRIPTS FOR ALL PAGES */

$(document).ready(function() {
	
	
	/* ON MOUSE-OVER BOX, CHANGE OF BACKGROUND COLOR AND SWITCH BOTTOM TRIANGLE  */
	$("div.box .content:not(.yellow)").hover(
	  function () {
	    $(this).addClass("boxhover").parent().find("span").addClass("bottomhover");    
	  },
	  function () {
	    $(this).removeClass("boxhover").parent().find("span").removeClass("bottomhover");
	  }
	);


	/* BIND GOOGLEMAPS URL TO LINK ON CONTACTPAGE (VIA JQUERY TO AVOID XHTML VALIDATION FAIL) */
	$("#googleMapsLink").click(function() {
		window.open('http://maps.google.nl/maps/place?cid=12106454212438049887&q=Active+Creations+internet+%26+design&gl=nl&dtab=0&sll=52.638369,6.070344&sspn=0.054186,0.128059&ie=UTF8&ll=52.641908,6.067768&spn=0,0&t=h&z=18', 'Active Creations on Google Maps', 'menubar=no,status=yes,width=1000px,height=800px');
	});
	
	
	/* SET DEFAULT VALUE FOR INPUT FIELD AND EMPTY DEFAULT VALUE ON MOUSE OVER */
	var phonefield   = $("#yellowboxform").find("input:text");
	var submitbutton = $("#yellowboxform").find("input:submit");
	var defaultvalue = '06-12345678';
	
	phonefield.val(defaultvalue);
	
	phonefield.hover(
	  function () {
	    if(phonefield.val() == '' || phonefield.val() == defaultvalue) { 
	    	phonefield.val('');
	    	phonefield.focus();
	    }    
	  },
	  function () {
	    if(phonefield.val() == '') { 
	    	phonefield.val(defaultvalue);
	    }
	  }
	);
	
	/* ON SUBMIT CHECK IF FIELD CONTAINS VALUE OTHER THAN DEFAULT VALUE OR EMPTY */
	submitbutton.click(function() {
	
		if(phonefield.val() == '' || phonefield.val() == defaultvalue) { 
			phonefield.val('');
			phonefield.focus();
			return false;
		}
	
	})
	
	/* ONLY ALLOW NUMBERS AND SPACE */
	jQuery.fn.ForceNumericOnly =
	function()
	{
	    return this.each(function()
	    {
	        $(this).keydown(function(e)
	        {
	            var key = e.charCode || e.keyCode || 0;
	            // allow backspace, tab, delete, arrows, numbers and keypad numbers ONLY
	            return (
	                key == 8 || 
	                key == 9 ||
	                key == 46 ||
	                (key >= 37 && key <= 40) ||
	                (key >= 48 && key <= 57) ||
	                (key >= 96 && key <= 105));
	        })
	    })
	};
	
	
	phonefield.ForceNumericOnly();	
	
});
