
function popup( scrollbars,url, name, w, h ) { 
	var l = (screen.availWidth-10 - w) / 2;
	var t = (screen.availHeight-20 - h) / 2;
	features = "width="+w+",height="+h+",left="+l+",top="+t+",screenX="+l+",screenY="+t+",scrollbars="+scrollbars+",resizable=0,location=no,menubar=no,toolbar=no,status=no";
	window.open(url, name, features);
}
function note( note ) {
	document.images['img_note'].src = './images/common/bon_plan/etoile'+note+'.gif';
	$('note').value = note;
}
function avatar(id) {
	$('avatar'+id).checked = true;
}
function myPopScroll(url,winName,Wwide,Whigh) { 
    if (winName=='') winName = '_blank';
    var wide = window.screen.availWidth;
    var high = window.screen.availHeight; // Screen size
    var left = 0; var top = 0; // Position
    if (wide > Wwide) left = (wide-Wwide)/2; else Wwide = wide; if (high > Whigh) top = (high-Whigh)/2; else Whigh = high; // Max Size
    var w = window.open(url,winName,'height='+Whigh+',innerHeight='+Whigh+',width='+Wwide+',innerWidth='+Wwide+',left='+left+',screenX='+left+',top='+top+ ',screenY='+top+',dependent=1,status=1,statusmenubar=1,directories=0,fullscreen=0,toolbar=0,location=0,menubar=0,scrollbars=1,resizable=0');
    w.focus();
    return false; // Don't open href link
}

var myTimerNs;
var marge = 10; // Marge fenetre
var infosWidth = 510; // Largeur de la fenetre "infos", en Pix

function showHideBoxesNs(visibility) { // visibility = hidden|visible
    if (visibility != 'hidden' || visibility == undefined) visibility = 'visible';
	var selects = $$('select');
    for (i = 0; i != selects.length; i++) selects[i].style.visibility = visibility;
    var iframes = $$('iframe');
    for (i = 0; i != iframes.length; i++) iframes[i].style.visibility = visibility;
}
function startOverlayNs() {
    showHideBoxesNs('hidden');
    if ($('divNode')){
        $('divNode').show();
        if (!$('dyn_overlay')) {
            //var objBody = document.getElementsByTagName("body").item(0);
            var objOverlay = document.createElement("div");
            objOverlay.setAttribute('id','dyn_overlay');
            objOverlay.setAttribute('style','display:none;');
            $('divNode').appendChild(objOverlay);
        }
        var arrayPageSize = getPageSize();
        Element.setHeight('dyn_overlay', arrayPageSize[1]);
        new Effect.Appear('dyn_overlay', {duration: 0.2, from: 0.0, to: 0.6, queue: 'front'});
    }
}
function removePrintInfoNs() {
    if (myTimerNs) {
        clearTimeout(myTimerNs);
        myTimerNs = null;
    }
    if ($('dyn_infos')) $('dyn_infos').remove();
    if ($('dyn_overlay')) $('dyn_overlay').hide();
    if($('divNode')) $('divNode').hide();
    showHideBoxesNs('visible');
}
function removeFadePrintInfoNs() {
    new Effect.Fade('dyn_infos', {duration: 0.2, from: 0.6, to: 0.0, queue: 'front'});
    new Effect.Fade('dyn_overlay', {duration: 0.2, from: 0.6, to: 0.0, queue: 'end', onfinish:removePrintInfoNs()});
}
function printInfoNs(infosHtml) { // printInfoNs('Bla bla bla'); ////////////////////////////////////////////////
	if (infosHtml == '') return false;
	infosHtml = infosHtml.stripScripts();
	//infosHtml = infosHtml.escapeHTML();
	removePrintInfoNs();
	startOverlayNs();
  if($('dyn_overlay')) {
    $('dyn_overlay').onclick = function() { removeFadePrintInfo(); return false; }
  }
	
	var timeOut = (parseInt(infosHtml.length) * 80);
	if (timeOut < 1600) timeOut = 2000;
	if (infosHtml.indexOf('<br>') >= 0 || infosHtml.indexOf('<br />') >= 0) infosHtml += '<br>&nbsp;';
	var arr_Scroll = getPageScroll();         
	var arr_pageSize = getPageSize(); // (pageWidth,pageHeight,windowWidth,windowHeight)
	offsetX = arr_Scroll[0] + ((arr_pageSize[2] - infosWidth - (marge*2)) / 2);
	offsetY = arr_Scroll[1] + (arr_pageSize[3] / 3)  + marge;
	if (offsetY < marge) offsetY = marge;
	var attrDivInfo = {};
	attrDivInfo['id'] = 'dyn_infos';
	attrDivInfo['style'] = 'width:'+infosWidth+'px;left:'+offsetX+'px;top:'+offsetY+'px;';
	creatDiv('',attrDivInfo,'');
	var attrDivPrint = {};
	attrDivPrint['id'] = 'fermer';
	attrDivPrint['class'] = 'fermer';
	var htmleu = '<a href="javascript:void(0);" onClick="removePrintInfoNs();">'+js_msg_03+'</a><div class="breaker"></div>';
	creatDiv($('dyn_infos'),attrDivPrint,htmleu);
	new Insertion.Bottom('dyn_infos', '<h1>'+infosHtml+'</h1>');	
    myTimerNs = setTimeout("removeFadePrintInfo();", timeOut);
}
function removeLightBoxNs() {
    if ($('lightboxUrl')) $('lightboxUrl').remove();
	if ($('dyn_lightbox')) $('dyn_lightbox').remove();
    if ($('dyn_overlay')) $('dyn_overlay').hide();
    $('divNode').hide();
    showHideBoxesNs('visible');
}
function startDivBoxNs(w,h) {
    if (w == undefined || w < 1) w = infosWidth;
    if (h  == undefined || h < 1) h = 510;
    if (!$('dyn_lightbox')) {
        var objLightbox = document.createElement("div");
        objLightbox.setAttribute('id','dyn_lightbox');
        objLightbox.style.display = 'none';
        objLightbox.style.width = w+'px';
        $('divNode').appendChild(objLightbox);
    }
	var arr_Scroll = getPageScroll();         
	var arr_pageSize = getPageSize();
	offsetX = arr_Scroll[0] + ((arr_pageSize[2] - w - (marge*2)) / 2);
	offsetY = arr_Scroll[1] + (arr_pageSize[3] / 4)  + marge;
	if (offsetY < marge) offsetY = marge;
    Element.setTop('dyn_lightbox', offsetY);
    Element.setLeft('dyn_lightbox', offsetX);
}
function loadUrlInOverlayNs(url,w,h) { // loadUrlInOverlayNs('popup.php?RID=19&simple=1');
    startOverlayNs();
    $('dyn_overlay').onclick = function() { removeLightBoxNs(); return false; }
    startDivBoxNs(w,h);
    if ($('lightboxUrl')) $('lightboxUrl').remove();
	var attrDivPrint = {};
	attrDivPrint['id'] = 'fermer';
	attrDivPrint['class'] = 'fermer';
	var htmleu = '<a href="javascript:void(0);" onClick="removeLightBoxNs();">'+js_msg_03+'</a><div class="breaker"></div>';
	creatDiv($('dyn_lightbox'),attrDivPrint,htmleu);
	var objlightboxUrl = document.createElement("div");
	objlightboxUrl.setAttribute('id','lightboxUrl');
	$('dyn_lightbox').appendChild(objlightboxUrl);
    $('dyn_lightbox').show();
    var specs = url.split('?');
    var url = specs[0]
    var param = specs[1];
	var laRequete = new Ajax.Updater({success:'lightboxUrl'}, url, {
		method: 'get',
		parameters: param,
		evalScripts: true,
		insertion: Insertion.Top
	});
    return false; // Don't open href
}

