(function($) {

	Namespace('StackContent', {
		
		'currentCat' : 0,
		'clickedCat' : 0,
		
		'prepare': function()
		{
			var newcontent = $('#new-content');
			
			//We delete all the old stuf if they are still here
			if($('#old-content'))
				$('#old-content').remove();
			
			//We switch content new in old
			newcontent.attr('id', 'old-content');
			
			//We create the new content
			var oldcontent = $('#old-content');
			
			if (StackContent.currentCat <= StackContent.clickedCat) {
				oldcontent.before('<div id="new-content"></div>');
				$('#new-content').css('left', -1*oldcontent.width());
			}
			else {
				oldcontent.after('<div id="new-content"></div>');
				$('#new-content').css('left', oldcontent.width());
			}
		},
		
		'animate': function()
		{
			var newcontent = $('#new-content');
			var oldcontent = $('#old-content');
			
			var leftwidth = newcontent.position().left;
			
			//left move
			if (StackContent.currentCat <= StackContent.clickedCat) {
				oldcontent.animate({left : -1*leftwidth}, 1000, "", function() {
					$('#old-content').remove();
				});
			}//right move
			else { 
				oldcontent.animate({left : '-'+leftwidth}, 1000, "", function() {
					$('#old-content').remove();
				});
			}

			newcontent.animate({left : '0px'}, 1000); 
			
			StackContent.currentCat = StackContent.clickedCat;
			StackContent.clickedCat = 0;
		}
	});
		
})(jQuery);
