function doTips(){
    //if(log && console) console.log('doTips');
    // Tips
    //new Tips('#logo');
    tips = new Tips(
        $$('.tip'),
        {
            maxTitleChars: 100,
            offsets: {'x': -80, 'y': 50},
            fixed: false
        }
    );
    $$('.tip').each(function(e){e.removeClass('tip')});


    //if(log && console) console.log('doTips');
}

function doBox(){
    // multibox
    if(log && console) console.log('doBox');
    //box = new MultiBox('mb', {descClassName: 'multiBoxDesc', useOverlay: false, 'showControls': true, 'showNumbers' : true, 'fixedTop': 0});    
   	milkbox.reloadGalleries();
}

function init(){
	//console.log("init"[,objects])
    //if(log && console) console.log('init');
	doTips();
	doBox();
}
function doDomready(){
    //if(log && console) console.log('doDomready');
	init();
	myFx = new Fx.Slide('canadaprovinces', {duration:500, onComplete:fxComplete});
}


function doAjaxReady()
{
	$$('.ajax-loader').each(function (e){e.style.visibility = 'hidden'});
    //if(log && console) console.log('doAjaxReady');
	init();
	//$('canadaprovinces').style.display='block';
	myFx.slideIn(); //display a transition from transparent to opaque.
	//$('canadaprovinces').show();
}


function fxComplete(e)
{
    //if(log && console) console.log('fxComplete');
	if(!way) 
	{
		var page_id = 'page_' + url_.replace('http://www.xdev.fr', '').replace('http://local.www.xdev.fr', '').replace(/[/-]/g, '_');	
		if($(page_id)) $(page_id).style.display = 'none';
		var new_page_id = 'page_' + url.replace('http://www.xdev.fr', '').replace('http://local.www.xdev.fr', '').replace(/[/-]/g, '_');		
		
		if($(new_page_id))
		{
			//console.log('page exist');
			$(new_page_id).style.display = 'block';
			myFx.slideIn();
		}
		else
		{
			//console.log('page dont exist');
			var newpage = $(page_id).clone().injectAfter(page_id);
			newpage.style.display = 'block';
			newpage.id = new_page_id;
			doAjaxMe();
		}
		url_ = url;
	}
	way = 1;
}

function evalScripts(A){
    //if(log && console) console.log('evalScripts');
	(window.execScript)?window.execScript(A):window.setTimeout(A,0);
}

function doAjaxMe()
{
	$$('.ajax-loader').each(function (e){e.style.visibility = 'visible'});
    //if(log && console) console.log('doAjaxMe');
	var new_page_id = 'page_' + url.replace('http://www.xdev.fr', '').replace('http://local.www.xdev.fr', '').replace(/[/-]/g, '_');
	//console.log('new page id ' + new_page_id);
	var a = new Request.HTML({url: url + '?ajax=1', method: 'get', update: $(new_page_id), evalScripts: true, onComplete: doAjaxReady});
	a.get();
}


function ajaxMe(o)
{
	if(_gaq) {_gaq.push(['_trackEvent', 'Pages', o.href]);}
    //if(log && console) console.log('ajaxMe');
	if(box.opened) box.close();
	way = 0;
	url = o.href;
	myFx.slideOut(); //display a transition from transparent to opaque.
	$$('.toc').each(function(e){e.removeClass('on')});
	o.addClass('on');
	return false;
}



function switchMe(o, e)
{
    //if(log && console) console.log('switchMe');
	var oo = $('box' + e + o.getProperty('numero'));
	if(lightup)
	{
		//if(!oo.hasClass('over')) cpt++;
		oo.addClass('over');
	}
	else
	{
		//alert(cpt);
		//if(oo.hasClass('over')) cpt++;
		oo.removeClass('over');
	}
	if($$('.over').length == $$('.box' + e).length) {lightup = 0;}
	if($$('.over').length == 0) {lightup = 1;}
}
function play()
{
    //if(log && console) console.log('play');
	t = 0;
	$$('.allR').each(function(el, i) {el.show()});
	rr = $$('.realisation');
	var d = new Array(
		rr[4], rr[3], rr[2], rr[1], rr[0], 
		rr[5], rr[10], rr[15], rr[20], rr[25], rr[30], 
		rr[31], rr[32], rr[33], rr[34], 
		rr[29], rr[24], rr[19], rr[14], rr[9],
		rr[8], rr[7], rr[6],
		rr[11], rr[16], rr[21], rr[26],
		rr[27], rr[28],
		rr[23], rr[18], rr[13],
		rr[12], rr[17], rr[22]);
		
	if($$('.over').length == $$('.realisation').length) {action = 'removeClass'; d.reverse();}
	else {
		$$('.all').each(function(el, i) {$('boxR' + el.getProperty('numero')).removeClass('over');});
		action = 'addClass';
	}
	
	
	d.each(function(e){setTimeout ( "$('" + e.id + "')." + action + "('over');", t = t + 40 );});
}
function play2()
{
    //if(log && console) console.log('play2');
	t = 0;
	rr = $$('.allT');
	var d = rr;
		
		
	$$('.all').each(function(el, i) {el.show()});
	
	if($$('.over').length == $$('.boxT').length) {action = 'removeClass'; d.reverse();}
	else {
		$$('.all').each(function(el, i) {$('boxT' + el.getProperty('numero')).removeClass('over');});
		action = 'addClass';
	}
	
	
	d.each(function(e){setTimeout ( "$('" + e.id + "')." + action + "('over');", t = t + 40 );});
}


function rubriqueOver(o, e)
{
	$$('.all' + e).each
	(
		function(el, i) {
		//console.log('box' + e + el.getProperty('numero'));
		if($('box' + e + el.getProperty('numero'))) $('box' + e + el.getProperty('numero')).removeClass('over');
		}
	);
	$$(o).each
	(
		function(el, i) {
		//console.log('box' + e + el.getProperty('numero'));
		if($('box' + e + el.getProperty('numero'))) $('box' + e + el.getProperty('numero')).addClass('over');
		}
	);
	
}
function rubriqueOut(o, e)
{
	$$('.all' + e).each(function(el, i) {$('box' + e + el.getProperty('numero')).removeClass('over');});
}
function rubriqueClick(o, e)
{
	$$(o).each(function(el, i) {el.show()});
	$$('.all' + e).each(function(el, i) {el.hide()});
}

function showAjaxLoader()
{
	$$('.ajax-loader').each(function (e){e.style.visibility = 'visible'});
}


function hideAjaxLoader()
{
	$$('.ajax-loader').each(function (d){d.style.visibility = 'hidden'});
}


function sendForm(form_id, update_id)
{
	showAjaxLoader();
	$(form_id).send({
		update:update_id, 
		onComplete: function(){
			hideAjaxLoader();
			$$('#' + form_id + ' input[type=text], #' + form_id + ' textarea').each(function(e){e.value = '';});
		}
	});
	
	//$('#' + a.id + ' option').each(function(e){e.selected = false;});
	return false;
}

function switchFont(font, el)
{
	var body = $(document.body);
	body.removeClass('NeuropolRegular');
	body.removeClass('CenturyGothic');
	body.removeClass('Helvetica');
	body.removeClass('V5ProphitCell');
	body.removeClass('Verdana');
	body.addClass(font);
	$$('.fontSwitch').each(function(e){e.removeClass('fontSwitchSelected')});
	el.addClass('fontSwitchSelected');
	return false;
}

