var Site = {
		
	/* Attributes */
	window: [],	

	/* Methods */
	
	init: function() {
		if (!Shin.isIE6()) {
			Site.window['height'] = $(window).height();
			if ($('#creation_date').length > 0 ) Site.updateCounter();
			if ($('#face').length>0) Site.Faces.init();
			if ($('#details').length > 0 ) Site.Work.init();
			if ($('#topframe #slideshow').length > 0 ) Site.initSlideShow();
		}
	},
	
	initLoading: function() {
		if (typeof window.history.pushState == "function") {
			$('header a').bind('click', function(event) {
				if (!$(this).hasClass('pause')) {
					Site.Work.hideWork();
					$('header a').toggleClass("pause");
					var uri = $(this).attr("href");
					$('header a').removeClass('current');
					$(this).addClass('current');
					window.history.pushState('', '', uri);
					$('#content').load(uri+' #content div.inner', function(responseText, textStatus, XMLHttpRequest){
						$('header a').toggleClass("pause");
					});
				}
				event.preventDefault();
			});
		}
	},
	
	initSlideShow: function() {
		$('#topframe #slideshow a:first img').one('load', function() {
			$(this).parent('a').fadeIn(function() {
				$('#topframe #slideshow').css('background-image', 'none');
				$('#topframe #slideshow').cycle({
					fx:      			'fade',
					delay:   			2000,
					timeout:       		4000,
					pause:  			1,
				    slideExpr:			'a.work'
				});
			});
        }).each(function() { if(this.complete) $(this).load(); });
	},
		
	updateCounter: function() {
		var creation = new Date(2006, 10, 15);
		var today = new Date();			
		var diff = Math.abs(today.getTime() - creation.getTime());
		var years = Math.floor(diff / (1000 * 60 * 60 * 24 * 365));
		diff -= years * (1000 * 60 * 60 * 24 * 365);
		var months = Math.floor(diff / (1000 * 60 * 60 * 24 * 30.5));
		diff -= months * (1000 * 60 * 60 * 24 * 30.5);
		var days = Math.floor(diff / (1000 * 60 * 60 * 24)); 
		diff -= days * (1000 * 60 * 60 * 24);			
		var hours = Math.floor(diff / (1000 * 60 * 60)); 
		diff -= hours * (1000 * 60 * 60);			
		var minutes = Math.floor(diff / (1000 * 60)); 
		diff -= minutes * (1000 * 60);		
		var seconds = Math.floor(diff / (1000)); 
		diff -= seconds * (1000);				
		var diff_sexy = years + " an" + ((years>1)?"s":"");
		if (months>0) diff_sexy = diff_sexy + " " + months + " mois";
		if (days>0) diff_sexy = diff_sexy + " "+ days + " jour" + ((days>1)?"s":"");
		if (hours>0) diff_sexy = diff_sexy + " "+ hours + " heure" + ((hours>1)?"s":"");
		if (minutes>0) diff_sexy = diff_sexy + " "+ minutes + " minute" + ((minutes>1)?"s":"");
		diff_sexy = diff_sexy + " et "+ seconds + " seconde" + ((seconds>1)?"s":"");
		$("span#creation_date").html(diff_sexy);
		window.setTimeout(Site.updateCounter, 1000);
	}
	
};

Shin.loadJavascript(';js/site.map.js');

