window.addEvent( 'domready', function() {
	 /**
     * Set default options, overrideable from later calls.
     */
    SqueezeBox.initialize({
        size: {x: 350, y: 320}
    });
 
    /**
     * Assign SqueezeBox to all links with rel="boxed" attribute, the class then reads the "href".
     */
    SqueezeBox.assign($$('a[class=agrandissement]'));
 
    /**
     * Open some content manually
     */
    /*SqueezeBox.open('manual.html'); // handler defaults to "ajax" for urls
    SqueezeBox.open('http://digitarald.de', {handler: 'iframe'}); // we force the "iframe" handler here ...
    SqueezeBox.open($('welcome'), {handler: 'adopt'}); // and here we force "adopt" handler*/

	$$('a[class=survol]').each(function(item){
		item.addEvent('mouseover', function(){
			trailOn(item.get('href'), 100, 100);
		});
		item.addEvent('mouseout', function(){
			trailOff();
		});
	});
			
 	$$( '.moreInfoWrapper' ).each(function(item){
		var thisSlider = new Fx.Slide( item.getElement( '.moreInfo' ), { duration: 500 } );
		thisSlider.hide();
		item.getElement( '.divToggle' ).addEvent( 'click', 
			function()
			{				
				thisSlider.toggle();
				var baliseTitre = this.getElement( 'h3' );	
				if( baliseTitre.className == "slideUp" ) baliseTitre.className = "slideDown" ;
				else baliseTitre.className = "slideUp"
			} );
 	} );
});

/**** Fonctions pour les vidéos ****/
function launch_video_montage()
{
	/*var video_flash = '<object style="margin:0;padding:0;" type="application/x-shockwave-flash" data="/video/video_montage.swf" width="320" height="280">';
	video_flash += '<param name="movie" value="/video/video_montage.swf">';
	video_flash += '<param name="loop" value="false">';
	video_flash += 'alt : <a href="/video/video_montage.swf">video_montage.swf</a>';
	video_flash += '</object>';*/
	SqueezeBox.open($('video_montage'), {
		handler: 'adopt',
		size: {x: 320, y: 280}
	});


	//document.getElementById('video_montage').innerHTML = video_flash;
}

function launch_video_liner()
{
	var video_flash = '<object style="margin:0;padding:0;" type="application/x-shockwave-flash" data="/video/video_liner.swf" width="320" height="280">';
	video_flash += '<param name="movie" value="/video/video_liner.swf">';
	video_flash += '<param name="loop" value="false">';
	video_flash += 'alt : <a href="/video/video_liner.swf">video_liner.swf</a>';
	video_flash += '</object>';

	document.getElementById('video_liner').innerHTML = video_flash;
}

/**** Affichage des images au survol ****/
var ua = navigator.userAgent.toLowerCase();
var divw=0;
var divh=0;
var xto;

if (document.getElementById || document.all)
	document.write('<div id="imgtrailer" style="position:absolute;visibility:hidden;z-index:121;"></div>')

function gettrailobject()
{
	if (document.getElementById)
		return document.getElementById("imgtrailer")
	else if (document.all)
		return document.all.trailimagid
}

function gettrailobj()
{
	if (document.getElementById)
		return document.getElementById("imgtrailer").style
	else if (document.all)
		return document.all.trailimagid.style
}

function truebody()
{
	return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function trailOff()
{
	if (xto && xto > 0)
	{
		clearTimeout(xto);
	}

	document.onmousemove='';
	gettrailobj().visibility="hidden";
}

function trailOn(thumbimg, largeur, hauteur, imgl, imgh){
	if (imgl && imgh)
	{ imagesize = 'style="width:'+imgl+'px;height:'+imgh+'px;"'; }
	else
	{ imagesize = ''; }
	
	gettrailobj().left="-500px";
	largeurdiv = largeur;
	divw = largeurdiv + 20;
	hauteurdiv = hauteur;
	divh = hauteurdiv + 20;
	gettrailobject().innerHTML = '<div id="trailcontainer" style="background: black url(../images/loading.gif) center center no-repeat; layer-background-color: black; border: 1px solid black; width:'+largeurdiv+'px;height:'+hauteurdiv+'px;z-index:122"><img src="'+thumbimg+'" '+imagesize+' id="btcontainer" alt="apercu" title="apercu" /></div>';
	$('btcontainer').addEvent('load', function(){
		var dimensions = $('btcontainer').getSize();
		$('trailcontainer').set('style', {
			'width': dimensions.x,
			'height': dimensions.y
		});
	});
	//setTimeOut
	xto = setTimeout("xtimeOut('"+thumbimg+"')",100);
	gettrailobj().visibility="visible";
	document.onmousemove=followmouse;
}

function xtimeOut(thumbimgg){
	if (document.getElementById)
		document.getElementById('btcontainer').src = thumbimgg;
	else if (document.all)
		document.all.btcontainer.src = thumbimgg;
}

function followmouse(e)
{
	var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-15
	var docheight=document.all? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(document.body.offsetHeight, window.innerHeight)
	if (typeof e != "undefined")
	{
		if(docwidth < 20+e.clientX+divw)
			xcoord = e.clientX-divw-10;
		else
			xcoord = 20+e.clientX;
		//alert((window.pageYOffset + window.innerHeight) +'<'+(e.clientY+divh));
		if( (window.innerHeight) < e.clientY+divh)
		{
			ycoord = window.pageYOffset + window.innerHeight - divh;
		}
		else
		{
			ycoord = window.pageYOffset + e.clientY - Math.max(0,(divh + e.clientY - window.innerHeight - truebody().scrollTop - 40));
		}
	}
	else if (typeof window.event != "undefined")
	{
		if(docwidth < 20+truebody().scrollLeft+event.clientX+divw)
			xcoord = truebody().scrollLeft-10+event.clientX-divw;
		else
			xcoord = truebody().scrollLeft+20+event.clientX;
		//alert(docheight +'<'+(event.clientY+divh));
		if(docheight < (event.clientY + divh))
		{
			//Position en bas
			ycoord = truebody().scrollTop + (docheight - divh);
		}
		else
		{
			//Suivi souris en hauteur
			ycoord = truebody().scrollTop + event.clientY - Math.max(0,(divh + event.clientY - docheight - 40));
		}
	}
	gettrailobj().left=xcoord+"px"
	gettrailobj().top=ycoord+"px"
}