$(document).ready(function() {
	$('.jscrollpane_here').jScrollPane();

	if('placeholder' in document.createElement('input') === false) {
		$('[placeholder]').live('focus',function() {
			if($(this).val() == $(this).attr('placeholder') && $(this).hasClass('placeholder')) {
				$(this).val('').removeClass('placeholder');
			}
		}).live('blur',function() {
			if ($(this).val() == '') {
				$(this).addClass('placeholder').val($(this).attr('placeholder'));
			}
		}).blur();
	}
	$('#booking_form_form').live('submit',function(event) {
		var bookingFormContents = $(this).serialize();
		loadSectionHere.fadeTo(200,0,function() {
			$.ajax({
				type: 'POST',
				url: 'submit/receive_booking_form.php?booking_form_submit=true',
				data: bookingFormContents,
				success: function(data) {
					$('.article').html(data);
					loadSectionHere.fadeTo(200,1,function() {
						$('.jscrollpane_here').jScrollPane();
						$('[placeholder]').blur();
					});
				}
			});
		});
		// alert('Load was performed : '+bookingFormContents);
		event.preventDefault();
	});
});

var 
	backgroundImages = ['home4.jpg','home4.jpg','ball_and_pins.jpg','shoes.jpg','kingpin_suite.jpg','pinball.jpg','fridge_bar.jpg','kingpin_wallpaper.jpg','karaoke3.jpg','kingpin_shoes.jpg','ball_and_pins.jpg'],
	pageId = 0,
	loadSectionHere = $('#load_section_here'),
	supersizeContainer = $('#supersize')
;

$('a.load_section').click(function(event) {
	var
		thisHref = $(this).attr('href'),
		pageToLoad = thisHref.split('?')[1],
		thisPageId = thisHref.split('=')[1].split('&')[0]
	;
	$('#menu2 li.selected').removeClass('selected');
	$(this).parents('#menu2 > li').addClass('selected');
	$('.ppt').remove();
	$('.pp_overlay').remove();
	$('.pp_pic_holder').remove();
	if(thisPageId != pageId) {
		loadSectionHere.fadeTo(200,0);
		supersizeContainer.fadeTo(200,0,function() {
			loadSectionHere.empty();
			supersizeContainer.empty().append('<img src="bg_images/'+backgroundImages[thisPageId]+'" id="background_image">');
			loadSectionHere.load('section_loader.php?'+pageToLoad,function() {
				$(document).ready(function() {
					$('.jscrollpane_here').jScrollPane();
					$('[placeholder]').blur();
				});
				supersizeContainer.fadeTo(200,1);
				loadSectionHere.fadeTo(200,1);
			});
		});
		pageId = thisPageId;
	}
	else {
		loadSectionHere.fadeTo(200,0, function() {
			loadSectionHere.empty();
			loadSectionHere.load('section_loader.php?'+pageToLoad,function() {
				$(document).ready(function() {
					$('.jscrollpane_here').jScrollPane();
					$('[placeholder]').blur();
				});
				loadSectionHere.fadeTo(200,1);
			});
		});
	}
	event.preventDefault();
});

