var clrz_lightbox = new Class({
	Implements: [Options,Events],

	options: {
		closeText:"Fermer",
		containerW:540,
		containerH:415,
		link: '',
		rel: '',
		url: 'wp-content/themes/vetideo/libraries/',
		
		destruct: false
	},
	
	initialize :function(options){
		
		this.setOptions(options);
			
		this.centerW = (window.getHeight()/2)+window.getScrollTop();
		this.containerCenter = (window.getWidth().toInt()/2)-(this.options.containerW/2);
		
		if(this.options.destruct == true)
		{
			this.preDestruct();
			this.divover = $('divover');
			
		}
		else
		{
			this.divover = new Element('div', {'id':'divover','styles': {'cursor':'pointer','display': 'block', 'background-color': 'black','position':'absolute','top':'0px','left':'0px','z-index':1000,'width':window.getWidth(),'margin-top':this.centerW,'opacity':0 }}).inject(document.body,'top');
		}
			

		this.divover_fx = new Fx.Morph(this.divover, {duration: 600, wait: false,transition: Fx.Transitions.Quart.easeInOut});
		
		this.divcontainer = new Element('div', {'id': 'container'+this.options.rel,'class':'clrz_divover','styles': {'z-index':1000,'overflow':'hidden','display': 'block', 'position':'absolute','top':(window.getScrollTop()+80),'left':this.containerCenter,'width':this.options.containerW,'height':this.options.containerH,'opacity':0 }});
			
		this.divcontainer_fx = new Fx.Morph(this.divcontainer, {duration: 600, wait: false,transition: Fx.Transitions.Quart.easeInOut});
		
		this.divcontainer.inject(this.divover,'after');

		this.setup();
	},
	
	preDestruct: function(){
	
		var divovers = $$('.clrz_divover');
		
		divovers.each(function(el,i){
		
			el.setStyle('display','none');
		
		});
	
	},
	
	initClosing: function(){
	
		var myclass = this;
			
		this.divover.addEvent("click",function(e){	
			e = new Event(e).stop();
			myclass.destruct();	
		});
		
		$('btn_close_send_message').addEvent("click",function(e){
			
			e = new Event(e).stop();	
			myclass.destruct();	
		});
	},
	
	setup:function(){
	
		var myclass = this;
		 myclass.letsmoove();	
	
		 
         var myhash = new Hash({'ajax':true});
         var query = myhash.toQueryString();			
         
         
         new Request.HTML({
      	   url: this.options.url, 
      	   data: query, 
      	   method: 'post',
      	   update : myclass.divcontainer,
      	   onComplete : function(e){
        	 myclass.initClosing();

           }
         }).send();	       				
	},
		
	frameloaded:function(){
		
		this.fireEvent('frameloaded');
		
	},
	
	letsmoove : function(){
	
		var myclass = this;
		
		this.divover.setStyle('display','block');
		
		if(myclass.options.destruct == false)
			this.divcontainer.setStyle('display','block');
				
		if(this.options.destruct != true)
		{	
			this.divover_fx.set({'height':window.getScrollHeight(),'margin-top':0,'margin-left':0});	
		

			this.divover_fx.start({'opacity':[0,.8],'width':[0,window.getWidth().toInt()]}).chain(function()
			{

				myclass.divcontainer_fx.start({'opacity':1,'left':[0,myclass.containerCenter],'margin-top':0}).chain(function(){
				myclass.fireEvent('onMoveComplete'); 
			
				});
			
			});
		}
		else
		{
				myclass.divcontainer_fx.start({'opacity':[0,1],'left':[0,myclass.containerCenter],'margin-top':0}).chain(function(){
				myclass.fireEvent('onMoveComplete'); 
			
				});
		}

	
	},
	
	destruct : function(){
		
		
		
		var myclass = this;
		
		var btnClose = $('btn_close_send_message');
		 
		//document.body.setStyle('overflow-x','hidden');
		
		new Fx.Morph(btnClose, {duration: 600, wait: false,transition: Fx.Transitions.Quart.easeInOut}).start().chain(function()
		{
			myclass.divcontainer_fx.start({'opacity':0,'left':window.getWidth().toInt()}).chain(function()
			{
				myclass.divover_fx.start({'width':0,'opacity':0,'margin-left':window.getWidth().toInt()}).chain(function(){ myclass.elreset(); });
			});
		});	
	
	},
	
	elreset : function(){
		//document.body.setStyle('overflow-x','auto');
		this.divover.setStyle('display','none');
		this.divcontainer.setStyle('display','none');
		this.divcontainer.set('html','');
	}

});
