/*
* Put any code in page_set() that needs to be run on window load
*/

function page_set(){
  if(typeof(photos_total) != 'undefined' && photos_total > 1){
    setTimeout('photo_display(1)', 1000);
  } 
  if($('payment_form')){
    $('payment_form').submit();
  }
}


/*
* Modal layers
*/

var player_outer_top_margin = 'undefined';
function set_modal(layer_name){
  if((typeof(layer_name)) == 'undefined') layer_name = 'player';
  if(player_outer_top_margin == 'undefined'){
    player_outer_top_margin = parseInt($('player_outer').getStyle('marginTop'));
  }
	offsets = adjust_modal($(layer_name + '_layer').getHeight());
	// adjust top margin of layer depending on scroll offsets
	if(offsets[1] && offsets[1] > 0){
    $('player_outer').style.marginTop = ( parseInt($('player_outer').getStyle('marginTop')) + offsets[1]) + 'px';
  }
	$('modal').style.display = 'block';
	$('player_outer').style.display = 'block';
	$(layer_name + '_layer').style.display = 'block';
	window.onscroll = function() { adjust_modal($(layer_name + '_layer').getHeight()); } 
	window.onresize = function() { adjust_modal($(layer_name + '_layer').getHeight()); } 
}

function adjust_modal(){
	var offsets = document.viewport.getScrollOffsets();
	$('modal').style.height = document.viewport.getHeight() + offsets[1] + 'px';
  $('modal').style.width = document.viewport.getWidth() + offsets[0] + 'px';
  return offsets;
}

function close_player(layer_name){
  if((typeof(layer_name)) == 'undefined') layer_name = 'player';
	$(layer_name + '_layer').innerHTML = ''; 
	$(layer_name + '_layer').style.display = 'none';
	$('player_outer').style.display = 'none';
	$('player_outer').style.marginTop = player_outer_top_margin + 'px';
	$('modal').style.display = 'none';
	window.onscroll = function() { return true; } 
	window.onresize = function() { return true; }
}

/*
*  End layer
*/


/*
* Slideshow for a group of photos
*/

var idPhotoCurr='img-0';
var iCountCurr=0;

var thumb_slide;
var next_photo;

function photo_display(count){
	var id='img-' + count;
	if(idPhotoCurr!=id){
		// new Effect.Appear(id, {duration: 1.5});
		$('#' + id).fadeIn(1500)
	}

	if(idPhotoCurr!='' && idPhotoCurr!=id){
		photoClose(idPhotoCurr);
	}
	
	idPhotoCurr=id;
	iCountCurr=count;
	
	if(count+1 == photos_total){
		next_photo=0;
	}else{
		next_photo=count+1;
	}
	setTimeout('photo_display(next_photo)', 5000);
}


function photoClose(id){
	//new Effect.Fade(id, {duration: 1.5});
	$('#' + id).fadeOut(1500)
}


/*
* Booking form
*/

function cancellation_insurance(field){
  if(field.value == 'true'){
    $('display_amount').innerHTML = '&euro; 450';
    $('booking_amount_paid').value = 450;
  }else{
    $('display_amount').innerHTML = '&euro; 400';
    $('booking_amount_paid').value = 400;
  }
}


/*
* Call the page set to kick things off
*/

window.onload = function () { page_set(); };