/******************************************************************************************************************
 * @file : window.js***********************************************************************************************
 * @autor : romain lenzotti (Rom makita)***************************************************************************
 * @date : 22/10/2009**********************************************************************************************
 * @version : 1.1**************************************************************************************************
 ******************************************************************************************************************/

/******************************************************************************************************************
 * @Class:AlertBox*************************************************************************************************
 ******************************************************************************************************************
/****V1.2 :
 		- Support des version IE 8, 7(sauf CSS), FF 3.5, 3.0 et Chrome
		- Changement du timer 
/****V1.1 :
 		- suppression de la bibliothèque effect géré par scriptaculous
		- modification de la méthode AlertBox.show() afin que l'appuie sur la touche entré actionne le onSubmit
*******************************************************************************************************************
*****V1.0 :
 		- Suppression du drag'n'drop géré par scriptaculous et ajout des methodes drag'n'drop. La bibliothèque de 
		scriptaculous empechait la selection du texte de la boite de dialogue.
		- lorsque la boite de dialogue est trop grande en hauteur à cause du message, une scrollbar apparait et la 
		taille de la boite de dialogue mesure 80% de la taille max de la fenetre du navigateur
*******************************************************************************************************************
*****V0.9 :
		- le call_back du onClickSubmit peut empecher la methode this.hide() d'etre activé en ajouter en fin de methode 
		return true. Cela permet de corriger le bug d'affichage lors d'appel recursif de l'alert.
*******************************************************************************************************************
*****V0.8 :
		- Gestion automatique de la largeur de la fenetre via CSS
		- Suppression de la methode setWidth()
*******************************************************************************************************************
*****V0.7 :
		- fontTransparent integré directement dans la classe Alert
		- fichier CSS refait
		- Gestion des evenements revue
		- Construction de la boite de diolague en div (et non en tableau)
		- ajout de l'effet d'apparition GROWL
		- Customisation facilité
		- Ajout d'un fichier index.php comme exemple d'utilisation de la classe Alert
		- Correctiond du drag'n'drop afin que l'alert ne depasse pas de la fenetre
		- Ajout des methodes onSnap(), onShow(), onClickSubmit(), onClickReset(), positionWindow()
		setOnSubmit() et setOnReset().
		- modification de l'ensemble des methodes.
*******************************************************************************************************************
*****V0.6 : 
		- ajout des methodes setResponder() et loading()
		- correction des paramètres d'entrés pour Alert.show(), pour affecter une fonction utiliser setResponder()
		- plus de disparition de la boite de dialogue lorsque l'on clique sur le font noir transparent
*******************************************************************************************************************
*****V0.5 : 
		- Ajout des methodes inputBox() et onKeyPress()
*******************************************************************************************************************
*****V0.4 :
		- Ajout de la methode wait()
*******************************************************************************************************************
*****V0.x : 
		- creation de la classe Alert
		- dissociation de la classe Alert de la classe main
*******************************************************************************************************************/
var alertBox = Class.create();