function swap_element(element)
{
	if(element.style.display=='block')
		element.style.display = 'none' ;
	else
		element.style.display = 'block' ;
}

var totalMail = 1;
function addEmailDest(contentId) {
	$(contentId).show();
	totalMail++;
	if (totalMail > 5) {
		if ($(contentId+'_info')) {
			$(contentId+'_info').update('<br>'+js_msg_04+'<br>&nbsp;');
			$(contentId+'_info').show();
		}
		else alert(js_msg_04);
	}
	else {
		if ($(contentId+'_info')) $(contentId+'_info').hide();
		new Insertion.Bottom($(contentId), '<p><label for="email_ami'+totalMail+'">'+js_msg_12+' '+totalMail+' :</label><input name="email_ami'+totalMail+'" id="email_ami'+totalMail+'" type="text" /></p>');
	}
}

// Niak niak
window.alert = function() {};
Event.observe(window, 'load', function(evt){
  window.alert = function(msg) { printInfoNs(fixDialogValue(msg)); };
});

var exec = function(func) {
	if (typeof(func) == 'string') func = eval(func);
	else if (typeof(func) != 'function') return false;
	try { func(); return true; }
	catch(e) { func; return true; }
	return false;
}

var echo = function(str) {
	document.write(str);
}

var inArray = function(myValue, myArray) {
	if (isWhat(myArray) != 'object') return false;
    for (var k in myArray) { if (myArray[k] == myValue) return true; }
    return false;
};

var isSet = function(myVar) {
	if (typeof(myVar) == 'undefined' || myVar === '' || myVar === null) return false;
	else return true;
};

var isId = function(element) {
	if (!isSet(element)) return false;
	try { 
		if ($(element)) return true;
		else return false;
	}
   	catch(e) { return false; }
};

