//function to check for a query parameter
//if there are multiple parameters with the same name, it picks up the first value
function getQueryVariable(variable) {
	var query = window.location.search.substring(1);
	var vars = query.split("&");
	for (var i=0;i<vars.length;i++) {
		var pair = vars[i].split("=");
		if (pair[0] == variable) {
			return pair[1];
		}
	}
	return false;
}

//start building urls
var photo_player_url = 'image_gallery.html';
var movie_url = 'movie_player.html';

//check for deep links
var view_param = getQueryVariable('view');
var image_start_id_param = getQueryVariable('image_start_id');
var style_param = getQueryVariable('style');
var movie_id_param = getQueryVariable('movie_id');

//if deep linking to the photo player
if (view_param && view_param == 'photo'){
	var photo_player_url_array = Array();
	
	//build the url
	if (image_start_id_param) photo_player_url_array[photo_player_url_array.length] = 'image_start_id='+ image_start_id_param;
	if (style_param) photo_player_url_array[photo_player_url_array.length] = 'style='+ style_param;
	
	if (photo_player_url_array.length > 0) photo_player_url += '?'+ photo_player_url_array.join('&');
	
	//alert(photo_player_url);
	
	//launch on load
	document.observe('lightview:loaded', function() {
		Lightview.show({
			href: photo_player_url,
			rel: 'iframe',
			options: {
				width: 915,
				height: 600,
				scrolling: false, 
				closeButton: false
			}
		});
	});
}

//if deep linking to the movie
if (view_param && view_param == 'movie' && movie_id_param){
	var movie_url_array = Array();
	
	//build the url
	movie_url_array[movie_url_array.length] = 'movie_id='+ movie_id_param;
	
	if (movie_url_array.length > 0) movie_url += '?'+ movie_url_array.join('&');
	
	//alert(movie_url);
	
	//launch on load
	document.observe('lightview:loaded', function() {
		Lightview.show({
			href: movie_url,
			rel: 'iframe',
			options: {
				width: 750,
				height: 642,
				scrolling: false, 
				closeButton: false
			}
		});
	});
}