alertBox.prototype = {
	height: "auto",
	onSubmit:"",
	onReset:'',
	x:0,
	y:0,
	///conteneur---------------------------------------------------------------------------------------------
	div_alert:'',
	background:'',
	bar_header:'',
	title:'',
	btn_close:'',
	win_corps:'',
	div_bottom:'',
	btn_ok:'',
	btn_cancel:'',
	input_search:'',
	isShow: false,
	//--------------------------------------------------------------------------------------------------------
	//Constructeur--------------------------------------------------------------------------------------------
	//--------------------------------------------------------------------------------------------------------
	initialize: function(mybody, background){
		
		this.background = background;
		
		this.div_alert = 	$(Builder.node('div', {className:'window w-alert'}));
		this.bar_header = 	$(Builder.node('div', {className:'win-header h-alert'}));
		this.title = 		$(Builder.node('div', {className:'win-title t-alert'}, 'title'));
		this.btn_close = 	$(Builder.node('div', {className:'win-close c-alert'}));
		this.win_corps = 	$(Builder.node('div', {className:'win-corps co-alert'})); 
		this.div_bottom = 	$(Builder.node('div', {className:'win-btn-b btn-b-alert'}));
		this.div_btn = 		$(Builder.node('div', {className:'cont-nav-btn'}));

		//build alert-----------------------------------------
		this.bar_header.appendChild(this.title);
		this.bar_header.appendChild(this.btn_close);
		this.div_alert.appendChild(this.bar_header);
		this.div_alert.appendChild(this.win_corps);
		this.div_alert.appendChild(this.div_bottom);
		this.div_bottom.appendChild(this.div_btn);

		mybody.appendChild(this.div_alert);

	
		//this.drag = new Draggable(this.div_alert,{snap:(this.onSnap).bind(this)});
		this.ondrag_mousedown = this.onDrag_MouseDown.bindAsEventListener(this);
		Event.observe(this.bar_header, 'mousedown', this.ondrag_mousedown);
		
		Event.observe(this.btn_close, 'click', (function(evt){Event.stop(evt); this.hide()}).bind(this));
		//Event.observe(this.win_corps, 'mousedown', function(evt){Draggables.unregister(sender.drag);});
		//Event.observe(this.win_corps,'mouseup', function(evt){Draggables.register(sender.drag)});

		this.hide();
	},
	//--------------------------------------------------------------------------------------------------------
	//Methods-------------------------------------------------------------------------------------------------
	//--------------------------------------------------------------------------------------------------------
	/**
	 * @brief : ouvre une boite de dialogue avec un champs texte
	 * @param[in] title : le titre de la boite de dialogue
	 * @param[in] text : le texte avant le champs input
	 */
	inputBox:function(title, text){
		
		if(title == undefined) title = 'Rechercher...';
		
		this.input_search = $(Builder.node('input', {className:"input-alert", type:'text'}));
		
		var elem = Builder.node('div');
		if(text != undefined) elem.innerHTML = text;
		elem.appendChild(this.input_search);
				
		this.show(title, elem,'SEARCH');
		
	},
	/**
	 * @brief: ouvre une boite de dialogue
	 * @param[in] strTitre : le titre de la fenetre
	 * @param[in] strText : le texte HTML à afficher dans la boite de dialogue
	 * @param[in] mode : type de boite (OK, SEARCH, CLOSE, O/N)
	 */
	show: function(strTitle, strText, mode){
		this.remove();
		$(this.div_bottom).show();
		if(strTitle == undefined) this.title.innerHTML = '';
		else this.title.innerHTML = strTitle;
		
		if(Object.isElement(strText)) this.win_corps.appendChild(strText);
		else if(Object.isString(strText) && strText != undefined) this.win_corps.innerHTML = strText;
		else this.win_corps.innerHTML = '';
		
		var inputs = this.win_corps.getElementsByTagName('input');
		
		for(var i = 0; i < inputs.length; i++){
			
			if(inputs[i].type == 'text' || inputs[i].type == 'password') $(inputs[i]).observe('keyup', this.onKeyPress.bind(this));
			
		}
		
		this.btn_ok = 		$(Builder.node('div', {className:'nav-ok nav-btn', id:'nav-ok'}, 'Ok')); 
		this.btn_reset = 	$(Builder.node('div', {className:'nav-reset nav-btn', id:'nav-reset'}, 'Annuler')); 
		
		this.div_btn.appendChild(this.btn_ok);
		this.div_btn.appendChild(this.btn_reset);
		
		this.onclick_submit = 	this.onClickSubmit.bindAsEventListener(this);
		this.onclick_reset = 	this.onClickReset.bindAsEventListener(this);
		
		Event.observe(this.btn_ok, 'click', this.onclick_submit);
		Event.observe(this.btn_reset, 'click', this.onclick_reset);
		Event.observe(this.btn_ok, 'mousedown', function(evt){evt.stop();});
		Event.observe(this.btn_reset, 'mousedown', function(evt){evt.stop();});
		
		switch(mode){
			case 'OK': 		this.btn_reset.hide();
							this.btn_ok.show();
							break;
							
			case 'SEARCH':	this.btn_reset.show();
							this.btn_ok.show();
							
							this.btn_ok.innerHTML = 'Rechercher';
							break;
			
			case 'INFO' :
			case 'CLOSE':	this.btn_reset.show();
							this.btn_ok.hide();
							
							this.btn_reset.innerHTML = 'Fermer';
							break;
							
			case 'Y/N': 	this.btn_reset.show();
							this.btn_ok.show();
							this.btn_ok.innerHTML = 'Oui';
							this.btn_reset.innerHTML = 'Non';
			default:
			case 'O/N':		this.btn_reset.show();
							this.btn_ok.show();
							break;
		}

		this.positionWindow();
		this.onShow();
	},
	/**
	 * @brief : fait disparaitre la boite de dialogue
	 */
	hide: function(){
		try{	
			Event.stopObserving(this.btn_ok, 'click', this.onclick_submit);
			Event.stopObserving(this.btn_reset, 'click', this.onclick_reset);
			Event.stopObserving(this.input_search,"keypress",  this.on_keypress);
		}catch(evt){}
		
		this.background.hide();
		this.div_alert.hide();
		this.remove();
		this.onSubmit = '';
		this.onReset = '';
		this.isShow = false;
	},
	remove:function(){
		this.title.innerHTML = '';
		this.div_btn.innerHTML = '';
		this.win_corps.innerHTML ='';
	},
	/**
	 * @brief : ouvre une boite de dialogue de type chargement
	 */
	loading:function(){
		this.div_bottom.hide();
		this.title.innerHTML = 'Chargement...';	
		this.win_corps.innerHTML = "<center>Chargement en cours...</center>";
		
		var loader = Builder.node('div', {className:"alert-loader"});
		this.win_corps.appendChild(loader);
		
		this.positionWindow();
		this.onShow();
		
	},
	/** 
	 * @brief : ouvre une boite de type chargement, traitement de l'operation en cours
	 */
	wait:function(){
		this.div_bottom.hide();
		this.title.innerHTML = 'En attente...';				
		this.win_corps.innerHTML = "<center>Op&eacute;ration en cours de traitement</center>";
		
		var loader = Builder.node('div', {className:"alert-loader"});
		this.win_corps.appendChild(loader);
		
		this.positionWindow();
		this.onShow();
		
	},
	/**
	 * @brief: special credit
	 */
	info:function(){
		this.div_bottom.hide();
		var title = 'A propos de...';
		var text = '<b>D&eacute;velopper par :</b> Lenzotti Romain<br /><b>Version :</b> 1.2<br /><b>Date :</b> 26/07/2009<br /><b>Framework :</b> <a href="http://prototypejs.org">Prototype.js</a>, <a href="http://script.aculo.us">scriptaculous.js</a>'
		
		this.show(title, text, 'INFO');
	},
	/**
	 * @brief : creer une progressbar paramètrable dans une boite de dialogue
	 */
	progressBar: function(start, maximum, message){
		this.div_bottom.hide();
		this.title.innerHTML = 'Chargement...';	
		
		this.win_corps.innerHTML = '<div class="win-mask-pr"><div class="win-progress" id="win-pr"></div></div><div class="win-message-pr" >'+message+'</div>';
		var pourcent = Math.round((start / maximum)* 100);

		$('win-pr').style.width = pourcent + "%";
		this.positionWindow();
		this.onShow()
	},

	//--------------------------------------------------------------------------------------------------------
	//Private-------------------------------------------------------------------------------------------------
	//--------------------------------------------------------------------------------------------------------
	onClickSubmit: function(evt){
		evt.stop();
		if(Object.isFunction(this.onSubmit)) 
			if(this.onSubmit.call('', evt, this.input_search)) return;
		this.hide();
	},
	
	onClickReset: function(evt){
		evt.stop();
		if(Object.isFunction(this.onReset)) this.onReset.call('', evt);
		this.hide();
	},
	/** 
	 * @brief : evenement liés aux inputs succeptibles d'etre dans la boite de dialogue
	 */
	onKeyPress: function(evt){
		if(evt.keyCode != 13) return;
		this.onClickSubmit(evt);
	},
	
	onShow: function(){
		if(this.isShow) return;
		this.background.show();
		this.div_alert.show();
		this.isShow = true;
	},
	
	onDrag_MouseDown: function(evt){
		Event.stop(evt);
		
		this.ondrag_mousemove = this.onDrag_MouseMove.bindAsEventListener(this);
		this.ondrag_mouseup = 	this.onDrag_MouseUp.bindAsEventListener(this);
		
		Event.observe(document, 'mousemove', this.ondrag_mousemove);
		Event.observe(document, 'mouseup', this.ondrag_mouseup);
		
		this.div_alert.setOpacity(0.7);
		
		this.decalX = Event.pointerX(evt) - this.x;
		this.decalY = Event.pointerY(evt) - this.y;
		
	},
	
	onDrag_MouseMove: function(evt){
		
		
		this.x = Event.pointerX(evt) - this.decalX;
		this.y = Event.pointerY(evt) - this.decalY;

		if(this.x < 0) this.x = 0;
		if(this.x + Element.getDimensions(this.div_alert).width > document.stage.stageWidth) this.x = document.stage.stageWidth - Element.getDimensions(this.div_alert).width;
		if(this.y < 0) this.y = 0;
		if(this.y + Element.getDimensions(this.div_alert).height > document.stage.stageHeight) this.y = document.stage.stageHeight - Element.getDimensions(this.div_alert).height;
		
		this.div_alert.setStyle({left:this.x +'px', top:this.y+'px'});
	},
	
	onDrag_MouseUp: function(evt){

		Event.stop(evt);
			
		Event.stopObserving(document, 'mousemove', this.ondrag_mousemove);
		Event.stopObserving(document, 'mouseup', this.ondrag_mouseup);
		
		this.div_alert.setOpacity(1);
	},
	
	positionWindow: function(){
		
		if(Element.getDimensions(this.div_alert).height > document.stage.stageHeight){
			this.win_corps.setStyle({overflowY:'scroll', height: (document.stage.stageHeight * 80 /100)+'px'});

		}else{
			this.win_corps.setStyle({overflowY:'auto', height: 'auto'});
		}
		this.div_alert.setStyle({top:"0px",left:"0px"});
		this.x = ((document.stage.stageWidth - Element.getDimensions(this.div_alert).width) / 2);
		this.div_alert.style.left = this.x + "px";
		this.y = ((document.stage.stageHeight - Element.getDimensions(this.div_alert).height) / 2);
		this.div_alert.style.top = this.y + "px";
	},
	//--------------------------------------------------------------------------------------------------------
	//Setteurs & Getteurs-------------------------------------------------------------------------------------
	//--------------------------------------------------------------------------------------------------------
	setProgress: function(start, maximum, message){
		this.title.innerHTML = 'Chargement...';	
		
		this.win_corps.innerHTML = '<div class="win-mask-pr"><div class="win-progress" id="win-pr"></div></div><div class="win-message-pr" >'+message+'</div>';

		var pourcent = Math.round((start / maximum)* 100);

		$('win-pr').style.width = pourcent + "%";
	},
	/**
	 * @brief: assigne les fonctions de retour après validation de la boite de dialogue
	 * @param[in] fn : function de si le bouton 'valider' est actif
	 * @param[in] fnreset : function en cas d'echec ou d'annulation
	 */
	setResponder:function(fn, fnreset){
		if(fn != undefined) this.onSubmit = fn;
		if(fnreset != undefined) this.onReset = fnreset;
	},
	setOnSubmit: function(fn){
		if(fn != undefined) this.onSubmit = fn;
	},
	setOnReset: function(fnreset){
		if(fnreset != undefined) this.onReset = fnreset;
	}
}
/******************************************************************************************************************
 @Class : Bubble***************************************************************************************************
 ******************************************************************************************************************/
