var base = '/';
var addthis_config={ui_language:"fr"};

$(document).ready(function(){pageInit();});

if (document.location.hash && document.location.hash.substr(1,1)=='/') {
	document.location=document.location.hash.substr(1);
} else {
	var lsth = '';
	function hashCheck() {
		var thsh = document.location.hash.substr(1);
		if (lsth !== thsh) {lsth = thsh;hashBrowse(lsth,0);}
	}
	setInterval(hashCheck, 100);
}

function hashBrowse(q) {
	if ($('#news').length) $('#news').mbStopAutoscroll();
	h = document.domain;
	if(q.indexOf(h)!=-1)q=q.substr(q.indexOf(h)+h.length);
	if ($(window).scrollTop() > 160) $('html,body').animate({scrollTop: 160}, 500);
	$('#content').load(q+(q.indexOf('?')!=-1?'&':'?')+'ajax', function(s) { 
		document.title = $('#title').text();
		pageInit();
		pageTracker._trackPageview(q);
	});
	location.hash = q;
	lsth = location.hash.substr(1);
}
function hashRefresh() {
	hashBrowse(hashReturn());	
}
function hashReturn() {
	return ((document.location.hash&&document.location.hash.substr(1,1)=='/')?location.hash.substr(1):window.location.pathname);	
}

function initAddThis(){addthis.init()}

function pageInit() {
	$('#news').mbScrollable();
	$('#color-demo').colorbox({innerWidth:680, innerHeight:450, iframe:true});
	$('ul.realisations li .img a').mouseenter(function(){$(this).find('img').fadeOut('fast')})
	$('ul.realisations li .img a').mouseleave(function(){$(this).find('img').fadeIn('fast')})
	$("ul.realisations li ul li a[rel]").colorbox();
	studios(null);
	if (window.addthis){window.addthis = null;}
	$.getScript('http://s7.addthis.com/js/250/addthis_widget.js#domready=1');
}

function scrollToElement(e) {
	var p = $(e);
	var offset = p.offset();
	$('html,body').animate({scrollTop:offset.top},500)
}
