/*@cc_on @*/
/*@if (@_win32)
	var ua = navigator.userAgent;
	var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
	if (re.exec(ua) != null) {
		ie_rv = parseFloat( RegExp.$1 );
	}
/*@end @*/
function fnOpenWindow(url,parameters)
{
	parameters=parameters.replace(/\s+/g,'');

	var aParameters=parameters.split(',');
	var data=new Array();
	for (var i=0;i<aParameters.length;i++) {
		var pr=aParameters[i];
		var key = pr.substr(0,pr.indexOf('='));
		var value=pr.substr(pr.indexOf('=')+1);
		data[key]=value;
	}

	if ( (data['hposition'])&&(data['width'])&&(data['hposition']!='system') )
	{
		var posX=null;
		if (data['hposition']=='left')
		{
			posX=0;
		}
		if ( (window.screen)&&(window.screen.availWidth) )
		{
			if (data['hposition']=='center')
				posX=(window.screen.availWidth-data['width'])/2;
			if (data['hposition']=='right')
				posX=window.screen.availWidth-data['width'];
		}

		if (posX!=null)
			parameters+=",left="+parseInt(posX);
	}

	if ( (data['vposition'])&&(data['height'])&&(data['vposition']!='system') )
	{
		var posY=null;
		if (data['vposition']=='top')
		{
			posY=0;
		}
		if ( (window.screen)&&(window.screen.availHeight) )
		{
			if (data['vposition']=='center')
				posY=(window.screen.availHeight-data['height'])/2;
			if (data['vposition']=='bottom')
				posY=window.screen.availHeight-data['height'];
		}

		if (posY!=null)
			parameters+=",top="+parseInt(posY);
	}


	var oWnd=window.open(url,'',parameters);
	oWnd.focus();
}

function getById(el) {
	return document.getElementById(el);
}

function getByTag(par,el) {
	var par = (par == '') ? document.body : par;
	if (!par) return new Array();
	return par.getElementsByTagName(el);
}

function getByClass(cla,par,el) {
	var getEls;
	if (/.*native code.*/.test(document.getElementsByClassName)) {
		getEls = function(cla,par,el) { 
			return par.getElementsByClassName(cla);
		}
	}
	else { 
		getEls = function(cla,par,el) { 
			var tagColl = par.getElementsByTagName(el);
			trimedColl = new Array;
			for (var i = 0; tagColl[i]; i++) {
				if(tagColl[i].className.match(new RegExp("( ?|^)"+cla+"\\b")))
					trimedColl[trimedColl.length]=tagColl[i];
			}
			return trimedColl;
		} 
	} 
	getByClass = function(cla,par,el) {
		var par = (!par||(par == '')) ? document.body : par;
		var el = (el == '') ? '*' : el;
		return getEls(cla,par,el); 
	}
	return getByClass(cla,par,el);
}

function addCSSRule(sheet,selector,val) {
	if(sheet.insertRule)
		sheet.insertRule(selector + ' {'+val+';}',sheet.cssRules.length);
	else if(sheet.addRule)
		sheet.addRule(selector, val)
}

function addClass(obj,newClass) {
	if(!obj.className.match(new RegExp(newClass)))
		obj.className+=(obj.className.length>0? " ": "") + newClass;
}

// Renamed from removeClass to rmClass();
function rmClass(obj,oldClass) {
	obj.className=obj.className.replace(new RegExp("( ?|^)"+oldClass+"\\b"), "");
}

function createEl(tag,classN,content) {
	var el = document.createElement(tag);
	if(classN&&(classN!='')) el.className = classN;
	if(content&&(content!='')) el.innerHTML = content;
	return el;
}

function getStyle(obj,cssRule) {
	if (document.defaultView && document.defaultView.getComputedStyle) {
		getStyle = function(obj,cssRule) {
			return document.defaultView.getComputedStyle(obj, "").getPropertyValue(cssRule);
		};
	}
	else {
		getStyle = function(obj,cssRule) {
			if (obj.currentStyle) {
				cssRule = cssRule.replace(/\-(\w)/g, function (match, p1) {
					return p1.toUpperCase();
				});
				return obj.currentStyle[cssRule];
			}
		};
	}
	getStyle(obj,cssRule);
}