/****V0.2 :	- Suppression des ID
 ******************************************************************************************************************
 ****V0.1 :	- Creation de la classe Bubble
 ******************************************************************************************************************/
var bubble = Class.create();
bubble.prototype = {
	div_bubble:'',
	timer:'',
	periodicalClean:4,
	//--------------------------------------------------------------------------------------------------------
	//Constructeur--------------------------------------------------------------------------------------------
	//--------------------------------------------------------------------------------------------------------
	initialize:function(mybody){
		
		this.div_bubble = $(Builder.node('div', {className:'div-bubble'}));
		mybody.appendChild(this.div_bubble);
		
		this.div_bubble.hide();
		
		this.timer = new Timer((this.hide).bind(this), this.periodicalClean);
		
	},
	//--------------------------------------------------------------------------------------------------------
	//Methods-------------------------------------------------------------------------------------------------
	//--------------------------------------------------------------------------------------------------------
	show:function(event, textHTML){

		this.timer.stop();
		this.div_bubble.innerHTML = textHTML;
		
		var dim = Element.getDimensions(this.div_bubble);
		var pos = {top:Event.pointerY(event)+20, left: Event.pointerX(event)+20};
		
		if(Event.pointerX(event) + dim.width > document.viewport.getDimensions().width){
			pos.left = document.viewport.getDimensions().width - dim.width - 20;
		}
		if(Event.pointerY(event) + dim.height > document.viewport.getDimensions().height - 20){
			pos.top = document.viewport.getDimensions().height - dim.height - 20;
		}
		this.div_bubble.setStyle({top: pos.top + "px", left: pos.left + "px"});
		this.div_bubble.show();
		//this.div_bubble.appear({duration:0.3});


		this.timer.start();
	},

	hide:function(){
		this.div_bubble.hide();
		this.timer.stop();
	}
}
/******************************************************************************************************************
 @Class : SlideWindow********************************************************************************************
 ******************************************************************************************************************/
