
$(window).load(function(){
	var $container=$('section#portfolio #holder');
	
	$container.isotope({
  	itemSelector:'article,.box',
  	animationOptions: {
    	duration: 500,
   		easing: 'linear',
    	queue: false
   	}
	});
});

$(document).ready(function(){
	var _200=($.browser.msie ? 0 : 200);
	var _300=($.browser.msie ? 0 : 300);
	var _400=($.browser.msie ? 0 : 400);
		
	$("a[rel=external],a[rel=me],a[rel=nofollow]").live("click", function(){
		window.open(''+$(this).attr("href")+'');
		return false;
	});
	
	$("a[rel=social-popup]").live("click", function(){
		window.open(''+$(this).attr("href")+'', 'twitter', 'toolbar=no, width=650, height=450');
		return false;
	});
	
	var on_globus=false;
	
	$('html').click(function(){ 
		$("#langs").fadeOut(_300);
		on_globus=false;
		$("header .globus").fadeOut(_400);
	});
	
	// HEADER ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		
	$("header #logo").hover(
		function(){
			$("header .globus").stop(true, true);
			on_globus=true;
			$("header .globus").fadeIn(_200);
		},
		function(){
			on_globus=false;
			$("header .globus").delay(_300);
			if(!on_globus) $("header .globus").fadeOut(_400);
		}
	);
	
	$("header .globus").hover(
		function(){
			$("header .globus").stop(true, true);
			on_globus=true;
		},
		function(){
			on_globus=false;
			$("header .globus").delay(_300);
			if(!on_globus) $("header .globus").fadeOut(_400);
		}
	);
	
	// HOME //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	
	$("section header a.contact").click(function(event){
		event.stopPropagation();
		$("header .globus").stop(true, true);
		on_globus=true;
		$("header .globus").fadeIn(_200);
		return false;
	});
	
	$(".filtre-projectes").click(function(){
		var f=$(this).attr("href").replace('#', '');
		
		if(f=='') f='*';
		else f='.'+f;
		$('section#portfolio #holder').isotope({filter:f});
		return false;
	});
	
	$("#portfolio article").hover(
		function(){
			$(this).find(".tags").stop(true, true).show();
			
			if($.browser.msie && parseInt($.browser.version, 10)<9){
				$(this).find(".tags").css({bottom:12});
				$(this).find(".wip").css({bottom:50});
			}else{
				$(this).find(".tags").css({bottom:6});
				$(this).find(".tags").stop(true, true).animate({bottom:12, opacity:1}, _200);
				$(this).find(".wip").stop(true, true).animate({bottom:50}, _200);
			}
			
			$(this).find(".img .gris").stop(true, true).fadeOut(_400);
			$(this).find(".img .color").stop(true, true).fadeIn(_400);
		},
		function(){
			if($.browser.msie && parseInt($.browser.version, 10)<9){
				$(this).find(".tags").stop(true, true).hide();
				$(this).find(".wip").css({bottom:12});
			}else{
				$(this).find(".tags").stop(true, true).animate({bottom:6, opacity:0}, _200);
				$(this).find(".wip").stop(true, true).animate({bottom:12}, _200);
			}
			
			$(this).find(".img .gris").stop(true, true).fadeIn(_400);
			$(this).find(".img .color").stop(true, true).fadeOut(_400);
		}
	);
	
	$("#portfolio article").click(function(){
		window.location=$(this).find("a.img").attr("href");
	});
	
	
	// PROJECT //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	
	if(document.documentElement.clientWidth<480){
		$("ul.gal").before($("div.col"));
		$("ul.gal").after("<div class=\"clearer\"></div>", $("div.col nav").clone());
	}

	
	// FOOTER //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	
	$(".alang").click(function(){
		$("#langs").fadeToggle(_300);
		return false;
	});
		
	$('.alang').click(function(event){ event.stopPropagation(); }); 
	
});
