window.onload = function()
{

	$('.flexslider').flexslider({
     	 animation: "fade",
		 slideshow: false,
		 controlNav: false
	});


function loading() {

$("div.workitem").fadeOut(0);
$("div.fullsize").fadeOut(0);

$('div.workitem').each(function(index) {
			$(this).delay(150*index).fadeIn(500,function () {
			});					
});					

$('div.workitem img').fadeTo(200,0.6);
$('div.workitem').hover(function () {
    $(this).find('img').stop().fadeTo('fast', 1);
  }, function () {
    $(this).find('img').stop().fadeTo('fast', 0.6);
  });
	
//check for hash.	

if (window.location.hash) {
	
	var theHash = window.location.hash;
	var viewopen = "div" + theHash;

			$(viewopen).fadeIn(500,function() {
				
				$("div.projectinfo").fadeIn(200);
				$("html, body").animate({scrollTop:$(viewopen).offset().top},600);
					
			});
	
} else {

	// nothing. show nothing.
	
}
	
}

loading(); // init loading function

// click thumbnail handler

$("a.top").click(function(event){
		event.preventDefault();
		$("html, body").animate({scrollTop:0},600);

	
});

$("div.workitem a").click(function(event) {
	
		event.preventDefault();
		window.location.hash = $(this).attr("rel");
		goingdown = $(this).attr("rel"); 
		var viewopen = "div#" + goingdown;
		
		$("div.fullsize").each(function() {
          if($(this).is(":visible"))
              $(this).hide();
      }	);
		
		// hide all, then fadein current + scroll.
		//$("div.fullsize").not(viewopen).fadeOut("fast",function() { //wait for it
		
			$(viewopen).fadeIn(200,function() {
				
			$("div.projectinfo").fadeIn(200);
				
			});
			
			$("html, body").animate({scrollTop:$(viewopen).offset().top},1000);
			
		//});
});



}
