
var galleries;

function getImageName(obj, size) {
	var s = obj.src;
	var i = s.lastIndexOf('.');
	s = s.substring(0, i - 1) + size + s.substring(i);
	
	return s;
}

function showMediumImage(obj, captionText, photoCredits) {
	var img = getImageName(obj, 'm');
	var i = img.lastIndexOf('/'); 
	img = img.substring(i + 1);
	$('mediumImage').style.visibility='hidden';
	ImageDWRController.getImageWidth(img, function(width) {
		if (width != -1) {
			widthBB = width + 16;
			widthIFE = (width / 2) - 4;
		} else {
			widthBB = 288;
			widthIFE = 124;
		}
		$('spi').style.width = widthBB + 'px';
		$('img-f').style.width = widthBB + 'px';
		$('captionTextId').style.width = widthIFE + 'px';
		$('photoCreditsId').style.width = widthIFE + 'px';
			
		if (captionText || photoCredits) {
			if ($('captionTextId')) {
				$('captionTextId').innerHTML = captionText;
			}
			var creditsText = '';
			if (photoCredits) {
				creditsText = '&copy; ' + photoCredits;
			}
			if ($('photoCreditsId')) {
				$('photoCreditsId').innerHTML = creditsText;
			}
			$('img-f').show();
		} else {
			$('img-f').hide();
		}
		
		$('mediumImage').src = getImageName(obj, 'm');
		$('mediumImageLink').href = getImageName(obj, 'l');
		setTimeout(function() {$('mediumImage').style.visibility='visible';}, 500);
	});
	
	return false;
}

function initGallery(items) {
	galleries = new Array();
	galleries['Species'] = new Array();
	galleries['Species']['IMG'] = new Array();
	
	for (j = 0; j < items.length; j++) {
		galleries['Species']['IMG'].push(Builder.node('a', {
			'href' : items[j], 
			'class': 'lightwindow', 
			'rel' : 'Species[IMG]',
			'id' : 'lightwindow_image_' + i
		}));
	}
	Event.observe(window, 'load', function() {
		if (!myLightWindow) {
			myLightWindow = new lightwindow();
		}
		myLightWindow.galleries = galleries;
	});
}
	
function showLargeImage(obj) {
	imgSrc = getImageName(obj, 'l');
	myLightWindow.activateWindow({href: imgSrc, type: 'image'});
	
	return false;
}

function showPopup(src, type) {
	if (type == 'image') { 
		myLightWindow.activateWindow(
			{href: src,	type: type}
		);
	}
	if (type == 'video') {
		myLightWindow.activateWindow(
			{href: CONTEXT_PATH + '/swf/player.swf?file=' + src + '&type=video', type: 'media', width: 328, height:200}
		);
	}
	if (type == 'audio') {
		myLightWindow.activateWindow(
			{href: CONTEXT_PATH + '/swf/player.swf?file=' + src + '&type=audio', type: 'media', width: 328, height:200}
		);
	}
	return false;
}

