var overlay;
window.addEvent('domready', function() {
	
	if($E('div.tel span')){
		if($E('div.tel span').getText()=='work'){$E('div.tel span').setText('T.');}
		fax = $E('div.tel').getNext().getFirst();
		if(fax.getText()=='fax'){fax.setText('F.');}
	}
	
	if(window.ie){
		$$('img[src$=png]').each(function(el) {
			el.replaceWith(new Element('input', {
			'styles': {
			'filter': 'progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=\'true\', sizingMethod=\'crop\', src=\'' + el.getProperty('src') + '\')',
			'position': 'relative',
			'background': 'transparent'
			},
			'title': el.getProperty('alt')
			}).setStyles(el.getStyles('padding','margin','border','height','width','left','top')).setProperties(el.getProperties('id','class')).setProperty('disabled', 'true'));
			});
	}
	
	
	$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'});
		
	}
	
	});
	
	//book precendent
	$ES('.previous 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'});
		
	}
	
	});
	//end book precedent
	
	//book back
	$ES('.back 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'});
		
	}
	
	});
	//end book back
	
	//book next
	$ES('.next 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'});
		
	}
	
	});
	//end book next
	
	//book precendent-bottom
	$ES('.previous-bottom 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'});
		
	}
	
	});
	//end book precedent-bottom
	
	/*$ES('.img-wrap img').each(function(e){
		if(e.getNext()) {e.getNext().setStyle('width',parseInt(e.getStyle('width'))-16+'px');}
		else{e.getParent().getNext().getNext().setStyle('width',parseInt(e.getStyle('width'))-16+'px');}
	});*/
	//gall images
		
	$ES('.www-link').each(function(e){
		
		e.setStyles({'margin-top':parseInt((parseInt(e.getPrevious().getStyle('height'))-100)/2)+'px','margin-left':parseInt((parseInt(e.getPrevious().getStyle('width'))-100)/2)+'px'});
		e.getParent().addEvent('mouseenter',function(v){
				var v = new Event(v);
				v.stop();
				e.setStyle('visibility','visible');
			});
		e.getParent().addEvent('mouseleave',function(v){
				var v = new Event(v);
				v.stop();
				e.setStyle('visibility','hidden');
			});

	});
	
	/*$ES('.img-wrap a').each(function(e){
			if(e.getProperty('class')!='dsk')
			{
			w=e.getNext();
			if(w.getProperty('class')=='www-link') {
			w.setStyles({'margin-top':(parseInt(e.getFirst().getStyle('height'))-100)/2+'px','margin-right':(parseInt(e.getFirst().getStyle('width'))-100)/2+'px'});
			e.getParent().addEvent('mouseenter',function(v){
				var v = new Event(v);
				v.stop();
				this.getNext().setStyle('visibility','visible');
			});
			e.getParent().addEvent('mouseleave',function(v){
				var v = new Event(v);
				v.stop();
				this.getNext().setStyle('visibility','hidden');
			});
			
		         }
		     }
		
	});*/
	//end gall images
	
	$ES('.gall a').each(function(e){ 	
		
		if((e.getProperty('class')!='big_a')&&(e.getProperty('class')!='dsk')) {

		s = e.getFirst();
		var fx = new Fx.Styles(s, {duration:200, wait:false});
		
		if(e.getProperty('nobook')!=1)
		{
			if(!window.ie)
			{
			
			e.addEvent('mouseenter',function()
				{
					
					var e_bid = e.getProperty("bid"); 
					var e_href = e.getProperty("href");
					book_html = new Element('a',{'class':'b_html',styles:{'color':'#FFFFFF','font-size':'11px'},'href':e_href}).appendText('BOOK HTML').injectInside(e.getFirst());
					book_swf =  new Element('a',{'class':'b_swf',styles:{'color':'#FFFFFF','font-size':'11px'},'href':e_href}).appendText('BOOK FLASH').injectInside(e.getFirst());	
					fx.start({'height': '50px'});

					book_swf.addEvent('click',function(c){
						var c = new Event(c);
						c.stop();
						overlay =  new Overlay({'colour':'#000000'});
						overlay.show();
						$('screencast').setStyle('display','block');
						
						var flashvars = {path:"/books/swf/main.swf",idBook: e_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);
						
					});
			 
				});
				
			e.addEvent('mouseleave',function(){
					book_html.remove();
					book_swf.remove();
					fx.start({'height': '25px'});
				});
			}
			
		
		
		if(window.ie){
			
			thumb = e.getPrevious();
			img = thumb.getFirst();

			img.addEvent('click',function(){window.location.href=e.getProperty("href")});
			e.addEvent('mouseenter',function()
				{
					var e_bid = e.getProperty("bid"); 
					var e_href = e.getProperty("href");
					book_html = new Element('a',{'class':'b_html',styles:{'color':'#FFFFFF','font-size':'11px'},'href':e_href}).appendText('BOOK HTML').injectInside(e.getFirst());
					book_swf =  new Element('a',{'class':'b_swf',styles:{'color':'#FFFFFF','font-size':'11px'},'href':e_href}).appendText('BOOK FLASH').injectInside(e.getFirst());	
					fx.start({'height': '50px'});

					book_swf.addEvent('click',function(c){
						var c = new Event(c);
						c.stop();
						overlay =  new Overlay({'colour':'#000000'});
						overlay.show();
						$('screencast').setStyle('display','block');
						
						var flashvars = {path:"/books/swf/main.swf",idBook: e_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);
						
					});
			 
				});

			e.addEvent('mouseleave',function(){
					book_html.remove();
					book_swf.remove();
					fx.start({'height': '25px'});
				});
		
			}
		}
		
		
		else{
			var s_o = new Array();
			e.addEvent('mouseenter',function(){
			s_o[e.getProperty('bid')] = e.getFirst().getFirst().getText();
			e.getFirst().getFirst().setText('Coming soon');
			});
			
			e.addEvent('mouseleave',function(){
			e.getFirst().getFirst().setText(s_o[e.getProperty('bid')]);
			});
			
			e.addEvent('click',function(c){
			var c = new Event(c);
			c.stop();
			});
			
		   }
		}
	});
	
	$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);
		
		if(window.ie){
			img = f.getStyle('background-image');
			len = img.length;
			f.setStyles({
			'filter': 'progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=\'true\', sizingMethod=\'crop\', src=\'' + img.substring(5,len-2) + '\')',
			'background':''
			});
		}
		
		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');
		}
	});}
	
	// 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();
	
	//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();});
		});
	
});
