/*
* 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)', 3000);
  } 
}


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


/*
* Slideshow for a group of photos
*/

var current_slide_id=0;
var current_slide=false;

function show_slides(id){
}

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


/*
* Combine closing any currently element layer in a group and opening the next one
*/
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)
}

/*
* Show any element with fading
*/
function show_layer(id){
  if(holding == id){
    new Effect.Appear(id, {duration: 0.5});
  	current_id = id;
  }
}

/*
* Hide any element with fading
*/
function close_layer(id){
	new Effect.Fade(id);
}

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