var Popup=Class.create();Popup.zIndex=1000;Popup.prototype={initialize:function(a,d){var b=Object.extend({modal:false,effect:"fade",hidden:true,closebox:"popup_closebox",draghandle:"popup_draghandle"},arguments[2]||{});b.position=b.position||(b.modal?"center":"auto");b.trigger=b.trigger||(b.modal?"click":"mouseover");b.duration=this.first_value(b.duration,Popup.duration,0.1);b.show_duration=this.first_value(b.show_duration,b.duration);b.hide_duration=this.first_value(b.hide_duration,b.duration);b.opacity=this.first_value(b.opacity,Popup.opacity,0.5);b.show_delay=this.first_value(b.show_delay,Popup.show_delay,500);b.hide_delay=this.first_value(b.hide_delay,Popup.hide_delay,200);b.cursor_margin=this.first_value(b.cursor_margin,Popup.cursor_margin,5);this.options=b;if(d){this.link=$$$(d)}this.popup=$$$(a);this.popup.popup=this;if(b.hidden){this.popup.hide()}if(b.closebox){this.closeboxes=document.getElementsByClassName(b.closebox,this.popup);if(this.popup.hasClassName(b.closebox)){this.closeboxes[this.closeboxes.length]=this.popup}}else{this.closeboxes=[]}if(b.draghandle){var c=document.getElementsByClassName(b.draghandle,this.popup);for(i=0;i<c.length;i++){new Draggable(this.popup,{handle:c[i]})}if(this.popup.hasClassName(b.draghandle)){new Draggable(this.popup,{handle:this.popup})}}this.register_events()},register_events:function(){var b;if(this.is_auto_open()){b=this.start_show_timer;if(this.link){Event.observe(this.link,"mouseout",this.stop_show_timer.bindAsEventListener(this))}}else{b=this.show}if(this.link){Event.observe(this.link,this.options.trigger,b.bindAsEventListener(this))}if(!this.options.modal){Event.observe(this.popup,"click",this.bring_to_front.bindAsEventListener(this))}if(this.closeboxes.length>0){for(var a=0;a<this.closeboxes.length;a++){Event.observe(this.closeboxes[a],"click",this.hide.bindAsEventListener(this))}}else{if(this.link){Event.observe(this.link,"mouseout",this.start_hide_timer.bindAsEventListener(this))}Event.observe(this.popup,"mouseover",this.stop_hide_timer.bindAsEventListener(this));Event.observe(this.popup,"mouseout",this.start_hide_timer.bindAsEventListener(this))}},bring_to_front:function(a){if(Number(this.popup.style.zIndex)<Popup.zIndex-1){this.popup.style.zIndex=Popup.zIndex++}},start_show_timer:function(a){this.stop_show_timer(a);this.mouse_x=Event.pointerX(a);this.mouse_y=Event.pointerY(a);this.show_timer=setTimeout(this.show.bind(this,a),this.options.show_delay)},stop_show_timer:function(a){if(this.show_timer){clearTimeout(this.show_timer);this.show_timer=null}},start_hide_timer:function(a){this.stop_hide_timer(a);this.hide_timer=setTimeout(this.hide.bind(this,a),this.options.hide_delay)},stop_hide_timer:function(a){if(this.hide_timer){clearTimeout(this.hide_timer);this.hide_timer=null}},show:function(a){this.stop_show_timer(a);this.stop_hide_timer(a);if(this.is_open){return}if(this.options.modal){this.show_overlay()}var b;if(!a){b=this.get_popup_position()}else{if(this.is_auto_open()){b=this.get_popup_position(this.mouse_x,this.mouse_y)}else{b=this.get_popup_position(Event.pointerX(a),Event.pointerY(a))}}Element.setStyle(this.popup,{top:b.y,left:b.x,zIndex:Popup.zIndex++});this.is_open=true;switch(this.options.effect){case"slide":Effect.SlideDown(this.popup,{duration:this.options.show_duration});break;case"grow":Effect.Grow(this.popup,{duration:this.options.show_duration});break;case"blind":Effect.BlindDown(this.popup,{duration:this.options.show_duration});break;case"fade":default:Effect.Appear(this.popup,{duration:this.options.show_duration});break}},hide:function(a){this.is_open=false;switch(this.options.effect){case"slide":Effect.SlideUp(this.popup,{duration:this.options.hide_duration});break;case"grow":Effect.Shrink(this.popup,{duration:this.options.hide_duration});break;case"blind":Effect.BlindUp(this.popup,{duration:this.options.hide_duration});break;case"fade":default:Effect.Fade(this.popup,{duration:this.options.hide_duration});break}if(this.options.modal){this.hide_overlay()}},first_value:function(){for(var a=0;a<arguments.length;a++){if(arguments[a]!==undefined){return arguments[a]}}return undefined},is_auto_open:function(){return this.options.trigger=="mouseover"},show_overlay:function(){if(!Popup.overlay){var a=document.createElement("div");a.setAttribute("id","popup_overlay");a.style.display="none";document.body.appendChild(a);Popup.overlay=a;Popup.overlay_levels=[]}Popup.overlay.style.height=this.get_page_dimensions().height+"px";var b=Popup.zIndex++;Popup.overlay.style.zIndex=b;Popup.overlay_levels.push(b);if(Popup.overlay_levels.length==1){new Effect.Appear(Popup.overlay,{duration:this.options.show_duration,to:this.options.opacity,queue:{position:"end",scope:"popup_overlay"}})}else{Popup.overlay.style.zIndex=b}},hide_overlay:function(){Popup.overlay_levels.pop();var a=Popup.overlay_levels.pop();if(a){Popup.overlay_levels.push(a);Popup.overlay.style.zIndex=a}else{new Effect.Fade(Popup.overlay,{duration:this.options.hide_duration,queue:{position:"end",scope:"popup_overlay"}})}},get_popup_position:function(b,a){var c;switch(this.options.position){case"auto":c=this.get_auto_position(b,a);break;case"center":c=this.get_center_position();break;case"below":c=this.get_below_position();break;default:if(mo=this.options.position.match(/^\s*([^\s,]+)\s*,\s*([^\s,]+)\s*$/)){c={x:mo[1],y:mo[2]};c.x=Number(c.x)||c.x;c.y=Number(c.y)||c.y}else{c={x:0,y:0}}break}if(typeof c.x=="number"){c.x+="px"}if(typeof c.y=="number"){c.y+="px"}return c},get_below_position:function(){var a=Position.cumulativeOffset(this.link);return{x:a[0],y:a[1]+Element.getHeight(this.link)}},get_center_position:function(){dim=Element.getDimensions(this.popup);var f=dim.width;var b=dim.height;dim=this.get_viewport_dimensions();var c=dim.width;var d=dim.height-50;var a;if(f>=c){a=0}else{a=(c-f)/2}var e;if(b>=d){e=0}else{e=(d-b)/2}return{x:a,y:e}},get_auto_position:function(f,e){dim=Element.getDimensions(this.popup);var k=dim.width;var m=dim.height;dim=this.get_viewport_dimensions();var d=dim.width;var b=dim.height;var a=d-(f+this.options.cursor_margin);var n=f-this.options.cursor_margin;var l=e-this.options.cursor_margin;var j=b-(e+this.options.cursor_margin);var c=this.options.cursor_margin;var h=f;var g=e;if(k>=d){h=0}else{if(k<=a){h+=c}else{if(k<=n){h-=k+c}else{if(a>=n){h=d-k}else{h=0}}}}if(m>=b){g=0}else{if(m<=j){g+=c}else{if(m<=l){g-=m+c}else{if(j>=l){g=b-m}else{g=0}}}}return{x:h,y:g}},get_viewport_dimensions:function(){var a=this.getPageSize();return{width:a[2],height:a[3]}},get_page_dimensions:function(){var a=this.getPageSize();return{width:a[0],height:a[1]}},getPageSize:function(){var c,a;if(window.innerHeight&&window.scrollMaxY){c=document.body.scrollWidth;a=window.innerHeight+window.scrollMaxY}else{if(document.body.scrollHeight>document.body.offsetHeight){c=document.body.scrollWidth;a=document.body.scrollHeight}else{c=document.body.offsetWidth;a=document.body.offsetHeight}}var b,d;if(self.innerHeight){b=self.innerWidth;d=self.innerHeight}else{if(document.documentElement&&document.documentElement.clientHeight){b=document.documentElement.clientWidth;d=document.documentElement.clientHeight}else{if(document.body){b=document.body.clientWidth;d=document.body.clientHeight}}}if(a<d){pageHeight=d}else{pageHeight=a}if(c<b){pageWidth=b}else{pageWidth=c}arrayPageSize=new Array(pageWidth,pageHeight,b,d);return arrayPageSize}};
