$(document).ready(function(){
	project_image_gallery();
	header_image_rotator();
	feature_slideshow();
	projectHover();
	client_quotes();
	contactForm_validation();
	project_n3();
//	project_filter();
	$("ul#page-portfolio-right").filterable({
		useTags: true,
		tagSelector: 'ul#filter-nav a',
		selectedTagClass: 'current',
		allTag: 'All'
	});
});

/* -------------------------------------------------------
	Contact form validation
------------------------------------------------------- */
function contactForm_validation(evt){

	$('#contact-form')
	   .validate({
	   
	   	errorClass: "invalid", // add invalid class to invalid input field
	   	//errorElement: "em", // it gets rid of the error message
	   	
		errorPlacement: function(error, element) {
			error.appendTo(element);
   		},
	   	
		rules: {
			// simple rule, converted to {required:true}
			name: "required",
			// compound rule
			email: {
				required: true,
				email: true
			},
			message: "required"
		},
		
         submitHandler: function(form) {
           $(form).ajaxSubmit({
                success: function() {
                    $('#contact-form').hide();
                    $('#thank_you').show();
                }
           });
         }
        });
}

/* -------------------------------------------------------
	Client quotes fade effect
------------------------------------------------------- */
function client_quotes(evt){
	$('body.clients #client_quotes').innerfade({ 
		animationtype: 'fade',
		speed: 'normal',
		timeout: 20000,
		type: 'random',
		containerheight: '500px',
		runningclass: 'client_quotes'
	}); 
}

/* -------------------------------------------------------
	Project item hover effect
------------------------------------------------------- */
function projectHover(evt){
	$("ul#page-portfolio-right li.page-portfolio-item a img").hover(function(){
		$(this).stop().fadeTo("slow", 0.5);
	},function(){
		$(this).stop().fadeTo("normal", 1.0);
	});
}

/* -------------------------------------------------------
	Page header image rotator
------------------------------------------------------- */

function header_image_rotator(evt){
	$('#page div#page-header-right').cycle({
		fx: 'fade',
		timeout: 4000
	});
}

/* -------------------------------------------------------
	Project image gallery
------------------------------------------------------- */

function project_image_gallery(evt){
	$('#project-images').cycle({
		fx: 'fade',
		speed: 'slow',
		timeout: 20000,
		next: '#project-gallery-tools .next8',
		prev: '#project-gallery-tools .prev8',
		pager: '#project-gallery-counter'
	}); 
}

/* -------------------------------------------------------
	Project Filter
------------------------------------------------------- */

function project_n3(evt){
//	$("ul#page-portfolio-right li:nth-child(3n)").addClass("last");
//	$("ul#page-portfolio-right li").filter(".hidden").addClass("last");

	$("ul#page-portfolio-right li:visible").each(
		function(i) {if((i+1)%3==0) $(this).addClass("last");});
}



function project_filter(evt){
	$('ul#filter-nav li a').click(function() {
		
		$('ul#filter-nav .current').removeClass('current');  
		$(this).parent().addClass('current');
	
		var filterVal = $(this).text().replace(' ','-');
		
		if(filterVal == 'All') {
			$('ul#page-portfolio-right li.hidden').fadeIn('slow').removeClass('hidden');
			project_n3();
		}else{
			$('ul#page-portfolio-right li').each(function() {
				if(!$(this).hasClass(filterVal)) {
					$(this).fadeOut('fast').addClass('hidden');
				} else {
					$(this).fadeIn('slow').removeClass('hidden');
				}
			});
		}
		return false;
	});	
}

/* -------------------------------------------------------
	Feature project rotator
------------------------------------------------------- */
function feature_slideshow(evt){
	$('#feature-image').cycle({
		fx: 'fade',
		speed: 1000,
		timeout: 4000,
		pager: '#feature-control div'
	}); 
}
