var overlay;
window.addEvent('domready', function() {
	
	$ES('.roll a').each(function(e){

	full = new Element('span',{'class':'full'});full.injectBefore(e);
	faded = new Element('span',{'class':'faded'});faded.injectBefore(full);
	
	x = e.getPrevious();
	var fx = new Fx.Styles(x, {duration:400, wait:false});
	
	if(e.getProperty('sel')!='1')
	{
		e.addEvent('mouseenter',function(){
			
			fx.start({'opacity': [1,1]});
			//e.getFirst().setStyle('padding-left','15px');
		});
		
		e.addEvent('mouseleave',function(){
			
			fx.start({'opacity': [1,0]});
			//e.getFirst().setStyle('padding-left','12px');
		});
	}
	else{
		fx.start({'opacity': [0,1]});
		e.getFirst().setStyles({'color':'#ffffff'});
		
	}
	
	});
		
	$ES('.gall a').each(function(e){
		shadow = new Element('span',{'class':'shadow',styles:{'opacity':'0.45'}});
		thumb = e.getPrevious();
		sh = shadow.injectInside(thumb);
		s = e.getFirst();
		var fx = new Fx.Styles(s, {duration:200, wait:false});
		e.addEvent('mouseenter',function(){
			t = e.getPrevious().getLast().setStyle('opacity','0');			
			 fx.start({'height': '0px'});
			 
		});
		e.addEvent('mouseleave',function(){
			t = e.getPrevious().getLast().setStyle('opacity','0.45');
			 fx.start({'height': '25px'});
		});
		e.addEvent('click',function(c){
			var c = new Event(c);
			c.stop();
			overlay =  new Overlay({'colour':'#000000'});
			overlay.show();
			$('screencast').setStyle('display','block');
			//if($('screencast').getProperty('type')!='application/x-shockwave-flash')
			//{
			var flashvars = {path:"/books/swf/main.swf",idBook: e.getProperty("bid")};
			var params = {scale: "noscale",quality: "best",allowScriptAccess: "always",allowFullScreen: "true",bgcolor:'#000000',wmode:"opaque"};
			var attributes = {id: "screencast",name: "screencast"};
			
			swfobject.embedSWF("/books/swf/main.swf", "screencast", "100%", "100%", "8.0.0","/books/js/expressInstall.swf", flashvars, params, attributes);
			//swfmacmousewheel.registerObject(attributes.id);
			//}
		});
	});
	
	$ES(".btn-menu a").each(function(e){
		bg = new Element('span',{'class':'bg'});
		f = new Element('span',{'class':'faded'});
		f.injectBefore(e);bg.injectBefore(f);
		b = e.getParent().getFirst();
		var fx = new Fx.Styles(b, {duration:300, wait:false});
		var fxa = new Fx.Styles(e, {duration:300, wait:false});	
		if(e.getParent().getProperty('class')!='btn-menu active')
		{
		e.addEvent('mouseenter',function(){		
			fx.start({'height': '44px','display':'block'});
			fxa.start({'opacity': [0.1,1]});
		});
		e.addEvent('mouseleave',function(){
			fx.start({'height': '21px','display':'block'});
			fxa.start({'opacity': [1,0.1]});
		});
		}
	});
	
	if($('email')){
	$('email').addEvent('focus',function(){
		if($(this).getProperty('value')=='votre adresse e-mail'){
			$(this).setProperty('value','');
		}
	});
	
	$('email').addEvent('blur',function(){
		if($(this).getProperty('value')==''){
			$(this).setProperty('value','votre adresse e-mail');
		}
	});
	}
	
	//#sect-clients #headline
	
	if($('sect-clients')){
		var fx = function() {
			opac =  Math.random();
				 $('headline').setStyles({'background':'transparent url(../layout/img/headline-clients'+Math.floor(Math.random()*8)+'.jpg) no-repeat scroll 0pt 50%'});
				 var myEffects = new Fx.Styles('headline', {duration: 400, transition: Fx.Transitions.linear});
				/* myEffects.start({
				    'opacity': [0.5, 1]
				});*/
			}
		
		var periodical;
		periodical = fx.periodical(200);

	}
	
	if($('sidebar_1')){$('sidebar_1').setStyle('height',$('content-left').getStyle('height'));}
	if($('sidebar_2')){$('sidebar_2').setStyle('height',$('content-left').getStyle('height'));}
		
	
	// Gab's class
	
	flashLaunch = {
		lanchflash:function(){
			if($('thisisthebook')){
				var bid = $('thisisthebook').getProperty('bid');
				overlay =  new Overlay({'colour':'#000000'});
				overlay.show();
				$('screencast').setStyle('display','block');
				var flashvars = {path:"/books/swf/main.swf",idBook: bid};
				var params = {scale: "noscale",quality: "best",allowScriptAccess: "always",allowFullScreen: "true",bgcolor:'#000000'};
				var attributes = {id: "screencast",name: "screencast"};
			
				swfobject.embedSWF("/books/swf/main.swf", "screencast", "100%", "100%", "8.0.0","/books/js/expressInstall.swf", flashvars, params, attributes);	
			}
		}
	}
	// Launch
	flashLaunch.lanchflash();
	
	if($('newsletter-response'))
	{
		var n = $('newsletter-response');
		if($E('form','newsletter-response')){
			//we have a form
		}
		else{
			//we have a message
			/* uncomment this when put in place
			n.getFirst().remove();
			t=n.getLast().innerHTML;
			n.getLast().innerHTML='&nbsp;'
			*/
			
		}
	}

	//legal
	$('legal').addEvent('click',function(e){
		//new Event(e).stop();
		var legalsfade = new Element('div',
				{ 
				'styles':{
						'background':'#000',
						'height':$E('.body').getStyle('height'),
						'width':$E('.body').getStyle('width'),
						'position':'absolute',
						'top':'0px',
						'left':'0px',
						'z-index':'9999',
						'display':'block',
						'overflow':'hidden',
						'opacity':'0.5'
				 	},
				 'id':'legalfade'
				}
			);
			
		var legals = new Element('div',
				{ 
				'styles':{
						'height':'600px',
						'width':'933px',
						'position':'absolute',
						'top':'0px',
						'margin':'0px auto',
						'z-index':'99999',
						'display':'block',
						'overflow':'hidden'
				 	},
				 'id':'legal_mention'
				}
			);
			
			var legalEffects = new Fx.Styles(legalsfade, {duration: 300, transition: Fx.Transitions.linear});
			var legals_text = '<p class="legaltext"><br/>MENTIONS LEGALES<br/><br/>'+
					   'Creasenso.fr est un site de la société CREASENSO™, SARL au capital de 7500 &euro;, dont le siège social est 21, rue de Trévise ; 75009 PARIS, immatriculé au Registre du Commerces et des Sociétés de Paris sous le numéro B 447 652 249'+
					    '<br/><br/>'+
					    'Gérant : Cédric BORDERIE'+
					    '<br/><br/>'+
					    'Le site web est hébergé par la société Typhon™ SAS au capital de 100 100 &euro; - 17 rue Réaumur, 75003 Paris - RCS PARIS B 480 288 97'+
					    '<br/><br/><a href="#">Retour</a></p>';
			legals.setHTML(legals_text);
			legalsfade.injectInside($E('.body'));
			legals.injectInside($('size'));
			legalEffects.start({'opacity': [0.5,0.8]});
			legalsfade.addEvent('click',function(){legals.remove();legalsfade.remove();});
			legals.addEvent('click',function(){legals.remove();legalsfade.remove();});
		});
	
});