// ------------------------- Type of ---------------------------------- //
var isWhat = function(myVar) {
	if (!isSet(myVar)) return '';
	else return typeof myVar; // number | string | object | boolean | function
};
Object.extend(Element, {
	setWidth: function(element,w) {
	   	element = $(element);
    	element.style.width = w +"px";
	},
	setHeight: function(element,h) {
   		element = $(element);
    	element.style.height = h +"px";
	},
	setTop: function(element,t) {
	   	element = $(element);
    	element.style.top = t +"px";
	},
	setLeft: function(element,l) {
	   	element = $(element);
    	element.style.left = l +"px";
	},
	getTop: function(element) {
	   	element = $(element);
    	return element.style.top;
	},
	getLeft: function(element) {
	   	element = $(element);
    	return element.style.left;
	},
	setSrc: function(element,src) {
    	element = $(element);
    	element.src = src; 
	},
	setHref: function(element,href) {
    	element = $(element);
    	element.href = href; 
	},
	setInnerHTML: function(element,content) {
		element = $(element);
		element.innerHTML = content;
	}
});

Array.prototype.removeDuplicates = function () {
	for (i = 1; i < this.length; i++) {
		if (this[i][0] == this[i-1][0]) this.splice(i,1);
	}
}

Array.prototype.empty = function () {
	for(i = 0; i <= this.length; i++) this.shift();
}

Element.BlockLevel = ["address", "blockquote", "center", "dl", "dir", "div", "fieldset", "form", "h1-6", "hr", "isindex", "menu", "noframes", "noscript", "ol", "p", "pre", "table", "ul", "center", "dir", "menu", "noframes", "isindex"];

Element.isBlockLevel = function(element) {
    return element.isBlockLevel = (Element.getStyle(element, "display") == "block" || element.isBlockLevel == true || Element.BlockLevel.indexOf(element.nodeName.toLowerCase()) !=- 1);
};

Element.show = function() {
    for (var i = 0; i < arguments.length; i ++ ) {
        var element = $(arguments[i]);
        element.style.display = Element.isBlockLevel(element) ? "block": "";
    }
};

Element.getDimensions = function(element) {
    element = $(element);
    var display = $(element).getStyle('display');
	if (display != 'none' && display != null)
		return {
		width: element.offsetWidth,
		height: element.offsetHeight
	};
    var els = element.style;
    var originalVisibility = els.visibility;
    var originalPosition = els.position;
    els.visibility = "hidden";
    els.position = "absolute";
    els.display = Element.isBlockLevel(element) ? "block": "";
    var originalWidth = element.clientWidth;
    var originalHeight = element.clientHeight;
    els.display = "none";
    els.position = originalPosition;
    els.visibility = originalVisibility;
    return {
        width: originalWidth,
        height: originalHeight
    };
};

Effect.Center = function(element) { // TO check
    try { element = $(element); }
    catch(e) { return; }

	var arraySize = getPageSize();
    var arrayScroll = getPageScroll();

	var my_width  = arraySize[2];
	var my_height = arraySize[3];
	var scrollY = arrayScroll[1];
	
	element.style.position = 'absolute';
	element.style.display  = 'block';
	element.style.zIndex   = 99;
	
	var elementDimensions = Element.getDimensions(element);
	
	var offsetX = ( my_width  - elementDimensions.width  ) / 2;
	var offsetY = ( my_height - elementDimensions.height ) / 2 + scrollY;
	
	offsetX = ( offsetX < 0 ) ? 0 : offsetX;
	offsetY = ( offsetY < 0 ) ? 0 : offsetY;
	
	Element.setTop(element, offsetY);
	Element.setLeft(element, offsetX);
}

Effect.divSwap = function(element,container) {
	var div = document.getElementById(container);
	var nodeList = div.childNodes;
	var queue = Effect.Queues.get('menuScope');
	
	if (queue.toArray().length<1) {
		if (Element.visible(element)==false) {
			for (i=0;i<nodeList.length;i++) {
				if (nodeList.item(i).nodeName == "DIV" && nodeList.item(i).id != element) {
					if (Element.visible(nodeList.item(i))==true) {
						Effect.SlideUp(nodeList.item(i),{queue:{position:'end',scope:'menuScope',limit:2}})
					}
				}
			}
			Effect.SlideDown(element,{queue:{position:'end',scope:'menuScope',limit:2}})
		}
	}
}

Effect.ScrollFromLeft = function(element) {
	Zelement = $(element);
	Element.cleanWhitespace(Zelement);
	var elementDimensions = Element.getDimensions(element);
	
	var PelementDimensions = Element.getDimensions($(element).parentNode); // Parent
	var centerY = (PelementDimensions.width - elementDimensions.width) / 2;
	
	var exLeft = parseInt(elementDimensions.width) ;
	var newLeft = exLeft * -1 + centerY;
	Element.setStyle(Zelement, {left: newLeft+'px' });
	
	return new Effect.MoveBy(element, 0, exLeft,
	Object.extend({ 
	restoreAfterFinish: true,
	beforeStartInternal: function(effect) { with(Element) {
		makePositioned(effect.element);
		makeClipping(effect.element);
		show(element); }}, 
	afterFinishInternal: function(effect) { with(Element) {
	   [undoClipping].call(effect.element);
		undoPositioned(effect.element.firstChild);
		undoPositioned(effect.element);
		/*setStyle(effect.Zelement, {left: 0});*/ }}
	}, arguments[1] || {})
	);
}

