var createPopup=new Class({Implements:[Events],initialize:function(json_object){this.popupOpen=false;if(this.popupOpen){if($('global'))$('global').fade(1);$('blockPopupBackground').fade(0);this.myPopup.erase_old();delete this.myPopup;this.popupOpen=false;}var oPopup_params=JSON.decode(json_object);var oParams=new Object();oParams.w=(oPopup_params.w)?oPopup_params.w:680;oParams.h=(oPopup_params.h)?oPopup_params.h:420;oParams.center=(oPopup_params.center!=undefined)?oPopup_params.center:true;oParams.titrePopup=(oPopup_params.titrePopup)?oPopup_params.titrePopup:'';oParams.links=(oPopup_params.href)?oPopup_params.href:'#';oParams.vars=(oPopup_params.vars)?oPopup_params.vars:false;oParams.contentType=(oPopup_params.type)?oPopup_params.type.toLowerCase():'iframe';oParams.contentDiv=(oPopup_params.content)?oPopup_params.content:false;oParams.newWindow=(oPopup_params.newWindow)?oPopup_params.newWindow:false;if(oParams.newWindow){if(!Browser.Engine.trident){oParams.h=(oParams.h).toInt()+1;}if(oParams.center){LeftPosition=(screen.width)?(screen.width-oParams.w)/2:100;TopPosition=(screen.height)?(screen.height-oParams.h)/2:100;}else{LeftPosition=0;TopPosition=20;}src=oParams.links;if(oParams.vars){src+='?'+oParams.vars;}settings=' width='+oParams.w+', height='+oParams.h+', top='+TopPosition+', left='+LeftPosition+', scrollbars=auto, location=no, directories=no, status=no, menubar=no, toolbar=no, resizable';window.open(src,oParams.titrePopup,settings);}else{this.myPopup=new Popup();this.myPopup.create_div(this,oParams);this.myPopup.myDrag=new Drag.Move('blockPopup',{handle:$('blockPopup').getElement('.moduleHeader'),snap:0,container:window,onSnap:function(el){this.move=true;},onComplete:function(el){this.move=false;}});this.popupOpen=true;this.mouseEvents();}},mouseEvents:function(){var close_buttons=$$('.closePopup');close_buttons.each(function(item,index){item.addEvent('click',function(e){if(!this.move&&this.popupOpen){e.stop();this.closePopup();}}.bind(this));},this);document.addEvent('click',function(e){if(!this.move&&this.popupOpen){if(!this.myPopup.hitTest){e.stop();this.closePopup();}}}.bind(this));},closePopup:function(){if($('global'))$('global').fade(1);$('blockPopupBackground').fade(0);this.myPopup.erase_old();delete this.myPopup;this.popupOpen=false;}});var Popup=new Class({Implements:[Events],initialize:function(){this.fadeSpeed=200;this.hitTest=false;},create_div:function(oPopup,oParams){this.newPopup=new Object();this.newPopup.w=new Number(oParams.w);this.newPopup.h=new Number(oParams.h);this.newPopup.src=oParams.links;if(oParams.vars)this.newPopup.src+='?'+oParams.vars;this.newPopup.titrePopup=oParams.titrePopup;this.newPopup.contentType=oParams.contentType;this.newPopup.contentDiv=oParams.contentDiv;this.newPopup.blockPopupBackground=new Element('div',{'id':'blockPopupBackground'});this.newPopup.blockPopup=new Element('div',{'id':'blockPopup'});this.newPopup.blockPopup.inject(this.newPopup.blockPopupBackground);this.newPopup.sideRight=new Element('div',{'class':'sideRightTop'});this.newPopup.sideRight.inject(this.newPopup.blockPopup);this.newPopup.sideLeft=new Element('div',{'class':'sideLeftTop'});this.newPopup.sideLeft.inject(this.newPopup.sideRight);this.newPopup.moduleHeader=new Element('div',{'class':'moduleHeader'});var str=(this.newPopup.titrePopup)?'<h1>'+this.newPopup.titrePopup+'</h1>':'';this.newPopup.moduleTitle=new Element('div',{'class':'title','html':str});this.newPopup.moduleTitle.inject(this.newPopup.moduleHeader);this.newPopup.moduleBtnClose=new Element('div',{'class':'closePopup'});this.newPopup.moduleBtnClose.inject(this.newPopup.moduleHeader);this.newPopup.moduleHeader.inject(this.newPopup.sideLeft);this.newPopup.sideRight=new Element('div',{'class':'sideRightContent'});this.newPopup.sideRight.inject(this.newPopup.blockPopup);this.newPopup.sideLeft=new Element('div',{'class':'sideLeftContent'});this.newPopup.sideLeft.inject(this.newPopup.sideRight);this.newPopup.moduleContent=new Element('div',{'class':'moduleContent'});this.newPopup.moduleContent.inject(this.newPopup.sideLeft);this.newPopup.sideRight=new Element('div',{'class':'sideRightBottom'});this.newPopup.sideRight.inject(this.newPopup.blockPopup);this.newPopup.sideLeft=new Element('div',{'class':'sideLeftBottom'});this.newPopup.sideLeft.inject(this.newPopup.sideRight);this.newPopup.moduleFooter=new Element('div',{'class':'moduleFooter'});this.newPopup.moduleFooter.inject(this.newPopup.sideLeft);switch(this.newPopup.contentType){case"html":this.newPopup.win=new Element('div',{'id':'popupContent','html':this.newPopup.contentDiv});this.newPopup.win.setStyles({width:this.newPopup.w,height:this.newPopup.h,overflow:'auto'});this.newPopup.win.inject(this.newPopup.moduleContent);break;default:this.newPopup.win=new Element('iframe',{'id':'myFrame','width':this.newPopup.w,'height':this.newPopup.h,'background':'#FFFFFF','src':this.newPopup.src,'frameborder':'0'});this.newPopup.win.inject(this.newPopup.moduleContent);break;}this.newPopup.blockPopup.setStyles({width:(this.newPopup.w+30)+'px',height:(this.newPopup.h+30)+'px'});this.newPopup.blockPopupBackground.inject(document.body);if(oParams.center==true||oParams.center=='true')this.center();$('global').set('tween',{duration:this.fadeSpeed});if($('global'))$('global').fade(0.2);$('blockPopupBackground').set('tween',{duration:this.fadeSpeed});$('blockPopupBackground').fade('hide');$('blockPopupBackground').fade(1);this.newPopup.blockPopup.addEvents({'mouseover':function(e){this.hitTest=true;}.bind(this),'mouseout':function(e){this.hitTest=false;}.bind(this)});},erase_old:function(){if(this.newPopup.blockPopupBackground)this.newPopup.blockPopupBackground.destroy();},center:function(){var oScroll=document.getScroll();this.newPopup.blockPopupBackground.setStyles
({left:'0px',top:(oScroll.y)+'px'});var size=this.newPopup.blockPopupBackground.getSize(),oScroll=this.newPopup.blockPopupBackground.getScroll();this.newPopup.blockPopup.setStyles
({left:(oScroll.x+(size.x-this.newPopup.blockPopup.offsetWidth)/2).toInt()+'px',top:(oScroll.y+(size.y-this.newPopup.blockPopup.offsetHeight)/2).toInt()+'px'});}});function open_popup(json_object){new createPopup(json_object);}window.addEvent("domready",function(){var popups_auto=$$('.PopupJS');popups_auto.each(function(item,index){item.addEvent('click',function(e){e.stop();if(this.getProperty('rel')){object=JSON.decode(this.getProperty('rel'));}if(this.getProperty('href')){if(!object)var object=new Object();object.href=this.getProperty('href');}if(object)new createPopup(JSON.encode(object));});});});
