$(document).ready(function(){

	//---------------------------
	// Header animation
	//---------------------------
	if ( $("#headerPanel").length ) {
		
		//Cache variables
		var headerPanel = $("#headerPanel"),
			height = headerPanel.height() - 30,
			toggler = $("#togglePanel");
			
		//Hide the header by default
		headerPanel.css({ marginTop: -height });
		toggler.addClass("closed");
		
		toggler.click(function(){
			slideHeader();
		});

		$("#header").find("a").click(function(){
			slideHeader();
			return true;
		});
		
		// Show and hide header
		function slideHeader(){
			if ( toggler.hasClass("closed") ){
				headerPanel.animate({
					marginTop: 0
				},400,"easeOutQuad");
				toggler.removeClass("closed");
			}else{
				headerPanel.animate({
					marginTop: -height
				},400,"easeOutQuad");
				toggler.addClass("closed");
			}
		}	
		
	}
	
	
	
	//---------------------------
	// Twitter feed
	//---------------------------
	if( $('#twitter').length ){
		
		var yourTwitterUsername = "SeanHynes"; //Insert your twitter username
		
		$.ajax({
			url : "http://twitter.com/statuses/user_timeline/"+yourTwitterUsername+".json?callback=?",
			dataType : "json",
			timeout: 15000,
			
			success : function(data){
				var time = data[0].created_at,
					text = data[0].text,
					id = data[0].id_str;
					
				time = time.replace(/(\+\S+) (.*)/, '$2');
				time = $.timeago( new Date( Date.parse( time ) ) );
										
				text = text.replace(/((https?|s?ftp|ssh)\:\/\/[^"\s\<\>]*[^.,;'">\:\s\<\>\)\]\!])/g, function(url){
								return '<a href="'+url+'" target="_blank">'+url+'</a>'});
				text = text.replace(/@(\w+)/g, function(url){
								return '<a href="http://www.twitter.com/'+url.substring(1)+'" target="_blank">'+url+'</a>'});
				text = text.replace(/#(\w+)/g, function(url){
								return '<a href="http://twitter.com/#!/search?q=%23'+url.substring(1)+'" target="_blank">'+url+'</a>'});
				text = "<a href='http://twitter.com/"+yourTwitterUsername+"/status/"+id+"' class='status'>" +time+ "</a> " + text;
				$("#twitter").html(text);
			},
			
			error : function(){
				$("#twitter").html("There was an error connecting to your Twitter account");
			}
		});
		
	}
	
	
	
	//---------------------------
	// Autofilling forms using placeholders
	//---------------------------
	if( !supports_placeholder() ){
		// If your browser does not support placeholders
		$("input[type=text], textarea").each(function(){
			$(this).val($(this).attr('placeholder'));
		}).focus(function(){
			if($(this).val() == $(this).attr('placeholder')) { $(this).val(""); }
		}).blur(function(){
			if($(this).val() == "") { $(this).val($(this).attr('placeholder')); }
		});
	}
	
	// Test placeholder support
	function supports_placeholder() {
		var i = document.createElement('input');
		return 'placeholder' in i;
	}


