$(document).ready(function(){			
	
	/* Profile Dropdown */
	$(".about").click(function(){
		if($(this).hasClass("open")){					   
			$(this).removeClass("open");			   				
			$("#container").animate({marginTop: "-250px"/*, "opacity": "1"*/},800);
			//$("#portfolio").animate({opacity: "1"},800);
			$(".portOverlay").remove();	
		} else {
			$(this).addClass("open");
			$("#container").animate({marginTop: "0px"/*, "opacity": ".3"*/},800);
			//$("#portfolio").animate({opacity: ".1"},800);
			$("#portfolio").prepend("<div class=\"portOverlay\"></div>");
			$(".portOverlay").animate({opacity: ".9"},800);
				$(".portOverlay").click(function(){
					if($(this).is(":visible")){			
						$("#container").animate({marginTop: "-250px"/*, "opacity": "1"*/},800);
						$(this).remove();						
						$(".about").removeClass("open");
					} else {
						
					}
			});
		}
		return false;
	});	

	/* Thumbs hover effect */
	$("#portfolio section").hover(function(){
        $(this).addClass("hover");	
		$(".hover span").stop().animate({opacity: "0"}, 800);
	}, function(){
        $(this).removeClass("hover");
		$("section span").stop().animate({opacity: "1"}, 800);
	});

	/* Init fancybox */
	$("#portfolio section a").fancybox(
		   {onComplete: function(){			   
			   $('#fancybox-right').click(function(){
					var loadThis = $('#'+currPageId).parent().next().children('a').eq(0).attr('id');
					setHistory(loadThis);		   												   
				});
				 $('#fancybox-left').click(function(){
					var loadThis = $('#'+currPageId).parent().prev().children('a').eq(0).attr('id');
					setHistory(loadThis);		   												   
				});
		   }}	   									   
		);
	
	/* Add window height to fancybox overlay */
	function resizeOverlay(){		
		var windowHeight = $(window).height();
		$("#fancybox-overlay").animate({height: windowHeight},600);		
	}

	/* Add class to body is fancybox is opened */
	$("#portfolio section a").click(function(){
		$("body").addClass("fb-on");
	});		
	
	/* Remove class to body is fancybox is closed */	
	$("#fancybox-close").click(function(){
		$("body").removeClass("fb-on");
	});


	
	/* History */
   function load(post_name) {
		//console.log(post_name);
		$('#'+post_name).click();
		currPageId = post_name;
	}

	$.history.init(function(hash) {
		if(hash == "") {
			// initialize your app
			
		} else {
			// restore the state from hash
			load(hash);
		}

	   });

	$('#portfolio a').live('click', function(e) {
		return setHistory($(this).attr('id'));
	});

	
	
	
	

}); //end doc ready			

var currPageId = null;	

function setHistory(page_url){
	var url = page_url;
	url = url.replace(/^.*#/, '');
	$.history.load(url);
	return false;
}