Effect.ScrollToRight = function(element) {
  Zelement = $(element);
  Element.cleanWhitespace(Zelement);
  var newRight = parseInt(Zelement.up().getStyle('width'));
  return new Effect.MoveBy(element, 0, newRight,
   Object.extend({ 
    restoreAfterFinish: true,
    beforeStartInternal: function(effect) { with(Element) {
		makePositioned(effect.element);
		makeClipping(effect.element);
		show(Zelement); }}, 
    afterFinishInternal: function(effect) { with(Element) {
       [hide, undoClipping].call(effect.element);
        undoPositioned(effect.element.firstChild);
        undoPositioned(effect.element);
        /*setStyle(effect.element, {left: 0}); */}}
   }, arguments[1] || {})
  );
}
Effect.SlideRight = function(element) {
	element = $(element);
	Element.cleanWhitespace(element);
	// SlideDown need to have the content of the element wrapped in a container element with fixed height!
	var oldInnerRight = Element.getStyle(element.firstChild, 'right');
	var elementDimensions = Element.getDimensions(element);
	return new Effect.Scale(element, 100, Object.extend({ 
		scaleContent: false,
		scaleY: false, 
		scaleFrom: 0,
		scaleMode: {originalHeight: elementDimensions.height, originalWidth: elementDimensions.width},
		restoreAfterFinish: true,
		afterSetup: function(effect) { with(Element) {
			makePositioned(effect.element);
			makePositioned(effect.element.firstChild);
			if(window.opera) setStyle(effect.element, {top: ''});
			makeClipping(effect.element);
			setStyle(effect.element, {width: '0px'});
			show(element); }},
		afterUpdateInternal: function(effect) { with(Element) {
			setStyle(effect.element.firstChild, {right: (effect.dims[0] - effect.element.clientWidth) + 'px' }); }},
		afterFinishInternal: function(effect) { with(Element) {
			undoClipping(effect.element); 
			undoPositioned(effect.element.firstChild);
			undoPositioned(effect.element);
			setStyle(effect.element.firstChild, {right: oldInnerRight}); }}
		}, arguments[1] || {})
  );
}
Effect.SlideLeft = function(element) {
  element = $(element);
  Element.cleanWhitespace(element);
  var oldInnerRight = Element.getStyle(element.firstChild, 'right');
  return new Effect.Scale(element, 0, 
   Object.extend({ scaleContent: false, 
    scaleY: false, 
    scaleMode: 'box',
    scaleFrom: 100,
    restoreAfterFinish: true,
    beforeStartInternal: function(effect) { with(Element) {
      makePositioned(effect.element);
      makePositioned(effect.element.firstChild);
      if(window.opera) setStyle(effect.element, {top: ''});
      makeClipping(effect.element);
      show(element); }},  
    afterUpdateInternal: function(effect) { with(Element) {
      setStyle(effect.element.firstChild, {right:
        (effect.dims[0] - effect.element.clientWidth) + 'px' }); }},
    afterFinishInternal: function(effect) { with(Element) {
        [hide, undoClipping].call(effect.element); 
        undoPositioned(effect.element.firstChild);
        undoPositioned(effect.element);
        setStyle(effect.element.firstChild, {right: oldInnerRight}); }}
   }, arguments[1] || {})
  );
}

