$(document).ready(function() {

	var textareaSupport = function(){
	  var support = {},
	      t = document.createElement('textarea');

	  support.placeholder = (t.placeholder !== undefined);

	  return support;
	};

	Modernizr.textarea = textareaSupport();
// 
	
	if(!Modernizr.input.placeholder || !Modernizr.textarea.placeholder){
		$("input, textarea").each(function(){
		    if ($(this).val() == "" && $(this).attr("placeholder") != "") {
		        if ($(this).attr("placeholder") != "e.g. I'm moving house" && $(this).attr("placeholder") != "e.g. I need an employment lawyer" && $(this).attr("placeholder") != "How can we help?" && $(this).attr("placeholder") != "Search..." && $(this).attr("placeholder") != "Search Person..." && $(this).attr("placeholder") != "Your message..." && $(this).attr("placeholder") != "Your Nominated Good Cause (Charity/Community Group/Private Initiative) (*)" && $(this).attr("placeholder") != "What does your organisation do and what help do you need? (*)")
                { 
				    $(this).val($(this).attr("placeholder"));
				    $(this).focus(function(){
					    if($(this).val()==$(this).attr("placeholder")) $(this).val("");
				    });
				    $(this).blur(function(){
					    if($(this).val()=="") $(this).val($(this).attr("placeholder"));
	                });
                }
                else
                {
                }
			}
		});
	}
		
	$('a[href*=#]').click(function() {
		var duration=1000;
		// easing values: swing | linear
		var easing='swing';
		// get / set parameters
		var newHash=this.hash;
		var target=$(this.hash+', a[name='+this.hash.slice(1)+']').offset().top;
		var oldLocation=window.location.href.replace(window.location.hash, '');
		var newLocation=this;
		// make sure it's the same location      
		if(oldLocation+newHash==newLocation) {     
		 if($.browser.safari) var animationSelector='body:not(:animated)'; // set selector
		 else var animationSelector='html:not(:animated)';
		 // animate to target and set the hash to the window.location after the animation
		 $(animationSelector).animate({ scrollTop: target }, duration, easing, function() {
			// add new hash to the browser location
			window.location.href=newLocation;
		 });
		 return false;
		}
	});


	$('.hero > *').each(function(){
		var $delay = Math.floor(Math.random()*1001);
		$(this).delay($delay).fadeIn(1000);
	});
	
    try{
	    var top = $('.glossary nav').offset().top - parseFloat($('.glossary nav').css('marginTop').replace(/auto/, 0));
	    $(window).scroll(function (event) {
		    // what the y position of the scroll is
		    var y = $(this).scrollTop();
		
		    // whether that's below the form
		    if (y >= top) {
		      // if so, ad the fixed class
		      $('.glossary nav').addClass('fixed');
		    } else {
		      // otherwise remove it
		      $('.glossary nav').removeClass('fixed');
		    }
	    });

    }
    catch (err) { }
});

function disableEnterKey(e) {
    var key;
    if (window.event)
        key = window.event.keyCode; //IE
    else
        key = e.which; //firefox  
    return (key != 13);
}
