function htmlspecialchars(text) {
	var chars = Array("&", "<", ">", '"', "'");
	var replacements = Array("&amp;", "&lt;", "&gt;", "&quot;", "'");
	for(var i=0; i<chars.length; i++) {
		var re = new RegExp(chars[i], "gi");
		if(re.test(text)) {
			text = text.replace(re, replacements[i]);
		}
	}
	return text;
}

function trim(string) {
	return string.replace(/(^\s+)|(\s+$)/g, "");
}

var show_modal = function() {
	$('.temp_image').unbind('load').load(function() {
		$('.temp_place, .temp_panel').show();
		var w = $(this).width();
		var h = $(this).height();
		$('.temp_panel').css('margin-left', -Math.round(w/2) + 'px').css('margin-top', -Math.round(h/2) + 'px');
	});

	$('.temp_place, .temp_panel').unbind('click').click(function() {
		$('.temp_place, .temp_panel').hide();
	});

	var str =
		$(this).attr('href').
		replace(/^.*\/([a-zA-Z0-9_\.\-]+)\/$/, '$1').replace(/\.\_/gi, '/').
		replace('\-100x100', '-400x500').replace('\-200x200', '-400x500').replace('\-150x150', '-400x500');
	$('.temp_image').attr('src', str);
	return false;
};

$(window).keypress(function(event) {
	if(event.keyCode == '27') {
		$('.temp_place, .temp_panel').hide();
	}
});

$(document).ready(function() {
	$('a.oldsite_left').live('click', show_modal);
	$('a.oldsite_right').live('click', show_modal);

	$('.temp_place').addClass('temp_fullscreen_place');
	$('.temp_panel').addClass('temp_fullscreen_panel');
	
	// Fancybox
	$('a.splasher').attr('rel', 'gallery').fancybox();
});

