jQuery(function($){
  // adds the browser name and js to the homepage
  if($.browser.mozilla) {
      $("html").addClass("js mozilla");
  } else if($.browser.safari) {
      $("html").addClass("js safari");
  } else if($.browser.msie) {
      $("html").addClass("js msie");
  } else {
      $("html").addClass("js");
  };

  $("#work li").hover(
      function () { 
          $('.overlay', this).fadeIn('fast');
      }, 
      function () { 
          $('.overlay', this).fadeOut('fast');
      } 
  );

  jQuery.fn.anchorAnimate = function(settings) {

   	settings = jQuery.extend({
  		speed : 1100
  	}, settings);	

  	return this.each(function(){
  		var caller = this
  		$(caller).click(function (event) {	
  			event.preventDefault()
  			var locationHref = window.location.href
  			var elementClick = $(caller).attr("href")
	
  			var destination = $(elementClick).offset().top;
  			$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination}, settings.speed, function() {
  				window.location.hash = elementClick
  			});
  		  	return false;
  		})
  	})
  }

  $("#nav a").anchorAnimate();
  
  $("#work ul a").fancybox();
  
  /* -------------------------------------- CONTACT FORM VALIDATION -------------------------------------- */
  $('#contact form').validate({
  	rules: {
  		name: {
  			required: true
  		},
  		email: {
  		  email: true,
  			required: true
  		},
  		comments: {
  		  required: true
  		}
  	},
  	messages: {
	    name: {
        required: "Don't worry I won't bite. You can tell me your name."
	    },
      email: {
        email: "Don't take this the wrong way but your email looks different.",
        required:  "Did you forget your email address?"
      },
      comments: {
        required: "I'm a man of few words myself but are you sure you have nothing to say?"
      }
  	}
  });
  
  /* -------------------------------------- PAGEVIEW AND EVENT TRACKING -------------------------------------- */
  var pathName = window.location.pathname;

  //page tracking
  $("#nav a").click(function(){
  	pageTracker._trackPageview($(this).attr('title'));
  });
  
  $("#work a").click(function(){
  	pageTracker._trackPageview($(this).attr('title'));
  });
  
  // event tracking
  $("a[rel*='external']").click(function(){
		pageTracker._trackEvent('External', 'Social', $(this).attr('title'));
	});
	
	$("a[rel*='download']").click(function(){
		pageTracker._trackEvent('Download', 'Resume', $(this).attr('title'));
	});

});
