// JavaScript Document

var menu = new Class({
	initialize : function(menu){
		this.menu = $(menu);
		this.menuItems = this.menu.getElements('li.item');
		this.create()
	},
	
	create:function(){
		this.menuItems.each(function(item){
									 
			item.addEvents({
			'mouseenter':function(){
				item.addClass('active');
			},
			'mouseleave':function() {
				item.removeClass('active');	
			}
			});			
		});
	}

});

window.addEvent('domready',function(){
									
	Playlist = new Playlist({'swfLocation': '/MooSound.swf'});								
									
	var mymenu = new menu('hmenu');
	
	var tooltips = $$('.tooltip');

	tooltips.each(function(item){
	item.store('tip:text', 'Ju¿ wkrótce...');
	item.addEvent('click',function(e){e.preventDefault();});
	});
	
	if($defined($('enhanced_form'))) {
	
	$('enhanced_form').getElements('input').each(function(input){
		input.addEvents({
						
			'focus':function(){this.getParent().addClass('processed');},
			'blur': function(){this.getParent().removeClass('processed');}
						
		});
	});

	$('enhanced_form').getElements('textarea').each(function(input){
		input.addEvents({
						
			'focus':function(){this.getParent().getParent().addClass('processed');},
			'blur': function(){this.getParent().getParent().removeClass('processed');}
						
		});
	});


	}
	
	$('languages').getElements('.not_active').each(function(item){
	item.setOpacity('0.3');		
	item.removeProperty('href');
	item.addEvent('click',function(event){event.preventDefault();});
	});
	
	
	if($defined($('newsletter_bottom_email'))) {
	
	$('newsletter_bottom_email').addEvents({
			'focus':function(){this.getParent().addClass('processed');},
			'blur': function(){this.getParent().removeClass('processed');}
	});
	}
	
	
	if($defined($('chair_set_table'))) {
		var modules = $('chair_set_table').getElements('.border');
		var height = 0;
		modules.each(function(item){
		
		item.addEvents(
		{
			'click':function(){
				
				$('chair_set_table').getElements('td').removeClass('checked');
				
				item.getParent().addClass('checked');
				item.getElement('input').checked="checked";
				
				}	
		}
		);
		
		var size = item.getSize();
		
		height = (height < size.y)?size.y:height;
		
		
		});
		
		modules.each(function(item){item.setStyle('height',height + 'px')});
		
		var checked = $('chair_set_table').getElement('input:checked');
		if(checked!=null) {
		checked.getParent().getParent().addClass('checked');
		}
	}
	
	if($defined($('reservation_terms'))) {
		var myFxR = new Fx.Slide($('reservation_terms')).hide();	

		$('reservation_switch').addEvents({
						'click' : function(event){
							event.preventDefault();
						
			 
						if($('reservation_switch').retrieve('stan') != 'hidden')
						{
							 myFxR.slideIn();								
							 $('reservation_switch').store('stan','hidden');
						}
						else
						{
							myFxR.slideOut();
							$('reservation_switch').store('stan','visible');
						}
						}
					});	
		}
/*		
		if($defined($('bottom_player'))){
		 var myCookie = Cookie.read('hideplayer');
		 if(myCookie != null) {
			 $('bottom_player_container').dispose();	
		 }
		}
	*/	
		if($defined($('bottom_player'))) {
		
		//Playlist = new Playlist({'swfLocation': 'http://localhost/hotelswing_new/MooSound.swf'});
		
		var box = $('bottom_player_container');

		
		
		var i = 0;
	var options = {
		'onRegister': function() {
			i++;
			this.el = new Element('div', {'class':'song'});
			this.title        = new Element('h3', {'class':'title', text:this.url}).inject(this.el);
			this.controls     = new Element('div', {'class':'controls'}).inject(this.el);
			this.seekbar      = new Element('div', {'class': 'seekbar'}).inject(this.el);
			this.position     = new Element('div', {'class':'position'}).inject(this.seekbar);
			this.seekbar.set('tween', {duration:this.options.progressInterval, unit:'%', link: 'cancel'});
			this.position.set('tween', {duration:this.options.positionInterval, unit:'%', link: 'cancel'});
			this.playEl       = new Element('img', {'class':'play',  src:'/images/play.png',id:'play'+i }).inject(this.controls);
			this.stopEl       = new Element('img', {'class':'stop',  src:'/images/stop.png',id:'stop'+i }).inject(this.controls);
			this.pauseEl      = new Element('img', {'class':'pause', src:'/images/pause.png',id:'pause'+i}).inject(this.controls);
			this.stopEl.addEvent('click', function() { this.stop(); }.bind(this));
			this.playEl.addEvent('click', function() { this.start(); }.bind(this));
			this.pauseEl.addEvent('click', function() { this.pause(); }.bind(this));
			this.seekbar.addEvent('click', function(e) {
				var coords = this.seekbar.getCoordinates();
				var ms = ((e.page.x - coords.left)/coords.width)*this.duration;
				this.jumpTo(ms);
			}.bind(this));
			this.el.inject($('playlist'));
			
			
		},
		'onLoad': function() {},
		'onPause': function() { 
				var pauseposition = this.pausedAt;
				var myCookie = Cookie.write('mp3pauseposition',pauseposition);
				},
		'onPlay': function() { this.el.addClass('playing');  var myCookie = Cookie.write('mp3action','play');  },
		'onStop': function() { this.el.removeClass('playing'); var myCookie = Cookie.write('mp3action','stop');},
		'onProgress': function(loaded, total) {
			var percent = (loaded / total*100).round(2);
			this.seekbar.get('tween').start('width', percent * .76);
		},
		'onPosition': function(position,duration) {
			var percent = (position/duration*100).round(2);
			this.position.get('tween').start('left', percent);
		},
		'onID3': function(key, value) {
			if (key == "TIT2") { this.title.set('text', value); }
		},
		'onComplete': function() {
			Playlist.playRandom.delay(100, Playlist);
		}
	};

		
	
		//Note: I have some funky file serving going on in my widgets app, which means that
		//the filesize isn't readily accessible.  So it bugs out a bit in the official demo.
		//You can try it at home for better luck.
	
		var songs = ["/muzyka/muzyka_1.mp3"]; //I only have one mp3. ;_; (But you can add more!)
	
		Playlist.loadSounds(songs, options);
		
		window.addEvent('unload',function() {
			var mySound = Playlist.getSound('/muzyka/muzyka_1.mp3');							  
			if(mySound) {
			
			if(mySound.playing) {
				var myCookie = Cookie.write('mp3action','play');	
			} else {
				var myCookie = Cookie.write('mp3action','stop');	
			}
			
						mySound.pause()
			}
		});

		$('bottom_player_action').addEvent('click',function(){
			if(	$('bottom_player').hasClass('playing_now')) {
				$('bottom_player').removeClass('playing_now');
				var mySound = Playlist.getSound('/muzyka/muzyka_1.mp3').stop();
			} else {
				$('bottom_player').addClass('playing_now');			
				var mySound = Playlist.getSound('/muzyka/muzyka_1.mp3');
				if(mySound) {
					mySound.start()	
				}
			}
		});
		
		var myCookiea = Cookie.read('mp3action');
			
			if(myCookiea == 'play') {
				$('bottom_player').addClass('playing_now');	
			//	this.start(pos);
			
			var myCookiep = Cookie.read('mp3pauseposition');
			
			if(myCookiep != null ) {
				var pos = myCookiep;
			} else {
				var pos = 0;	
			}
			Playlist.playRandom();
			var mySound = Playlist.getSound('/muzyka/muzyka_1.mp3');
				if(mySound) {
					mySound.start(pos)	
				}
			
			}

		}
	
});

window.addEvent('load',function(){

if($defined($('newsletter_bottom_email'))) {
	new OverText($('newsletter_bottom_email'));
}
								
});