//class_popup.js
function Popup(conteneur,width,btn_open,btn_close,windowTop,content_popup,style_transfer,hider,page,page_contenu){
	
  this.conteneur=conteneur+'';
  this.width=width;
  this.btn_open=btn_open+'';
  this.btn_close=btn_close+'';
  this.windowTop=windowTop+'';
  this.style_transfer=style_transfer+'';
  this.hider = hider!='' ? hider+'' : '';
  this.page = page!='' ? page+'' : '';
  this.content_popup=content_popup+'';
  this.active_minmax = hider!='' ? false : true;
  this.active_deplace = hider!='' ? false : true;
  this.maxi=true;
  this.page_contenu=page_contenu+'';

  this.popup_ouvrir = function (){
	content=this.conteneur;
	hide_page = this.hider != "" ? this.hider : "" ;
	page=this.page;
	affichage=this.page_contenu;
	ou_affiche=this.content_popup;
	if($('#'+this.conteneur).css('display') == 'none') {
					$('#'+this.conteneur).css("left",(document.body.clientWidth/2) - (this.width/2) + "px");
					$('#'+this.windowTop).css("width",this.width + "px");
					top_c=(document.body.scrollTop || document.documentElement.scrollTop)+10;
					$('#'+this.conteneur).css("top",top_c+"px");
					$('#'+this.btn_open).TransferTo(
						{
							to:this.conteneur, 
							className:this.style_transfer,
							duration: 400,
							complete: function(){
								if(affichage!=""){
								    $('#'+content).show(1,function(){
									     $.post(affichage,function(data){
											loader = $(document.createElement("img")).attr({
                                                alt: '',
                                                title: '',
                                                src: 'images/preload.gif'
                                            });
											ploder = $(document.createElement("div")).attr({
												id:'img_loader'
                                            });
											ploder.css("position","absolute");
											ploder.append(loader);
											
											$("#div_loder").html(data);
											//$("#"+ou_affiche).html(data);
											//$("#"+ou_affiche).append(ploder);
											if(document.all){
												function checkReadyState() {
                                                   var state = document.readyState;
												   ploder.css("position","absolute");
												   ploder.css("z-index",100);
                                                   if (state == "complete") {//La page est complètement chargée
                                                      clearInterval(timer);
													  $("#"+ou_affiche).html(data);
													  $("#div_loder").html("");
													  //$("#img_loader").css("display","none");
                                                   }
												}
												timer = setInterval(checkReadyState, 10);
											}else{
											  imgContent =document.getElementsByTagName("img"); //$("img");
											  totalImage = imgContent.length;
											  for(i=0;i<totalImage;i++){
												    if (imgContent.item(i).complete && i==(totalImage-1)) {
														//$("#img_loader").css("display","none");
														$("#"+ou_affiche).html(data);
														$("#div_loder").html("");
														i=totalImage;
											        }
											  }
											}
										 });
								    });
								}else{
									$('#'+content).show(0);
								}
								
								h_cont=document.getElementById(content).offsetHeight;
								//$('#'+content).css("height",(h_cont-4)+"px");
								
								if(hide_page != ""){
									
									hidder=document.getElementById(hide_page);
									$("#"+hide_page).css('display','block');
	
	                                if(document.all && !window.opera){ 
                                        hidder.style.filter = "alpha(opacity=" + 50 + ");"
	                                    hidder.style.width=document.body.clientWidth;
	                                    hidder.style.height=document.getElementById(page).offsetHeight; 
                                    } 
                                    else{ 
                                       var Val = 50/100; 
                                       hidder.style.setProperty( "-moz-opacity", Val, ""); 
                                       hidder.style.setProperty( "-khtml-opacity", Val, ""); 
                                       hidder.style.setProperty( "opacity", Val, "");
	                                   hidder.style.width=document.body.clientWidth+"px";
	                                   hidder.style.height=(document.body.scrollHeight)+"px";
                                    } 
								}
							}
						}
					);
	}
  }

  this.popup_fermer = function (){
	hider_page=this.hider;
	content=this.content_popup;
	if(this.hider!=''){
			hidder=document.getElementById(hider_page);
			hidder.style.display="none";
	}
	$('#'+this.conteneur).TransferTo(
					{
						to:this.btn_open,
						className:this.style_transfer, 
						duration: 400,
						complete: function(){$("#"+content).html('<center><img src="images/preload.gif" width="220" height="19"></center>');}
					}
	).hide();
  }
  
  this.popup_fermer_redir = function (id,lien){
	hider_page=this.hider;
	if(this.hider!=''){
			hidder=document.getElementById(hider_page);
			hidder.style.display="none";
	}
	$('#'+this.conteneur).TransferTo(
					{
						to:this.btn_open,
						className:this.style_transfer, 
						duration: 400,
						complete: function(){window.location=base_href+"voyage-sur-mesure/"+id+"/"+lien+".html";}
					}
	).hide();
  }

  this.popup_deplacer = function (){
	  if(this.active_deplace==true) {
		$('#'+this.conteneur).Resizable(
			{
				dragHandle: '#'+this.windowTop,
				handlers: {},
				onResize : function(position) {}
			}
	     );
      }
  }
  
  this.min_max = function (){
	w_top_h=document.getElementById(this.windowTop).offsetHeight;
	mm_axi=this.maxi;
	if(this.active_minmax==true) {
	  if(mm_axi==true) {
	    $('#'+this.content_popup).SlideToggleUp(300);
	    //$('#'+this.conteneur).animate({height:w_top_h},300).get(0).isMinimized = true;
	    this.maxi=false;
	  }else{
		var windowSize = $.iUtil.getSize(document.getElementById(this.content_popup));
		$('#'+this.content_popup).SlideToggleUp(300);
		//$('#'+this.conteneur).animate({height: windowSize.hb+w_top_h}, 300).get(0).isMinimized = false;
		this.maxi=true;
	  }
	}  
  }
  
}  