var diaporama = Class.create();
diaporama.prototype = { // EN COURS D'EVOLUTION... N'EST PAS FINI !!!! // CHECK IF NO CONTROL !!

	initialize: function(arrImage) {
		
		// Arguments
		var options = Object.extend({arrImage:arrImage}, arguments[1] || {});

		// Whitch conteneur
		if (isId(options.div)) this.boxElement = options.div;
		else if (isSet(startDivBox) && typeof startDivBox == 'function') {
			startOverlay();
			
			this.boxElement = 'dyn_overlay';
			new Effect.Opacity(this.boxElement,100);
			Element.setStyle(this.boxElement, {border:'none', background:'none', textAlign:'center'});
		}
		else return printInfo('diaporama() : Pas de div containeur');

		// Sequence images
		this.arrImage = options.arrImage;
		this.currentImg = 0;
		this.totImg = 0;
		for (var att in this.arrImage) this.totImg++; // this.arrImage.length; // Not work ?
		if (this.totImg < 1) return printInfo('diaporama() : aucune image d&eacute;tect&eacute;e');

		// Params utilisateur
		this.control = (options.control == true ? true : false); // Bouttons actions ?
		this.printInfo = (options.printInfo == true ? true : false); // Afficher les actions des controls
		this.globalTempo = options.tempo ? options.tempo : 6; // 6 secondes par defaut
		this.transition = options.transition ? options.transition : this.globalTempo/10; // 0.6 seconde par defaut
		this.marge = options.marge ? options.tempo : 6;
		this.imgStyle = options.imgStyle ? ' style="'+options.imgStyle+'"' : '';
		this.imgStyle += options.imgClass ? ' class="'+options.imgClass+'"' : '';
		this.lienStyle = options.lienStyle ? ' style="'+options.lienStyle+'"' : '';
		this.lienStyle += options.lienClass ? ' class="'+options.lienClass+'"' : '';
		this.effect = options.effect ? options.effect : 'scroll';
	
		if (this.effect == 'slide') this.effect = 'scroll'; // hack ftk
		// Params interne
		var allowEffect = $w('appear slide scroll blind');
		if (!inArray(this.effect, allowEffect)) this.effect = 'appear';

		this.tempo = this.globalTempo; // Current Tempo 
		this.objetTimeOut = null; // Stock timeOut event
		
		$(this.boxElement).makePositioned();
		$(this.boxElement).makeClipping();
		
		this.boxHeight = parseInt(Element.getHeight(this.boxElement));
		this.boxWidth = parseInt(Element.getWidth(this.boxElement));

		this.ctrHeight = 0; // Not yet
		this.imgBoxHeight = 0; // Not yet

		this.imgBoxId = 'diaporamaBoxImage';
		this.imgBoxIdEffect = 'diaporamaBoxImageEffect';
		this.imgId = 'diaporamaImage';
		this.ctrBoxId = 'diaporamaControler';
		
		// Html Templates
		this.divConteneurImg = '<div id="'+this.imgBoxId+'" style="display:none;position:relative;display:block;overflow:hidden;texte-align:center;"><div id="'+this.imgBoxIdEffect+'" style="position:relative;display:block;margin-top:0px"></div></div>';
		this.lienOpenTpl = new Template('<a href="#{lien}" '+this.lienStyle+' onFocus="this.blur();" >'); // target="_blank"
		this.imgTpl = new Template('<img id="'+this.imgId+'" alt="#{alt}" src="#{src}" width="#{width}" height="#{height}" #{title} border="0" '+this.imgStyle+' />');
		this.lienClose = '<a/>';
		this.divControler = '<div id="'+this.ctrBoxId+'" style="position:relative;display:block;margin-top:'+this.marge+'px;">&nbsp;</div>';
		
		// Images bouttons control
		this.imgBack = 'images/ico_js/back.gif';
		this.imgPause = 'images/ico_js/pause.gif';
		this.imgPlay = 'images/ico_js/play.gif';
		this.imgNext = 'images/ico_js/next.gif';
		this.imgTempo = 'images/ico_js/tempo.gif';
		
		// Let's go
		this._makeContainer();
		this._setImgSrc();
	},

	setTempo: function(tempo) {
		tempo = parseInt(tempo);
		if (this.tempo < 2 || this.tempo > 99999) this.tempo = this.globalTempo;
		else this.tempo = tempo;
		this.suivante();
	},
	
	lecture: function() {
		this._stopTime();
		this._makeTimed();
		if (this.control) {
			Element.hide('lecture');
			Element.show('pause');
		}
		if (this.printInfo) printInfo('Lecture');
	},
	
	pause: function() {
		this._stopTime();
		if (this.control) {
			Element.hide('pause');
			Element.show('lecture');
		}
		if (this.printInfo) printInfo('Pause');
	},
	
	suivante: function() {
		this._stopTime();
		if (!isSet(this.currentImg) || this.currentImg >= (this.totImg-1)) this.currentImg = 0;
		else this.currentImg++;
		if (this.control) {
			Element.hide('lecture');
			Element.show('pause');
		}
		this._unloadImage();
		if (this.printInfo) printInfo('Suivante');
	},
	
	precedante: function() {
		this._stopTime();
		if (!isSet(this.currentImg) || this.currentImg < 1) this.currentImg = this.totImg - 1;
		else this.currentImg--;
		if (this.control) {
			Element.hide('lecture');
			Element.show('pause');
		}
		this._unloadImage();
		if (this.printInfo) printInfo('Pr�cedante');
	},

	_makeContainer: function() {
		
		$(this.boxElement).update(this.divConteneurImg);

		if (this.control) { // To finish :)

			new Insertion.Bottom(this.boxElement, this.divControler); // After ?
			
			// Make control images
			var controler = '<img src="'+this.imgBack+'" border="0" title="Pr�c�dante" id="precedante" style="cursor:pointer;">';
			controler += ' <img src="'+this.imgPause+'" border="0" title="Pause" id="pause" style="cursor:pointer;">';
			controler += ' <img src="'+this.imgPlay+'" border="0" title="Lecture" id="lecture" style="cursor:pointer; display:none;">';
			controler += ' <img src="'+this.imgNext+'" border="0" title="Suivante" id="suivante" style="cursor:pointer;">';
			
			$(this.ctrBoxId).hide();
			$(this.ctrBoxId).update(controler);
			Effect.Appear(this.ctrBoxId, {duration : 0.2} ); // (this.tempo/2)
			
			Event.observe('precedante', 'click', this.precedante.bindAsEventListener(this));
			Event.observe('pause', 'click', this.pause.bindAsEventListener(this));
			Event.observe('lecture', 'click', this.lecture.bindAsEventListener(this));
			Event.observe('suivante', 'click', this.suivante.bindAsEventListener(this));

			// Fill box height
			this.ctrHeight = parseInt(Element.getHeight(this.ctrBoxId)) + (this.marge * 2); 
			this.imgBoxHeight = this.boxHeight - this.ctrHeight;
		}
		else this.imgBoxHeight = this.boxHeight;
		
		Element.setStyle(this.imgBoxId, {height:this.imgBoxHeight+'px'});
	},
	
	_makeImg: function() {
		this._centerDivImg(imgPreloader.width, imgPreloader.height);
		
		$(this.imgBoxIdEffect).hide();
		
		var myHtml = '';
		var imgInfoArr = {};
		var lienInfoArr = {};
   
		if (isSet(this.arrImage[this.currentImg]['lien'])) {
			lienInfoArr['lien'] = this.arrImage[this.currentImg]['lien'];
			myHtml += this.lienOpenTpl.evaluate(lienInfoArr);
		}
	
		imgInfoArr['src'] = this.arrImage[this.currentImg]['img'];
		imgInfoArr['alt'] = baseName(imgInfoArr['src']);
		imgInfoArr['width'] = imgPreloader.width;
		imgInfoArr['height'] = imgPreloader.height;
		
		if (isSet(this.arrImage[this.currentImg]['titre']))
			imgInfoArr['title'] = ' title="'+this.arrImage[this.currentImg]['titre']+'"';
		else if (isSet(this.arrImage[this.currentImg]['lien']))
			imgInfoArr['title'] = ' title="'+this.arrImage[this.currentImg]['lien']+'"';
		
		myHtml += this.imgTpl.evaluate(imgInfoArr);
	 
		$(this.imgBoxIdEffect).update(myHtml);

		switch(this.effect) {
			case 'slide' : Effect.SlideDown(this.imgBoxIdEffect, {duration : this.transition, afterFinish: this._makeTimed.bind(this) }); break;
			case 'scroll' : Effect.ScrollFromLeft(this.imgBoxIdEffect, {duration : this.transition, afterFinish: this._makeTimed.bind(this) }); break;
			case 'blind' : Effect.BlindDown(this.imgBoxIdEffect, {duration : this.transition, afterFinish: this._makeTimed.bind(this) }); break;
			default : Effect.Appear(this.imgBoxIdEffect, {duration : this.transition, afterFinish: this._makeTimed.bind(this) });
		}
		
		if (!this.control) { // Fly over auto-pause
			Event.observe(this.imgId, 'mouseover', this.pause.bindAsEventListener(this));
			Event.observe(this.imgId, 'mouseout', this.lecture.bindAsEventListener(this));
			Event.observe(this.imgId, 'click', this.pause.bindAsEventListener(this));
		}
	},
	
	_centerDivImg: function(imgWidth, imgHeight) {
		var divImgPadTop = (this.imgBoxHeight - imgHeight) / 2;
		var divImgPadLeft = (this.boxWidth - imgWidth) / 2;
		Element.setStyle(this.imgBoxIdEffect, {left:divImgPadLeft, marginTop:divImgPadTop+'px'});
	},
	
	_stopTime: function() {
		if (this.objetTimeOut) this.objetTimeOut.stop();
	},
	
	_unloadImage: function() {
		this._stopTime();

		if (isId(this.imgId)) {
			switch(this.effect) {
				case 'slide' : Effect.SlideUp(this.imgBoxIdEffect, {duration : (this.transition/2), afterFinish: this._setImgSrc.bind(this) } ); break;
				case 'scroll' : Effect.ScrollToRight(this.imgBoxIdEffect, {duration : (this.transition/2), afterFinish: this._setImgSrc.bind(this) } ); break;
				case 'blind' : Effect.BlindUp(this.imgBoxIdEffect, {duration : (this.transition/2), afterFinish: this._setImgSrc.bind(this) } ); break;
				default : Effect.Fade(this.imgBoxIdEffect, {duration : (this.transition/2), afterFinish: this._setImgSrc.bind(this) } ); break;
			}
		}
		else this._setImgSrc();
	},

	_setImgSrc: function() {
		imgPreloader = new Image();
		imgPreloader.onload = this._makeImg.bindAsEventListener(this);
		imgPreloader.src = this.arrImage[this.currentImg]['img'];
	},
	
	_makeTimed: function() {
		this.objetTimeOut = new PeriodicalExecuter(this.suivante.bind(this), this.tempo);
		this._preloadImage();
	},
	
	_preloadImage: function() {
		var nextImg;
		if (!isSet(this.currentImg) || this.currentImg >= (this.totImg-1)) nextImg = 0;
		else nextImg = this.currentImg + 1;
		loadImg(this.arrImage[nextImg]['img']);
	}
}

