if(typeof PG_dhtml_v3 == "undefined"){
	var LS_PG_dhtml_v3_obj = new Array();
	var PG_dhtml_v3 = function (conf,template){
		this.conf 		= conf;
		this.template 	= template;
		this.baseZindex = 2000;
		this.FirstTime = true;
		this.isStart = false;
		this.init();
	};
	PG_dhtml_v3.prototype = {
		init : function(){
			this.id 				= LS_PG_dhtml_v3_obj.length;
			this.conf.id 			= this.id;
			
			this.conf_check();
			jQuery(document).bind('ready', {self:this}, function(e){
			    e.data.self.html();		
			});
		},
		conf_check : function(){
			this.div_name 			= "pg_dhtml_v3_"+this.id;
			this.div_contener_name 	= "pg_dhtml_v3_"+this.id+"_contener";
			this.conf.click_classname 	= "pg_dhtml_v3_"+this.id+"_click";
			
			this.cont_form 			= 'pg_dhtml_v3_'+this.id+'_form';
			this.conf.form_haut		= '<form action="'+this.conf.form_submit+'" method="post" id="'+this.cont_form+'" target="_blank">';
			this.cont_email 		= 'pg_dhtml_v3_'+this.id+'_email';
			this.conf.email_input 	= '<input type="text" name="pg_mail" value="'+this.conf.email_defaut+'" id="'+this.cont_email+'">';
			this.conf.form_bas  	= this.conf.form_hidden+'</form>';
			
			this.conf.close_link 	= '<a class="pg_dhtml_v3_close_a'+this.id+'">';
			
			this.div_voile_name 	= "pg_box_v3_"+this.id+"_voile";
			
			this.blink_cfg = {email : this.conf.email_defaut};
			if(KeyExists(this.conf,'blink_color')){
				this.blink_cfg.highlight = this.conf.blink_color;
			}
			if(!KeyExists(this.conf,'exit_mode')){
				this.exit_mode = 1;
			}
			
			this.conf.flash_index	= this.baseZindex+2;
			this.conf.flash_index_c	= this.baseZindex+3;
			this.conf.main_index	= this.baseZindex;
			this.conf.bg_index		= this.baseZindex+1;
			this.conf.content_index		= this.baseZindex+4;
			this.conf.close_index		= this.baseZindex+20;
		},
		html : function(){
			if(this.FirstTime){
				this.FirstTime = false;
				if(this.exit_mode == 1) jQuery('body').prepend('<div id="'+this.div_contener_name+'_exit"></div>');
				jQuery('body').prepend('<div id="'+this.div_contener_name+'"><div id="'+this.div_name+'"></div></div>');
				
				this.contener 	= jQuery("#"+this.div_contener_name);
				this.div 		= jQuery("#"+this.div_name);
				this.push 		= jQuery("#"+this.div_push_name);
				
				this.template = this.template.replace("#close#",'pg_dhtml_v3_close_a'+this.id);
				this.contener.append(jQuery.template(this.template),this.conf);
				
				this.contener.css( { 
							position 	: 'absolute',
							height 		: this.conf.height+"px",
							width 		: this.conf.width+"px",
							overflow 	: 'hidden',
							zIndex		: this.baseZindex + LS_PG_dhtml_v3_obj.length 
				} ).hide();
				
				
				this.moveTo( this.getStartX(), this.getStartY() );
				
				if(KeyExists(this.conf,'voile') && this.conf.voile==1){
					jQuery('body').prepend( '<div id="'+this.div_voile_name+'"></div>'		);	
					
					this.voile 		= jQuery( "#"+this.div_voile_name );
					this.voile.hide().css ( 
						{	
							backgroundColor	: '#000',
							width			: jQuery(window).width()+"px",
							height			: jQuery(window).height()+"px",
							position 		: 'absolute',
							top				: 0,
							left			: 0,
							zIndex			: this.baseZindex-1
						}
					);
					this.voile.bind( 'click', {self:this}, function (e){
						 e.data.self.close();
					});
				}
				
				
				jQuery(window).bind	( 'scroll resize', 	{self:this}, function(e) {	e.data.self.scroll();		});
				
				
				jQuery('.pg_dhtml_v3_close_a'+this.id)
					.bind('click',{self:this},function(e){			
						e.data.self.close();
					}).css('cursor','pointer');
				
					
				
					/*correction css*/
				jQuery("#pg_dhtml"+this.conf.template+"_js"+this.id+"  .submit input")
				.css({'height':'auto'});
			}
			
		},
		start : function(){	
			this.isStart = true;
			/*affichage du voile*/
			if(KeyExists(this.conf,'voile',1)){ 
				this.voile.fadeOut(0);
				if(KeyExists(this.conf,'delay') && this.conf.delay>0){ 
					this.voile.idle(this.conf.delay)
				}
				if(KeyExists(this.conf,'vfade',1)){
					this.voile.fadeTo(parseInt(this.conf.fade_vtime),this.conf.fade_vopacity); 
				}else{
					this.voile.qshow().fadeTo(0,this.conf.fade_vopacity); 
				}
			}
			
			if(KeyExists(this.conf,'delay') && this.conf.delay>0){ 
				this.contener.idle(this.conf.delay);
			}
			/*affichage de la pop*/
			if(KeyExists(this.conf,'fade',1)){	
				this.contener.fadeOut(0).fadeIn(parseInt(this.conf.fade_time));
			}else{
				this.contener.qshow();
			}
		},
		close : function(){		
			if( KeyExists(this.conf,'voile',1) ){ 
				if(KeyExists(this.conf,'vfade',1)){ 
					this.voile.fadeOut(parseInt(this.conf.fade_vtime)); 
				}else{
					this.voile.hide();
				}
			}
			if(KeyExists(this.conf,'fade',1)){		
				this.contener.fadeOut(this.conf.fade_time);	
			}else{
				this.contener.hide();
			}
			
			this.isStart = false;
			this.scrollUnbind();
		},
		exit : function(){
			if(jQuery.browser.msie){
				window.open(this.conf.exit_url,"_blank",'toolbar=1,location=1,directories=1,status=1,scrollbars=1,resizable=1,copyhistory=1,menuBar=1');
				self.focus();
			}
			else{
				exit_win = window.open(this.conf.exit_url,'_blank','toolbar=1,location=1,directories=1,status=1,scrollbars=1,resizable=1,copyhistory=1,menuBar=1');
				exit_win.blur();
			}
		},
		moveTo : function(x,y){	this.contener.css( { left : x, top: y } );	},
		scroll 	: function(){ this.moveTo(this.getStartX(),this.getStartY()); },
		
		getStartX : function(){
			if(this.conf.pos_left == "auto")
				return parseInt( (jQuery(window).width()/2)  + jQuery(window).scrollLeft()  - (this.conf.width/2) );
			else
				return parseInt( this.conf.pos_left ) + jQuery(window).scrollLeft() ;
		},
		getStartY : function(){
			if(this.conf.pos_top == "auto")
				return parseInt( (jQuery(window).height()/2)  + jQuery(window).scrollTop()  - (this.conf.height/2) );
			else
				return parseInt( this.conf.pos_top ) + jQuery(window).scrollTop() ;
		},		
		scrollBind : function(){			
			jQuery(window).bind ( 'scroll resize', {self:this}, this.scrollFunc);
		},
		scrollUnbind : function(){						
			jQuery(window).unbind ( 'scroll resize' , this.scrollFunc);
		},
		scrollFunc : function(e){
			 e.data.self.scroll();
		},
		scroll : function(){
			if(KeyExists(this.conf,'voile',1)){
				this.voile.css (
					{ 
						'top'				: jQuery(window).scrollTop(),
						'left'				: jQuery(window).scrollLeft(),
						'width'				: jQuery(window).width()+"px",
						'height'			: jQuery(window).height()+"px"
					}	
				);
			}
			this.moveTo(this.getStartX(),this.getStartY());
		}
	};
}