/****V0.1 :	- Creation de la classe SlideWindow
 ******************************************************************************************************************/
var slidewindow = Class.create();
slidewindow.prototype = {
	x:0,
	y:0,
	duration:1,
	frequency:0.05,
	pas:2,

	///conteneur---------------------------------------------------------------------------------------------
	div_content:'',
	div_header:'',
	div_title:'',
	div_close:'',
	div_corps:'',
	div_bottom:'',
	//callback------------------------------------------------------------------------------------------------
	afterShow: '',
	//--------------------------------------------------------------------------------------------------------
	//Constructeur--------------------------------------------------------------------------------------------
	//--------------------------------------------------------------------------------------------------------
	initialize: function(mybody){
		
		this.div_content = 	$(Builder.node('div', {className:'window w-slide'}));
		this.div_header = 	$(Builder.node('div', {className:'win-header h-slide'}));
		this.div_title = 	$(Builder.node('div', {className:'win-title t-slide'}, 'title'));
		this.div_close = 	$(Builder.node('div', {className:'win-close c-slide'}));
		this.div_corps = 	$(Builder.node('div', {className:'win-corps co-slide'})); 
		this.div_bottom = 	$(Builder.node('div', {className:'win-btn-b btn-b-slide'}));
		

		//build alert-----------------------------------------
		this.div_header.appendChild(this.div_title);
		this.div_header.appendChild(this.div_close);
		this.div_content.appendChild(this.div_header);
		this.div_content.appendChild(this.div_corps);
		this.div_content.appendChild(this.div_bottom);

		mybody.appendChild(this.div_content);
		
		Event.observe(this.div_close, 'click', (function(evt){Event.stop(evt); this.hide()}).bind(this));
		
		this.div_content.hide();
		
		this.height = 0;
		
		

		//timer
		this.timerOpen = new Timer(this.onClock_Tick_Show.bind(this), this.frequency);
		this.timerClose = new Timer(this.onClock_Tick_Hide.bind(this), this.frequency);
	},
	//--------------------------------------------------------------------------------------------------------
	//Methods-------------------------------------------------------------------------------------------------
	//--------------------------------------------------------------------------------------------------------
	show: function(mode){

		this.timerOpen.stop();
		this.timerClose.stop();
		
		this.mode = mode;
		switch(mode){
			default:
			case 'up':
				this.div_content.setStyle({top:'0px', bottom:'auto', height:'0%'});
				break;
			case 'down':
				this.div_content.setStyle({top:'auto', bottom:'-2px', height:'0%'});
		}
				
		this.div_content.show();
		
		this.div_header.hide();
		this.div_corps.hide();
		this.div_bottom.hide();

		var tick = this.duration / this.frequency;
		this.heightAdd = 100 / tick;
		
		
		this.timerOpen.start();
	},
	hide: function(){
		this.timerOpen.stop();
		this.timerClose.stop();
		
		this.div_header.hide();
		this.div_corps.hide();
		this.div_bottom.hide();
		
		this.div_corps.innerHTML = '';
		this.div_title.innerHTML = 'title';
		this.removeFooterElement();
		
		this.timerClose.start();
	},
	onClock_Tick_Show: function(){
		this.timerOpen.stop();
		
		if(this.height < 100){
			
			this.height += this.heightAdd;
			this.div_content.setStyle({height: this.height + "%"});
			this.timerOpen.start();
			return;
		}
		
		this.div_content.setStyle({height: "100%"});
		
		this.height = 100;
		
		this.div_header.show();
		this.div_corps.show();
		this.div_bottom.show();
		
		var height = document.stage.stageHeight - Element.positionedOffset(this.div_corps).top * 2 - Element.getDimensions(this.div_bottom).height;
		this.div_corps.setStyle({height: (height)+'px'});
		
		if(Element.getDimensions(this.div_corps).height > document.stage.stageHeight){

			this.div_corps.setStyle({overflowY:'scroll', height: (height)+'px'});

		}else{
			this.div_corps.setStyle({overflowY:'auto'});
		}
		
		if(Object.isFunction(this.afterShow)){
			this.afterShow.call('', this);
			this.afterShow = '';
		}
	},
	onClock_Tick_Hide: function(pe){

		this.timerClose.stop();
		
		if(this.height > 0){
			
			this.height -= this.heightAdd;
			this.div_content.setStyle({height: this.height + "%"});
			this.timerClose.start();
			return;
		}
		
		this.div_content.hide();
		this.div_content.setStyle({height: "0%"});
		this.height = 0;

		if(Object.isFunction(this.afterHide)) {
			this.afterHide.call('', this);
			this.afterHide ='';
		}
	},
	//--------------------------------------------------------------------------------------------------------
	//setteurs & Getteurs-------------------------------------------------------------------------------------
	//--------------------------------------------------------------------------------------------------------
	setTitle:function(elem){
		if(Object.isElement(elem)) 	this.div_title.appendChild(elem);
		if(Object.isString(elem))	this.div_title.innerHTML = elem;
	},
	setFooterElement:function(elem){
		if(Object.isElement(elem)) 	this.div_bottom.appendChild(elem);
		if(Object.isString(elem))	this.div_bottom.innerHTML = elem;
	},
	getDimensions: function(){
		return this.div_corps.getDimensions();
	},
	removeFooterElement:function(){
		this.div_bottom.innerHTML = '';
	},
	appendChild: function(elem){
		if(Object.isElement(elem)) 	this.div_corps.appendChild(elem);
		if(Object.isString(elem))  	this.div_corps.innerHTML = elem;
	},
	removeChild: function(elem){
		if(Object.isElement(elem)) 	this.div_corps.removeChild(elem);
		if(Object.isString(elem))  	this.div_corps.innerHTML = '';
	},
	setAfterShow: function(fn){
		this.afterShow = fn;
	},
	setAfterHide: function(fn){
		this.afterHide = fn;
	},
	setDuration: function(t){
		this.duration = t;
	},
	className: function(className){
		this.div_content.className += " "+className;	
	}
}
/******************************************************************************************************************
 @Class : Window***************************************************************************************************
 ******************************************************************************************************************/
