// JavaScript Document

Playlist = new Playlist({'swfLocation': basehref + 'MooSound.swf'});

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');	
			}
			});			
		});
		
	if($(document.body).hasClass('ru') == false)
	Cufon.replace('#hmenu li.item', { fontFamily: 'goldswh-menu', hover: true, hoverables: { li: true },
    ignore: { ul: true } });
	}

});

function write_cookie(name,val) {
	
	var req = new Request({
						method: 'post',
						url: basehref + 'set_music',
						data: { 'name': name, 'val': val }
					}).send();
	
};

window.addEvent('domready',function(){
									
	//Playlist = new Playlist({'swfLocation': basehref + '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 myCookiea = Cookie.read('mp3action');
		var myCookiep = Cookie.read('mp3pauseposition');	
					
		
		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;
				write_cookie('mp3pauseposition',pauseposition);
				},
		'onPlay': function() { this.el.addClass('playing');  write_cookie('mp3action','play');  },
		'onStop': function() { this.el.removeClass('playing'); write_cookie('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);
		}
	};

	
	
		var songs = [basehref + "muzyka/muzyka_1.mp3"]; 
	
		Playlist.loadSounds(songs, options);
		
		
			
			if(myCookiea == 'play') {
				$('bottom_player').addClass('playing_now');	
		
			if(myCookiep != null ) {
				var pos = myCookiep;
			} else {
				var pos = 0;	
			}
			Playlist.playRandom();
			var mySound = Playlist.getSound(basehref + "muzyka/muzyka_1.mp3");
				if(mySound) {
					mySound.start(pos);	
				}
			
			}

		
		
		window.addEvent('unload',function() {
			var mySound = Playlist.getSound(basehref + "muzyka/muzyka_1.mp3");							  
			if(mySound) {
			
			if(mySound.playing) {
				 write_cookie('mp3action','play');	
			} else {
				 write_cookie('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(basehref + "muzyka/muzyka_1.mp3");
				if(mySound) {
					mySound.stop();
				}
			} else {
				$('bottom_player').addClass('playing_now');			
				var mySound = Playlist.getSound(basehref + 'muzyka/muzyka_1.mp3');
				if(mySound) {
					mySound.start();	
				}
			}
		});
		
		
		}
		
		
		if($defined($('myGallery'))){
			
					var myGallery = new gallery($('myGallery'), {
					  delay: 5000,
					timed: true,
					showArrows: false,
					showCarousel: false,
					showInfopane: false,
					embedLinks: false
				});
		}
		
		var fxs = Array();
		
		
		
		if($defined($('offers_vertical_outer'))) {
				var sMoo = new SlideItMoo({
						overallContainer: 'offers_vertical_outer',
						elementScrolled: 'offers_vertical_inner',
						thumbsContainer: 'offers_vertical_items',		
						itemsVisible:3,
						elemsSlide:1,
						duration:400,
						itemsSelector: '.offer_container',
						itemWidth: 236,
						itemHeight: 124,
						slideVertical: true,
						showControls:1,
						direction:-1,
						autoSlide:null,
						navs:{ /* starting this version, you'll need to put your back/forward navigators in your HTML */
									fwd:'.offers_back', /* forward button CSS selector */
									bk:'.offers_forward' /* back button CSS selector */
								}
			});
		}
		
		
		
		$$('.offer_container').each(function(item, index){
		
			var masked = item.getElement('.mask');
			masked.set('morph', {duration: 'short'});
			var ahref = item.getElement('a');


			ahref.addEvents({
							 'mouseenter':function() {
								masked.morph({
									'width':[231,244],
									'height':[120,124],
									'left': [3, -3],
									'top': [0, -2]
									});  
								},
							 'mouseleave':function() {
								masked.morph({
									'width':231,
									'height':120,
									'left': 3,
									'top': 0
									});
								}
							 
							 
							 });
											 
		});
	
});

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

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