jQuery(document).ready(function($) {

	function formatTitle(title, currentArray, currentIndex, currentOpts) {
		prodTitle = new Array();
		prodTitle = title.split("@");
    return '<p class="itemPop"><a href="javascript:;" onclick="jQuery.fancybox.close();">[ Close ]</a></p>';
	}

	$("a.screenshot").fancybox({
		'showCloseButton'	: false,
		'titlePosition'		: 'inside',
		'titleFormat'			: formatTitle,
		'speedIn'					: 800,
		'overlayColor'		: '#000',
		'cyclic'					: true,
		'hideOnContentClick'	: true
	});
	
	$("a.screenshotLink").fancybox({
		'showCloseButton'	: false,
		'titlePosition'		: 'inside',
		'titleFormat'			: formatTitle,
		'speedIn'					: 800,
		'overlayColor'		: '#000',
		'cyclic'					: true,
		'hideOnContentClick'	: true
	});
	
	$("h2.title").hide();
	
	var pageId;
	if (window.location.hash) pageId = /#([^#]+)$/.exec(window.location.hash)[1];
	else pageId = "portfolio";

	if (pageId == "clients" || pageId == "worksheet" || pageId == "thanks" || pageId == "error") {
		$(".portfolio").addClass("navOn");
		$("#bar").addClass("portfolioBg");
		$("footer").addClass("portfolioBg");
	}

	$("#worksheetForm").validate({
		rules: {
			name: "required",
			email: {
				required: true,
				email: true
			},
			phone: "required",
			project_description: "required"
		},
		messages: {
			name: "&#8593; Please enter your name.",
			email: "&#8593; Please enter valid email address.",
			phone: "&#8593; Please enter phone number.",
			project_description: "&#8593; Please describe the project."
		}
	});

	$("nav a").click(function() {
		if (!$(this).hasClass("navOn")) {
			$("#bar").removeClass();
			$("footer").removeClass();
		}
		var thisClass = $(this).attr("class");
		thisClass = thisClass.split(" ");
		thisClass = thisClass[0];
		window.location.hash = thisClass;
		$('#'+thisClass).siblings().hide();
		$(this).siblings().removeClass("navOn");
		$('#'+thisClass).fadeIn();
		$("#bar").addClass($(this).attr("class")+"Bg");
		$("footer").addClass($(this).attr("class")+"Bg");
		$(this).addClass("navOn");
		return false;
	});

	$(".clients a").click(function() {
		window.location.hash = "clients";
		$('#clients').fadeIn();
		$('#items').cycle('pause'); 
		$('#items').hide(); 
		$(".clients").hide(); 
		$(".clickNav").hide(); 
		$(".portfolioNav").hide();
		$(".portfolio").addClass("navOn");
		$("#clients").css("margin-top","-18px"); // hack-o-rama
		return false;
	});

	$(".portfolio").click(function() {
		var thisClass = $(this).attr("class");
		thisClass = thisClass.split(" ");
		thisClass = thisClass[0];
		window.location.hash = thisClass;
		$("#clients").hide();
		$(".clickNav").fadeIn(); 
		$(".clients").fadeIn();
		$('#items').fadeIn(); 
		$('#items').cycle('resume'); 
		$(".portfolioNav").fadeIn();
		return false;
	});

	$(".colA.featured li:last").addClass("lastItem");
	$(".colB.featured li:last").addClass("lastItem");
	$(".colA li:last").addClass("lastItem");
	$(".colB li:last").addClass("lastItem");

	$("#bar").addClass(pageId+"Bg");
	$("footer").addClass(pageId+"Bg");

	$("#"+pageId).siblings().hide();
	$("#"+pageId).fadeIn();
	$("."+pageId).addClass("navOn");
	
	if ($("input[@name='worksheet_yes']:checked").val() == "yes") {
		$("#worksheetExtra").show();
	}
	if ($("input[@name='worksheet_no']:checked").val() == "no") {
		$("#worksheetExtra").fadeOut();
	}

	$("#worksheet_yes").click(function() {
		$("#worksheetExtra").fadeIn();
	});
	$("#worksheet_no").click(function() {
		$("#worksheetExtra").fadeOut();
	});


});
