
var mooSlider = new Class(
{
	options:
	{
		slideSpeed: 500,
		fadeSpeed:	500,
		effects:	Fx.Transitions.linear,
		toggler:	"toggle",
		content:	"loginPanel",
		subContent:	null,
		removeOnClick: false,
		from:		'bottom',
		opacity:	1,
		height:		0,
		isOpen:		0,
		executeFunction: null,
		loadExternal: null,
		request: 	null,
		checker:	null,
		autoCloseDelay: 0,
		closeBtn:	"mooToggler"
	},

	initialize:	function(options)
	{
		this.setOptions(options);
		if(options['toggler']) this.toggler = options['toggler'];
		if(options['content']) this.content = $(options['content']);
		if(options['subContent']) this.subContent = $(options['subContent']);
		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['executeFunction']) this.executeFunction = options['executeFunction'];
		if(options['loadExternal']) this.loadExternal = options['loadExternal'];
		if(options['autoCloseDelay']) this.autoCloseDelay = options['autoCloseDelay'];
		if(options['closeBtn']) this.closeBtn = options['closeBtn'];
		
		if(this.options.removeOnClick == true){	
			$(this.content).addEvent('click',this.clearit.bindWithEvent(this));
		}	
		
		if(this.options.closeBtn){	
			$(this.closeBtn).addEvent('click',this.clearit.bindWithEvent(this));
		}	
		
		if(options['effects']){
			this.effects = options['effects'];
		}else{
			this.effects = Fx.Transitions.linear;
		}
		
		// remember initial height
		var size = this.content.getSize();
		this.intialHeight = size.y;
		
		// remember content/slider background and remove
		// fixed for multiple instances
		//this.contentBgImage = this.content.getStyle('backgroundImage');
		this.contentBgImage	= 'url("tl_files/jukevox/images/bg_toggler.png")';
		//this.contentBgColor = this.content.getStyle('backgroundColor');
		this.contentBgColor = '#141414';
		this.content.setStyle('backgroundImage', 'none');
		this.content.setStyle('backgroundColor', 'transparent');

		$(this.content).setStyle('position','absolute');
		
		$(this.toggler).addEvent('click',this.toggle.bindWithEvent(this));
	},
	
	
	clearit: function(e)
	{
		e = new Event(e).stop();
	
		if(this.isOpen)
		{
			var scroll = window.getScrollSize();
			var baseLine  = scroll.y;
			var boxHeight = this.height;
	
			var myEffect = new Fx.Morph(this.content, {duration: this.slideSpeed, transition: this.effects});
			this.content.setStyle('overflow', 'hidden');
			
			myEffect.addEvents({
				complete: function (event) { 
					event.setStyle('backgroundImage', 'none');
					event.setStyle('backgroundColor', 'transparent');
					$('mooToggler').setStyle('backgroundImage', "url('tl_files/jukevox/images/arrowu.png')");
					$('mooToggler').setStyle('cursor', 'default');
					$('mooTogglerText').setStyle('visibility', 'visible');
					$('mooKontakt').setStyle('visibility', 'hidden');
					$('mooNewsletter').setStyle('visibility', 'hidden');
					$('mooVeranstalter').setStyle('visibility', 'hidden');
					$('mooImpressum').setStyle('visibility', 'hidden');
				}
			});
		
			myEffect.start({
				'top': [baseLine - boxHeight, baseLine - this.intialHeight],
				'height': [boxHeight, this.intialHeight]
			});
			
			this.isOpen = 0;
		}
	},
	
	toggle: function(e)
	{
		e = new Event(e).stop();
	
		var scroll = window.getScrollSize();
		var baseLine  = scroll.y;
		var boxHeight = this.height;
		
		// open
		if(!this.isOpen)
		{
			this.content.setStyle('backgroundImage', this.contentBgImage);
			this.content.setStyle('backgroundColor', this.contentBgColor);
			
			this.subContent.setStyle('visibility', 'visible');
			$('mooTogglerText').setStyle('visibility', 'hidden');
			
			var myEffect = new Fx.Morph(this.content, {duration: this.slideSpeed, transition: this.effects});
			
			myEffect.addEvents({
				complete: function (event) { 
					$('mooToggler').setStyle('backgroundImage', "url('tl_files/jukevox/images/arrowd.png')");
					$('mooToggler').setStyle('cursor', 'pointer');
					event.setStyle('overflow', 'visible');
				}
			});
			
			myEffect.start({
				'top': [baseLine - this.intialHeight, baseLine - boxHeight],
				'height': [this.intialHeight, boxHeight]
			});
			
			this.isOpen = 1;
		}
		
		// close
		else
		{
			var myEffect = new Fx.Morph(this.content, {duration: this.slideSpeed, transition: this.effects});
			this.content.setStyle('overflow', 'hidden');
			
			myEffect.addEvents({
				complete: function (event) { 
					event.setStyle('backgroundImage', 'none');
					event.setStyle('backgroundColor', 'transparent');
					$('mooToggler').setStyle('backgroundImage', "url('tl_files/jukevox/images/arrowu.png')");
					$('mooToggler').setStyle('cursor', 'default');
					$('mooTogglerText').setStyle('visibility', 'visible');
					$('mooKontakt').setStyle('visibility', 'hidden');
					$('mooNewsletter').setStyle('visibility', 'hidden');
					$('mooVeranstalter').setStyle('visibility', 'hidden');
					$('mooImpressum').setStyle('visibility', 'hidden');
				}
			});
		
			myEffect.start({
				'top': [baseLine - boxHeight, baseLine - this.intialHeight],
				'height': [boxHeight, this.intialHeight]
			});
			
			this.isOpen = 0;
		}
	}
})

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