function page_set(){
  if(typeof(photos_total) != 'undefined' && photos_total > 1){
    setTimeout('photo_display(1)', 3000);
  } 
  
  if(typeof(quotes_total) != 'undefined' && quotes_total > 1){
    setTimeout('quote_display(1)', 7000);
  } 
}


/*
* Video with modal
*/

function set_modal(layer_name){
  if((typeof(layer_name)) == 'undefined') layer_name = 'player';
	adjust_modal($(layer_name + '_layer').getHeight());
	$('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(layer_height){
	var offsets = document.viewport.getScrollOffsets();
	$('modal').style.height = document.viewport.getHeight() + offsets[1] + 'px';
  $('modal').style.width = document.viewport.getWidth() + offsets[0] + 'px';
  if(offsets[1] && offsets[1] > 0){
    // This doesn't work well when we have varying top margins on different layers
    // $('player_outer').style.marginTop = ( ( (0 - layer_height) / 2) + offsets[1]) + 'px';
  }
}

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';
	$('modal').style.display = 'none';
	window.onscroll = function() { return true; } 
	window.onresize = function() { return true; }
}

/*
*  End layer
*/


function map_over(){
  $('map_text').style.color = '#ffffff';
  $('map_image').src = '/images/map_70_white.png';
}

function map_out(){
  $('map_text').style.color = '#ffda9c';
  $('map_image').src = '/images/map_70_orange.png';
}

var current_slide_id=0;
var current_slide=false;

function show_slides(id){
}


/*
* Rotating 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});
	}

	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});
}

/*
* End rotating photos
*/ 

/*
* Rotating quotes
*/

var idQuoteCurr='quote-0';
var iCountCurr=0;

var thumb_slide;
var next_quote;
function quote_display(count){
	
	var id='quote-' + count;
	if(idQuoteCurr!=id){
		new Effect.Appear(id, {duration: 1.5});
	}

	if(idQuoteCurr!='' && idQuoteCurr!=id){
		quoteClose(idQuoteCurr);
	}
	
	idQuoteCurr=id;
	iCountCurr=count;
	
	if(count+1 == quotes_total){
		next_quote=0;
	}else{
		next_quote=count+1;
	}
	setTimeout('quote_display(next_quote)', 8000);
}

function quoteClose(id){
	new Effect.Fade(id, {duration: 1.5});
}

/*
* End rotating quotes
*/ 



var current_id = false;
var holding = false;
function display_layer(id){
  
	if(current_id != false && current_id != id){
		close_layer(current_id);
	}
	holding = id;
	setTimeout("show_layer('" + id + "')", 500)
}

function show_layer(id){
  if(holding == id){
    new Effect.Appear(id, {duration: 0.5});
  	current_id = id;
  }
}

function close_layer(id){
	new Effect.Fade(id);
}

function play_video(){
  close_layer('video_front');
  var pos_1 = video_hold.indexOf('src="');
  var pos_2 = video_hold.indexOf('"', pos_1 + 6);
  var video_src = video_hold.substring(pos_1+5, pos_2);
  $('video_show').update(video_tpl.replace(/src=""/, 'src="' + video_src + '&autoPlay=1' + '"'));  
}

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


