/******************************************************************/
/*                        MOOdalBox 1.2.1                         */
/* A modal box (inline popup), used to display remote content     */
/* loaded using AJAX, written for the mootools framework          */
/*         by Razvan Brates, razvan [at] e-magine.ro              */
/******************************************************************/
/*               http://www.e-magine.ro/moodalbox                 */
/******************************************************************/
/*                                                                */
/* MIT style license:                                             */
/* http://en.wikipedia.org/wiki/MIT_License                       */
/*                                                                */
/* mootools found at:                                             */
/* http://mootools.net/                                           */
/*                                                                */
/* Original code based on "Slimbox", by Christophe Beyls:         */
/* http://www.digitalia.be/software/slimbox                       */
/******************************************************************/

// Constants defined here can be changed for easy config / translation
// (defined as vars, because of MSIE's lack of support for const)

var _ERROR_MESSAGE = "Oops.. there was a problem with your request.<br /><br />" +
					"Please try again.<br /><br />" +
					"<em>Click anywhere to close.</em>"; // the error message displayed when the request has a problem
var _RESIZE_DURATION 		= 400; 		// Duration of height and width resizing (ms)
var _INITIAL_WIDTH			= 250;		// Initial width of the box (px)
var _INITIAL_HEIGHT			= 250;		// Initial height of the box (px)
var _CONTENTS_WIDTH 		= 500;		// Actual width of the box (px)
var _CONTENTS_HEIGHT		= 400;		// Actual height of the box (px)
var _DEF_CONTENTS_WIDTH		= 500;		// Default width of the box (px) - used for resetting when a different setting was used
var _DEF_CONTENTS_HEIGHT	= 400;		// Default height of the box (px) - used for resetting when a different setting was used
var _ANIMATE_CAPTION		= true;		// Enable/Disable caption animation
var _EVAL_SCRIPTS			= true;	// Option to evaluate scripts in the response text
var _EVAL_RESPONSE			= false;	// Option to evaluate the whole response text

var _DIAPO_RATIO_SWF		= 390/515;	// Ratio largeur sur hauteur des diaporamas

var _MAX_MEDIA_HEIGHT		= 511;	

/**
*
*  URL encode / decode
*  http://www.webtoolkit.info/
*
**/
 
var Url = {
 
	// public method for url encoding
	encode : function (string) {
		return escape(this._utf8_encode(string));
	},
 
	// public method for url decoding
	decode : function (string) {
		return this._utf8_decode(unescape(string));
	},
 
	// private method for UTF-8 encoding
	_utf8_encode : function (string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";
 
		for (var n = 0; n < string.length; n++) {
 
			var c = string.charCodeAt(n);
 
			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}
 
		}
 
		return utftext;
	},
 
	// private method for UTF-8 decoding
	_utf8_decode : function (utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;
 
		while ( i < utftext.length ) {
 
			c = utftext.charCodeAt(i);
 
			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			}
			else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}
 
		}
 
		return string;
	}
 
}