var horloge = Class.create();
horloge.prototype = {

	initialize: function(boxElement, arrParam) {
		try { this.boxElement = $(boxElement); }
		catch(e) { return false; }

		this.objetTimeOut = null; // Stock timeOut event
		
		this.affichage = arrParam.affichage ? arrParam.affichage : 'chiffre'; // chiffre || image
		this.timeFormat = arrParam.timeFormat ? arrParam.timeFormat : ''; // 'locale' || 'gtmdiff' || 'gtm'
		this.dateStyle = arrParam.dateStyle ? arrParam.dateStyle : 'font: bold 14px Arial, Helvetica, sans-serif;'; // Style de la date
		this.heureStyle = arrParam.heureStyle ? arrParam.heureStyle : 'font: 10px Arial, Helvetica, sans-serif;'; // Style si chiffre
		this.imgStyle = arrParam.imgStyle ? 'style="'+arrParam.imgStyle+'"' : ''; // Style si chiffre
		this.printDate = arrParam.printDate ? arrParam.printDate : false; // chiffre || image
		
		this.imgPath = arrParam.imgPath ? arrParam.imgPath : '';
		this.imgExt = arrParam.imgExt ? arrParam.imgExt : '';
		if (this.imgPath == '' && this.affichage == 'image') return printInfo(js_msg_09+' : imgPath')
		if (this.imgExt == '' && this.affichage == 'image') return printInfo(js_msg_10+' : imgExt')

		this.dateTpl = new Template('<div style="'+this.dateStyle+'" id="date_'+boxElement+'">#{d}/#{m}/#{y}</div>');
		
		switch(this.affichage) {
			case 'image' :
				this.tempsTpl = new Template('<img src="'+this.imgPath+'#{imgNumber}.'+this.imgExt+'" border="0" id="#{imgId}" '+this.imgStyle+'/>');
				// Preload image
				for (var i=0; i < 10; i++) loadImg(this.imgPath+i+'.'+this.imgExt);
			break;
			default :
				this.tempsTpl = new Template('<div style="'+this.heureStyle+';" id="heure_'+boxElement+'">#{imgNumber}</div>');
			break;
		}

		this.makeTime();
		this.setTimed();
	},
	
	setTimed: function() {
		this.objetTimeOut = new PeriodicalExecuter(this.makeTime.bind(this), 1);
	},
	
	makeTime: function() {
		
		var Stamp = new Date();
		
		switch(this.timeFormat) {
			case 'locale' : Stamp.toLocaleString(); break;
			case 'gtmdiff' : Stamp.getTimezoneOffset(); break;
			case 'gtm' : Stamp.toGMTString(); break;
		}
		
		var myHtml = '';
		
		if (this.printDate) { // DATE
			var y = Stamp.getFullYear();
			var m = (Stamp.getMonth() + 1).toPaddedString(2);
			var d = Stamp.getDate();
			
			var dateArr = { d: d, m: m, y: y };
			myHtml += this.dateTpl.evaluate(dateArr);
		}
		
		// TEMPS
		var he = Stamp.getHours().toPaddedString(2);
		var mi = Stamp.getMinutes().toPaddedString(2);
		var se = Stamp.getSeconds().toPaddedString(2);
		
		if (!$('he0')) { // Create image sequence
			
			// heures
			var he0 = { imgPath: this.imgPath, imgExt: this.imgExt, imgId:'he0', imgNumber: he.charAt(0) };
			myHtml += this.tempsTpl.evaluate(he0);
			var he1 = { imgPath: this.imgPath, imgExt: this.imgExt, imgId:'he1', imgNumber: he.charAt(1) };
			myHtml += this.tempsTpl.evaluate(he1);
			
			var hh = { imgPath: this.imgPath, imgExt: this.imgExt, imgId:'h', imgNumber: 'h' };
			myHtml += this.tempsTpl.evaluate(hh);
			
			// minutes
			var mi0 = { imgPath: this.imgPath, imgExt: this.imgExt, imgId:'mi0', imgNumber: mi.charAt(0) };
			myHtml += this.tempsTpl.evaluate(mi0);
			var mi1 = { imgPath: this.imgPath, imgExt: this.imgExt, imgId:'mi1', imgNumber: mi.charAt(1) };
			myHtml += this.tempsTpl.evaluate(mi1);
			
			var mm = { imgPath: this.imgPath, imgExt: this.imgExt, imgId:'m', imgNumber: 'm' };
			myHtml += this.tempsTpl.evaluate(mm);
			
			// secondes
			var se0 = { imgPath: this.imgPath, imgExt: this.imgExt, imgId:'se0', imgNumber: 's'+se.toString().charAt(0) }; // Cas particulier image Sec. plus petite "s1.png"
			myHtml += this.tempsTpl.evaluate(se0);
			var se1 = { imgPath: this.imgPath, imgExt: this.imgExt, imgId:'se1', imgNumber: 's'+se.toString().charAt(1) };
			myHtml += this.tempsTpl.evaluate(se1);
			
			var ss = { imgPath: this.imgPath, imgExt: this.imgExt, imgId:'s', imgNumber: 's' };
			myHtml += this.tempsTpl.evaluate(ss);
			
			$('horlogeBox').update(myHtml);	

		}
		else { // update only if change
			if ($('he0').src != this.imgPath+he.charAt(0)+'.'+this.imgExt ) $('he0').src = this.imgPath+he.charAt(0)+'.'+this.imgExt;
			if ($('he1').src != this.imgPath+he.charAt(1)+'.'+this.imgExt ) $('he1').src = this.imgPath+he.charAt(1)+'.'+this.imgExt;
			
			if ($('mi0').src != this.imgPath+mi.charAt(0)+'.'+this.imgExt ) $('mi0').src = this.imgPath+mi.charAt(0)+'.'+this.imgExt;
			if ($('mi1').src != this.imgPath+mi.charAt(1)+'.'+this.imgExt ) $('mi1').src = this.imgPath+mi.charAt(1)+'.'+this.imgExt;
			
			if ($('se0').src != this.imgPath+se.charAt(0)+'.'+this.imgExt ) $('se0').src = this.imgPath+'s'+se.charAt(0)+'.'+this.imgExt;
			if ($('se1').src != this.imgPath+se.charAt(1)+'.'+this.imgExt ) $('se1').src = this.imgPath+'s'+se.charAt(1)+'.'+this.imgExt;
		}
	}
}

