$(document).ready(function() {
	    
	/* initial fade */
	$('.page-content').hide().fadeIn(500);

	/* navigation functions */
	$('.mainnav li a').click(function(event){
		var url = $(this).attr('href');
		if(location.pathname.indexOf(url) > 0) {
			return false;
			}
    });
    
	$('ul.projects-nav li a,.a-filter').click(function(event){
		event.preventDefault();
		if($(this).hasClass('active')){
			return false;
		}
		else {
			if($(this).attr('filter') == 'all'){
				$('ul.projects-nav li a').addClass("active").not(this).removeClass("active");
				$(".grid-item").removeClass('disabled').animate({opacity: 1});
			}
			else {
				$('ul.projects-nav li a').addClass("active").not(this).removeClass("active");
				var filterBy = $(this).attr('filter');

				$(".grid-item[filter !=" + filterBy + "]").addClass('disabled'); 
				$(".grid-item[filter *=" + filterBy + "]").removeClass('disabled').animate({opacity: 1});
				$('.disabled').animate({opacity: .2});
			}
		};
	}); 
	
	
	/* flickr */
	if('#flickr-container'){
		$('#flickr-container').jflickrfeed({
			limit: 5,
			qstrings: {
				id: '90386073%40N00'
			},
			itemTemplate: '<li><a href="{{image_b}}"><img src="{{image_s}}" alt="{{title}}" /></a></li>'
		});
	}


/*
 * 
 * slideshow functions (not in use...)
 * 
 */
	
/*
	function onAfter(curr,next,opts) {
		var height = $(this).css('height');
		$(this).parent().parent().find('.info').css('height', height);
	    $(this).parent().parent().find('.caption').html('<span>' + (opts.currSlide + 1) + '</span> of <span>' + opts.slideCount + '</span>');
	    var slideCap = $(this).parent().parent().find('.slide' + '0' + (opts.currSlide + 1));
	    slideCap.addClass('active');
	    slideCap.siblings().removeClass("active");
	};
	

	var $slideshows = $(this).find('.slideshow');
	$slideshows.each(function(key,value){
		$(value).attr("class", "slideshow slideshow" + key);
	    $(value).parent().find(".prev").attr("class", "prev prev" + key);
	    $(value).parent().find(".next").attr("class", "next next" + key);
	    $(value).cycle({
	        fx: 'fade',
	        after: onAfter,
	        speed: 300,
	        timeout: 0,
	        prev: '.prev' + key,
	        next: '.next' + key,
	    });
	  
	}); // end each

*/

/*
 * 
 * Smooth scrolling
 * 
 */ 
	$('a[href*=#]').click(function() {
	    $(this).preventDefault;
	    if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
	    	var $target = $(this.hash);
	    	$target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
    	    
	    	if ($target.length) {
	    		if ($('.project-images').hasClass('quick')) {
	    			/* if there are no header(s) on project-images */
	    			var targetOffset = ($target.offset().top) - (20);
	    			$('html,body').animate({scrollTop: targetOffset}, 600);
	    			return false;
	            }
	    		else {
	            	/* if this is a regular hash click */
	                var targetOffset = ($target.offset().top);
	                $('html,body').animate({scrollTop: targetOffset}, 600);
	                return false;
	    		}
	    	}
	    }
	});
	

	
	if ($('#jumpToTop').length) {
		$('#jumpToTop').hide();
		var topper = $('#info').offset().top - parseFloat($('#info').css('marginTop').replace(/auto/, 0));
		$(window).scroll(function (event) {
			// what the y position of the scroll is
			var y = $(this).scrollTop();
			
			// whether that's below the form
			if (y >= topper) {
				// if so, add the fixed class
				$('#info').addClass('fixed');
				$('.project-header.first').show();
				$('#jumpToTop').fadeIn(300);
			} else {
				// otherwise remove it
				$('#jumpToTop').fadeOut(300);
				$('#info').removeClass('fixed');
				$('.project-header.first').hide();
			}
		});
	};
	
	

    
    
/* 
 * 
 * Form Plugin
 * 
 */			
	 function validate(formData, jqForm, options) { 
         
         var form = jqForm[0]; 
         if (!form.firstname.value || !form.lastname.value || !form.message.value) {
	    	 $('#target').append('<p style="color: #990000;">Please fill out all required fields before submitting.');
	    	 return false;
         }
       
     //    alert('fields contain values.'); 
     }
	 if($('#contactForm').length){
		 // bind form using ajaxForm 
		 $('#contactForm').ajaxForm({ 
			 // target identifies the element(s) to update with the server response
			 beforeSubmit: validate,
			 target: '#target', 
			 resetForm: true,
			 
			 //success identifies the function to invoke when the server response 
			 // has been received; here we apply a fade-in effect to the new content 
			 success: function() { 
			 	$('#target').fadeIn('slow'); 
			 }
		}); 
	};
	
 
/* END */
});



