/*
 * jQuery hashchange event - v1.1 - 1/21/2010
 * http://benalman.com/projects/jquery-hashchange-plugin/
 * 
 * Copyright (c) 2010 "Cowboy" Ben Alman
 * Dual licensed under the MIT and GPL licenses.
 * http://benalman.com/about/license/
 */
(function($,i,b){var h=i.location,j,k=$.event.special,c="hashchange",e=$.browser,f=document.documentMode,g=e.msie&&(f===b||f<8),d="on"+c in i&&!g;function a(l){l=l||h.href;return l.replace(/^[^#]*#?(.*)$/,"$1")}$[c+"Delay"]=100;k[c]=$.extend(k[c],{setup:function(){if(d){return false}j.start()},teardown:function(){if(d){return false}j.stop()}});j=(function(){var l={},q,m,n,p;function o(){n=p=function(r){return r};if(g){m=$('<iframe src="javascript:0"/>').hide().appendTo("body")[0].contentWindow;p=function(){return a(m.document.location.href)};n=function(t,r){if(t!==r){var s=m.document;s.open().close();s.location.hash="#"+t}};n(a())}}l.start=function(){if(q){return}var s=a();n||o();(function r(){var u=a(),t=p(s);if(u!==s){n(s=u,t);$(i).trigger(c)}else{if(t!==s){h.href=h.href.replace(/#.*/,"")+"#"+t}}q=setTimeout(r,$[c+"Delay"])})()};l.stop=function(){if(!m){q&&clearTimeout(q);q=0}};return l})()})(jQuery,this);

/*
 * Website scripts
 *
 */

$(function() {
	function show_article(ae, fading) {
		fading = fading || false;
		$("nav li a").removeClass("current");
		$("nav li a[href='"+ae+"']").addClass("current");
		$("article").hide();
		if (fading) {
			$("article"+ae).fadeIn('slow');
		} else {
			$("article"+ae).show();
		}
		window.location.hash = ae;
		$('html, body').scrollTop(0);
	}
	ae = window.location.hash;
	if (ae.length > 0) {
		show_article(ae);
	};
	
	$(window).bind('hashchange', function() {
		ae = window.location.hash;
		if (ae.length > 0) {
			show_article(ae);
		} else {
			show_article("#home");
		};
	})
	
	$("a[href]").click(function(){
		ae = $(this).attr("href");
		if (ae.slice(0,1) == "#") {
			show_article(ae, true);
			return false;
		}
	});
	
	$("figure a").fancybox({
		'hideOnContentClick': true,
		'titleShow': true,
		'titlePosition': 'over',
		'titleFormat': function(title, currentArray, currentIndex, currentOpts) {
			return "<span id='fancybox-title-over'><strong><em>Omphalos</em> S2G1 </strong> &mdash; &copy; 2010 by Giovanni Riccardi<br>(<em>Code generated with Processing. Color correction: Adobe Photoshop</em>)</span>"
		}
	});
	
	$("a.fancyhref").live("click", function(){
		$.fancybox.close();
		return true;
	})


})