// -------------------------------------------------
// artViper's mooSlide 3.2.1 revamp for mooTools 1.2
// -------------------------------------------------
// if you make significant changes, extensiosn etc
// please drop us a copy at admin@artviper.net
// -------------------------------------------------
// more mootools based stuff can be found at:
// ------------- www.artviper.net ------------------

	var mooSlide2 = new Class({
		options:	{
						slideSpeed: 500,
						fadeSpeed:	500,
						effects:	Fx.Transitions.linear,
						toggler:	"myToggle",
						content:	 null,
						removeOnClick: false,
						from:		'top',
						fromwindow: 20,
						title: null,
						opacity:	1,
						height:		0,
						isOpen:		0,
						executeFunction: null,
						loadExternal: null,
						request: null						
					},
					
		initialize:	function(options){
			this.setOptions(options);
			if(options['toggler']) this.toggler = options['toggler'];
			if(options['content']) this.content = $(options['content']);
			if(options['height']) this.height = options['height'];
			if(options['opacity']) this.opacity = options['opacity'];
			if(options['slideSpeed']) this.slideSpeed = options['slideSpeed'];
			if(options['fadeSpeed']) this.fadeSpeed = options['fadeSpeed'];
			if(options['removeOnClick']) this.removeOnClick = options['removeOnClick'];
			if(options['from']) this.from = options['from'];
			if(options['fromwindow']) this.fromwindow = options['fromwindow'];
			if(options['title']) this.title = options['title'];
			if(options['executeFunction']) this.executeFunction = options['executeFunction'];
			if(options['loadExternal']) this.loadExternal = options['loadExternal'];
			
			$(this.content).setStyle('display','none');
			
			if(this.removeOnClick){	
			$(this.content).addEvent('click',this.clearit.bindWithEvent(this));
			}
			
			$(this.content).set('html', '<div id="facebox"><table><tbody><tr><td class="fbtl"/><td class="fbb"/><td class="fbtr"/></tr><tr><td class="fbb"/><td class="fbdialog-content"><h2 class="fbtitle"><span></span></h2><div class="fbbody"><div class="fbcontent"></div><div class="fbfooter"></div></div></td><td class="fbb"/></tr><tr><td class="fbbl"/><td class="fbb"/><td class="fbbr"/></tr></tbody></table></div>');
			$(this.content).getElement('.fbtitle').set('html', this.title);
			if(this.loadExternal){			
				
				/*
				this.request = new Request.HTML({ url: this.loadExternal, method: 'get', evalScripts: true });
				this.request.addEvent('success',this.loadExt.bindWithEvent(this));				
				this.request.send();
				*/
				$(this.content).getElement('.fbcontent').load(this.loadExternal);
			}
		
			if(options['effects']){
				this.effects = options['effects'];
			}else{
				this.effects = Fx.Transitions.linear;
			}
			this.content.setStyle('opacity','1');
			this.content.setStyle('visibility','hidden');	
			$(this.content).setStyle('z-index','5000');	
			$(this.toggler).addEvent('click',this.toggle.bindWithEvent(this));
          
		
		},
		
		clearit: function(){
			
			var myEffects = new Fx.Morph(this.content, {duration: this.fadeSpeed, transition: Fx.Transitions.linear});
			myEffects.start({
   				 'opacity': [1, 0]
			});;
					this.isOpen = 0;
					var p = new Function(this.executeFunction);
					p();
			
		},

		run: function(){
			if(this.from == "bottom"){				
					var top =  window.getHeight().toInt();
				}else{
					var top =  0;
				}
			var width;
			
			if (document.documentElement && document.documentElement.clientWidth) {
				width=document.documentElement.clientWidth;
			}else if (document.body) {
				width=document.body.clientWidth;
			}
			
			var pad1 = $(this.content).getStyle('padding-left').toInt();
			var pad2 = $(this.content).getStyle('padding-right').toInt();
			
			width =  width - (pad1+pad2+5);
			
			if(!window.ie){
				//width -= 15;
			}
			//var hoehe = $(this.content).height;
			//alert(hoehe);
			if(!this.isOpen){
				$(this.content).setStyle('display','block');
				$(this.content).setStyle('text-align','center');
				$(this.content).setStyle('position','fixed');
				$(this.content).setStyle('top',top);
				//$(this.content).setStyle('height','');
			    $(this.content).setStyle('padding-top','15px');
			    $(this.content).setStyle('padding-bottom','25px');
			    $(this.content).setStyle('visibility','visible');
				$(this.content).setStyle('opacity',this.opacity);
				$(this.content).setStyle('width','100.01%');
				$(this.content).setStyle('left','0');
				
				var end;
				if(this.from == "bottom"){				
					end = top - this.height - this.fromwindow;
				}else{
					end = 0;
				}
				if(this.from == "bottom"){
				
					var myEffect = new Fx.Morph(this.content, {duration: this.slideSpeed, transition: this.effects});
					var totalEnd = top;
				
 					myEffect.start({
   					 'top': [totalEnd, end]
					});
					this.isOpen = 1;
				
				}else{
					
				var myEffect = new Fx.Morph(this.content, {duration: this.slideSpeed, transition: this.effects});
				var totalEnd = this.fromwindow;
				//var totalEnd = window.getHeight().toInt()/2 - this.height/2;
				//if ($(this.content).getStyle('height').toInt() <= 0) $(this.content).setStyle('height','300');
				//var totalEnd = window.getHeight().toInt()/2 - $(this.content).getStyle('height').toInt()/2;
				//alert(window.getHeight().toInt() + ' /2 = ' +window.getHeight().toInt()/2 + ' - Höhe ' + $(this.content).getStyle('height').toInt()/2 + ' = '+ totalEnd);
 				myEffect.start({
   				 'top': [end, totalEnd]
				});
					
					this.isOpen = 1;
				}
			
			}else{
			var myEffects = new Fx.Morph(this.content, {duration: this.fadeSpeed, transition: Fx.Transitions.linear});
			myEffects.start({
   				 'opacity': [1, 0]
			});
				
				this.isOpen = 0;
				var p = new Function(this.executeFunction);
				p();
			}
		},
		
/*	
		loadExt: function(response,xml){
				$(this.content).set('html', response);
				
		},
					
	*/	
		toggle: function(e){
			e = new Event(e).stop();
			
			if(this.from == "bottom"){				
					var top =  window.getHeight().toInt();
				}else{
					var top =  0;
				}
			var width;
			
			if (document.documentElement && document.documentElement.clientWidth) {
				width=document.documentElement.clientWidth;
			}else if (document.body) {
				width=document.body.clientWidth;
			}
			
			var pad1 = $(this.content).getStyle('padding-left').toInt();
			var pad2 = $(this.content).getStyle('padding-right').toInt();
			
			width =  width - (pad1+pad2+5);
			
			if(!window.ie){
				//width -= 15;
			}
			
			if(!this.isOpen){
				$(this.content).setStyle('display','block');
				$(this.content).setStyle('text-align','center');
				$(this.content).setStyle('position','fixed');
				$(this.content).setStyle('top',top);
				//$(this.content).setStyle('height','');
			    $(this.content).setStyle('visibility','visible');
				$(this.content).setStyle('opacity',this.opacity);
				$(this.content).setStyle('width','100.01%');
				$(this.content).setStyle('left','0');
				
				var end;
				if(this.from == "bottom"){				
					end = top - this.height - this.fromwindow;
				}else{
					end = 0;
				}
				if(this.from == "bottom"){
				
					var myEffect = new Fx.Morph(this.content, {duration: this.slideSpeed, transition: this.effects});
					var totalEnd = top;
				
 					myEffect.start({
   					 'top': [totalEnd, end]
					});
					this.isOpen = 1;
				
				}else{
					
				var myEffect = new Fx.Morph(this.content, {duration: this.slideSpeed, transition: this.effects});
				var totalEnd = this.fromwindow;
				//var totalEnd = window.getHeight().toInt()/2 - this.height/2;
 				//var totalEnd = window.getHeight().toInt()/2 - $(this.content).getStyle('height').toInt()/2;
				myEffect.start({
   				 'top': [end, totalEnd]
				});
					
					this.isOpen = 1;
				}
			
			}else{
			var myEffects = new Fx.Morph(this.content, {duration: this.fadeSpeed, transition: Fx.Transitions.linear});
			myEffects.start({
   				 'opacity': [1, 0]
			});
				
				this.isOpen = 0;
				var p = new Function(this.executeFunction);
				p();
			}
		}
	})

mooSlide2.implement(new Options);
mooSlide2.implement(new Events);