/**
 * Fonction pour la pagination
 * @param int po Page offset
 */
function jump(po) {
	document.getElementById('frm_jump').action = document.getElementById('frm_jump').action+'offset='+po;
	document.getElementById('frm_jump').submit();
}

function rss(etat,id){
	if(etat=='over'){
		$('infos_rss_'+id).style.display = 'block';
	}else{
		$('infos_rss_'+id).style.display = 'none';
	}
}


/* MISE A JOUR AL 19/03/2008 */
// ROLLOVER INPUT IMAGE + IMAGE
Event.observe(window, 'load', function(evt){
	var input = $$('img.rollover');
	input.each( function(e,index){
		var chemin = input[index].src;
		var pos_debut = chemin.lastIndexOf('/')+1;
		var pos_fin = chemin.lastIndexOf('.');
		var chemin_fichier = chemin.substring(0,pos_debut);
		var nom_fichier = chemin.substring(pos_debut,pos_fin);
		var ext_fichier = chemin.substr(pos_fin);
		Event.observe(e, 'mouseover', function(evt){
			e.src = chemin_fichier+nom_fichier+'_on'+ext_fichier;
		});			 
		Event.observe(e, 'mouseout', function(evt){
			e.src = chemin_fichier+nom_fichier+ext_fichier;
		});			 
	});
});
// ENVOI AMI
var ajoutDestinataire = function(){
	if($('liste_destinataire').style.display=='none'){
		$('liste_destinataire').style.display='block';
		$('ajout_destinataire').addClassName("supprimer");
		$('ajout_destinataire').blur();
	}else{
		$('liste_destinataire').style.display='none';
		$('ajout_destinataire').removeClassName("supprimer");
		$('ajout_destinataire').blur();
	}
}
var initEnvoiAmi = function(){
	$('envoi_ami').style.display='none';
	var boutons = new Array('bt_envoyer_ami','bt_fermer_ami');
	// ACTIONS
	boutons.each( 
		function(e,index){
			Event.observe(boutons[index],'click',function(){
				$(boutons[index]).blur();
				if($('envoi_ami').style.display=='none'){
					new Effect.BlindDown('envoi_ami',{duration:0.3,afterFinish:
						function(){
							new Effect.ScrollTo('envoi_ami',{duration:0.7});
						}
					});
				}else{
					new Effect.BlindUp('envoi_ami',{duration:0.3,afterFinish:
						function(){
							new Effect.ScrollTo('bandeau',{duration:0.7});
						}
					});
					//$('confirm_ami').style.display = 'none';
					//$('erreur_ami').style.display = 'none';					
				}
			});
		}
	);
}
Event.observe(window, 'load', function(evt){
	if(isId("envoi_ami")){
		initEnvoiAmi();							   
	}
});


