$(document).ready(function() {
	/* Tabs */
	var aboutHeight = $("div#about").height();
	var portfolioHeight = $("div#portfolio").height();
	var socialHeight = $("div#social").height();
	var contactHeight = $("div#contact").height();
	$("div.content").height(0);
	
	var current = "about";
	$("div#" + current).height( eval(current+"Height") );
	
	$("a.tablink").click( function() {
		$("a.tablink").removeClass("selected");
		$(this).addClass("selected");
		$("div#" + current).animate({ height: 0 }, 500, function() { $(this).hide(); });
		var toShow = $(this).attr("rel");
		if( toShow == "contact" ) toAdd = 30;
		else toAdd = 0;
		$("div#" + toShow).show().animate({ height: eval(toShow+"Height") + toAdd }, 500);
		current = toShow;
		return false;
	});
	
	/* Portfolio */
	$("a.break").click( function() { return false; });
	$("a[rel^='prettyPhoto']").prettyPhoto({ default_width: 800, theme: 'light_rounded', overlay_gallery: false });
	$("#slider").scrollable({ size: 1, clickable: false, keyboard: false });
	
	/* Social Networks */
	$('#socialnetworks ul li').hover(
		function() {
			$(this).animate({
			    left: '-=10'
			  }, 200, function() {
			    // Animation complete.
			  });
		},
		function() {
			$(this).animate({
			    left: '+=10'
			  }, 200, function() {
			    // Animation complete.
			  });
		}
	);
	
	/* Contact Form */
	$('.required').hide();
	$("#sendform").click( function() {
		alert("Sorry! My current webhost is terrible - don't ever get FatCow to host your sites. It's having problems with PHP scripts, so please shoot me an e-mail instead.");
		return false;
		
		$('.required').hide();  
	    var name = $("input#contact_name").val();  
	    if (name == "") {  
	      $("label#name_error").show();  
	      $("input#contact_name").focus();  
	      return false;  
	    }  
	    var email = $("input#contact_email").val();  
	    if (email == "") {  
	      $("label#email_error").show();  
	      $("input#contact_email").focus();  
	      return false;  
	    }  
	    var message = $("textarea#contact_message").val();  
	    if (message == "") {  
	      $("label#message_error").show();  
	      $("textarea#contact_message").focus();  
	      return false;  
	    }
	    
	    var dataString = 'name='+ name + '&email=' + email + '&message=' + message;
		
		/* Note: To enable this AJAX form, make sure this is on the same path as the included mail.php, then
		         simply uncomment this area here, and remove the area indicated below. If you have questions
		         don't hessitate to e-mail me: hello -at- cricketlachica.com. */
		         
		$.ajax({
		    type: "POST",
		    url: "mail.php",
		    data: dataString,
		    success: function() {
		      $('#contactform form').html("<div id='message'></div>");
		      $('#message').html("<h2>Message Sent.</h2>")
		      .append("<p>Thank you for your message. I'll make sure to get back to you in a couple of days.</p>")
		      .hide()
		      .fadeIn(1500);
		    }
		});
		
		
		/* ------------------------ SNIP ------------------------ 
		$('#contactform form').html("<div id='message'></div>");
		      $('#message').html("<h2>Message Sent.</h2>")
		      .append("<p>Thank you for your message. I'll make sure to get back to you in a couple of days.</p>")
		      .hide()
		      .fadeIn(1500);
		 ------------------------ SNIP ------------------------ */
		
		return false;
	});
	
	$("#themes a").click( function() {
		$("body").removeClass();
		$("body").addClass( $(this).attr("rel") );
		return false;
	});
});

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-20495890-1']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();
