$(document).ready(function() { 
	
	// hide #info
	$('#info').hide();
	
	// Toggle info and stop scrolling of images.
	$('.showInfo').click(function() {
		$info = $('#info');
		$info.slideToggle('slow');
		$info.toggleClass('selected');
		return false;
	});
	
	// Portfolio Scroller
	$("#portfolio-wrap").smoothDivScroll({
		scrollingHotSpotLeft:	"div.scrollingHotSpotLeft",	
		scrollingHotSpotRight:	"div.scrollingHotSpotRight",
		scrollWrapper:			"#portfolio",
		scrollableArea:			"#scroller",
		mouseDownSpeedBooster: 	3
	});
	
	$('#portfolio-wrap>div')
	.mouseover(function(){
		$(this).addClass('hoveration');	
	}).mouseout(function(){
		$(this).removeClass('hoveration');
	});
	
	// append ':' to labels
	$('label').append(' : ');
	
	// remove border from last element
	$('fieldset ol li:last-child').css({border:0});

	// setup form AJAX options
	var options = {
		target : '#output',
		beforeSubmit : function(data){
			$('#contactSend').attr('disabled',true);
			$('img.loading').show();
		},
		success: function(data) {
			$('#output').fadeIn();
			$('img.loading').hide();
			$('#contactSend').attr('disabled',false);
		}
	};
	
	// Fix outgoing links to be tracked
	var domain = window.location.href.split('/')[2];
	$('a[href^=http://]').filter('a:not([href*="'+domain+'"])').each(function(){
		$(this).click(function(e){
			var page = this.href.replace(/^http:\/\//i, '/ob/');
			pageTracker._trackPageview(page);
		});	
	});

	// set up form validation and AJAX call
	$('form#contact_form').validate({
		rules: {
			contactName: "required",
			contactEmail: {
				required: true,
				email: true
			},
			contactMessage: "required"
		},
		messages: {
			contactName: "Please enter your name.",
			contactEmail: "Please enter a valid email.",
			contactMessage: "Please enter a message."
		},
		submitHandler: function(form) {
			$(form).ajaxSubmit(options);
		}
	});
});
