$('html').addClass('js');
$(document).ready(function(){

	$("h2.title").hide();
	
	$(".screenshot").colorbox({
		transition: 'elastic',
		speed: 500
	});

	var pageId;
	if (window.location.hash) pageId = /#([^#]+)$/.exec(window.location.hash)[1];
	else pageId = "portfolio";

	$("#contactForm form").validate({
		rules: {
			fm_name: "required",
			fm_email: {
				required: true,
				email: true
			},
			fm_message: "required"
		},
		messages: {
			fm_name: "&#8593; Please enter your name.",
			fm_email: "&#8593; Please enter valid email address.",
			fm_message: "&#8593; Please enter a message."
		}
	});

	// position labels over inputs
	$('label').labelOver('over-apply');

	$("#sidebar li a").click(function() {
		window.location.hash = $(this).parent().attr("class");
		if (!$(this).parent().children('a').hasClass("navOn")) {
			$("#bar").removeClass();
			$("#footer").removeClass();
		}
		$('#'+$(this).parent().attr("class")).siblings().hide();
		$(this).parent().siblings().children('a').removeClass("navOn");
		$('#'+$(this).parent().attr("class")).fadeIn();
		$("#bar").addClass($(this).parent().attr("class")+"Bg");
		$("#footer").addClass($(this).parent().attr("class")+"Bg");
		$(this).parent().children('a').addClass("navOn");
		return false;
	});

	$(".clients a").click(function() {
		window.location.hash = $(this).parent().attr("class");
		$('#'+$(this).parent().attr("class")).fadeIn();
		$('#items').cycle('pause'); 
		$('#items').hide(); 
		$(this).parent().hide(); 
		$(".clickNav").hide(); 
		$(".portfolioNav").hide();
		$(".portfolio").children('a').addClass("navOn");
		return false;
	});

	$(".portfolio a").click(function() {
		$("#clients").hide();
		$(".clickNav").fadeIn(); 
		$(".clients").fadeIn();
		$('#items').fadeIn(); 
		$('#items').cycle('resume'); 
		$(".portfolioNav").fadeIn();
		return false;
	});

	$('#items')
	.before('<ul class="portfolioNav">')
	.cycle({ 
    fx: 'fade', 
    timeout: 16000, 
		containerResize: 0,
		next: ".next",
		prev: ".prev",
		speed: "slow",
		pause: 1,
		pauseOnPagerHover: 1,
    pager: '.portfolioNav',
		pagerAnchorBuilder: function(idx, slide) { 
			var imgPath = $("#portfolio"+idx).children("a").children("img").attr("src").split("_md.jpg")[0]+"_sm.jpg";
			return '<li><a href="#portfolio'+ idx +'"><img src="' + imgPath + '" alt="' + $("#portfolio"+idx).children("img").attr("alt") + '" /></a></li>'; 
    } 
	});
	
	$(".clients").fadeIn();
	$("#bar").addClass(pageId+"Bg");
	$("#footer").addClass(pageId+"Bg");

	$("#"+pageId).siblings().hide();
	$("#"+pageId).fadeIn();
	$("."+pageId).children("a").addClass("navOn");
	
});