
var dont_close = false;
var dont_close_once = false;

function show_info() {
	$('.window_frame').css({opacity: 0.0, visibility: "visible"}).animate({opacity: 1.0}, 500, function() {
		/*if ($.browser.msie) {
			cufon_x();
		}*/
	});
}

$(function() {
	$('body').click(function (e) {
		if (typeof $.window != 'undefined') {
			if ($(e.target).parents('.window_panel').length == 0 && $.window.getAll().length > 0 && dont_close === false && dont_close_once === false) {
				$.window.closeAll(true);
			} else if (dont_close_once === true) {
				dont_close_once = false;
			}
		}
	});
	
	$('#login_window').click(function(e) {
		e.preventDefault();
		$.window.closeAll(true);
		dont_close_once = true;
		var this_obj = $(this);
		var top = $(window).scrollTop();
		var li_x = this_obj.position().left + (this_obj.outerWidth(true) / 2) - 210;
		var li_y = this_obj.offset().top + this_obj.outerHeight(true) - top + 20;
		if (screen.width <= 1024) {
			li_x = -1;
			li_y = -1;
		}
		
		var href = this_obj.attr('href');
		$.window({
			title: "Prisijunkite",
			url: '/ajax.php?action=login&redirect='+href,
			z: 1409,
			x: li_x,
			y: li_y,
			width: 420,
			height: 240,
			animationSpeed: 500,
			scrollable: false,
			showFooter: false,
			onShow: function (wnd) {
				if ($('div.window_panel').length > 0) {
					$('div.window_panel').append('<div class="rod2"></div>');
				}
				show_info();
				//console.log(dont_close);
				//dont_close = false;
			}
		});
	});
});