// AVIS
var initAvis = function(){
	$('depot_avis').style.display='none';
	var boutons = new Array('bt_donner_avis','bt_fermer_avis');
	// ACTIONS
	boutons.each( 
		function(e,index){
			Event.observe(boutons[index],'click',function(){
				if($('depot_avis').style.display=='none'){
					new Effect.BlindDown('depot_avis',{duration:0.3,afterFinish:
						function(){
							new Effect.ScrollTo('depot_avis',{duration:0.7});
						}
					});
				}else{
					new Effect.BlindUp('depot_avis',{duration:0.3,afterFinish:
						function(){
							new Effect.ScrollTo('bandeau',{duration:0.7});
						}
					});
					//$('confirm_ami').style.display = 'none';
					//$('erreur_ami').style.display = 'none';					
				}
			});
		}
	);
}
Event.observe(window, 'load', function(evt){
	if(isId("depot_avis")){
		initAvis();							   
	}
});

Event.observe(window, 'load', function() {
  if($$('.localize')[0]) {
    var geocoder = new GClientGeocoder();
    var searchString = $F('adresse') + ', ' + $F('ville') + ', ' + $F('pays');
    
    if( geocoder ) {
      geocoder.getLatLng(searchString, function( point ) {
        if(point) {
          $('coords').setAttribute('value', point.lng() + ';' + point.lat());
        }
      });
    }
  }
});

var townClicked = false;
Event.observe(window, 'load', function() {
	$$('#town-search, #ville-tools, #keyword-id').each(function(item){
		Event.observe(item, 'click', function(event) {
			Event.element(event).value = "";
		});
	});
});