function findPosition( oElement ) {
  if( typeof( oElement.offsetParent ) != 'undefined' ) {
    for( var posX = 0, posY = 0; oElement; oElement = oElement.offsetParent ) {
      posX += oElement.offsetLeft;
      posY += oElement.offsetTop;
    }
    return [ posX, posY ];
  } else {
    return [ oElement.x, oElement.y ];
  }
}

function getPageY() {
	var docHeight = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
	// Order maters here as for IE 6 documentElement.clientHeight != body.clientHeight
	var docScrollY = document.documentElement.scrollTop || document.body.scrollTop;
	return [docHeight,docScrollY];
}

function GET_XMLHTTPRequest() {
	var request;
	try{
		request = new ActiveXObject("Microsoft.XMLHTTP");
	}
	catch(ex1){
		try{
			request = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(ex2){
			try{
				request = new ActiveXObject("Msxml3.XMLHTTP");
			}
			catch(ex3){
				request = null;
			}
		}
	}
	if(!request && typeof XMLHttpRequest != "undefined"){
		request = new XMLHttpRequest();
	}
	return request;
}

function SetCookie(cookieName,cookieValue,nDays) {
	var today = new Date();
	var expire = new Date();
	if (nDays==null || nDays==0) nDays=1;
	expire.setTime(today.getTime() + 3600000*24*nDays);
	document.cookie = cookieName+"="+escape(cookieValue)
	                + ";expires="+expire.toGMTString() + ";path=/;";
}

function ReadCookie(cookieName) {
	var theCookie=""+document.cookie;
	var ind=theCookie.indexOf(cookieName);
	if (ind==-1 || cookieName=="") return ""; 
	var ind1=theCookie.indexOf(';',ind);
	if (ind1==-1) ind1=theCookie.length;
	return unescape(theCookie.substring(ind+cookieName.length+1,ind1));
}

/* Font size
----- */
function getFontPixels(obj) {
	if(!obj) obj = document.getElementsByTagName('body')[0];
	if (document.defaultView && document.defaultView.getComputedStyle)
		return parseInt(getStyle(obj,'font-size'),10);
	else {
		var t = document.createElement('span');
		t.innerHTML = 'X';
		t.className = 'wai';
		obj.appendChild(t);
		t.style.left = '10em';
		var fs = Math.round( t.style.pixelLeft / 10 );
		obj.removeChild(t);
		return fs;
	}
}

/* Google analytics
----- */
function addGoogleAnalytics() {
	if(typeof(gaJsTrackerId)!='string') return;
	var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
	var ga = document.createElement('script');
	document.getElementsByTagName('head')[0].appendChild(ga);
	ga.onload = function() {
		try {
		var pageTracker = _gat._getTracker(gaJsTrackerId);
		pageTracker._trackPageview();
		} catch(err) {}
	}
	ga.src = gaJsHost + 'google-analytics.com/ga.js';
}

/* Set links
----- */
function setLinks(linkTags,prt){
	var linkCollection = [];
	for (var j = 0; linkTags[j]; j++) {
		linkCollection[j] = getByTag(prt,linkTags[j]);
		for (var i = 0; linkCollection[j][i]; i++) {
			if(/zoom/.test(linkCollection[j][i].getAttribute('rel'))) {
				new Zoom(linkCollection[j][i]);
			}
			else if(/photo/.test(linkCollection[j][i].getAttribute('rel'))) {
				new Photo(linkCollection[j][i]);
			}
			else if(/bookmark|external|corporate|download/.test(linkCollection[j][i].getAttribute('rel'))) {
				linkCollection[j][i].onclick = function(e) {
					if (!e) var e = window.event;
					if (e.shiftKey || e.altKey || e.ctrlKey || e.metaKey)
						return true;
					window.open(this.href);
					return false;
				}
			}
		}
	}
}

// TODO Photo: improve roll as it can induce v scroll thus h page shift
/* Photo
----- */
function Photo(a) {
	this.call = a;
	this.path = a.href;
	this.tgt = a.appendChild(createEl('img','zoom',''));
	this.tgt.src = this.path;
	this.call.onclick = function() {return false;}

	
}

/* fixIE
----- */
function fixIE() {
	
}

/* fixLowIE
----- */
function fixLowIE() {
	
}

/* csSwitch
----- */
function CsSwitch() {
	var f = getById('footer');
	if(!f) return;
	this.tgt = document.getElementsByTagName('body')[0];
	var cnt = (/i18n-fr/.test(this.tgt.className)) ? '<em>Choisissez l\'ambiance graphique</em><ul><li class="cs1"><button type="button" class="cs1" title="Gris foncé">Gris foncé</button></li><li class="cs2"><button type="button" class="cs2" title="Gris moyen">Gris moyen</button></li><li class="cs3"><button type="button" class="cs3" title="Beige">Beige</button></li><li class="cs4"><button type="button" class="cs4" title="Blanc">Blanc cassé</button></li></ul>':'<em>Choose a colored background</em><ul><li class="cs1"><button type="button" class="cs1" title="Dark gray">Dark gray</button></li><li class="cs2"><button type="button" class="cs2" title="Medium gray">Medium gray</button></li><li class="cs3"><button type="button" class="cs3" title="Beige">Beige</button></li><li class="cs4"><button type="button" class="cs4" title="White">White</button></li></ul>';

	var d = createEl('div','',cnt);
	d.id='csSwitch';
	f.appendChild(d);

	this.cId = this.tgt.className.split('cs')[1];
	var cookieCid = ReadCookie('doisneauCSSPrefs');
	cookieCid = parseInt(cookieCid,10);

	if(cookieCid) {
		this.switchCs(cookieCid);
	}
	var b = getByTag(getById('csSwitch'),'button');
	for(var i = 0; b[i]; ++i) {
		b[i].cId = b[i].className.split('cs')[1];

		b[i].onclick = function (that) {
			return function () {
				that.switchCs(this.cId);
				return false;
			}
		}(this);
	}
}
CsSwitch.prototype={
	switchCs: function(cId) {
		cId = parseInt(cId,10);
		this.cId = parseInt(this.cId,10);
		if(cId!=this.cId) {
			
			rmClass(this.tgt,'cs'+this.cId);
			addClass(this.tgt,'cs'+cId);
			this.cId=cId;
			SetCookie('doisneauCSSPrefs',this.cId,60)
		}
	}
}

/* Diaporama
----- */
function setDiaporama(prt,type) {
	if(!prt) var prt = getById('content');
	var d = getByClass('diaporama',prt,'div');
	if(!d||!d[0]) return;
	for(var i = 0; d[i]; ++i) {
		var di = getByClass('diapo',d[i],'div');
		var id = (type&&(type=='overlay')) ? i + '_o': i;
		if(di&&di[1]) new Diapo(d[i],di,id,type);
	}
}

function Diapo(container,diapos,id,type) {
	this.container = container;
	addClass(this.container,'diapo_'+id+'_');
	this.dClass = '.diapo_'+id+'_';
	this.cId = 0;
	this.data_h = 20;
	this.speed = 5000;
	var s = document.styleSheets;
	var lastS = -1;
	for(var i = 0; i < s.length; ++i) {
		if(s[i].disabled==false)
			if(!/print|text/.test(s[i].href)) lastS = i;
	}
	for(var i = 0; diapos[i]; ++i) {
		if(/current/.test(diapos[i].className))
			this.cId = i;
		var d = getByClass('data',diapos[i],'div');
		if(d&&d[0]) {
			if(i==0) {
				var w = this.container.clientWidth - parseInt(getStyle(d[0],'padding-left'),10) - parseInt(getStyle(d[0],'padding-right'),10);
				if(lastS!=-1)
					addCSSRule(s[lastS],this.dClass+' .data','width: '+w+'px')
			}
			if(d[0].clientHeight > this.data_h) this.data_h = d[0].clientHeight;
		}
	}
	var fs = 14;
	if (document.defaultView && document.defaultView.getComputedStyle)
		fs = parseInt(getStyle(this.container,'font-size'),10);
	else {
		var t = createEl('span','wai','X');
		this.container.appendChild(t);
		t.style.left = '10em';
		fs = t.style.pixelLeft / 10;
		this.container.removeChild(t);
	}
	var h = parseInt(this.data_h,10) / fs;
	if(lastS!=-1)
		addCSSRule(s[lastS],this.dClass+' .data','height: '+h+'em');
	this.diapos = diapos;
	this.max = diapos.length;
	this.addNav(type);
	this.state = 'play';
	this.ppTxt = ['<strong>||</strong>', '►'];
	if(/speed/.test(container.className)){
		var reg = new RegExp("speed-([0-9]*)", "gi");
		var s = container.className.match(reg)[0];
		s = s.split('speed-')[1];
		this.speed = parseInt(s,10);
	}
	this.rotate();
}

Diapo.prototype = {
	addNav: function (type) {
		var dn = createEl('div','diapoNav','');
		this.container.appendChild(dn);
		this.nav_r = dn.appendChild(createEl('button','reposition',''));
		this.nav_pp = dn.appendChild(createEl('button','playPause','<strong>||</strong>'));
		this.nav_p = dn.appendChild(createEl('button','prev','&laquo;'));
		this.count_d = dn.appendChild(createEl('span','',this.cId+1+'/'+this.max));
		this.nav_n = dn.appendChild(createEl('button','next','&raquo;'));
		this.nav_r.onclick = function (that) {
	        return function () {
				that.focusOn();
				return false;
			}
		}(this);
		this.nav_p.onclick = function (that) {
			return function () {
				that.budge('prev');
				return false;
			}
		}(this);
		this.nav_n.onclick = function (that) {
	        return function () {
				that.budge('next');
				return false;
			}
		}(this);
		this.nav_pp.onclick = function (that) {
	        return function () {
				that.toggleState();
				return false;
			}
		}(this);
		/*@if (@_win32)
			if(ie_rv < 8) {
				var bs = getByTag(this.container,'button');
				if(bs&&bs[0]){
					for(var i = 0; bs[i]; ++i) {
						bs[i].onmouseover = function() {addClass(this,'hover');}
						bs[i].onmouseout = function() {rmClass(this,'hover');}
						bs[i].onfocus = function() {addClass(this,'focus');}
						bs[i].onblur = function() {rmClass(this,'focus');}
					}
				}
			}
		/*@end @*/
		if(type&&(type=='overlay')) {
			var c = getByClass('closer',getById('overlayContainer'),'a');
			if(c&&c[0]){
				this.shortcuts = 'on';
				this.addShortcuts();
				this.close = c[0].onclick;
				c[0].onclick = function(that) {
					return function() {
						document.onkeydown = function () {}
						that.close();
						return false;
					}
				}(this);

			}
			this.reFocus();
		}
		
	},
	addShortcuts: function() {
		document.onkeydown = function (that) {
	        return function (e) {
				if (!e) var e = window.event;
				if (e.metaKey || e.ctrlKey) return;
				var pressed = false;
				switch(e.keyCode) {
					case 27: // escape
						document.onkeydown = function () {}
						that.close();
						pressed = true;
					break;
					
					case 32: // space
						that.toggleState('keypress');
						pressed = true;
					break;

					case 37: // left
						that.budge('prev');
						pressed = true;
					break;

					case 39: // right
						that.budge('next');
						pressed = true;
					break;
				}
				if (pressed && e.preventDefault)
					e.preventDefault();
			}
		}(this);
	},
	shift: function(dir) {
		var n = (dir=='next') ? ( (this.cId+1 == this.max) ? 0 : this.cId+1 ) : ( (this.cId-1 < 0) ? this.max-1 : this.cId-1 );
		rmClass(this.diapos[this.cId],'current');
		addClass(this.diapos[n],'current');
		this.cId = n;
		this.count_d.innerHTML = this.cId+1+'/'+this.max;
	},
	rotate: function() {
		var speed = (this.rotate.arguments.length>0) ? this.rotate.arguments[0] : this.speed;
		this.rTimeout = setTimeout(function (that) {
			return function () {
				that.shift('next');
				that.rotate();
			}
		}(this), speed);
	},
	toggleState: function(t) {
		var p = (this.state=='play');
		if(p) clearTimeout(this.rTimeout);
		else this.rotate(300);
		if(t=='keypress') {
			this.nav_pp.innerHTML = (p) ? this.ppTxt[0] : this.ppTxt[1];
			clearTimeout(this.kTimeout);
			this.kTimeout = setTimeout(function (that) {
				return function () {
					that.nav_pp.innerHTML = (that.state!='play') ? that.ppTxt[1] : that.ppTxt[0];
				}
			}(this), 1600);
		}
		else
			this.nav_pp.innerHTML = (p) ? this.ppTxt[1] : this.ppTxt[0];
		this.state = (p) ? 'pause' : 'play';
		this.reFocus();
	},
	budge: function(d) {
		clearTimeout(this.rTimeout);
		this.shift(d);
		if(this.state=='play') this.rotate();
		this.reFocus();
	},
	reFocus: function() {
		if(window.focus) this.nav_r.focus();
	},
	focusOn: function() {
		if(window.focus) {
			this.nav_pp.focus();
			if(this.shortcuts=='on') {
				clearTimeout(this.fTimeout);
				this.fTimeout = setTimeout(function (that) {
					return function () {
						that.nav_r.focus();
					}
				}(this), 1500);
			}
		}
	}
}

/* Tabs
----- */
function setTabs() {
	var t = getByClass('tabbed',getById('content'),'div');
	if(!t||!t[0]) return;
	for(var i = 0; t[i]; ++i) {
		var ts = getByClass('tab',t[i],'div');
		if(ts&&ts[1]) new Tabs(t[i],ts);
	}
}

function Tabs(prt,tabs) {
	this.prt = prt;
	this.tabs = tabs;
	this.cId = -1;
	this.nav = createEl('div','tabs','');
	for(var i = 0; tabs[i]; ++i) {
		tabs[i].cId = i;
		var h = getByTag(tabs[i],'h3');
		var btnHTML = h[0] ? h[0].innerHTML : ' ' + i + ' ';
		var btn = createEl('button','',btnHTML);
		if(/currentTab/.test(tabs[i].className)) {
			this.cId = i;
			btn.className = 'current';
		}
		btn.cId = i;
		btn.onclick = function(that) {
			return function() {
				that.toggle(this.cId);
				return false;
			}
		}(this);
		btn.onfocus = function(that) {
			return function() {
				that.toggle(this.cId);
				return false;
			}
		}(this);
		this.nav.appendChild(btn);
	}
	this.prt.insertBefore(this.nav,this.prt.firstChild);
	this.btns = getByTag(this.nav,'button');
}

Tabs.prototype = {
	toggle: function(cId) {
		if(cId==this.cId) return;
		rmClass(this.tabs[this.cId],'currentTab');
		addClass(this.tabs[cId],'currentTab');
		rmClass(this.btns[this.cId],'current');
		addClass(this.btns[cId],'current');
		this.cId=cId;
	}
}

/* Folds
----- */
function setFolds() {
	var f = getByClass('folds',getById('content'),'div');
	if(!f||!f[0]) return;
	for(var i = 0; f[i]; ++i) {
		var fs = getByClass('fold',f[i],'div');
		if(fs&&fs[1]) new Folds(f[i],fs);
	}
}

function Folds(prt,folds) {
	this.prt = prt;
	this.folds = folds;
	this.cId = -1;
	for(var i = 0; folds[i]; ++i) {
		if(/current/.test(folds[i].className)) 
			this.cId = i;
		var h = getByTag(folds[i],'h4')[0];
		var b = createEl('button','',h.innerHTML);
		b.cId = i;
		h.innerHTML = '';
		h.appendChild(b);
		b.onclick = function(that) {
			return function() {
				that.toggle(this.cId);
				return false;
			}
		}(this);
		b.onfocus = function(that) {
			return function() {
				that.toggle(this.cId);
				return false;
			}
		}(this);
	}
}

Folds.prototype = {
	toggle: function(cId) {
		if(cId==this.cId) return;
		rmClass(this.folds[this.cId],'current');
		addClass(this.folds[cId],'current');
		this.cId=cId;
	}
}


/* Rollos
----- */
function setRollos() {
	var m = getByClass('rollMop',getById('page'),'div');
	if(!m || !m[0]) return;
	for(var i = 0; m[i]; ++i) {
		var r = getByClass('rollo',m[i],'a');
		if(r&&r[0])
			new Rollo(m[i],r);
	}
}

function Rollo(mop,rollos) {
	this.prt = mop;
	for(var i=0; rollos[i]; ++i) {
		rollos[i].onmouseover = function(that) {
			return function() {
				that.rollOn();
			}
		}(this);
		rollos[i].onmouseout = function(that) {
			return function() {
				that.rollOff();
			}
		}(this);
	}
}

Rollo.prototype = {
	rollOn: function() {
		addClass(this.prt,'rollin');
	},
	rollOff: function() {
		rmClass(this.prt,'rollin');
	}
}

/* Gallery
----- */
function setGalleries() {
	var g = getByClass('gallery','','div');
	if(!g) return;
	for (var i = 0; g[i]; ++i) {
		var c = getByClass('callers',g[i],'div');
		if(c&&c[0]) {
			var its = getByClass('item',c[0],'div');
			if(its) 
				new Gallery(g[i],c[0],its);
		}
	}
}

function Gallery(gallery,callBox,items) {
	this.gallery = gallery;
	this.callBox = callBox;
	this.items = items;
	this.cId = 0;
	this.scrollable = false;
	var d = document.createElement('div');
	d.className = 'displayer';
	this.displayer = d;
	var z = document.createElement('div');
	z.className = 'illustration';
	this.zoom = z;
	
	var nb = getById('galleryNav');
	this.galleryNav=nb;
	
	
	var lb = document.createElement('div');
	lb.className = 'legendBlock';
	this.legendBlock = lb;
	
	var cnter = document.createElement('div');
	cnter.className = 'counter';
	this.cnter = cnter;
	
	var sep = document.createElement('span');
	sep.className = 'separator';

	
	var l = document.createElement('div');
	l.className = 'legend';
	this.legend = l;
	d.appendChild(z);
	lb.appendChild(cnter);
//	lb.appendChild(sep);
	lb.appendChild(l);
	
	nb.appendChild(lb);
	this.gallery.appendChild(d);
	this.gallery.appendChild(nb);
	
	
	
	var prv = document.createElement('span');
		prv.className = 'prev';
		this.prv = prv;
		var nxt = document.createElement('span');
		nxt.className = 'next';
		this.nxt = nxt;
		d.appendChild(prv);
		d.appendChild(nxt);
	
	
	// var debug = document.createElement('div');
	// debug.id = "debug";
	// debug.setAttribute('style', "position: absolute; top: 0; right: 0;");
	// this.gallery.appendChild(debug);
	// this.debug = debug;
	
	for(var i = 0; items[i]; ++i) {
		items[i].cId = i;
		if(/current/.test(items[i].className))
			this.cId = i;
		var a = getByTag(items[i],'a');
		if(a&&a[0]) {
			var tgt = a[0].href;
			items[i].call = a[0];
			items[i].call.cId = i;
			items[i].img = tgt;
			var l = getByClass('desc',items[i],'div');
			items[i].legend = (l&&l[0]) ? l[0].innerHTML : '';
			items[i].call.onclick = function (that) {
				return function () {
					that.toggle(this.cId,'noScroll');
					return false;
				}
			}(this);
			items[i].call.onfocus = function (that) {
				return function () {
					that.toggle(this.cId,'noScroll');
					return false;
				}
			}(this);
		}
	}
	this.max = items.length-1;
	var m = getByClass('interstice',callBox,'div');
	var w = getByClass('wrap',callBox,'div');
	if(m&&w&&m[0]&&w[0])
		this.setScroll(m[0],w[0]);
	this.toggle(this.cId,'scroll');
}

Gallery.prototype = {
	toggle: function(cId,scroll) {
		addClass(this.displayer,'loading');
		this.zoom.innerHTML = '';
		var img = document.createElement('img');
		this.zoom.appendChild(img);
		img.onload = function (that) {
			return function () {
				rmClass(that.displayer,'loading');
			//	that.zoom.style.height = img.offsetHeight + 'px';
				return false;
			}
		}(this);
		img.src = this.items[cId].img;
		this.legend.innerHTML = this.items[cId].legend;
		rmClass(this.items[this.cId],'current');
		addClass(this.items[cId],'current');
		this.cId = cId;
		if((this.scrollable==true) && (scroll=='scroll'))
			this.init(this.cId);
		this.setNav();
		setLinks(['a'],this.legend);
		var pTxt = /i18n-fr/.test(document.getElementsByTagName('body')[0].className) ? ' photographies' : ' photos';
		this.cnter.innerHTML = cId+1 + '/' + parseInt(this.max + 1,10) + pTxt;
	},
	setNav: function() {
		var b = document.getElementsByTagName('body')[0];
		var txtP = /i18n-fr/.test(b.className) ? 'Précédent' : 'Previous';
		var txtN = /i18n-fr/.test(b.className) ? 'Suivant' : 'Next';
		if(this.cId>0) {
			
			this.prv.innerHTML = '<a href="#" title="'+txtP+'">&laquo;</a>';
			getByTag(this.prv,'a')[0].onclick = function (that) {
				return function () {
					that.toggle(that.cId-1,'scroll');
					return false;
				}
			}(this);
			getByTag(this.prv,'a')[0].onfocus = function (that) {
				return function () {
					that.toggle(that.cId-1,'scroll');
					return false;
				}
			}(this);
		}
		else
			this.prv.innerHTML = '';
		if(this.cId<this.max) {
			this.nxt.innerHTML = '<a href="#" title="'+txtN+'">&raquo;</a>';
			getByTag(this.nxt,'a')[0].onclick = function (that) {
				return function () {
					that.toggle(that.cId+1,'scroll');
					return false;
				}
			}(this);
			getByTag(this.nxt,'a')[0].onfocus = function (that) {
				return function () {
					that.toggle(that.cId+1,'scroll');
					return false;
				}
			}(this);
		}
		else
			this.nxt.innerHTML = '';
	},
	setScroll: function(m,w) {
		this.interstice = m;
		this.wrap = w;
		this.callBox.w = this.callBox.offsetWidth;
		this.items.w = 0;
		this.items[this.items.length-1].style.marginRight = 0;
		for(var i = 0; this.items[i]; ++i) {
			if(i==0)
				this.items.mr = 6;
				this.items.w = this.items.w + this.items[i].offsetWidth + this.items.mr;
		}

		this.items.w = this.items.w - this.items.mr;
		this.wrap.style.width = this.items.w+'px';
		if(this.items.w > this.callBox.w) {
			this.scrollable = true;
			var b = document.createElement('div');
			b.className = 'scrollBar';
			this.scrollBar = b;
			var s = document.createElement('div');
			s.className = 'scroller';
			this.scroller = s;
			b.appendChild(s);
			this.galleryNav.insertBefore(b,this.legendBlock);
			this.w = this.scroller.offsetWidth;
			this.bW = this.wrap.offsetWidth;
			this.prtX = findPosition(this.scrollBar)[0];
			this.prtW = this.scrollBar.offsetWidth;
			this.prtZ = this.prtX + this.prtW;
			this.ratio =  (this.bW - this.prtW) / (this.prtW - this.w);
			this.state = null;
		    this.prevX = null;
			this.curOffset = null;
			this.scrolled = null;
			this.makeDraggable();
		}
	},
	makeDraggable: function () {
		this.scroller.onmousedown = function (that) {
			return function (e) {
			that.mousedown(e);
			return false;
			}
		}(this);
			this.interstice.onscroll = function (that) {
			return function (e) {
				that.scrollH();
			}
		}(this);
		this.init(this.cId);
	},
	scrollH: function () {
	//	var nX = ((this.interstice.scrollLeft - this.wrap.offsetLeft) / this.ratio);
		var nX = ((this.interstice.scrollLeft ) / this.ratio);
		// this.debug.innerHTML=this.wrap.offsetLeft;
		this.scroller.style.left = nX + 'px';
		this.curOffset = this.w/2;
	},
	init: function (cId) {
		x = this.items[cId].offsetLeft;
		this.interstice.scrollLeft = x;

		if(!this.curOffset) {
			this.curOffset = x - this.prtX;
		}
		else if(this.prevX) {
			this.curOffset = x - (this.prtX + this.prevX);
		}

	},
	mousedown: function (e) {
		e = e ? e : window.event;
		var x = e.clientX ? e.clientX : e.pageX;
		if(!this.curOffset) {
			this.curOffset = x - this.prtX;
		}
		else if(this.prevX) {
			this.curOffset = x - (this.prtX + this.prevX);
		}
		this.state = "drag";
		addClass(this.scroller,'scrolling');
		document.onmousemove = function (that) {
	        return function (e) {
	            that.mousemove(e);
	 			return false;
	        }
	    }(this);
	    document.onmouseup = function (that) {
	        return function (e) {
	            that.mouseup(e);
	        }
	    }(this);
	},
	mousemove: function (e) {
		e = e ? e : window.event;
		var x = e.clientX ? e.clientX : e.pageX;
		if(this.state === "drag") {
			if( (x > this.prtX) && (x < this.prtZ)) {
				var scrollerX = (x - this.curOffset) - this.prtX;
				var scrollItemsX = (this.prtX - (x - this.curOffset)) * this.ratio;
				if( (scrollerX > -1) && ( (x - this.curOffset) < (this.prtZ - this.w) )) {
					this.scroller.style.left = scrollerX + 'px';
					this.interstice.scrollLeft = - scrollItemsX;
				}
				else if(scrollerX < 0) {
					this.scroller.style.left = 0 + 'px';
					this.interstice.scrollLeft = 0;
				}
				else if (scrollerX > (this.prtW - this.w)) {
					this.scroller.style.left = (this.prtW - this.w) + 'px';
					this.interstice.scrollLeft = - (this.prtW - this.bW);
				}
			}
		}
	},
	mouseup: function (e) {
		e = e ? e : window.event;
		this.state = '';
		this.prevX = this.scroller.offsetLeft;
		rmClass(this.scroller,'scrolling');
	}
}

/* 
----- */
function setNews() {
	var news = getById('news');
	if(!news) return;
	var newsItems = getByClass('news',news,'div');
	if(newsItems&&newsItems[1])
		new News(news,newsItems);
}

function News(prt,items) {
	this.prt = prt;
	for(var i = 0; items[i]; ++i) {
		items.cId = i;
	}
	this.itms = items;
	this.cId = 0;
	this.max = items.length;
	this.speed = 5000;
	if(/speed/.test(prt.className)){
		var reg = new RegExp("speed-([0-9]*)", "gi");
		var s = prt.className.match(reg)[0];
		s = s.split('speed-')[1];
		this.speed = parseInt(s,10);
	}
	
	this.setNav();

	this.rotating = (this.speed==0) ? false : true;
	
	if(this.rotating)
		this.rotate();
		
}

News.prototype = {
	setNav: function() {

		var rNav = this.prt.appendChild(createEl('div','rnNav',''));
		for(var i = 0; this.itms[i]; ++i) {
			var c = (i == this.cId) ? 'rnBtn current' : 'rnBtn';
			var btn = rNav.appendChild(createEl('button',c,parseInt(i+1,10)));
			btn.cId = i;
			btn.onclick = function(that) {
				return function() {
					that.change(this.cId);
				}
			}(this);
		}
		this.btns = getByTag(rNav,'button');

	},
	change: function(cId) {
		if(this.rotating)
			clearTimeout(this.rTimeout);
		if(this.btns) {
			rmClass(this.btns[this.cId],'current');
			addClass(this.btns[cId],'current');
		}
		rmClass(this.itms[this.cId],'currentNews');
		addClass(this.itms[cId],'currentNews');
		this.cId = cId;
		if(this.rotating)
			this.rotate();
	},
	shift: function(dir) {
		var n = (dir=='next') ? ( (this.cId+1 == this.max) ? 0 : this.cId+1 ) : ( (this.cId-1 < 0) ? this.max-1 : this.cId-1 );
		if(this.btns) {
			rmClass(this.btns[this.cId],'current');
			addClass(this.btns[n],'current');
		}
		rmClass(this.itms[this.cId],'currentNews');
		addClass(this.itms[n],'currentNews');
		this.cId = n;
	},
	rotate: function() {
		var speed = this.speed;
		this.rTimeout = setTimeout(function (that) {
			return function () {
				that.shift('next');
				that.rotate();
			}
		}(this), speed);
	}
}


/* Init
----- */
function init() {
	if (arguments.callee.done) return;
	arguments.callee.done = true;
	/*@if (@_win32)
		if(ie_rv < 6) return;
	/*@end @*/

	if(!document.getElementsByTagName) return;

	addClass(document.getElementsByTagName('body')[0],'scripted');
	setLinks(['a','area'],'');
	
	setDiaporama();
	setTabs();
	setFolds();
	setRollos();
	setGalleries();
	setNews();
	new CsSwitch();

	/*@if (@_win32)
		if(ie_rv < 7) fixLowIE();
		if(ie_rv < 8) fixIE();
	/*@end @*/
}

if (document.addEventListener) {
	document.addEventListener("DOMContentLoaded", function(){
		document.removeEventListener("DOMContentLoaded",arguments.callee,false);
		init();
	},false);
}
else if (document.attachEvent) {
	document.attachEvent("onreadystatechange", function(){
		if (document.readyState === "complete") {
			document.detachEvent("onreadystatechange",arguments.callee);
			init();
		}
	});
	if (document.documentElement.doScroll && window == window.top) (function(){
		if (arguments.callee.done) return;
		try {
			document.documentElement.doScroll("left");
		} catch(error) {
			setTimeout(arguments.callee, 0);
			return;
		}
		init();
	})();
}
window.onload = init;
