
	// Works Page
	$(document).ready(function(){
		
		$(".project_panel_close").click(function()
		{
			$(".project_panel").slideUp("normal");
			$(".quote").stop().slideDown("normal").fadeTo("slow", 1);
			$(".project_panel_close").stop().fadeOut("normal");
			$(".viewLink").hide();
			quote_hidden = false;
			browsing_id = 0;
			browsing_image_id = 0;
			
			window.location.hash = "#portfolio";
			return false;
		});
	});
	
	// Set Image Placeholder [Lazy Load]
	$(document).ready(function()
	{
		$(".portfolio_entry img").lazyload({
			placeholder: "css/placeholder.gif",
			threshold: 300
		});
		$('.ppnxtclk').click(function(){
			var dataId=$(this).attr('name');
			var nextid=$($('[data-id="'+dataId+'"]').next()).attr('data-id'); 
			if(nextid!=undefined){
			window.location.href = "#portfolio-" + nextid;
			location.reload();
			}
		});
		$('.ppprvclk').click(function(){
			var dataId=$(this).attr('name');
			var previd=$($('[data-id="'+dataId+'"]').prev()).attr('data-id');
			if(previd!=undefined){
			window.location.href = "#portfolio-" + previd;
			location.reload();
			}
		});
	});
	
	// Sorting
	$(document).ready(function()
	{
		var works = $(".works");
		var datas = works.clone();
		
		var content = $("#content123");
		var list_len = datas.find('li').length;
		var size_animated;
		
		$(".filter li a").each(function(e)
		{
			var $this = $(this);
			
			var find_category = $this.attr("data-category");
			
			$this.click(function(ev)
			{		
				ev.preventDefault();
				$(".filter li").removeClass('active');
				$(this).parent().addClass('active');
				
				var list = datas.find('> li').filter(function(i){
					
					var el = $(this);
					var category = el.attr("data-category");
					
					return find_category == "all" || category.indexOf( find_category ) > -1;
				});
				
				// Content Height Set Still
				if( list_len > list.length )
				{
					var content_height = content.height();
					content.height(content_height);
					size_animated = false;
				}
				else
				{
					var content_height = parseInt(works.find('li:first-child').outerHeight() * Math.ceil(list.length / 3), 10);
					content_height = content_height + 70;// + content_height
					
					content.stop(true, true).animate({height: ""+content_height}, 800, function()
					{
						content.height("auto");
					});
					
					
					size_animated = true;
				}
				
				list_len = list.length;
				
				
				works.quicksand(list, {
					easing: "easeInOutQuad",
					duration: 800
				}, function()
				{
					add_captions();
						
					if( !size_animated )
					{
						var new_height = content.height("auto").height();
						content.height(content_height);
						
						content.stop().animate({height: new_height}, 800, function()
						{
							content.height("auto");
						})
					}
				});
			});
		});
	});
