var site = {

	start: function(){
		site.lightbox();
		site.fixNav();
		site.isHover();
		if(!window.ie6 && !window.ie5) site.faceLift();
		site.tips();
		site.verbatim();
		site.headerDiap();
	},
	
	restant: function(ta, hw, re){
		restant = hw - $(ta).value.length;
		if(restant >= 0){
			$(re).innerHTML = restant;
		}else{
			$(re).innerHTML = 0;
			$(ta).value = $(ta).value.substr(0, hw);
		}
	},
	
	headerDiap: function(){
		myShow = new Slideshow('header', {
			hu: '/media/theme/header/'+ chapterUrl +'/', 
			images: diapPix, 
			height: 137, 
			width: 714, 
			type: 'fade', 
			pan: 'rand',
			zoom: 'rand',
			navigation: 'arrows+'
		});
	},

	verbatim: function(){
		$$('.verbatim').each(function(me){
			vr = new Element('div').addClass('blockColored verbatim');	
			go = new Element('div').addClass('verbatimGO').injectInside(vr);
			gc = new Element('div').addClass('verbatimGC').injectInside(go);

			gc.innerHTML = me.innerHTML;
			vr.injectAfter(me);
			me.remove();
		});

		$$('.verbatimSimple').each(function(me){
			vr = new Element('div').addClass('blockColored verbatimSimple');	
			go = new Element('div').addClass('verbatimGO').injectInside(vr);
			gc = new Element('div').addClass('verbatimGC').injectInside(vr);

			gc.innerHTML = me.innerHTML;
			vr.injectAfter(me);
			me.remove();
		});
	},

	faceLift: function(){
		$$('.block2 .data h2').addClass('w224');
		$$('.block2 .data .eaves').addClass('pw224');
		$$('.block2 .data div.headlinesPNG').addClass('lw224');

		$$('.block3 .data h2').addClass('w345');
		$$('.block3 .data div.headlinesPNG').addClass('lw345');

		$$('.block4 .data h2').addClass('w462');
		$$('.block4 .data .eaves').addClass('pw462');
		$$('.block4 .blockVerbatim h2').addClass('w462');
		$$('.block4 .data div.headlinesPNG').addClass('lw462');

		$$('.block6 .data h2').addClass('w708');
		$$('.block6 .data .eaves').addClass('pw708');
		$$('.block6 .data .headlinesPNG').addClass('pw708');

		$$('.block7 .data h2').addClass('w829');

		$$('.block8 .data h2').addClass('w950');
		$$('.block8 .data div.headlinesPNG').addClass('lw950');

		FLIR.init({ path:'/plugins/facelift/' });
		FLIR.replace('h2.w224', 	new FLIRStyle({	cWidth:'224', mode:'wrap', output:'png', cColor:'rgb(0,0,0)', cFont:'eaves2'}));		
		FLIR.replace('h2.w345', 	new FLIRStyle({	cWidth:'345', mode:'wrap', output:'png', cColor:'rgb(0,0,0)', cFont:'eaves2'}));		
		FLIR.replace('h2.w462', 	new FLIRStyle({	cWidth:'462', mode:'wrap', output:'png', cColor:'rgb(0,0,0)', cFont:'eaves2'}));		
		FLIR.replace('h2.w708', 	new FLIRStyle({	cWidth:'708', mode:'wrap', output:'png', cColor:'rgb(0,0,0)', cFont:'eaves2'}));		
		FLIR.replace('h2.w829', 	new FLIRStyle({	cWidth:'829', mode:'wrap', output:'png', cColor:'rgb(0,0,0)', cFont:'eaves2'}));		
		FLIR.replace('h2.w950', 	new FLIRStyle({	cWidth:'950', mode:'wrap', output:'png', cColor:'rgb(0,0,0)', cFont:'eaves2'}));		

		FLIR.replace('*.pw224', 	new FLIRStyle({	cWidth:'224', mode:'wrap', output:'png', cColor:'rgb(0,0,0)', cFont:'eaves' }));
		FLIR.replace('*.pw462', 	new FLIRStyle({	cWidth:'462', mode:'wrap', output:'png', cColor:'rgb(0,0,0)', cFont:'eaves' }));
		FLIR.replace('*.pw708', 	new FLIRStyle({	cWidth:'708', mode:'wrap', output:'png', cColor:'rgb(0,0,0)', cFont:'eaves' }));

		FLIR.replace('*.lw224', 	new FLIRStyle({ cWidth:'224', mode:'wrap', output:'png', cColor:'rgb(0,0,0)', cFont:'eaves' }));
		FLIR.replace('*.lw345', 	new FLIRStyle({ cWidth:'345', mode:'wrap', output:'png', cColor:'rgb(0,0,0)', cFont:'eaves' }));
		FLIR.replace('*.lw462', 	new FLIRStyle({ cWidth:'462', mode:'wrap', output:'png', cColor:'rgb(0,0,0)', cFont:'eaves' }));
		FLIR.replace('*.lw950', 	new FLIRStyle({ cWidth:'950', mode:'wrap', output:'png', cColor:'rgb(0,0,0)', cFont:'eaves' }));
	},	

	lightbox: function(){
		Lightbox.init({descriptions: '.lightboxDesc', showControls: true});
	},

	fixNav: function(){
		$ES('#subnav .node li').setStyle('opacity', .90);
	},

	loginField: function(c){
		if(c.value == 'login') 					c.value = '';
		if(c.value == 'mot de passe')			c.value = '';
		if(c.value == 'rechercher sur le site')	c.value = '';
	},

	submiting:function(f){
		if($(f)) $(f).submit();
	},

	viewMonth:function(month){
		n = ($(month).getStyle('display') == 'inline') ? 'none' : 'inline';
		$(month).setStyle('display', n);
	},

	tips: function(){
		new Tips($$('.Tips'), {
			initialize:function(){
				this.fx = new Fx.Style(this.toolTip, 'opacity', {duration: 500, wait: false}).set(0);
			},
			onShow: function(toolTip) {
				this.fx.start(1);
			},
			onHide: function(toolTip) {
				this.fx.start(0);
			}
		});
	},

/* ----------------------------------------------------------------------------------------------------------- */

	isHover: function() { // Mimicks li:hover for IE, which doesn't support it :(
		try{
			var sfEls = document.getElementById("subnav").getElementsByTagName("li");
			for (var i=0; i<sfEls.length; i++) {
				sfEls[i].onmouseover=function() {
					this.className+=" ishover";
				}
				sfEls[i].onmouseout=function() {
					this.className=this.className.replace(new RegExp(" ishover\\b"), "");
				}
			}
		}
		catch(err){ }
	},

	jumpMenu: function(targ,selObj,restore){
		eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
		if (restore) selObj.selectedIndex=0;
	},

	goToURL: function(target, url){ 
		eval(target + ".location='" + url + "'");
	},

	openBrWindow: function(theURL,winName,features){
		window.open(theURL,winName,features);
	}
};

window.addEvent('domready', site.start);