baseLightWindow = Class.create({
			options: {
					trigger: 'lightbox',
					width: '200px',
					height: '100px',
					closeclass: '.closebutton',
					evalscripts: false,
					size: 'auto',
					optattr: 'options',
					scrolls:false,
					canclose:true,
					element: null
				},
			vars: {
				onCreateEffect:false
			},
			initialize: function() {
			},
			init: function(opts) {
				this.apply(this.options,opts || {});
				$$("."+this.options.trigger).each(function(item) {
					item.onclick=function(){ return this.lightbox().show();};
				})
				this.create();
				$$(this.options.closeclass).each(function(e)
					{ e.onclick=function() { LightWindow.autoclose(); };	});
			},
			enableClose: function() {
				$$(this.options.closeclass).each(function(e)
					{ e.onclick=function() { this.lightbox().autoclose(); };	});
			},
			disableClose: function() {
				$$(this.options.closeclass).each(function(e)
					{ e.onclick=function() {  };	});
			},
			newClose: function(clsname) {
				$$(this.options.closeclass).each(function(e)
					{ e.onclick=function() {  };	});
				this.options.closeclass=clsname;
				$$(this.options.closeclass).each(function(e)
					{ e.onclick=function() { this.lightbox().autoclose(); };	});
			},
			autoclose: function()
			{
				if (this.options.canclose)
					$$('.autoclose').each(function(e)
					{	e.fade({duration:0.3});	});
			},

			setElement:function(e) {
				this.options.element=e;
			},
			create:function() {
				if ($('lightbox')==undefined) {
					var overlay = new Element('div', { 'id':'overlay','class':'autoclose closebutton', 'style':'display:none;position:fixed;float:none;height:100%;left:0px; background-color:#000; top:0px;width:100%; z-index:500;-moz-opacity: 0.5;opacity:.50;filter: alpha(opacity=50);_height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight+\'px\')'});	
					document.body.appendChild(overlay);
					var lightbox = new Element('div', { 'id':'lightbox','class':'autoclose', 'style':'display:none; position:absolute; width:365px; z-index:1000; font-family:Tahoma,Helvetica,sans-serif;background:#FFFFFF none repeat scroll 0 0;padding:10px;overflow:auto; border:2px solid black;' });	
					document.body.appendChild(lightbox);
				}
			},
			
			showBox:function(href,element,width,height,run) {
				if (run==undefined)
		    	    run=false;
				new Ajax.Request(href,{
					method:'get',
					onSuccess:function(transport) {			
						if (LightWindow.options.evalscripts)
							transport.responseText.evalScripts();
						if ($('lightbox')) {
							if (!LightWindow.options.scrolls) { $('lightbox').setStyle({'overflow':'hidden'}); } else	{ $('lightbox').setStyle({'overflow':'auto'}); }
							if (LightWindow.options.size=='auto') {
								if (LightWindow.vars.onCreateEffect)
									LightWindow.vars.onCreateEffect.cancel();
								
								$lWidth=$('lightbox').getStyle('width'); 
								$lHeight=$('lightbox').getStyle('height'); 
								$('lightbox').style.visibility='hidden';
								$('lightbox').setStyle({'width':'auto','height':'auto'})
								$('lightbox').innerHTML=transport.responseText;
								$r=$('lightbox').getDimensions();
								$nd=document.viewport.getDimensions();
								if (parseInt($r.width)>parseInt($nd.width))
									$r.width=$nd.width;
								if (parseInt($r.height)>parseInt($nd.height))
									$r.height=$nd.height-25;
//								$('lightbox').setStyle({'visibility':'visible','width':'10px','height':'10px'});
								$('lightbox').setStyle({'visibility':'visible','width':$lWidth,'height':$lHeight});
								xPoz=document.documentElement.scrollLeft+parseInt($nd.width/2)-parseInt(parseInt($r.width)/2);
								yPoz=document.documentElement.scrollTop+parseInt($nd.height/2)-parseInt(parseInt($r.height)/2);
								new Effect.Morph('lightbox', {style:'width:'+$r.width+'px; height:'+$r.height+'px;left:'+xPoz+'px; top:'+yPoz+'px;',duration:0.4});
							} else  { $('lightbox').innerHTML=transport.responseText; }
						}
						if (run!=false)
							  eval(run);
					},
					onFailure:function(){
						$('lightbox').innerHTML='Error on request!';
					},
					onCreate:function() {
						$('overlay').appear({duration:0.3,from: 0.0, to: 0.8});
						$nd=document.viewport.getDimensions();
						xPoz=document.documentElement.scrollLeft+parseInt($nd.width/2)-parseInt(parseInt(width)/2);
						yPoz=document.documentElement.scrollTop+parseInt($nd.height/2)-parseInt(parseInt(height)/2);
						if (element!=false) {
								$('lightbox').innerHTML='';							
								sdim=LightWindow.findPos(element);

								$('lightbox').style.top=sdim.top+'px';
								$('lightbox').style.left=(sdim.left+20)+'px';
								$('lightbox').setStyle({'width':'60px','height':'26px'});
								$('lightbox').appear({duration:0.4});
								morph=1;
							   LightWindow.vars.onCreateEffect =	new Effect.Morph('lightbox', {style:'width:'+LightWindow.options.width+'; height:'+LightWindow.options.height+';left:'+xPoz+'px; top:'+yPoz+'px;',duration:0.4,afterFinish:function(){ if ($('lightbox').innerHTML=='') $('lightbox').innerHTML='<p style="text-align:center">Loading... please wait...</p>'; }});
							} else {
								$('lightbox').innerHTML='Plase wait...';
								$('lightbox').style.top=yPoz+'px';
								$('lightbox').style.left=xPoz+'px';
								$('lightbox').setStyle({'width':width+'px','height':height+'px'});
								$('lightbox').appear({duration:0.4});
							}
					}
				});
				return false;
			},
			show: function() {
				if ($('lightbox')==undefined)
					this.create();
				$options=this.options.element.readAttribute(this.options.optattr);
				run=this.checkOption($options,'run',false);
				width=this.checkOption($options,'width',this.options.width);
				height=this.checkOption($options,'height',this.options.height);
				return this.showBox(this.options.element.href,this.options.element,width,height,run);
			},
			checkOption: function ($in,$opt,$default)
			{
				if ( $default === undefined ) {
				  $default = false;
			   }
				var $options;
				if ($in!=null) {
					$options=$in.split(',');
					for ($i=0;$i<$options.length;$i++)			
						if ($options[$i].split(':')[0]==$opt)		
								return $options[$i].split(':')[1];
				}
				return $default
			},
			findPos: function(obj) {
				var curleft = curtop = 0;
				sdim=obj.cumulativeOffset();
				while (sdim.left==0 && sdim.top==0 && obj)
				{	
					obj=obj.up(0);
					sdim=obj.cumulativeOffset();
				}
				return sdim;
			},

			apply: function(o, e){
				for(var p in e) o[p] = e[p];
				return o;
			}
		});

var LightWindow=new baseLightWindow;
l={ lightbox : function(e) { LightWindow.setElement(e); return LightWindow; }}
Element.addMethods(l);

/*lightWindowLoad =function() {

}
document.observe("dom:loaded", function() {   lightWindowLoad();  }); */

