$(document).ready(function() {

	// Initiate lightbox for design thumbs
	$(function() {
		$('.thumbs a').lightBox();
		$('.recent a').lightBox();
	});
	
	function autoWidth(obj_id)
	{
		var obj = $(obj_id),
			space = $(obj).width(),
			width = 0,
			add;
		
		$(obj).children().each(function() {
			width += $(this).width();
		});
		
		add = (space - width) / $(obj).children().length;
		
		$(obj).children().each(function() {
			$(this).css('width', function() {
				return $(this).width() + add;
			});
		});
	}
	
	// Code for the code samples
	$('#code-samples div').slideUp();
	$('#code-samples a').click(function() {
		if( $(this).next().is(':hidden') )
		{ 
			$('#code-samples div').slideUp();
			$(this).next().slideDown();
		}
		else
		{
			$(this).next().slideUp();                
		}
		return false;
	});
	
	// validate the comment form when it is submitted
	//$("#contact").validate();

	// validate signup form on keyup and submit
	$("#contact").validate({
		rules: {
			name: {
				required: true,
				checkLabel: true
			},
			email: {
				required: true,
				checkLabel: true,
				email: true
			},
			message: {
				required: true,
				checkLabel: true
			}
		},
		messages: {
			name: "Name is required",
			email: "Email is required",
			message: "Message is required"
		}
	});
	
	// Inline labels for inputs
	$("#contact input[type=text]").attr('value', function(){return this.title}).addClass('unfilled');
	$("#contact input[type=text]").focus(function() {
		if (this.value == this.title)
			$(this).val('').removeClass('unfilled');
	});
	$("#contact input[type=text]").blur(function() {
		if (this.value == '')
			$(this).attr('value', function(){return this.title}).addClass('unfilled');
	});
	
	// Inline labels for textareas
	$("#contact textarea").html(function(){return this.title}).addClass('unfilled');
	$("#contact textarea").focus(function() {
		if (this.innerHTML == this.title)
			$(this).html('').removeClass('unfilled');
	});
	$("#contact textarea").blur(function() {
		if (this.innerHTML == '')
			$(this).html(function(){return this.title}).addClass('unfilled');
	});

	// Check input value against inline label
	jQuery.validator.addMethod("checkLabel", function( value, element ) {
		return this.optional(element) || value != element.title;
	}, "Please enter a value.");


});
