function showVideo(file, small) {
	if ($('#flash-nav-container').hasClass('mobile')) {
		return true;
	}
	if (small) {
		var width = 476;
		var height = 247;
		var size = "_s";
		var swf =  "oiartvideoplayer_small.swf";
	} else {
		var width = 1006;
		var height = 499;
		var size = "";
		var swf = "oiartvideoplayer_large.swf";
	}

	var flashvars = {
			'video' : file
		};
					
		var params = {
				'wmode'				: 'transparent',
				'bgcolor'			: '',
				'allowScriptAccess'	: 'always',
				'pluginspage'		: 'http://www.adobe.com/go/getflashplayer',
				'align'				: 'middle',
				'play'				: 'true',
				'loop'				: 'true',
				'scale'				: 'showall',
				'allowFullScreen'	: 'true'
		};
	
	swfobject.embedSWF("static/swf/" + swf, "lightbox-flash", width, height, "9.0.0","expressInstall.swf", flashvars, params);

	toggleLightbox('lightbox-flash-container', height);

	return false;
}
function showGallery(id) {
	var flashvars = {
			'data' : $('base').attr('href') + 'services/gallery.php?id=' + id
		};
					
		var params = {
				'wmode'				: 'transparent',
				'bgcolor'			: '',
				'allowScriptAccess'	: 'always',
				'pluginspage'		: 'http://www.adobe.com/go/getflashplayer',
				'align'				: 'middle',
				'play'				: 'true',
				'loop'				: 'true',
				'scale'				: 'showall',
				'allowFullScreen'	: 'true'
			};

	swfobject.embedSWF("static/swf/oiart_photoviewer.swf", "lightbox-flash", "903", "600", "9.0.0","expressInstall.swf", flashvars, params);
	
	toggleLightbox('lightbox-flash-container', 600);
}

$(document).keyup(function(event) {
	if (event.keyCode == 27) { // ESC
		// check if the video lightbox is open
		if ($('#lightbox-player:visible').length == 0) {
			closeLightbox();
		}
	}
});

$(function() {
	$('div#blanket').click(function() {
		// kill the player
		if ($('#lightbox-player:visible').length == 0) {
			closeLightbox();
		}
	});
});


function toggleLightbox(id, winHeight) {
	$('div.lightbox-wrapper').hide();
	var myLB = $('#' + id).parents('div.lightbox-wrapper');

	myLB.show();

	var windowWidth  = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight; // the height of the browser window


	if (typeof(winHeight) != 'undefined') {
		var lbtop =  windowHeight/2 - winHeight/2 + $().scrollTop();
	} else {
		var lbtop =  windowHeight/2 - myLB.height()/2 + $().scrollTop();
	}

	if (lbtop + myLB.height() > $('body').height()) {
		$('body').height(lbtop + myLB.height());
	}

	$('#blanket').show();
	$('#blanket').height(height + 800);

	// to compensate for the body { position: relative }, which fixes the resizing issue
	/*
	if ($.browser.msie) {
		var diff = $('html').width() - $('body').width();
		var offset = Math.round(diff / 2) * -1;
		$('#blanket').css('left', offset);
	} else {
		var offset = 0;
	}
	*/

	//$('#blanket').css('z-index', 200);

	// centering
	$('.lightbox-wrapper').css({  
		'top':  lbtop, 
		'left': windowWidth/2  - myLB.width()/2,
		'z-index': 1000
	});
	
	return false;
}

function closeLightbox() {
	if ($.browser.msie){ // kill everything now
		$('#blanket').hide();
		$('div.lightbox-wrapper').hide();
	} else { // fade out both blanket and content
		$('#blanket').fadeOut();
		$('div.lightbox-wrapper').fadeOut();
	}

	var off = $('#footer').offset();
	$('body').height(off.top + 150);

	$('#lightbox-flash-container').html('<div id="lightbox-flash"></div>');

	return false;
}

