/*
	name: Horodecki labs
	encoding: UTF-8
	author: Dawid Horodecki, http://horodecki.eu
*/

/*	Cats
	==================================== */

var Cats = {
	init: function() {
		var set = false;
		var speed = 250;
		var $project = $('.project');
		
		if (location.hash && $project.length) {
			//console.log(location.hash);
		}
		
		$('.project-cat a').click(function() {
			if (set) {
				$project.animate({
					opacity: 1
				}, speed).find('.project-cat a').css('background', 'transparent');
				
				window.location.hash = '#/';
				
				set = false;
			} else {
				var cat = $(this).text();
				var new_hash = $(this).attr('href').replace(location.protocol+'//'+location.host, '');
				
				$project.filter(function(index) {
					if (!$(this).find('.project-cat a:contains('+cat+')').css('background', '#000').length) {
						return true;
					}
				}).animate({
					opacity: 0.2
				}, speed);
				
				window.location.hash = new_hash;
				
				set = true;
			}
			
			return false;
		});
	}
};

/*	Animated hover
	==================================== */

var AniHover = {
	init: function() {
		$('.project').hover(function() {
			$(this).animate({
				backgroundColor: "#fc0"
			}, 'slow');
			return false;
		});
	}
};

/*	On load
	==================================== */

var OnLoad = {
	init: function() {
		$('.hide').addClass('js');
		$('.only-js').removeClass('js');
	}
};

/*	Grid
	==================================== */

var Grid = {
	init: function() {
		$('body')
			.append('<p style="position: absolute; top: 10px; right: 10px; font-size: 10px; cursor: pointer;">grid on/off</p>')
			.toggle(function() {
				$('#container').css('background', 'transparent url(/img/grid-bg.gif) repeat 0 1px');
			}, function() {
				$('#container').css('background', '#fff');
			});
	}
};

/*	Document ready
	==================================== */

$(document).ready(function() {
	OnLoad.init();
	AniHover.init();
	//Cats.init();
	//Grid.init();
});