/*********************************************************************************************************
 * @file : extends.js*************************************************************************************
 * @autor : romain lenzotti ******************************************************************************
 * @date : 24/07/2009*************************************************************************************
 * @version : 0.7*****************************************************************************************
 *********************************************************************************************************/
/*** v0.7: 	- Suppression de l'extension de classe Image et creationd la classe Picture afin d'etre 
				compatible avec Opera
			- nouvelle classe Timer pour la gestion d'evenement répété
**********************************************************************************************************/
/*** v0.6: 	- correction classe Image.resize()
			- support IE pour l'event oncomplete dans la classe Image
**********************************************************************************************************/
/*** v0.5: 	- Ajout de l'extension de la classe Image
			- Ajout de méthode à la classe String
**********************************************************************************************************/
 
 
//Variables générales-------------------------------------------------------------------------------------
var $_GET = [];
//--------------------------------------------------------------------------------------------------------
//Extension Classe String---------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------


Object.extend(String.prototype, (function(){
	/**
	 * @brief : transformation du string en date si possible
	 */
	function toDate(){
		var date = new Date();
		var string = this.split(' ');
		
		if(string.length >1){
			var h = string[1].split(':');
			date.setHours(h[0],h[1],h[2]);
			
		}
	
		string = string[0];
	
		if(string.substr(4,1) == "-") {
			
			string = string.split('-');
			
	
			date.setFullYear(string[0]);
			date.setMonth(new Number(string[1]) -1);
			date.setDate(string[2]);
		}
		else {
		
			string = string.split('/');
			
	
			date.setFullYear(string[2]);
			date.setMonth(new Number(string[1]) -1);
			date.setDate(string[0]);
		}
	
		return date;	
	}
	/**
	 * @brief : encode les caractères en équivalent HTML
	 * @param[out] : string encode au format HTML
	 */
	function htmlEntities(){
		function convert(char){
			var htmlentities = {' ':'nbsp','¡':'iexcl','¢':'cent','£':'pound','¤':'curren','¥':'yen','¦':'brvbar','§':'sect','¨':'uml','©':'copy','ª':'ordf','«':'laquo','¬':'not','­':'shy','®':'reg','¯':'macr','°':'deg','±':'plusmn','²':'sup2','³':'sup3','´':'acute','µ':'micro','¶':'para','·':'middot','¸':'cedil','¹':'sup1','º':'ordm','»':'raquo','¼':'frac14','½':'frac12','¾':'frac34','¿':'iquest','×':'times','÷':'divide','ƒ':'fnof','•':'bull','…':'hellip','′':'prime','″':'Prime','‾':'oline','⁄':'frasl','℘':'weierp','ℑ':'image','ℜ':'real','™':'trade','ℵ':'alefsym','←':'larr','↑':'uarr','→':'rarr','↓':'darr','↔':'harr','↵':'crarr','⇐':'lArr','⇑':'uArr','⇒':'rArr','⇓':'dArr','⇔':'hArr','∀':'forall','∂':'part','∃':'exist','∅':'empty','∇':'nabla','∈':'isin','∉':'notin','∋':'ni','∏':'prod','∑':'sum','−':'minus','∗':'lowast','√':'radic','∝':'prop','∞':'infin','∠':'ang','∧':'and','∨':'or','∩':'cap','∪':'cup','∫':'int','∴':'there4','∼':'sim','≅':'cong','≈':'asymp','≠':'ne','≡':'equiv','≤':'le','≥':'ge','⊂':'sub','⊃':'sup','⊄':'nsub','⊆':'sube','⊇':'supe','⊕':'oplus','⊗':'otimes','⊥':'perp','⋅':'sdot','\u2308':'lceil','\u2309':'rceil','\u230a':'lfloor','\u230b':'rfloor','\u2329':'lang','\u232a':'rang','◊':'loz','♠':'spades','♣':'clubs','♥':'hearts','♦':'diams','"':'quot','>':'gt','ˆ':'circ','˜':'tilde',' ':'ensp',' ':'emsp',' ':'thinsp','‌':'zwnj','‍':'zwj','‎':'lrm','‏':'rlm','–':'ndash','—':'mdash','‘':'lsquo','’':'rsquo','‚':'sbquo','“':'ldquo','”':'rdquo','„':'bdquo','†':'dagger','‡':'Dagger','‰':'permil','‹':'lsaquo','›':'rsaquo','€':'euro',' ':'nbsp','¡':'iexcl','¢':'cent','£':'pound','¤':'curren','¥':'yen','¦':'brvbar','§':'sect','¨':'uml','©':'copy','ª':'ordf','«':'laquo','¬':'not','­':'shy','®':'reg','¯':'macr','°':'deg','±':'plusmn','²':'sup2','³':'sup3','´':'acute','µ':'micro','¶':'para','·':'middot','¸':'cedil','¹':'sup1','º':'ordm','»':'raquo','¼':'frac14','½':'frac12','¾':'frac34','¿':'iquest','×':'times','÷':'divide','ƒ':'fnof','•':'bull','…':'hellip','′':'prime','″':'Prime','‾':'oline','⁄':'frasl','℘':'weierp','ℑ':'image','ℜ':'real','™':'trade','ℵ':'alefsym','←':'larr','↑':'uarr','→':'rarr','↓':'darr','↔':'harr','↵':'crarr','⇐':'lArr','⇑':'uArr','⇒':'rArr','⇓':'dArr','⇔':'hArr','∀':'forall','∂':'part','∃':'exist','∅':'empty','∇':'nabla','∈':'isin','∉':'notin','∋':'ni','∏':'prod','∑':'sum','−':'minus','∗':'lowast','√':'radic','∝':'prop','∞':'infin','∠':'ang','∧':'and','∨':'or','∩':'cap','∪':'cup','∫':'int','∴':'there4','∼':'sim','≅':'cong','≈':'asymp','≠':'ne','≡':'equiv','≤':'le','≥':'ge','⊂':'sub','⊃':'sup','⊄':'nsub','⊆':'sube','⊇':'supe','⊕':'oplus','⊗':'otimes','⊥':'perp','⋅':'sdot','\u2308':'lceil','\u2309':'rceil','\u230a':'lfloor','\u230b':'rfloor','\u2329':'lang','\u232a':'rang','◊':'loz','♠':'spades','♣':'clubs','♥':'hearts','♦':'diams','"':'quot','>':'gt','ˆ':'circ','˜':'tilde',' ':'ensp',' ':'emsp',' ':'thinsp','‌':'zwnj','‍':'zwj','‎':'lrm','‏':'rlm','–':'ndash','—':'mdash','‘':'lsquo','’':'rsquo','‚':'sbquo','“':'ldquo','”':'rdquo','„':'bdquo','†':'dagger','‡':'Dagger','‰':'permil','‹':'lsaquo','›':'rsaquo','€':'euro', 'À':'Agrave','Á':'Aacute','Â':'Acirc','Ã':'Atilde','Ä':'Auml','Å':'Aring','Æ':'AElig','Ç':'Ccedil','È':'Egrave','É':'Eacute','Ê':'Ecirc','Ë':'Euml','Ì':'Igrave','Í':'Iacute','Î':'Icirc','Ï':'Iuml','Ð':'ETH','Ñ':'Ntilde','Ò':'Ograve','Ó':'Oacute','Ô':'Ocirc','Õ':'Otilde','Ö':'Ouml','Ø':'Oslash','Ù':'Ugrave','Ú':'Uacute','Û':'Ucirc','Ü':'Uuml','Ý':'Yacute','Þ':'THORN','ß':'szlig','à':'agrave','á':'aacute','â':'acirc','ã':'atilde','ä':'auml','å':'aring','æ':'aelig','ç':'ccedil','è':'egrave','é':'eacute','ê':'ecirc','ë':'euml','ì':'igrave','í':'iacute','î':'icirc','ï':'iuml','ð':'eth','ñ':'ntilde','ò':'ograve','ó':'oacute','ô':'ocirc','õ':'otilde','ö':'ouml','ø':'oslash','ù':'ugrave','ú':'uacute','û':'ucirc','ü':'uuml','ý':'yacute','þ':'thorn','ÿ':'yuml','Œ':'OElig','œ':'oelig','Š':'Scaron','š':'scaron','Ÿ':'Yuml', 'Α':'Alpha','Β':'Beta','Γ':'Gamma','Δ':'Delta','Ε':'Epsilon','Ζ':'Zeta','Η':'Eta','Θ':'Theta','Ι':'Iota','Κ':'Kappa','Λ':'Lambda','Μ':'Mu','Ν':'Nu','Ξ':'Xi','Ο':'Omicron','Π':'Pi','Ρ':'Rho','Σ':'Sigma','Τ':'Tau','Υ':'Upsilon','Φ':'Phi','Χ':'Chi','Ψ':'Psi','Ω':'Omega','α':'alpha','β':'beta','γ':'gamma','δ':'delta','ε':'epsilon','ζ':'zeta','η':'eta','θ':'theta','ι':'iota','κ':'kappa','λ':'lambda','μ':'mu','ν':'nu','ξ':'xi','ο':'omicron','π':'pi','ρ':'rho','ς':'sigmaf','σ':'sigma','τ':'tau','υ':'upsilon','φ':'phi','χ':'chi','ψ':'psi','ω':'omega','\u03d1':'thetasym','\u03d2':'upsih','\u03d6':'piv'};
			
			if(htmlentities[char] != undefined) return "&"+htmlentities[char]+";";
			return char;
		}
		var tmp = '';
		for(var i = 0; i < this.length; i++){
			tmp += convert(this[i]);
		}
		return tmp;
	}
	/**
	 * @brief : decode les caractères HTML
	 * @param[in] quote_style : type de conversion	-> 'HTML_SPECIALCHARS', 'HTML_ENTITIES', 'ENT_NOQUOTES', 'ENT_COMPAT', 'ENT_QUOTES';
	 * @param[out] : html décodé
	 */
	function html_entity_decode(quote_style) {
		var string = this;
		//if(quote_style == undefined) quote_style = 'HTML_SPECIALCHARS';
		// http://kevin.vanzonneveld.net
		// +   original by: john (http://www.jd-tech.net)
		// +      input by: ger
		// +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
		// +    revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
		// +   bugfixed by: Onno Marsman
		// +   improved by: marc andreu
		// +    revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
		// +    bugfixed by: Brett Zamir (http://brett-zamir.me)
		// +      input by: Ratheous
		// -    depends on: get_html_translation_table
		// *     example 1: html_entity_decode('Kevin &amp; van Zonneveld');
		// *     returns 1: 'Kevin & van Zonneveld'
		// *     example 2: html_entity_decode('&amp;lt;');
		// *     returns 2: '&lt;'
	 
		var hash_map = {}, symbol = '', tmp_str = '', entity = '';
		tmp_str = string.toString();
		
		if (false === (hash_map = document.get_html_translation_table('HTML_ENTITIES', quote_style))) {
			return false;
		}
	 
		for (symbol in hash_map) {
			entity = hash_map[symbol];
			tmp_str = tmp_str.split(entity).join(symbol);
		}
		tmp_str = tmp_str.split('&#039;').join("'");
		
		return tmp_str;
	}
	/**
	 * @brief : vérification de la syntaxe du mail
	 * @param[in] mail : le mail à tester
	 * @param[out] : boolean, true si c'est bon false dans la cas contraire
	 */
	function isMail(){
		var reg = new RegExp("([@]([a-z0-9]+)[\-]?([a-z0-9]+)[\.](([a-z]+)[\.]?([a-z]+)))");
		return reg.exec(this);
	}
	/**
	 * @brief : vérification de la syntaxe d'une date (à modifier pour vérifier les jours-mois)
	 * @param[in] date : la date à tester
	 * @param[out] : boolean, true si c'est bon false dans la cas contraire
	 */
	function isDate(){
		var regdate = new RegExp("([0-9]{2})/([0-9]{2})/([0-9]{4})");
		var tab;
		var tMonth;
		if(regdate.exec(this)) {
			tab = this.split("/");
			tMonth = (new Date(tab[2], 0, 1)).getArrayDaysByMonth();
			if(tab[1] > 12) return false;
			if(tab[0] < 0 && tab[0] > tMonth[tab[1] - 1]) return false;
			return true;
		}
		regdate = new RegExp("([0-9]{4})-([0-9]{2})-([0-9]{2})");
		if(regdate.exec(this)){
			tab = this.split("-");
			tMonth = (new Date(tab[0], 0, 1)).getArrayDaysByMonth();
			if(tab[1] > 12) return false;
			if(tab[2] < 0 && tab[2] > tMonth[tab[1] - 1]) return false;
			return true;
		}
		return false;
	}
	/**
	 * @brief : vérification de la syntaxe d'un numéro de telephone
	 * @param[in] tel : le numéro de telephone à tester
	 * @param[out] : boolean, true si c'est bon false dans la cas contraire
	 */
	function isTel(){
		var regtel = new RegExp("^(01|02|03|04|05|06|08|09)[0-9]{8}");
		return regtel.exec(this);
	}
	/**
	 * @brief : indique si il s'agit d'un nombre
	 * @param[in] number : l'expression à tester
	 * @param[out] : boolean, true si c'est bon false dans la cas contraire
	 */
	function isNumber(){
		return !isNaN(this);
	}
	/**
	 * @brief : convertie le string en nombre si il s'agit d'un nombre
	 */
	function toNumber(){
		if(this.isNumber) return new Number(this);
		return false;
	}
	/**
	 * @brief : indique si la chaine passé est un code postal français
	 * @param[in] string : l'expression à tester
	 * @param[out] : boolean, true si c'est bon false dans la cas contraire
	 */
	function isCodePostal(){
		var sp = this.substr(0,2);
		return (this.length == 5 && this.isNumber(this.substr(0,1))&& this.isNumber(this.substr(2,1)) && this.isNumber(this.substr(4,1)) && (sp.toUpperCase() == '2A' || sp.toUpperCase() == '2B' || this.isNumber(sp)));
	}
	/**
	 * @brief : Un booléen qui vaut 'true' si le code SIRET passé en paramètre est valide, false sinon.
	 * @param[out] : boolean  
	 */
	function isSiret(){

		var somme = 0;
		var tmp;
		//temporairement
		return true;
		if ((this.length != 14) || (isNaN(this)) ) return false;

		 // Donc le SIRET est un numérique à 14 chiffres
		 // Les 9 premiers chiffres sont ceux du SIREN (ou RCS), les 4 suivants
		 // correspondent au numéro d'établissement
		 // et enfin le dernier chiffre est une clef de LUHN.
		 
		 for (var cpt = 0; cpt < this.length; cpt++) {
			if ((cpt % 2) == 0) { // Les positions impaires : 1er, 3è, 5è, etc...
					tmp = this.charAt(cpt) * 2; // On le multiplie par 2
					if (tmp > 9) tmp -= 9; // Si le résultat est supérieur à 9, on lui soustrait 9
			}
			else tmp = this.charAt(cpt);
			somme += parseInt(tmp);
		 }
		 
		 if ((somme % 10) == 0) return true; // Si la somme est un multiple de 10 alors le SIRET est valide
		 return false;
	}
	/**
	 * @brief : Un booléen qui vaut 'true' si le code SIREN passé en paramètre est valide, false sinon.
	 * @param[out] : boolean  
	 */
	function isSiren(){

		var somme = 0;
		var tmp;
		if((this.length != 9) || (isNaN(this)))return false;

		// Donc le SIREN est un numérique à 9 chiffres
		for (var cpt = 0; cpt < this.length; cpt++){
			if((cpt % 2) == 1){ // Les positions paires : 2ème, 4ème, 6ème et 8ème chiffre
				tmp = this.charAt(cpt) * 2; // On le multiplie par 2
				if (tmp > 9) tmp -= 9; // Si le résultat est supérieur à 9, on lui soustrait 9
			}
			else tmp = this.charAt(cpt);
			somme += parseInt(tmp);
		}
		if ((somme % 10) == 0) return true; // Si la somme est un multiple de 10 alors le SIREN est valide
		return false;

	}	
	function addslashes(){
		return this.replace(/\\("|'|\\)/g, "$1");
	}
	/**
	 * @brief : enlève les slashes
	 */
	function stripslashes(){
		 return this.replace(/("|'|\\)/g, "\\$1");
	}
	
	// startsWith(String)
	function startsWith(strChar){
 		if(Object.isUndefined(strChar)) return false;
		
 		strChar += '';
 		var intLength = strChar.length;
 		return (this.substr(0, intLength) == strChar);
	}
 	
	function endsWith(strChar){
		if(Object.isUndefined(strChar)) return false;
		
 		strChar += '';
 		var intLength = strChar.length;
 		return (this.substr(this.length - intLength, intLength) == strChar);
	}

	function equals(strChar){
 		if(!strChar) {return false;}
 		strChar += '';
 		return (this == strChar);
	}

	// format(String0, String1, ..., StringN)
	function format(){
 		if(arguments.length == 0) {return this;}
 		var strThis = this, i = 0;
 		for (i = 0; i < arguments.length; i++) {
			strThis = strThis._replace(new RegExp('\\{' + i + '\\}', 'gi'), arguments[i]);
		}
 		return strThis;
	}

// insert(Integer, String)
	function insert(intIndex, strChar){
 		if(isNaN(intIndex))	return this;
 		if(intIndex < 0)	return this;
 
 		if(!strChar) return this;
		strChar += '';
 		intIndex = parseInt(intIndex, 10);
 		return (this.substr(0, intIndex) + strChar + this.substr(intIndex, this.length));
	}


// padLeft(Integer)
// padLeft(Integer, String)
	function padLeft(){
 		if(arguments.length == 0 || (arguments.length >= 1 && isNaN(arguments[0])) || arguments[0] < 0) return this;
 
 		var strThis = this, intLength = parseInt(arguments[0], 10), strChar = String.fromCharCode(32);
 		
		if(arguments.length == 2) 	strChar = '' + arguments[1];
 		while (strThis.length < intLength) strThis = strChar + strThis;
		
 		return strThis;
	}

// padRight(Integer)
// padRight(Integer, String)
 	function padRight(){
 		if(arguments.length == 0 || (arguments.length >= 1 && isNaN(arguments[0])) || arguments[0] < 0) return this;
	
		var strThis = this, intLength = parseInt(arguments[0], 10), strChar = String.fromCharCode(32);
 		if(arguments.length == 2) strChar = '' + arguments[1];
		
 		while (strThis.length < intLength) strThis = strThis + strChar;
 		return strThis;
	}

// remove(Integer, Integer)
	function remove(intIndex, intLength){
 		if(isNaN(intIndex) || isNaN(intLength) || intIndex < 0 || intLength < 0) return this;

 		intIndex = parseInt(intIndex, 10);
		intLength = parseInt(intLength, 10);
 		return (this.substr(0, intIndex) + this.substr(intIndex + intLength, this.length));
	}


	function trim(){
 		return this.replace(/(^\s*)|(\s*$)/g, '');
	}


	function rtrim(){
 		return this.replace(/\s*$/g, '');
	}


	function ltrim(){
 		return this.replace(/^\s*/g, '');
	}
	
	
	
	
	return	{
				toDate:					toDate,
				htmlEntities: 			htmlEntities,
				html_entity_decode : 	html_entity_decode,
				isMail:					isMail,
				isDate:					isDate,
				isTel:					isTel,
				isNumber:				isNumber,
				toNumber:				toNumber,
				isCodePostal:			isCodePostal,
				isSiret:				isSiret,
				isSiren:				isSiren,
				addslashes:				addslashes,
				stripslashes: 			stripslashes,
				trim:					trim,
				rtrim:					rtrim,
				ltrim:					ltrim,
				remove:					remove,
				padRight:				padRight,
				padLeft:				padLeft,
				insert:					insert,
				format:					format,
				equals:					equals,
				startsWith:				startsWith,
				endsWith:				endsWith
			};
})());

//---------------------------------------------------------------------------------------------------------------
//Extension classe Date------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------
Object.extend(Date.prototype,(function(){
	/**
	 * @brief : formate la date selon le string passé en paramètre ex : "'y-M-d h:m:s" retournera 2009-09-28 10:52:10
	 * @param[in] formatString : expression
	 * @param[out] : custom string
	 */
	function format(formatString){ 
		var Y,M,D,h,m,s;
		Y = this.getFullYear();
		M = (M = this.getMonth()+1)<10?('0'+M):M;
		D = (D = this.getDate())<10?('0'+D):D;
	
		formatString = formatString.replace("y",Y).replace("M",M).replace("d",D);
	
		h = this.getHours() < 10 ? ('0' + this.getHours()) : this.getHours();
	
		m = (m = this.getMinutes())<10?('0'+m):m;
		s = (s = this.getSeconds())<10?('0'+s):s;
		return formatString.replace("h",h).replace("m",m).replace("s",s);
	}
	/**
	 * @brief : convertie la date et l'heure en string et selon le format demandé (fr ou eng)
	 * @param[in] frm : fr ou eng
	 * @param[out] : string date formaté
	 */
	function toStringFormated(frm){
		frm = frm.toLowerCase();
		switch(frm){
			default:
			case 'eng':
				return this.format('y-M-d h:m:s');
				break;
			case 'fr':
				return this.format('d/M/y h:m:s');
		}
	}
	/** 
	 * @brief: convertie la date en string avec seulement la partie date
	 */
	function toStringDate(frm){
		if(Object.isUndefined(frm)) frm = 'eng';
		frm = frm.toLowerCase();
		
		switch(frm){
			default:
			case 'eng':
				return this.format('y-M-d');
				break;
			case 'fr':
				return this.format('d/M/y');
		}	
	}
	/**
	 * @brief: convertie l'heure en string
	 */
	function toStringHours(){
		return this.format('h:m:s');
	}
	/**
	 * @brief : function spécialement écrite pour les blog
	 */
	function toStringBlog(frm, word){

		if(word == undefined) word = "";
	
		var dateToday = new Date();
	
		if(dateToday.format('y-M-d') + this.format('y-M-d')) return word + " le " + this.toStringDate(frm);
	
		var stime = dateToday.getTime() - this.getTime();
		stime = stime/1000;
		var sseconde = Math.floor(stime%60);
		var sminute = Math.ceil(stime/60)%60;
		var sheure = dateToday.getHours() - Theure[0];
	
		//if(sheure < 0 && sminute == 1) return $word + " il y a " + $minute + " minute";
		if(sheure < 1) return word + " il y a " + ("0" + sminute).substr(-2) + " min";
	
		return word + " il y a " + Math.abs(sheure) + "h";
	
	}
	/**
	 * @brief: retourne un tableau de jour par mois courant à la date
	 */
	function getArrayDaysByMonth(){
		//On initialise le nombre de jour par mois
		var nbJoursfevrier = (this.getFullYear() % 4) == 0 ? 29 : 28;
		//Initialisation du tableau indiquant le nombre de jours par mois
		return new Array(31,nbJoursfevrier,31,30,31,30,31,31,30,31,30,31);
	}
	/**
	 * @brief: retourne le nombre de jour entre deux dates
	 */
	function dateDiff(date){
		
		var date_start = this.format('y-M-d') + " 00:00:00";
		date_start = date_start.toDate();
		var date_end = date.format('y-M-d') + " 00:00:00";
		date_end = date_end.toDate();
		
		return (Math.abs(date_start.getTime() - date_end.getTime())/ (1000*60*60*24));
	}
	
	function hoursDiffWithInterval(interval){

		if(Object.isUndefined(interval)){
			interval = [0,23];	
		}

		if(this.getHours() < interval[0]) return 0;
		if(this.getHours() > interval[1]) return interval[1] - interval[0];
		
		return this.getHours() - interval[0];
				
	}
	return {
				format:				format,
				toStringFormated:	toStringFormated,
				toStringDate:		toStringDate,
				toStringHours:		toStringHours,
				toStringBlog:		toStringBlog,
				getArrayDaysByMonth:getArrayDaysByMonth,
				dateDiff:			dateDiff,
				hoursDiffWithInterval: hoursDiffWithInterval
			}
})());
//---------------------------------------------------------------------------------------------------------------
//Extension Classe Document--------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------
document.navigator = {
	client: 'undefined',
	version:'undefined',
	
	initialize:function(){
		var obj = Prototype.Browser;

		if(obj.IE){
			/MSIE (\d+\.\d+);/.test(navigator.userAgent);
			this.client = 'IE';
			var ieversion=new Number(RegExp.$1);
			if (ieversion>=8) this.version = 8;
			else if (ieversion>=7) this.version = 7;
			else if (ieversion>=6) this.version = 6;
			else if(ieversion>=5) this.version = 5;
			return;
		}
		
		if(obj.Gecko){
			
			/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent);
			this.client = 'Firefox';
			var ffversion = new Number(RegExp.$1);
			if(ffversion >= 3) this.version = 3;
			else if(ffversion >= 2) this.version = 2;
			else if(ffversion >= 1) this.version = 1;
			return;
		}
		
		if(obj.Webkit){
			//Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent);
			this.client = 'Safari';
			 /*var ffversion = new Number(RegExp.$1);
			 if(ffversion >= 3) this.version = 3;
			 else if(ffversion >= 2) this.version = 2;
			 else if(ffversion >= 1) this.version = 1;*/
			return;
		}
		
		if(obj.Opera){

			/Opera[\/\s](\d+\.\d+)/.test(navigator.userAgent);//test for Opera/x.x or Opera x.x (ignoring remaining decimal places);
			var oprversion = new Number(RegExp.$1) // capture x.x portion and store as a number
			this.client = 'Opera';
			if (oprversion >= 10) this.version = 10;
			else if(oprversion >= 9) this.version = 9;
			else if(oprversion >= 8) this.version = 8;
			else if(oprversion >= 7) this.version = 7;
			return;
		}
		
		if(/Chrome[\/\s](\d+\.\d+)/.test(navigator.userAgent)){
			var chromeversion = new Number(RegExp.$1) // capture x.x portion and store as a number
			this.client = 'chrome';
			
			if(chromeversion >= 2) this.version = 2;
			else if(chromeversion >= 1) this.version = 1;
		}
	},
	/**
	 * @brief : Parse le champs GET et retourne un tableau associatif
	 * @param[out] : tableau associatif
	 */
	parseGet:function(){
		var string = window.location.search;
		string = string.substr(1, string.length-1);
		var tab = string.split('&');
		$_GET = {};
		for(var i = 0; i < tab.length; i++){
			var tmp = tab[i].split('=');
			$_GET[tmp[0]] = tmp[1];
		}
		return $_GET;
	},
	/**
	 * @brief : retourne un element du tableau de la method GET
	 * @param[in] value : le champs
	 * @param[out] : valeur du champs (string)
	 */
	$_GET: function(value){
		return $_GET[value];
	}
	
}

/** 
 * @brief : recupère les dimensions de document exploitable
 */
document.stage = {
	stageWidth:0,
	stageHeight:0,
	body: '',
	/**
	 * @brief: donne la dimensions de la fenetre utilisable par le HTML
	 * @param[out] : tableau associatif obj.height, obj.width
	 */
	getDimensions:function(){
		var div = document.createElement('div');
		div.style.height = "100%";
		div.style.width  = "100%";
		div.style.position = "fixed";
		div.style.top = "0";
		div.style.lef = "0";
		
		this.body.appendChild(div);
		
		var t = Element.getDimensions(div);
		
		this.stageWidth = t.width;
		this.stageHeight = t.height;
		this.body.removeChild(div);
		return t;
	}
}
/**
 * @brief : retourne la table de translation HTML
 */
document.get_html_translation_table = function(table, quote_style) {
		// http://kevin.vanzonneveld.net
		// +   original by: Philip Peterson
		// +    revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
		// +   bugfixed by: noname
		// +   bugfixed by: Alex
		// +   bugfixed by: Marco
		// +   bugfixed by: madipta
		// +   improved by: KELAN
		// +   improved by: Brett Zamir (http://brett-zamir.me)
		// +   bugfixed by: Brett Zamir (http://brett-zamir.me)
		// +      input by: Frank Forte
		// +   bugfixed by: T.Wild
		// +      input by: Ratheous
		// %          note: It has been decided that we're not going to add global
		// %          note: dependencies to php.js, meaning the constants are not
		// %          note: real constants, but strings instead. Integers are also supported if someone
		// %          note: chooses to create the constants themselves.
		// *     example 1: get_html_translation_table('HTML_SPECIALCHARS');
		// *     returns 1: {'"': '&quot;', '&': '&amp;', '<': '&lt;', '>': '&gt;'}
		
		var entities = {}, hash_map = {}, decimal = 0, symbol = '';
		var constMappingTable = {}, constMappingQuoteStyle = {};
		var useTable = {}, useQuoteStyle = {};
		
		// Translate arguments
		constMappingTable[0]      = 'HTML_SPECIALCHARS';
		constMappingTable[1]      = 'HTML_ENTITIES';
		constMappingQuoteStyle[0] = 'ENT_NOQUOTES';
		constMappingQuoteStyle[2] = 'ENT_COMPAT';
		constMappingQuoteStyle[3] = 'ENT_QUOTES';
	 
		useTable       = !isNaN(table) ? constMappingTable[table] : table ? table.toUpperCase() : 'HTML_SPECIALCHARS';
		useQuoteStyle = !isNaN(quote_style) ? constMappingQuoteStyle[quote_style] : quote_style ? quote_style.toUpperCase() : 'ENT_COMPAT';
	 
		if (useTable !== 'HTML_SPECIALCHARS' && useTable !== 'HTML_ENTITIES') {
			throw new Error("Table: "+useTable+' not supported');
			// return false;
		}
	 
		entities['38'] = '&amp;';
		if (useTable === 'HTML_ENTITIES') {
			entities['160'] = '&nbsp;';
			entities['161'] = '&iexcl;';
			entities['162'] = '&cent;';
			entities['163'] = '&pound;';
			entities['164'] = '&curren;';
			entities['165'] = '&yen;';
			entities['166'] = '&brvbar;';
			entities['167'] = '&sect;';
			entities['168'] = '&uml;';
			entities['169'] = '&copy;';
			entities['170'] = '&ordf;';
			entities['171'] = '&laquo;';
			entities['172'] = '&not;';
			entities['173'] = '&shy;';
			entities['174'] = '&reg;';
			entities['175'] = '&macr;';
			entities['176'] = '&deg;';
			entities['177'] = '&plusmn;';
			entities['178'] = '&sup2;';
			entities['179'] = '&sup3;';
			entities['180'] = '&acute;';
			entities['181'] = '&micro;';
			entities['182'] = '&para;';
			entities['183'] = '&middot;';
			entities['184'] = '&cedil;';
			entities['185'] = '&sup1;';
			entities['186'] = '&ordm;';
			entities['187'] = '&raquo;';
			entities['188'] = '&frac14;';
			entities['189'] = '&frac12;';
			entities['190'] = '&frac34;';
			entities['191'] = '&iquest;';
			entities['192'] = '&Agrave;';
			entities['193'] = '&Aacute;';
			entities['194'] = '&Acirc;';
			entities['195'] = '&Atilde;';
			entities['196'] = '&Auml;';
			entities['197'] = '&Aring;';
			entities['198'] = '&AElig;';
			entities['199'] = '&Ccedil;';
			entities['200'] = '&Egrave;';
			entities['201'] = '&Eacute;';
			entities['202'] = '&Ecirc;';
			entities['203'] = '&Euml;';
			entities['204'] = '&Igrave;';
			entities['205'] = '&Iacute;';
			entities['206'] = '&Icirc;';
			entities['207'] = '&Iuml;';
			entities['208'] = '&ETH;';
			entities['209'] = '&Ntilde;';
			entities['210'] = '&Ograve;';
			entities['211'] = '&Oacute;';
			entities['212'] = '&Ocirc;';
			entities['213'] = '&Otilde;';
			entities['214'] = '&Ouml;';
			entities['215'] = '&times;';
			entities['216'] = '&Oslash;';
			entities['217'] = '&Ugrave;';
			entities['218'] = '&Uacute;';
			entities['219'] = '&Ucirc;';
			entities['220'] = '&Uuml;';
			entities['221'] = '&Yacute;';
			entities['222'] = '&THORN;';
			entities['223'] = '&szlig;';
			entities['224'] = '&agrave;';
			entities['225'] = '&aacute;';
			entities['226'] = '&acirc;';
			entities['227'] = '&atilde;';
			entities['228'] = '&auml;';
			entities['229'] = '&aring;';
			entities['230'] = '&aelig;';
			entities['231'] = '&ccedil;';
			entities['232'] = '&egrave;';
			entities['233'] = '&eacute;';
			entities['234'] = '&ecirc;';
			entities['235'] = '&euml;';
			entities['236'] = '&igrave;';
			entities['237'] = '&iacute;';
			entities['238'] = '&icirc;';
			entities['239'] = '&iuml;';
			entities['240'] = '&eth;';
			entities['241'] = '&ntilde;';
			entities['242'] = '&ograve;';
			entities['243'] = '&oacute;';
			entities['244'] = '&ocirc;';
			entities['245'] = '&otilde;';
			entities['246'] = '&ouml;';
			entities['247'] = '&divide;';
			entities['248'] = '&oslash;';
			entities['249'] = '&ugrave;';
			entities['250'] = '&uacute;';
			entities['251'] = '&ucirc;';
			entities['252'] = '&uuml;';
			entities['253'] = '&yacute;';
			entities['254'] = '&thorn;';
			entities['255'] = '&yuml;';
		}
	 
		if (useQuoteStyle !== 'ENT_NOQUOTES') {
			entities['34'] = '&quot;';
		}
		if (useQuoteStyle === 'ENT_QUOTES') {
			entities['39'] = '&#39;';
		}
		entities['60'] = '&lt;';
		entities['62'] = '&gt;';
	 
	 
		// ascii decimals to real symbols
		for (decimal in entities) {
			symbol = String.fromCharCode(decimal);
			hash_map[symbol] = entities[decimal];
		}
		
		return hash_map;
	}

//---------------------------------------------------------------------------------------------------------------
//Extension classe Event-----------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------
Object.extend(Event, {
	wheel:function (event){
		var delta = 0;
		if (!event) event = window.event;
		if (event.wheelDelta) {
			delta = event.wheelDelta/120; 
			if (window.opera) delta = -delta;
		} else if (event.detail) { delta = -event.detail/3;	}
		return Math.round(delta); //Safari Round
	}
});

//---------------------------------------------------------------------------------------------------------------
//Extension classe Picture---------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------

var Picture = Class.create();
Picture.prototype = {
	element:'',
	//--------------------------------------------------------------------------------------------------------
	//Constructeur--------------------------------------------------------------------------------------------
	//--------------------------------------------------------------------------------------------------------
	initialize: function(){
		this.onComplete_call = '',
		this.onLoad_call = '',
		this.array_call = '',
		this.element = 	$(new Image());
		this.width = 	0;
		this.height = 	0;
		this.src = 		'';
		this.title = 	'';
		this.alt = 		'';
		this.id = 		'';
		this.className = '';
		this.timer =	new Timer(this.onTick_Timer.bind(this), 0.1);
	},
	//--------------------------------------------------------------------------------------------------------
	//Constructeur--------------------------------------------------------------------------------------------
	//--------------------------------------------------------------------------------------------------------
	clone: function(picture){
		
		var pict = '';
		if(Object.isUndefined(picture)) pict = new Picture();
		else pict = picture;
		
		pict.setUrl(this.getUrl());
		pict.element.title = pict.element.title;
		
		return pict;
	},
	observe: function(eventName, handler){
		eventName = eventName.toLowerCase();

		switch(eventName){
			case 'complete':
				this.onComplete_call = handler;
				break;
			case 'error':
				this.element.onerror = function(evt){handler.call(this, evt)}.bind(this);
				break;
			case 'load':
				this.element.load = function(evt){handler.call(this, evt)}.bind(this);
				break;
			case 'abort':
				this.element.onabort = function(evt){handler.call(this, evt)}.bind(this);
				break;
			case 'click':
				this.onClick = handler;
				this.element.observe('click', function(evt){
													   			if(Object.isFunction(this.onClick)) this.onClick.call('', evt, this)
															}.bind(this));
				break;
			case 'mouseover':
				this.onMouseOver = handler;
				this.element.observe('mouseover', function(evt){
														   		if(Object.isFunction(this.onMouseOver)) this.onMouseOver.call(this, evt, this)
															}.bind(this));
				break;
			case 'mouseout':
				this.onMouseOver = handler;
				this.element.observe('mouseout', function(evt){
														  		if(Object.isFunction(this.onMouseOut)) this.onMouseOut.call(this, evt, this)
															}.bind(this));
				break;
			case 'mousemove':
				this.onMouseMove = handler;
				this.element.observe('mousemove', function(evt){
														   		if(Object.isFunction(this.onMouseMove)) this.onMouseMove.call(this, evt, this)
															}.bind(this));
				break;
			case 'mousedown':
				this.onMouseDown = handler;
				this.element.observe('mousedown', function(evt){
														   		if(Object.isFunction(this.onMouseDown)) this.onMouseDown.call(this, evt, this)
														   }.bind(this));
				break;
			case 'mouseup':
				this.onMouseUp = handler;
				this.element.observe('mouseup', function(evt){
														   		if(Object.isFunction(this.onMouseUp)) this.onMouseUp.call(this, evt, this)
															}.bind(this));
				break;
			default:break;
		}

	},
	
	stopObserving:function(eventName, handler){
		eventName = eventName.toLowerCase();
		try{
			switch(eventName){
				case 'oncomplete':
					this.onComplete_call = '';
					break;
				case 'onerror':
					this.element.onerror = '';
					break;
				case 'onload':
					this.element.load = '';
					break;
				case 'onabort': 
					this.element.onabort = '';
					break;
				case 'click':
					this.onClick = '';break;
				case 'mouseover':
					this.onMouseOver = '';break;
				case 'mouseout':
					this.onMouseOver = '';break;
				case 'mousemove':
					this.onMouseMove = '';break;
				case 'mousedown':
					this.onMouseDown = '';break;
				case 'mouseup':
					this.onMouseUp ='';break;
				default:break;
			}
		}catch(er){}
	},
	/**
	 * @brief : redimensionne l'image en fonction de la taille de la diapo mais ne redimensionne pas les images plus petite que la taille de la visionneuse
	 * pour éviter le flou de pixel
	 * @param[in] heightMax : hauteur Maximal de l'image
	 * @param[in] widthImg : largeur Maximal de l'image
	 * @param[out] : tableau de taille hauteur et largeur
	 */
	resize:function(widthMax, heightMax){
			
		var height = 	this.element.height;
		var width = 	this.element.width;
		
		if(height > width){
			
			width = Math.round((heightMax / height) * width);				
			height = heightMax; 
			
			
		}
		else if(height < width){
			
			if(widthMax <= heightMax){
				height = Math.round((widthMax / width) * height);
				//Largeur du nouveau logo
				width = widthMax;
			}else{
				
				width = Math.round((heightMax / height) * width);				
				height = heightMax; 
				
				if(width > widthMax){
					height = Math.round((widthMax / width) * height);
					//Largeur du nouveau logo
					width = widthMax;
				}
				
			}
			
		}
		else if(height == width){
			//Largeur & hauteur du nouveau logo
			
			if(heightMax > widthMax){
				width = widthMax;
				height = widthMax;
			}
			else{
				width = heightMax;
				height = heightMax;
				
			}
		}
		
		this.element.setStyle({width:width+'px', height:height+'px'});
		this.width = width;
		this.height = height;
		
		return {width:width, height:height};
	},
	hide:function(){
		this.element.hide();
	},
	show: function(){
		this.element.show();
	},
	//--------------------------------------------------------------------------------------------------------
	//Event methods--------------------------------------------------------------------------------------------
	//--------------------------------------------------------------------------------------------------------
	onTick_Timer: function(timer){
		this.timer.stop();
		this.width = this.element.width;
		this.height = this.element.height;
		
		if(this.element.complete){
			if(Object.isFunction(this.onComplete_call)) this.onComplete_call.call(this, this);
			return;
		}
		this.timer.start();

	},
	//--------------------------------------------------------------------------------------------------------
	//Setteurs && Getteurs------------------------------------------------------------------------------------
	//--------------------------------------------------------------------------------------------------------
	setStyle: function(obj){
		this.element.setStyle(obj);
	},
	setUrl: function(link){
		this.timer.start();
		this.element.src = link;
		this.src = link;
	},
	getUrl: function(){
		return this.element.src;
	},
	setId: function(id){
		this.id = id;
		this.element.id = id;
	},
	getId: function(id){
		return this.element.id;
	},
	setClassName: function(className){
		this.className = 	className;
		this.element.className = 	className;
	},
	getClassName: function(id){
		return this.element.className;
	},
	setTitle: function(title){
		this.title = title;
		this.element.title = title;
	},
	getTitle: function(title){
		return this.element.title;
	},
	setAlt: function(alt){
		this.alt = alt;
		this.element.alt = alt;
	},
	getAlt: function(title){
		return this.element.alt;
	},
	getElement: function(){
		
		if(!Object.isUndefined(this.title)) 	this.element.title = 		this.title;
		if(!Object.isUndefined(this.className))	this.element.className = 	this.className;
		if(!Object.isUndefined(this.id))		this.element.id = 			this.id;
		if(!Object.isUndefined(this.alt))		this.element.alt = 			this.alt;

		return this.element;	
	},
	setOpacity: function(nb){
		this.element.setOpacity(nb);
	}
	
									
}

//---------------------------------------------------------------------------------------------------------------
//Classe Timer---------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------
var Timer = Class.create()
Timer.prototype = {
	
	isStart:false,
	callback:'',
	frequency:'',
	timer:'',
	//-----------------------------------------------------------------------------------------------------------
	//Constructeur-----------------------------------------------------------------------------------------------
	//-----------------------------------------------------------------------------------------------------------
  	initialize: function(callback, frequency) {
    	this.callback = callback;
    	this.frequency = frequency;
  	},

  	start: function() {
		if(this.isStart) return;

		this.isStart = true;
    	this.timer = setInterval(this.onTimer_Tick.bind(this), this.frequency * 1000);
  	},
	
	stop: function(){
		if(this.isStart){
			clearInterval(this.timer);
		}
		this.timer = null;
		this.isStart = false;

	},
	
	execute: function(){
		
		this.callback(this);	
	},

	onTimer_Tick: function(){
	
		if(!this.isStart){
			this.stop();
			return;
		}
		
		this.execute();
	}

};
//--------------------------------------------------------------------------------------------------------
//Execution-----------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------
document.navigator.initialize();

document.navigator.parseGet();
document.observe('dom:loaded',function(){
									   	document.stage.body = document.getElementsByTagName("body")[0];
										document.stage.getDimensions();
										window.onresize = function(){document.stage.getDimensions()};
									   });