/****V0.1 :	- Creation de la classe Bubble
 ******************************************************************************************************************/
/*var windows = Class.create();
var Windows = '';

windows.prototype = {
	decalageTop: 0,
	decalageLeft: 0,
	onSubmit:"",
	onReset:'',
	loading_path: 'sources/loading.gif',
	drag: '',
	///conteneur---------------------------------------------------------------------------------------------
	div_alert:'',
	background:'',
	bar_header:'',
	title:'',
	btn_close:'',
	win_corps:'',
	div_bottom:'',
	btn_ok:'',
	btn_cancel:'',
	input_search:'',
	//--------------------------------------------------------------------------------------------------------
	//Constructeur--------------------------------------------------------------------------------------------
	//--------------------------------------------------------------------------------------------------------
	initialize: function(mybody){
				
		this.background = Builder.node('div', {id:"fontTransparent"});
		
		this.div_alert = Builder.node('div', {className:'window w-win', id:"w-win"});
		this.bar_header = Builder.node('div', {className:'win-header', id:'h-win'});
		this.menu = Builder.node('div', {className:'win-menu', id:'m-win'});
		this.title = Builder.node('div', {className:'win-title t-win', id:'t-win'}, 'window title');
		this.btn_close = Builder.node('div', {className:'win-close c-win', id:'c-win'});
		this.btn_switch = Builder.node('div', {className:'win-switch s-win', id:'s-win'});
		this.win_corps = Builder.node('div', {className:'win-corps co-win', id:'co-win'}); 
		this.div_bottom = Builder.node('div', {className:'win-btn-b btn-b-win', id:'btn-b'});
		this.div_btn = Builder.node('div', {className:'cont-nav-btn'});
		
		//build window-----------------------------------------
		this.bar_header.appendChild(this.title);
		this.bar_header.appendChild(this.btn_close);
		this.bar_header.appendChild(this.btn_switch);
		this.div_alert.appendChild(this.bar_header);
		this.div_alert.appendChild(this.menu);
		this.div_alert.appendChild(this.win_corps);
		this.div_alert.appendChild(this.div_bottom);
		this.div_bottom.appendChild(this.div_btn);
		
		//mybody.appendChild(this.background);
		mybody.appendChild(this.div_alert);

		var sender = this;
		
		this.drag = new Draggable(this.div_alert,{snap:(this.onSnap).bind(this)});
		Event.observe(this.btn_close, 'click', function(evt){evt.stop(); sender.hide()});
		Event.observe(this.win_corps, 'mousedown', function(evt){Draggables.unregister(sender.drag);});
		Event.observe(this.win_corps,'mouseup', function(evt){Draggables.register(sender.drag)});
		this.stage = document.viewport.getDimensions();
	
	///teste
		var ul = Builder.node('ul');
		var li = Builder.node('li');
		var span = Builder.node('span',{className:"hide"},'File');
		var ulss = Builder.node('ul', {className:'ul-win'});
		var liss = Builder.node('li',[Builder.node('a', {href:"#", onclick:'alert("ici")'}, 'ssmenu'),Builder.node('a', {href:"#", onclick:'alert("ici")'}, 'ssmenu'),Builder.node('a', {href:"#", onclick:'alert("ici")'}, 'ssmenu')]);
		
		ul.appendChild(li);
		li.appendChild(span);
		li.appendChild(ulss);
		ulss.appendChild(liss);
		
		this.menu.appendChild(ul);
		
		var ul1 = Builder.node('ul');
		var li1 = Builder.node('li');
		var span1 = Builder.node('span',{className:"hide"},'Edit');
		var ulss1 = Builder.node('ul', {className:'ul-win'});
		var liss1 = Builder.node('li',[Builder.node('a', {href:"#", onclick:'alert("ici")'}, 'ssmenu')]);
		
		ul1.appendChild(li1);
		li1.appendChild(span1);
		li1.appendChild(ulss1);
		ulss1.appendChild(liss1);
		
		this.menu.appendChild(ul1);
		//this.hide();
		//this.background.setOpacity(0.8);
	},
	//--------------------------------------------------------------------------------------------------------
	//Methods-------------------------------------------------------------------------------------------------
	//--------------------------------------------------------------------------------------------------------
	/** 
	 * @brief : gestion du drag 'n' drop
	 */
	/*onSnap: function(x, y, draggable){
		
		var height = this.stage.height - Element.getHeight(this.div_alert);
		var width = this.stage.width - Element.getWidth(this.div_alert) + 5;
		
		if(x < 0 && y <0) return[0,0];
		if(x < 0) {
			if(y > height) return [0, height];
			return [0, y];
		}
		if(y < 0){
			if(x > width) return [width, 0];
			return [x, 0];
		}
		
		if(x > width && y > height) 
			return [width, height];
			
		if(x > width) return [width, y];
		if(y > height) return [x, height];
		return [x, y];
	},

	/**
	 * @brief: ouvre une boite de dialogue
	 * @param[in] strTitre : le titre de la fenetre
	 * @param[in] strText : le texte HTML à afficher dans la boite de dialogue
	 * @param[in] mode : type de boite (OK, SEARCH, CLOSE, O/N)
	 */
	/*show: function(strTitle, strText, mode){
		this.remove();
		
		if(strTitle == undefined) this.title.innerHTML = '';
		else this.title.innerHTML = strTitle;
		
		if(Object.isElement(strText)) this.win_corps.appendChild(strText);
		else if(Object.isString(strText) && strText != undefined) this.win_corps.innerHTML = strText;
		else this.win_corps.innerHTML = '';
	
		
		this.btn_ok = Builder.node('div', {className:'nav-ok nav-btn', id:'nav-ok'}, 'Ok'); 
		this.btn_reset = Builder.node('div', {className:'nav-reset nav-btn', id:'nav-reset'}, 'Annuler'); 
		
		
		
		this.div_btn.appendChild(this.btn_ok);
		this.div_btn.appendChild(this.btn_reset);
		
		this.onclick_submit = this.onClickSubmit.bindAsEventListener(this);
		this.onclick_reset = this.onClickReset.bindAsEventListener(this);
		
		Event.observe(this.btn_ok, 'click', this.onclick_submit);
		Event.observe(this.btn_reset, 'click', this.onclick_reset);
		Event.observe(this.btn_ok, 'mousedown', function(evt){evt.stop();});
		Event.observe(this.btn_reset, 'mousedown', function(evt){evt.stop();});
		
		switch(mode){
			case 'OK': 		this.btn_reset.hide();
							this.btn_ok.show();
							break;
							
			case 'SEARCH':	this.btn_reset.show();
							this.btn_ok.show();
							
							this.btn_ok.innerHTML = 'Rechercher';
							break;
			
			case 'INFO' :
			case 'CLOSE':	this.btn_reset.show();
							this.btn_ok.hide();
							
							this.btn_reset.innerHTML = 'Fermer';
							break;
							
			case 'Y/N': 	this.btn_reset.show();
							this.btn_ok.show();
							this.btn_ok.innerHTML = 'Oui';
							this.btn_reset.innerHTML = 'Non';
			default:
			case 'O/N':		this.btn_reset.show();
							this.btn_ok.show();
							break;
		}

		this.positionWindow();
		this.onShow();
	},
	
	onClickSubmit: function(evt){
		evt.stop();
		if(Object.isFunction(this.onSubmit)) this.onSubmit.call('', evt, this.input_search.value);
		this.hide();
	},
	
	onClickReset: function(evt){
		evt.stop();
		if(Object.isFunction(this.onReset)) this.onReset.call('', evt);
		this.hide();
	},
	
	onShow: function(){
		this.background.show();
		this.div_alert.hide();
		new Effect.Appear(this.div_alert,{duration: 0.3});
	},
	positionWindow: function(){
		this.div_alert.style.left = (((document.viewport.getWidth() - this.div_alert.getWidth()) /2)- this.decalageLeft) + "px";
		this.div_alert.style.top = (((document.viewport.getHeight() - this.div_alert.getHeight()) /2) - this.decalageTop) + "px";
	},
	/**
	 * @brief : fait disparaitre la boite de dialogue
	 */
	/*hide: function(){
		try{	
			Event.stopObserving(this.btn_ok, 'click', this.onclick_submit);
			Event.stopObserving(this.btn_reset, 'click', this.onclick_reset);
			Event.stopObserving(this.input_search,"keypress",  this.on_keypress);
		}catch(evt){}
		
		this.background.hide();
		this.div_alert.hide();
		this.remove();
		this.onSubmit = '';
		this.onReset = '';
	},
	remove:function(){
		this.title.innerHTML = '';
		this.div_btn.innerHTML = '';
		this.win_corps.innerHTML ='';
	},
	
	//--------------------------------------------------------------------------------------------------------
	//Setteurs & Getteurs-------------------------------------------------------------------------------------
	//--------------------------------------------------------------------------------------------------------
	/**
	 * @brief: assigne les fonctions de retour après validation de la boite de dialogue
	 * @param[in] fn : function de si le bouton 'valider' est actif
	 * @param[in] fnreset : function en cas d'echec ou d'annulation
	 */
	/*setResponder:function(fn, fnreset){
		if(fn != undefined) this.onSubmit = fn;
		if(fnreset != undefined) this.onReset = fnreset;
	},
	setOnSubmit: function(fn){
		if(fn != undefined) this.onSubmit = fn;
	},
	setOnReset: function(fnreset){
		if(fnreset != undefined) this.onReset = fnreset;
	}*/
/*}*/
