	(function($){
		$.fn.clearDefault = function(){
			return this.each(function(){
				var default_value = $(this).val();
				$(this).focus(function(){
					if ($(this).val() == default_value) $(this).val("");
				});
				$(this).blur(function(){
					if ($(this).val() == "") $(this).val(default_value);
				});
			});
		};
	})(jQuery);

$(document).ready(function() {		
		// Initialize clearInput
	    $('input.clearinput').clearDefault();
	    
	    // Main Navigation Rollovers
	    $('#nav').droppy();
	    
		$('#masthead a.altimeter').hover(function(){
			$('#altimeter_hover').stop(true, true).fadeIn(400);
		},function() {
			$('#altimeter_hover').stop(true, true).fadeOut(400);
		});

        $('#masthead a.freelunch').hover(function(){
			$('#freelunch_hover').stop(true, true).fadeIn(400);
		},function() {
			$('#freelunch_hover').stop(true, true).fadeOut(400);
		});
		
	    // Navigation Highlights
	    urlArray = window.location.href.split('/');
		size = urlArray.length;
		currentPage = urlArray.slice(size-1, size);
		
		
		$("#left_nav li a").each(function(i) {
			if ($(this).attr('href') == currentPage) {
				$(this).addClass("on");
			}
		});
				
		$(".sidenav .on, #left_nav .on span").append(" &raquo;");
				
		// Initialize Social Toolbar Tooltips
		$("#social ul li a[title]").tooltip({effect: 'slide', position: 'top left', offset: [6, 26]});
		
		// Featured Case Studies
		if($("#featured-case-studies").length > 0)
		{
			$("#featured-case-studies .prev, #featured-case-studies .next").hide();
			$("#featured-case-studies").hover(function() {
				$(this).find(".prev").animate({ opacity: "show", left: "10px", filter: "" }, 300);
				$(this).find(".next").animate({ opacity: "show", right: "17px", filter: "" }, 300);
			}, function() {
				$(this).find(".prev").animate({ opacity: "hide", left: "-10px", filter: "" }, 500);
				$(this).find(".next").animate({ opacity: "hide", right: "-3px", filter: "" }, 500);
			});
			
			$("#featured-case-studies").scrollable({
				circular: true,
				keyboard: false,
				items: ".case-studies"
			}).autoscroll({
				interval: 8000,
				autopause: true
			});
		}
		
		// Tabs
		if($("#side-tabs").length > 0)
		{
			$(document).ready(function() {
				var tabsTopOffset = parseInt($("#side-tabs").css('top'));
				
				if(!$("#side-tabs").hasClass("shown"))
				{
					$.post(window.location.protocol + "//" + window.location.hostname + "/session.php");
					
					$("#stuck-tab .handle-wrap").delay(300).stop().animate({ marginLeft: "40px" }, 300, function() {
						$("#disrupt-tab .handle-wrap").stop().animate({ marginLeft: "40px" }, 300);
					});
				}
				else
				{
					$("#side-tabs").find(".handle-wrap").css({ marginLeft: "40px" });
				}
			});
				
			$("#side-tabs .tab").mouseenter(function() {
				$(this).find(".panel").stop().animate({ marginLeft: "0px" }, 400);
				$(this).find(".handle-wrap").stop().delay(200).animate({ marginLeft: "-40px" }, 400);
				
				$("#side-tabs .tab .panel").click(function() {
					window.location = $(this).find(".rollover a").attr("href");
				});
			}).mouseleave(function() {
				$(this).find(".panel").stop().animate({ marginLeft: "-380px" }, 400);
				$(this).find(".handle-wrap").stop().delay(200).animate({ marginLeft: "40px" }, 400);
			});
		}		
				
		// Index RSS
		if($("#rss-feed").length > 0)
		{
			$(".posts").load('inc/load_rss.php', function() {
				$(this).hide().fadeIn(500);
			});
		}
});
