function resizeLightbox()
{
	var top = $(window).height() / 2 - ($('#ligntbox').css('height').substr(0, 3) / 2 + 20);
	if (top < 0)
		top = 10;
	var left = $(window).width() / 2 - ($('#ligntbox').css('width').substr(0, 3) / 2);
	if (left < 0)
		left = 10;
		
	$('#ligntbox').css('top', top+'px');
	$('#ligntbox').css('left', left+'px');
	
	$('#opacity_div').css('width', $(window).width()+'px');
	$('#opacity_div').css('height', $(window).height()+'px');
}

function showLightbox(item_index)
{
	$('#lightbox_image').attr('src', lightbox_items[item_index]);
	$('#current_index').val(item_index);
	$('#opacity_div').show();
	$('#ligntbox').show();
}
function hideLightbox()
{
	$('#opacity_div').hide();
	$('#ligntbox').hide();
	$('#lightbox_image').attr('src', '');
}
function lightboxPrev()
{
	var current_index = $('#current_index').val() * 1;
	var prev_index = parseInt(current_index - 1);
	
	if (lightbox_items[prev_index] == null)
		prev_index = lightbox_items.length - 1;
		
	showLightbox(prev_index);
}
function lightboxNext()
{
	var current_index = $('#current_index').val() * 1;
	var next_index = parseInt(current_index + 1);

	if (lightbox_items[next_index] == null)
		next_index = 0;
		
	showLightbox(next_index);
}

function showLocationLightbox(item_index)
{
	var address = $('#location_'+item_index+'_title').html();
	$('#ligntbox_title').html(address);
	$('#lightbox_image').attr('src', lightbox_items[item_index]);
	$('#current_index').val(item_index);
	
	$('#opacity_div').show();
	$('#ligntbox').show();
	
	var map = new GMap2(document.getElementById("map_canvas"));
	map.setUIToDefault();
	var geocoder = new GClientGeocoder();	
	geocoder.getLatLng(
		address,
		function(point) {
			if (!point) {
				alert(address + " not found");
			} else {
				map.setCenter(point, 13);
				var marker = new GMarker(point);
				map.addOverlay(marker);
//				marker.openInfoWindow(document.createTextNode(address));
			}
		}
	);
}
function hideLocationLightbox()
{
	$('#opacity_div').hide();
	$('#ligntbox').hide();
	$('#lightbox_image').attr('src', '');
	$('#ligntbox_title').html('');
	$('#map_canvas').html('');
}
function locationLightboxPrev()
{
	var current_index = $('#current_index').val() * 1;
	var prev_index = parseInt(current_index - 1);

	if (lightbox_items[prev_index] == null)
		prev_index = lightbox_items.length - 1;
		
	showLocationLightbox(prev_index);
}
function locationLightboxNext()
{
	var current_index = $('#current_index').val() * 1;
	var next_index = parseInt(current_index + 1);

	if (lightbox_items[next_index] == null)
		next_index = 0;
		
	showLocationLightbox(next_index);
}

function showVideoLightbox(item_index)
{
	var title = $('#item_'+item_index+'_title').html();
	$('#ligntbox_title').html(title);
	$('#current_index').val(item_index);
	
	var flash_html = '<object width="555" height="370">';
	flash_html += '<param name="movie" value="http://www.youtube-nocookie.com/v/'+lightbox_items[item_index]+'?fs=1&amp;hl=ru_RU&amp;color1=0x3a3a3a&amp;color2=0x999999"></param>';
	flash_html += '<param name="allowFullScreen" value="true"></param>';
	flash_html += '<param name="allowscriptaccess" value="always"></param>';
	flash_html += '<param name="wmode" value="opaque"></param>';
	flash_html += '<embed src="http://www.youtube-nocookie.com/v/'+lightbox_items[item_index]+'?fs=1&amp;hl=ru_RU&amp;color1=0x3a3a3a&amp;color2=0x999999" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="555" height="370" wmode="opaque"></embed>';
	flash_html += '</object>';
	$('#video_container').html(flash_html);
	
	$('#opacity_div').show();
	$('#ligntbox').show();
}
function hideVideoLightbox()
{
	$('#opacity_div').hide();
	$('#ligntbox').hide();
	$('#ligntbox_title').html('');
}
function videoLightboxPrev()
{
	var current_index = $('#current_index').val() * 1;
	var prev_index = parseInt(current_index - 1);

	if (lightbox_items[prev_index] == null)
		prev_index = lightbox_items.length - 1;
		
	showVideoLightbox(prev_index);
}
function videoLightboxNext()
{
	var current_index = $('#current_index').val() * 1;
	var next_index = parseInt(current_index + 1);

	if (lightbox_items[next_index] == null)
		next_index = 0;
		
	showVideoLightbox(next_index);
}
