jQuery.noConflict();
jQuery(document).ready(indexPopup);
function indexPopup() {
	var win = jQuery(window);
	var wr = jQuery('#ppIndA');
	var wr_bg = jQuery('#ppInd');

	function hasBeenShowed() {
		return (document.cookie.length>0 && document.cookie.indexOf('ppinx') != -1);
	}
	function markAsShowed() {
		var exdate = new Date();
		exdate.setDate(exdate.getDate() + 1);
		document.cookie = 'ppinx=1;expires=' + exdate.toGMTString();
	}
	function centerIt() {
		var x = (win.width() - wr.outerWidth()) / 2;
		var y = (win.height() - wr.outerHeight()) / 2;
		if (x < 0) {
			x = 0;
		}
		if (y < 0) {
			y = 0;
		}
		wr.css({
			'left': x + 'px',
			'top' : y + 'px'
		});
	}
	function fullBg() {
		var b = jQuery('body');
		var w = b.width();
		var h = b.height();
		wr_bg.css({
			'width': w,
			'height': h
		});
	}
	function resize() {
		fullBg();
		centerIt();
	}
	function showIt() {
		wr.addClass('v');
		wr_bg.addClass('v');
		fullBg();
		centerIt();
		jui_dialog_startWatch();
		markAsShowed();
	}
	if (hasBeenShowed()) {
		return true;
	}
	win.resize(resize);
	showIt();
}
function jui_dialog_startWatch() {
	jQuery(document).click(jui_dialog_watchClick).keypress(jui_dialog_ESC);
}
function jui_dialog_watchClick(event) {
    var target = jQuery(event.target);
    if (target.is('#ppIndA') || target.parents('#ppIndA').length) {
        return;
    }
	jui_dialog_close();
}
function jui_dialog_ESC(event) {
	if (event.keyCode == 27) {
		jui_dialog_close();
	}
}

function jui_dialog_close() {
    jQuery('#ppInd, #ppIndA').removeClass('v');
    jQuery(document).unbind('click', jui_dialog_watchClick);
}
