/*

Created as: Central Hotellet javascript
Created by: John Philip
Created in: August 2007

-------------------------------------*/



/* REPAIR FOOTER

Notes: When the page height is bigger than the window height,
the footer won't change back to static position. This needs to
get fixed. FIXED!
-----------------------------------------------------------------*/
	
function repair_footer () {
	//All the heights in layout
	var margin_top = 40; //Set in the stylesheet
	var height_wrapper = document.getElementById('wrapper').offsetHeight;
	var height_footer = document.getElementById('footer').offsetHeight;
	var height_page = height_wrapper + margin_top + height_footer;
	
	var height_window = window.innerHeight;
	
	if(height_page < height_window) {
		
		document.getElementById('footer').style.position = 'absolute';
		document.getElementById('footer').style.bottom = '0';
		
	}
	
	if(height_page > height_window) {
		
		document.getElementById('footer').style.position = 'static';
		
	}

}



/* SUBMIT RESERVATION SCRIPT
-----------------------------------------------------------------*/

if(document.getElementById('myForm')) {
		
		
	
window.addEvent('domready', function() {

	var mySlide = new Fx.Slide('sender');
	var mySlidedoc = new Fx.Slide('myForm');
	mySlide.hide();

	document.getElementById('sender').innerHTML = '<div id="text"><div id="indicator"></div><p>Kommunikerer med booking @ centralhotellet</p></div>';


	$('myForm').addEvent('submit', function(e) {

		new Event(e).stop();
		mySlidedoc.slideOut();
		mySlide.toggle();
		repair_footer();
		/**
		 * This empties the log and shows the spinning indicator
		 */
		var log = $('text').addClass('ajax-loading');
	 
		/**
		 * send takes care of encoding and returns the Ajax instance.
		 * onComplete removes the spinner from the log.
		 */
		this.send({
			update: log,
			onComplete: function() {
				log.removeClass('ajax-loading');
			}
		});
	});
});

}



/* SLIDESHOW
-----------------------------------------------------------------*/

var tal = 1;
var antal_billeder = 5;

function slideshow_previous() {

	if(tal > 1) {
		tal = tal - 1;
		document.getElementById('imageslide').src = '/images/vaerelser-' + tal + '.jpg';
	}
}

function slideshow_next() {

	if(tal < antal_billeder) {
		tal = tal + 1;
		document.getElementById('imageslide').src = '/images/vaerelser-' + tal + '.jpg';
	}
}



/* Thingy
-----------------------------------------------------------------*/

function JP_onload() { repair_footer(); }
function JP_onresize() { repair_footer(); }

window.onload = JP_onload;
window.onresize = JP_onresize;