/* 
 * This software and source code is private property protected
 * under copyright laws. Any form of using this software or
 * source code for commercial or non-commercial purposes is
 * strictly forbidden. If you don't own written permission to
 * view or use this source code from author of the software, you
 * are to close and delete this file immediately.
 * 
 * Any non-permitted use of this software or source code will be
 * punished by law.
 * 
 * Copyright (2011) Michal Sukupčák (michal.sukupcak@gmail.com)
 */

var popupStatus = 0;
var background = '#background';
var popupId;

function showPopup(id) {
    if (popupStatus == 0) {
	popupId = '#' + id;
	var viewportHeight;
	if (self.pageYOffset) {
	    viewportHeight = self.pageYOffset;
	}  else {
	    if (document.documentElement && document.documentElement.scrollTop) {
		viewportHeight = document.documentElement.scrollTop;
	    } else {
		viewportHeight = document.scrollTop;
	    }
	}
	if (!viewportHeight) {
	    viewportHeight = 0;
	}
	$(popupId).css({
	    'position': 'absolute',
	    'top': viewportHeight + 50,
	    'left': document.documentElement.clientWidth/2-$(popupId).width()/2
	});
	$(background).css({
	    'height': document.documentElement.clientWidth
	});
	$(background).css({
	    'opacity': '0.7'
	});
	$(background).fadeIn('slow');
	$(popupId).fadeIn('slow');
	$(document).find('object,embed,iframe').hide();
	popupStatus = 1;
    }
}

function hidePopup() {
    if (popupStatus == 1) {
	$(background).fadeOut('slow');
	$(popupId).fadeOut('slow');
	$(document).find('object,embed,iframe').show();
	popupStatus = 0;
    }
}

$(document).ready(function() {
    $(background).click(function(){
	hidePopup();
    });
    $(document).keypress(function(e) {
	if(e.keyCode == 27 && popupStatus == 1){
	    hidePopup();
	}
    });
});
