$(document).ready(function() {  
	var contactstatus = 0, ishome = 0;
	
	// Initiate filter
	var initialPage = window.location.hash;
    if(initialPage != "") {
    	var hashvalues = new Array();
	    hashvalues = initialPage.split('/');
		updateFilter(hashvalues[1]);
    }
	
	// Toggle filters
	$('#filter a').click(function(event) {  
		event.preventDefault();
		// Fetch filter
		var filterVal = $(this).text().replace(' ','-');  
		// Assign filter to hash
		window.location.hash = "/" + filterVal;
		
		
		updateFilter(filterVal);
		/* Projects  */
		if($('#project').is(':visible')){
			
			if($('.related').is(':visible')){
				$(".related").animate({"opacity": "hide"}, "fast", function() {
					$('#project').slideUp('slow', function() {
						activeProject=false;
					});		
				});
			}else{
				$('#project').slideUp('slow', function() {
					activeProject=false;
				});
			}
			
		}else{
			//updateFilter(filterVal);	
			activeProject=false;
		}
	});
	
	// Apply filter
	function updateFilter(filterVal){
		
		$("#projects").animate({"opacity": "hide"}, 150, function() {
																	
			$('#filter a.active').removeClass('active').parent().find('#'+filterVal).addClass('active');
			$('#projects div.first').removeClass('first'); 
			if(filterVal == 'All-projects') {  
				$('#projects div.hidden').removeClass('hidden'); 
				$("#projects div").each(function(i) {
					if(i%3==0){
						 $(this).addClass("first");
					}
				 });	
			}else{  
				$('#projects div').addClass('hidden').filter('.'+filterVal).removeClass('hidden');
				$("#projects div."+filterVal).each(function(i) {
				//$("#projects div").each(function(i) {
					if(i%3==0){
						 $(this).addClass("first");
					}
				 });			
			}
			
			$("#projects").animate({"opacity": "show"},300);
			
	
		});		

	}	
	/*
   $(".info").hover(function(){
    	$(this).prev(".image").addClass("on");
 	 	$(this).addClass("hover");
	},function(){
	  	$(this).removeClass("hover");
		$(this).prev(".image").removeClass("on");
	});
   */ 
	 
});  