// The MOOdalBox object in its beauty
function funcMOOdalBox () {
	
	// init the MOOdalBox
	this.init = function (options) {
		
		// init default options
		this.options = Object.extend({
			resizeDuration: 	_RESIZE_DURATION,
			initialWidth: 		_INITIAL_WIDTH,	
			initialHeight: 		_INITIAL_HEIGHT,
			contentsWidth: 		_CONTENTS_WIDTH,
			contentsHeight: 	_CONTENTS_HEIGHT,
			defContentsWidth: 	_DEF_CONTENTS_WIDTH,
			defContentsHeight: 	_DEF_CONTENTS_HEIGHT,
			animateCaption: 	_ANIMATE_CAPTION,
			evalScripts: 		_EVAL_SCRIPTS,
			evalResponse: 		_EVAL_RESPONSE
		}, options || {});
		
		// scan anchors for those opening a MOOdalBox
		this.anchors = [];
		$A($$('a')).each(function(el){
			// we use a regexp to check for links that 
			// have a rel attribute starting with "moodalbox"
			if(el.rel && el.href && el.rel.test('^moodalbox', 'i')) {
				el.onclick = this.click.pass(el, this);
				this.anchors.push(el);
			}
		}, this);
		
		// add event listeners
		this.eventKeyDown = this.keyboardListener.bindWithEvent(this);
		this.eventPosition = this.position.bind(this);
		
		// init the HTML elements
		// the overlay (clickable to close)

		this.overlay = new Element('div').setProperty('id', 'mb_overlay').injectInside(document.body);
		// the top element
		this.divtop = new Element('div').setProperty('id', 'mb_top').setStyle('display', 'none').injectInside(document.body);
		// the top element 1
		this.divtop1 = new Element('div').setProperty('id', 'mb_top1').injectInside(this.divtop);
		// the top element 2
		this.divtop2 = new Element('div').setProperty('id', 'mb_top2').injectInside(this.divtop);
		// the center element
		this.center = new Element('div').setProperty('id', 'mb_center').setStyles({width: this.options.initialWidth+'px', height: this.options.initialHeight+'px', marginLeft: '-'+(this.options.initialWidth/2)+'px', display: 'none'}).injectInside(document.body);
		this.center1 = new Element('div').setProperty('id', 'mb_center1').injectInside(this.center);
		this.center2 = new Element('div').setProperty('id', 'mb_center2').injectInside(this.center);
		// the actual page contents
		this.contents = new Element('div').setProperty('id', 'mb_contents').injectInside(this.center);
		this.contentsInt = new Element('div').setProperty('id', 'mb_contents_int').injectInside(this.contents);

		// the bottom part (caption / close)
		this.bottom = new Element('div').setProperty('id', 'mb_bottom').setStyle('display', 'none').injectInside(document.body);
		// the bottom part1
		this.bottom1 = new Element('div').setProperty('id', 'mb_bottom1').injectInside(this.bottom);
		//this.bottomclose = new Element('a').setProperty({id:'mb_bottomclose', href: '#'}).setHTML('Fermer la fenêtre').injectInside(this.bottom1);
		// the bottom part2
		this.bottom2 = new Element('div').setProperty('id', 'mb_bottom2').injectInside(this.bottom);
		//this.closelink = new Element('a').setProperties({id: 'mb_close_link', href: '#'}).injectInside(this.center);
		//this.closelink2 = new Element('a').setProperties({id: 'mb_close_link2', href: '#'}).injectInside(this.center);
		//this.closelink2.setHTML('Fermer la fen&ecirc;tre');
		this.caption = new Element('div').setProperty('id', 'mb_caption').injectInside(this.bottom);
		//new Element('div').setStyle('clear', 'both').injectInside(this.bottom);
		
		this.error = new Element('div').setProperty('id', 'mb_error').setHTML(_ERROR_MESSAGE);		
		
		// attach the close event to the close button / the overlay
		//this.closelink.onclick = this.closelink2.onclick = this.overlay.onclick = this.close.bind(this);
		//this.closelink.onclick = this.overlay.onclick = this.close.bind(this);
		
		// init the effects
		var nextEffect = this.nextEffect.bind(this);
		this.fx = {
			overlay: 	this.overlay.effect('opacity', { duration: 500 }).hide(),
			resize: 	this.center.effects({ duration: this.options.resizeDuration, onComplete: nextEffect }),
			contents: 	this.contents.effect('opacity', { duration: 500, onComplete: nextEffect }),
			//closelink:	this.closelink.effect('opacity', { duration: 500, onComplete: nextEffect }),
			//closelink2:	this.closelink2.effect('opacity', { duration: 500, onComplete: nextEffect }),
			divtop: 	this.divtop.effects({ duration: 400, onComplete: nextEffect }),
			bottom: 	this.bottom.effects({ duration: 400, onComplete: nextEffect })
		};
		
		this.ajaxRequest = Class.empty;

	}
	
	/*this.click = function(link) {
		return this.open (link.href, link.title, link.rel);
	}*/

	this.open = function(sLinkHref, sLinkTitle, sLinkRel,cssFile) {
		this.href = Url.decode(sLinkHref);
		this.title = sLinkTitle;
		this.rel = sLinkRel;
		this.position();
		this.setup(true);
		this.fx.overlay.custom(0.8);
		//chargement du css temporaire
		if(cssFile){
			this.addCss(cssFile);
		} 
		
		return this.loadContents(sLinkHref);
	}

	this.position = function() {
		var Mysize = getPageSize();
		
		//mboilley - la hauteur de la fenetre est calculée via le différentiel entre la taille et la position haute, cela évite un effet d'augmentation de la div overlay lors du scrolling
		//this.overlay.setStyles({top: Window.getScrollTop()+'px', height: Mysize[1]+'px'});  //ligne originale
		this.overlay.setStyles({top: Window.getScrollTop()+'px', height: (Mysize[1]-Window.getScrollTop())+'px'});
		
	}

	this.setup = function(open) {
		//var elements = $A($$('object'));
		//elements.extend($$(window.ActiveXObject ? 'select' : 'embed'));
		//elements.each(function(el){ el.style.visibility = open ? 'hidden' : ''; });
		var fn = open ? 'addEvent' : 'removeEvent';
		window[fn]('scroll', this.eventPosition)[fn]('resize', this.eventPosition);
		document[fn]('keydown', this.eventKeyDown);
		this.step = 0;
	}
	
	this.loadContents = function() {
		if(this.counter) delete this.counter;
		if(this.step) return false;
		this.step = 1;
		
		// check to see if there are specified dimensions
		// if not, fall back to default values
		var aDim = this.rel.match(/[0-9]+/g);
		this.options.contentsWidth = (aDim && (aDim[0] > 0)) ? aDim[0] : this.options.defContentsWidth;
		this.options.contentsHeight = (aDim && (aDim[1] > 0)) ? aDim[1] : this.options.defContentsHeight;
						
		this.divtop.setStyles({height: '0px', display: 'none'});
		this.bottom.setStyles({height: '0px', display: 'none'});
		//this.closelink.setStyles({opacity: '0', height: '0px', display: 'none'});
		//this.closelink2.setStyles({opacity: '0', height: '0px', display: 'none'});
		this.center.className = 'mb_loading';
		var Mysize = getPageSize();
		var Myscroll = getPageScroll();
		var newtop = Mysize[3];
		var newtop2 = parseInt(this.options.contentsHeight)+52;
		newtop = parseInt(newtop-newtop2);
		newtop = (newtop/2)+Myscroll[1];
		this.top = newtop;
		this.left = parseInt((Mysize[0]-this.options.contentsWidth)/2);
		this.center.setStyles({top: this.top+26+'px', display: ''});
		if (navigator.appName.toLowerCase() == "microsoft internet explorer") {
			$$('html').setStyle('overflow','hidden');
		}
		if (navigator.userAgent.indexOf('Firefox/2')==-1){
			$$('body').setStyle('overflow','hidden');
		}
		this.hideSWFObject(); //Cache les swf objects
		
		this.fx.contents.hide();
		
		// AJAX call here
		var nextEffect = this.nextEffect.bind(this);
		var ajaxFailure = this.ajaxFailure.bind(this);
		var ajaxOptions = {
			method: 		'get',
			update: 		this.contentsInt, 
			evalScripts: 	this.options.evalScripts,
			evalResponse: 	this.options.evalResponse,
			onComplete: 	nextEffect, 
			onFailure: 		ajaxFailure
			};
		this.ajaxRequest = new Ajax(this.href, ajaxOptions).request();		
		return false;
	}
	
	this.ajaxFailure = function (){
		this.contents.setHTML('Erreur de chargement AJAX');
		this.error.clone().injectInside(this.contentsInt);
		this.nextEffect();
		this.center.setStyle('cursor', 'pointer');
		this.bottom.setStyle('cursor', 'pointer');
		this.center.onclick = this.bottom.onclick = this.close.bind(this);	
	}
	
	this.nextEffect = function() {		
		
		switch(this.step++) {
		case 1:
			// remove previous styling from the elements 
			// (e.g. styling applied in case of an error)
			this.center.className = '';
			this.center.setStyle('cursor', 'default');
			this.bottom.setStyle('cursor', 'default');
			this.center.onclick = this.bottom.onclick = '';
			this.caption.setHTML(this.title);
			this.contentsInt.setHTML(this.contentsInt.innerHTML.replace(new RegExp('class="?quiz_accueil_accroche"?', "gi"),'class="quiz_accueil_accroche2"'));
			this.contentsInt.setHTML(this.contentsInt.innerHTML.replace(new RegExp('class="?quiz_question_accroche"?', "gi"),'class="quiz_question_accroche2"'));
			this.contentsInt.setHTML(this.contentsInt.innerHTML.replace(new RegExp('class="?jsonly"?', "gi"),'class="jsonly2"'));
			this.contentsInt.setHTML(this.contentsInt.innerHTML.replace(new RegExp('class="?bandeauhautmodal"?', "gi"),'class="bandeauhautmodal2"'));
			this.contentsInt.setHTML(this.contentsInt.innerHTML.replace(new RegExp('class="?klee_quiz_int"?', "gi"),'class="klee_quiz_int2"'));
			this.contentsInt.setHTML(this.contentsInt.innerHTML.replace(new RegExp('class="?quiz_form_central_question"?', "gi"),'class="quiz_form_central_question2"'));
			this.contentsInt.setHTML(this.contentsInt.innerHTML.replace(new RegExp('class="?quiz_form_central_accueil"?', "gi"),'class="quiz_form_central_accueil2"'));
			this.contentsInt.setHTML(this.contentsInt.innerHTML.replace(new RegExp('class="?boutonoff"?', "gi"),'class="boutonoff2"'));
			this.contentsInt.setHTML(this.contentsInt.innerHTML.replace(new RegExp('id="?quiz_boutonsuiv"?', "gi"),'id="quiz_boutonsuiv2"'));
			this.contentsInt.setHTML(this.contentsInt.innerHTML.replace(new RegExp('class="?boutonprecdecale"?', "gi"),'class="boutonprecdecale2"'));
			this.contentsInt.setHTML(this.contentsInt.innerHTML.replace(new RegExp('class="?boutonprec"?', "gi"),'class="boutonprec2"'));
			this.contentsInt.setHTML(this.contentsInt.innerHTML.replace(new RegExp('class="?boutonsuiv"?[>]+', "gi"),'class="boutonsuiv2">'));
			this.contentsInt.setHTML(this.contentsInt.innerHTML.replace(new RegExp('class="?boutonsuivdecale"?', "gi"),'class="boutonsuivdecale2"'));
			this.contentsInt.setHTML(this.contentsInt.innerHTML.replace(new RegExp('div class="?boutonresult"?[>]+', "gi"),'div class="boutonresult2">'));
			this.contentsInt.setHTML(this.contentsInt.innerHTML.replace(new RegExp('div class="?boutonresultlist"?[>]+', "gi"),'div class="boutonresultlist2">'));
			this.contentsInt.setHTML(this.contentsInt.innerHTML.replace(new RegExp('class="?klee_quiz"?[>]+', 'gi'),'class="klee_quiz2">'));
			this.contentsInt.setHTML(this.contentsInt.innerHTML.replace(new RegExp('class="?quiz_accueil"?[>]+', 'gi'),'class="quiz_accueil2">'));
			this.contentsInt.setHTML(this.contentsInt.innerHTML.replace(new RegExp('class="?quiz_voir_aussi"?', 'gi'),'class="quiz_voir_aussi2"'));
			this.contentsInt.setHTML(this.contentsInt.innerHTML.replace(new RegExp('class="?tipafrieiend"?', 'gi'),'class="tipafriend2"'));this.contentsInt.setHTML(this.contentsInt.innerHTML.replace(new RegExp('class="?tipafriend"?', 'gi'),'class="tipafriend2"'));
			this.supph3 = 0;
			if (this.contentsInt.getElement('.video_single')) {
				if(parseInt(this.contentsInt.getElement('.video_single').getElement('h3').getStyle('height'))>=27) {
					this.supph3 = 27;
				}
				if(parseInt(this.contentsInt.getElement('.video_single').getElement('h3').getStyle('height'))>=54) {
					this.supph3 = 54;
				}
			}
			if (this.contentsInt.getElement('.flash_single')) {
				if(parseInt(this.contentsInt.getElement('.flash_single').getElement('h3').getStyle('height'))>=27) {
					this.supph3 = 27;
				}
				if(parseInt(this.contentsInt.getElement('.flash_single').getElement('h3').getStyle('height'))>=54) {
					this.supph3 = 54;
				}
			}
			this.contents.setStyles ({width: this.options.contentsWidth + "px", height: parseInt(this.options.contentsHeight) + "px"});
			this.contentsInt.setStyles ({width: this.options.contentsWidth + "px"});
			if(this.center.clientHeight != this.contents.offsetHeight) {
				this.fx.resize.custom({height: [this.center.clientHeight, this.contents.offsetHeight]});
				break;
			}
			this.step++;
					
		case 2:
			if(this.center.clientWidth != this.contents.offsetWidth) {
				var mywidth = this.contents.offsetWidth;
				mywidth = parseInt(mywidth+52);
				this.left = parseInt((mywidth+52)/2);
				//alert(this.center.clientWidth + ' --> ' + this.contents.offsetWidth);
				this.center.setStyles({width:this.contents.offsetWidth+52+"px",marginLeft:-this.left+"px"});
				//this.fx.contents.custom(0,1);
				//this.fx.resize.custom({width: [this.contents.offsetWidth+"px", this.contents.offsetWidth]+"px", marginLeft: [-this.left+"px"]});
				//break;
			}
			this.step++;
		
		case 3:
			mywidth = this.contents.style.width.split("px");
			//var Mysize = getPageSize();
			//this.center.setStyles({width: (parseInt(mywidth[0])+52)+'px'});
			this.left=this.center.offsetWidth/2;
			this.center.setStyles({marginLeft: -this.left+'px'});
			this.bottom.setStyles({marginLeft: -this.left+'px'});
			this.divtop.setStyles({marginLeft: -this.left+'px'});
			this.bottom.setStyles({height:'26px', top: (26 + this.top + this.center.clientHeight)+'px', width: (parseInt(mywidth[0])+52)+'px', display: ''});
			//this.closelink.setStyles({height: '21px', display: '', opacity: '1'});
			//this.closelink2.setStyles({height: '22px', display: '', opacity: '1'});
			this.center.setStyles({height:this.center.offsetHeight+"px"});
			this.divtop.setStyles({top: this.top+'px', width: (parseInt(mywidth[0])+52)+'px', height:'26px', display: ''});//,opacity: '1'});
			this.center1.setStyles({height:this.center.offsetHeight+'px'});
			this.center2.setStyles({height:this.center.offsetHeight+'px'});
			this.contents.setStyles({visibility:'visible',opacity:'1'});	

			var this2 = this;
			
			setTimeout(function(){
			
			var maxMonmediaH = _MAX_MEDIA_HEIGHT - 22 - this2.supph3;
			var monmedia = this2.center.getElements('.media_content');
			
			/*correctif mboilley pour sarah*/
			if (monmedia == '') {return false;}
			
			var monmediaH = (parseInt(this2.contents.getStyle('height'))-22-this2.supph3);
			var realMediaH = parseInt(monmedia[0].getStyle('height')) + 22;
			
			if(monmediaH > maxMonmediaH){
				monmediaH = maxMonmediaH;
				this2.center.setStyles({height:_MAX_MEDIA_HEIGHT+"px"});			
				this2.center1.setStyles({height:_MAX_MEDIA_HEIGHT+'px'});
				this2.center2.setStyles({height:_MAX_MEDIA_HEIGHT+'px'});
				this2.contents.setStyles({height:_MAX_MEDIA_HEIGHT+'px'});
				this2.bottom.setStyles({height:'26px', top: (26 + this2.top + this2.center.clientHeight)+'px', width: (parseInt(mywidth[0])+52)+'px', display: ''});
			}	

			
			if(realMediaH < monmediaH){
				monmediaH = realMediaH;
				this2.center.setStyles({height:(monmediaH + this2.supph3 + 22)+"px"});			
				this2.center1.setStyles({height:(monmediaH + this2.supph3 + 22)+'px'});
				this2.center2.setStyles({height:(monmediaH + this2.supph3 + 22)+'px'});			
				this2.bottom.setStyles({height:'26px', top: (26 + this2.top + this2.center.clientHeight)+'px', width: (parseInt(mywidth[0])+52)+'px', display: ''});
			}

			//monmedia.setStyles({height:monmediaH+'px',overflowY:'auto'});
			},1);
			
			
			//this.fx.contents.custom(0,1);
			/*
			var this2 = this;
			setTimeout(function(){
				var monmedia = this2.center.getElements('.media_content');
				var monmediaH = monmedia[0].offsetHeight + 22;
				var contentH = parseInt(this2.contents.getStyle('height'));
				if(contentH > 511){
					contentH = 511;
				}
				//Cas popin avec scroll
				if(monmediaH >= 350){
					monmedia.setStyles({height:(contentH-49-this2.supph3)+'px',overflowY:'auto'});
					this2.contents.setStyles({height:(contentH)+"px"});
					this2.center.setStyles({height:(contentH)+"px"});
					this2.center1.setStyles({height:(contentH)+'px'});
					this2.center2.setStyles({height:(contentH)+'px'});
					this2.bottom.setStyles({height:'26px', top: (26 + this2.top + this2.center.clientHeight)+'px', width: (parseInt(mywidth[0])+52)+'px', display: ''});
				}
				//Cas popin sans scroll
				else{
					monmedia.setStyles({height:monmediaH+'px',overflowY:'auto'});	
					this2.center.setStyles({height:(monmediaH + this2.bottom.offsetHeight + this2.divtop.offsetHeight)+"px"});			
					this2.center1.setStyles({height:(monmediaH + this2.bottom.offsetHeight + this2.divtop.offsetHeight)+'px'});
					this2.center2.setStyles({height:(monmediaH + this2.bottom.offsetHeight + this2.divtop.offsetHeight)+'px'});			
					this2.bottom.setStyles({height:'26px', top: (26 + this2.top + this2.center.clientHeight)+'px', width: (parseInt(mywidth[0])+52)+'px', display: ''});
				}
			}			
			,1);	*/		
			break;
		
		case 4:
			if(this.options.animateCaption) {
				//opacity: [0, 1], 
				this.fx.bottom.custom({height: [0, this.bottom.scrollHeight]});
				break;
			}
			this.bottom.setStyles('height',this.bottom.scrollHeight+'px');
			this.divtop.setStyles('height','26px');
		case 5:			
			this.step = 0;
		}
		this.resizeFlash();		
	},
	
	
	this.keyboardListener = function(event) {
		// close the MOOdalBox when the user presses CTRL + W, CTRL + X, ESC
		if ((event.control && event.key == 'w') || (event.control && event.key == 'x') || (event.key == 'esc')) {
			this.close();
			event.stop();
		}		
	}
	
	this.close = function() {
		if(this.step < 0) return;
		this.step = -1;
		for(var f in this.fx) this.fx[f].clearTimer();
		this.center.style.display = this.bottom.style.display = this.divtop.style.display = 'none';
		this.center.className = 'mb_loading';
		this.contentsInt.setHTML('');
		this.fx.overlay.chain(this.setup.pass(false, this)).custom(0);
		if (navigator.appName.toLowerCase() == "microsoft internet explorer") {
			$$('html').setStyle('overflow','auto');
		}
		$$('body').setStyle('overflow','auto');
		
		this.removeCSS();//suppression du css temporaire		
		this.showSWFObject(); //Reaffiche les swf objects
		return false;
	}
	
	//insertion dynamique de css
	this.addCss = function(cssCode) {
		var scriptObj = document.createElement('link');
		scriptObj.type = 'text/css';
		scriptObj.rel = 'stylesheet';
		scriptObj.href = cssCode;
	 
		document.getElementsByTagName("head")[0].appendChild(scriptObj);
	}
	//suppression dynamique de css
	this.removeCSS = function() {
		var cssCode = document.getElementsByTagName("head")[0].lastChild;

		try {
             document.getElementsByTagName("head")[0].removeChild(cssCode);
         } catch (e)
           {
			//suppression moche du css pour ie6
			cssCode.href='';
           } 
	}
	
	this.countMyself = function() {
		// Check to see if the counter has been initialized
		if ( typeof this.counter == 'undefined') {
			// It has not... perform the initilization
			this.counter = 1;
		}
		else this.counter++;
	}
	
	//Reduire la largeur des objets Flash lorsqu'il y a un scrollbar
	this.resizeFlash = function(){
		this.countMyself();
		if(this.counter == (this.options.resizeDuration/100)){			
			divObj = this.center.getElements('.media_content');
			if(divObj.scrollHeight > (this.center.offsetHeight - 49)){
				if(this.center.getElementsByTagName('embed') && navigator.appName.toLowerCase() !== "microsoft internet explorer"){
					var monFlash = this.center.getElementsByTagName('embed');
				}
				else if(this.center.getElementsByTagName('object')){
					var monFlash = this.center.getElementsByTagName('object');
				}
				if(monFlash){
					var monFlashWidth = monFlash[0].width;
					monFlash[0].width = monFlashWidth - 25;
					var flashVars = monFlash[0].getAttribute('flashVars');
					if(flashVars){
						var reg = new RegExp("(width="+ monFlashWidth +")", "g");
						flashVars = flashVars.replace(reg, "width="+ monFlash[0].width);
						monFlash[0].setAttribute('flashVars',flashVars);
					}
					
					//Cas diaporama -> rapport hauteur/largeur fixe
					if(monFlash[0].id.toLowerCase() == "diaporama"){
						var monFlashHeight = monFlash[0].height;
						monFlash[0].height = Math.round(monFlash[0].width * _DIAPO_RATIO_SWF);
					}
				}
			}
		}
	}
	
	//Cache les swf objects
	this.hideSWFObject = function(){
		var listeSWFObj;
		if(this.center.getElementsByTagName('embed') && navigator.appName.toLowerCase() !== "microsoft internet explorer"){
			listeSWFObj = document.getElementsByTagName('embed');
			var monFlash = this.center.getElementsByTagName('embed');
		}
		else if(this.center.getElementsByTagName('object')){
			listeSWFObj = document.getElementsByTagName('object');
			var monFlash = this.center.getElementsByTagName('object');
		}
		if(monFlash && listeSWFObj){
			var curSWF;
			for(var i=0; i<listeSWFObj.length; i++){
				if(listeSWFObj[i]){
					curSWF = listeSWFObj[i];
					if(curSWF.id !== monFlash.id){
						curSWF.style.visibility = "hidden";
					}
				}
			}
		}
	}
	
	//Reaffiche les swf objects
	this.showSWFObject = function(){
		var listeSWFObj;
		if(this.center.getElementsByTagName('embed') && navigator.appName.toLowerCase() !== "microsoft internet explorer"){
			listeSWFObj = document.getElementsByTagName('embed');
			var monFlash = this.center.getElementsByTagName('embed');
		}
		else if(this.center.getElementsByTagName('object')){
			listeSWFObj = document.getElementsByTagName('object');
			var monFlash = this.center.getElementsByTagName('object');
		}
		if(monFlash && listeSWFObj){
			var curSWF;
			for(var i=0; i<listeSWFObj.length; i++){
				if(listeSWFObj[i]){
					curSWF = listeSWFObj[i];
					if(curSWF.id !== monFlash.id){
						curSWF.style.visibility = "visible";
					}
				}
			}
		}
	}
}
//MOOdalBox.implement(new Options(), new Events());

// startup
window.addEvent ('load', function() { MOOdalBox = new funcMOOdalBox();
	MOOdalBox.init(); });
//addLoadEvent(domodal);

/*
var MOOdalBox;
//MOOdalBox.init.bind(MOOdalBox)
Window.onDomReady(MOOdalBox.init.bind(MOOdalBox));
//addLoadEvent(domodal);

function domodal (event) {
	MOOdalBox = new funcMOOdalBox();
	MOOdalBox.init();
	//Window.onDomReady(MOOdalBox.init.bind(MOOdalBox));
//	MOOdalBox.init.bind(MOOdalBox);
}*/

