// Fonctions de mise en page avec lib Mootools


// fonctions a executer a partir du domready

window.addEvent('domready', function() {

	if ($('bloc-projets'))
	{	
		var list_projet = $$('#bloc-projets .projet');
		
		list_projet.each( function(projet, i) {
							   
			//projet.setStyle('visibility', 'hidden')
			var duree = 800 + (i*800);
			var myFx	 = new Fx.Tween(projet, {duration:duree});
			myFx.start('opacity', '0', '1');			
	
		});
		
	}
	

	
	if ($('zones_extensibles'))
	{	
			var list = $$('#contenu .zone');
			var headings = $$('#contenu .zone h1');
			var spans = new Array();	
			var collapsibles = new Array();
			var zone = $('zones_extensibles').innerHTML;
			
			headings.each( function(heading, i) {

				//var collapsible = new Fx.Style(list[i], 'height',{duration: 500});
				var collapsible = new Fx.Tween(list[i]);

				collapsibles[i] = collapsible;
				
				heading.onclick = function(){
				
				  //var span = $E('span', heading);
					for(var j = 0; j < collapsibles.length; j++){
						if(j!=i && j!=(zone-1)) {
							collapsibles[j].start('height', '25px');
						}
					}			
			
				  if (i != (zone-1))
				  {
					  if(list[i].getStyle('height').toInt() > 25){
						//hide
						collapsible.start('height', '25px');
						//span.setHTML('Lire la suite');
					  }else{
						//show
						collapsible.start('height', c1Height);
						//span.setHTML('Replier');
					  }
				  }
				   return false;
				}
				//collapsible.setStyle(’display','block’);
				var c1Height = list[i].getScrollSize().y;
			
				
			  	if (i == (zone-1))
			  	{
					list[i].setStyle('height', '100%');
			  	}	

				
			});

	}


	// gestion du slideout
	if ($('splash'))
	{	
		var splash = new SplashScreen('splash',{'delay':'80000','showOnce':true});	


	    document.id('btCloseSplash').addEvent('click',function(){
		  splash.closeSplash();
	    });

	    document.id('btOpenSplash').addEvent('click',function(){
		  splash.showSplash();
	    });
		
	
	}


});

var SplashScreen = new Class({
  Implements: Options,
  options: {
    'delay':5000 ,
    'showOnce':true
  },
  initialize: function(element, options){
    this.setOptions(options);
    this.splash=document.id(element);
	this.splash_cadre = $('splash_fond');
	
    if(this.options.showOnce){
      // check cookie to see if splash has been shown in this session
      var splashCookie = Cookie.read('showSplashCookie') || 'yes';
      if(splashCookie=='yes'){
        this.showSplash();
        Cookie.write('showSplashCookie', 'no');
      }
	  else
	  {
			$('btOpenSplash').setStyles({
				'display':'block'
			});
	  }
    }else{
      this.showSplash();
    }
  },
  showSplash:function(){

    this.splash_cadre.setStyles({
 	  'height':window.getScrollHeight(),
      'display':'block',
      'opacity':'0.4'
    });	

	this.splash.setStyles({
      
      'display':'block',
      'opacity':'1'
    });
	

    // iframe for ie6 <Bah! Humbug!>
    if(Browser.Engine.trident4){
      var iframe2 = new Element('iframe',{
        styles:{'position':'absolute','width':'120%','height':'120%','top':'-10%','left':'-10%'},
	height:'100%',
	width:'100%',
        frameborder:0
      }).setOpacity(0).inject(this.splash,'top');
    }
    this.closeSplash.delay(this.options.delay, this);
  },
  closeSplash: function(){
	$('btOpenSplash').setStyles({
		'display':'block'
	});
	this.splash.fade('out');
	this.splash_cadre.fade('out');
  }
});

