$(document).ready(function(){

/*	

 	Shoots and Ladders (Actually Just Shoots, Slides and Toggles, Tabs, Accordians, and Carousels) /// and a high top fade

=================================================================*/
	
	if (!$.browser.msie) 
	{
		$('.dropdown').hide();	
		$('li#courses a').click(function() {	
				$(this).toggleClass('dropped');	
				$('.dropdown').slideToggle();
				return false;
		});

	}

	
	

/*	

 	Gotcha! (Advanced CSS Selectors for Styling)

=================================================================*/


	$("li a[href$='pdf']").parent().addClass("pdf");
	$("li a[href$='ppt']").parent().addClass("ppt");
	$("li a[href$='pptx']").parent().addClass("ppt");
	$("li a:contains('article'), li a:contains('Article')").parent().addClass("article");
	$("li:contains('book:'), li:contains('Book:')").addClass("book");
	$("li a[href$='png'], li a[href$='gif'], li a[href$='jpg']").parent().addClass("picture");
	$.extend($.expr[':'],{
	    external: function(a,i,m) {
	        if(!a.href) {return false;}
	        return a.hostname && a.hostname !== window.location.hostname;
	    }
	});
	$("li a:external").parent().addClass("external");

	$(".main-nav ul li").hover(
		function(){$(this).parent().parent().addClass("current");},
		function(){$(this).parent().parent().removeClass("current");}		
	);
	

/*	

 	Stop repeating me (contact form preview)

=================================================================*/
	
   var $comment = ''; // that's two single quotation-marks at the end
   $('#comment').keyup(function() {
     $comment = $(this).val();
     $comment = $comment.replace(/\n/g, "<br />")
       .replace(/\n\n+/g, '<br /><br />');
     $('#commentpreview').html( '<strong>What  I would like to say is:</strong><br />' + $comment );
   });

   $name = ''; // that's two single quotation-marks at the end
   $('#name').keyup(function() {
     $name = $(this).val();
     $('#namepreview').html( '<strong>I am</strong> ' + $name );
   });
	 
   $email = ''; // that's two single quotation-marks at the end
   $('#email').keyup(function() {
     $email = $(this).val();
     $email = $email.replace(/\n/g, "<br />")
       .replace(/\n\n+/g, '<br /><br />');
     $('#emailpreview').html( 'and I appreciate you not spamming me.');
   });	 

   $url = ''; // that's two single quotation-marks at the end
   $('#url').keyup(function() {
     $url = $(this).val();
     $url = $email.replace(/\n/g, "<br />")
       .replace(/\n\n+/g, '<br /><br />');
     $('#urlpreview').html( 'Linking to my site? Sweet!');
   });	 

 	


/*	

 	Drop it like it's hot (jump down to the question form)

=================================================================*/

	$('a.askaquestion').click(function(){
			$("#question").modal({
				overlay:100,
				overlayCss: {backgroundColor:"#3a5a31"}			
			});

			/*
			$("#question textarea").focus();
			$("#question textarea").highlightFade({color:'rgb(241,255,146)',speed:1000, iterator:'exponential'}).highlightFade({attr:'borderColor',start:'#FFCC00',speed:2000, iterator:'exponential'});
			*/
			return false
	});
	

	//Plugin to add text to an input field that disappears on focus
	jQuery.fn.inputFieldText = function(string) { 		
		this.each(function() {
			$(this).val(string);
			$(this).focus(function(){
				if ($(this).val() == string){$(this).val('');}
			});
			$(this).blur(function(){
				if ($(this).val() == '' ){$(this).val(string);}
			});	
		});
	}
	$('input[name=username]').inputFieldText('username');	

/*
	$('input[name=password]').inputFieldText('Password');		
	$('#contact input[name=name]').inputFieldText('Your Name');
	$('#contact input[name=email]').inputFieldText('Your Email');
*/	

});