$(function() {
	$('a[rel~=external]').each(function() {
		this.title += 'This link will open another site in a new browser window.';

		//open a resized window if theres window|windowWidth|windowHeight
		var rel = $(this).attr('rel');
		var width, height;
		if(rel.indexOf('|') > -1)
		{
			var dimensions = rel.split('|');
			width = dimensions[1];
			height = dimensions[2];
		}
		$(this).click(function() {
			var url = $(this).attr('href');
			if(width && height)
			{
				window.open(url, '', 'resizeable, width=' + width + ',height=' + height);
			}
			else
			{
				window.open(url);
			}
			return false;
		});
	});
});


$(function() {
	$(document.body).append("<div id='imageDialogContainer'></div>");
	$('a[rel^=imageGallery]').each(function() {
		var rel = $(this).attr('rel');
		var width, height;
		if(rel.indexOf('|') > -1)
		{
			var dimensions = rel.split('|');
			width = dimensions[1];
			height = dimensions[2];
		}
	//	var ratio = width / height;
	//	var documentWidth = $(window).width();
	//	var documentHeight = $(window).height();
	//	var imageWidth = width > documentWidth ? documentWidth / ratio : width;
	//	var imageHeight = height > documentHeight ? documentHeight / ratio : height;

		var imageWidth = width;
		var imageHeight = height;
		
		$(this).click(function() {
			var dialogContainer = 'imageDialogContainer';
			var htmlOutput = "<a href='#' title='Click image to close' onclick='return CloseDialogContainer(this.parentNode.id);'><img src='" + $(this).attr('href') + "' width='" + imageWidth + "' height='" + imageHeight + "' alt='Original image' /></a>";
			$('#' + dialogContainer).css( 'top', $(window).scrollTop() ).empty().html(htmlOutput).show('fast');
			return false;
		});
	});
});

function CloseDialogContainer(dialogContainer)
{
	$('#' + dialogContainer).hide('fast');
	return false;
}