$(document).ready(function(){

	//When you click on a link with class of poplight and the href starts with a #
	$('#popup').each(function() {
		var popID = $(this).attr('id'); //Get Popup Name

		//Fade in the Popup and add close button
		$('#' + popID).fadeIn().prepend('<a href="#" id="popup-close"><img src="images/popup/popup-close.png" class="png" border="0" title="Zatvor okno" alt="Zatvor" /></a>');

		//Define margin for center alignment (vertical + horizontal) - we add 80 to the height/width to accomodate for the padding + border width defined in the css
		var popMargTop = ($('#' + popID).height() + 11) / 2;
		var popMargLeft = ($('#' + popID).width() + 11) / 2;

		//Apply Margin to Popup
		$('#' + popID).css({
			'margin-top' : -popMargTop,
			'margin-left' : -popMargLeft
		});

		$('body').append('<div id="popup-fade"></div>');
		$('#popup-fade').css({'filter' : 'alpha(opacity=25)'}).fadeIn();

		return false;
	});
	$("#popup-close").click(function() {
		$("#popup").fadeOut(function(){
			$("#popup-fade,#popup-close").remove();
		});
		return false;
	});
	$('.png').ifixpng();
});
