/*
****************************************************
	^ ENTYPE
----------------------------------------------------
	jquery_functions
	Updated:	12/24/09

	Coded by super ninja koala bears.

****************************************************
*/

$(document).ready(function(){

/* Add .active class ---------------------------- */
	$('div.proj, span.pt, p.site').hover(function() {
		$(this).addClass('active');
	}, 	function() {
	 		$(this).removeClass('active');
	});

/* Link hover functionality --------------------- */
	$("div.proj, span.pt, p.site").click(function(){
    	window.location=$(this).find("a").attr("href");
    		return false;
	});

	$("div.proj img.view, div.featured img.view").hide();
	$("div.proj, div.featured").hover(function() {
		$(this).find('img').fadeIn(200);
	}, 	function() {
			$(this).find('img.view').fadeOut(200);
	});

/* Tab functionality ---------------------------- */
	$("#process").tabs();

/* Add class to last element -------------------- */
	$(".ui-tabs-nav ul li:last-child, div.blog ul.gallery li:last-child").addClass('last');
	
	$("div.blog ul#posts li:nth-child(3)").addClass("last");
	$("div.blog ul#posts li:nth-child(6)").addClass("last");

/* Project Request Hidden Fields ---------------- */
	$(".hide").hide();
	$("#topic").change(function() {
		switch ($('#topic :selected').val()) {
			case 'New Project Request':	
				$(".hide").show();
			break;
			case 'Redesign Project':	
				$(".hide").show();
			break;
			default:	
				$(".hide").hide();
		}
	})

/* Attachment toggle ---------------------------- */
	$("div#attachment").toggle(function() {
		$(this).addClass("active"); },
		function(){ $(this).removeClass("active");
	});
	$("div#attachment").click(function(){
		$(this).next("div#attachment-file").slideToggle("fast");
	});

/* Validate requestform ------------------------- */
	$("#requestform").validate({
		invalidHandler: function(e, validator) {
		var errors = validator.numberOfInvalids();
		if (errors) {
			var message = errors == 1
				? 'You missed 1 field. It has been highlighted above'
				: 'You missed ' + errors + ' fields.  They have been highlighted above';
				$("div.error span").html(message);
				$("div.error").show();
			} else {
				$("div.error").hide();
			}
		}
	});

/* Title Tooltip -------------------------------- */
	$('div.about .group a').hover ( function() {
		this.tip = this.title; $(this).append (
			'<div class="bubble">'
				+this.tip
			+'</div>'
		);
		this.title = "";
			$('.bubble').fadeIn(400);
	},	function() {
		$('.bubble').fadeOut(100);
		$(this).children().remove();
			this.title = this.tip;
		}
	);

/* Gallery Swap --------------------------------- */
	$("ul.gallery a").click(function() {
		var largeimg = $(this).attr("href");
	$("#image").attr({ src: largeimg });
		return false;
	});


/* Project Image rotation ----------------------- */
    $("#display").cycle ({
        fx:    	 'fade',
        timeout:  0,
        prev:    '#prev a',
        next:    '#next a',
        pager:   '#rotate',
        pagerAnchorBuilder: pagerFactory
    });

    function pagerFactory(idx, slide) {
        var s = idx > 4 ? ' style="display:none"' : '';
        return '<li'+s+'><a href="#"></a></li>';
    };

/* End jquery.function -------------------------- */
});