var OpenedModal;

$( function() {
	window.onresize = calculateSizes;
	calculateSizes();
	$(".newsticker").newsticker(5000);
	$('#page-top li a').click( function() {
		$('#page-top li a').removeClass('active');
		$(this).addClass('active');
		$('#feature-left div div').hide();
		$('#plz' + $(this).attr('id').substr(2, 1)).show();
	});

	$('#gs').click( function() {
		// $('#overlay').height($().height());
			// $('#overlay').show();
			showModal('#global');
			return false;

		});

	$('._close').click( function() {
		hideModalWindow(true);
		return false;
	});
	
	$('#loginU').focus(function(){
		if(!($('#loginU').val() != 'email')){
			$('#loginU').val('');
		}
	}).blur(function(){
		if(!($('#loginU').val() != '')){
			$('#loginU').val('email');
		}
	});
	
	
	$('#loginD').focus(function(){
		$(this).hide();
		$('#loginP').show().trigger('focus').blur(function(){
			if(!($('#loginP').val() != '')){
				$('#loginP').hide();
				$('#loginD').show();
			}
		});
	});

});

function calculateSizes() {
	// appHight = $().height();
	$('#overlay').height($().height());
};

function hideWhenEscapePressed(e) {
	if (e.which == 27) {
		hideModalWindow(true);
		return false;
	}
	return true;
};

function hideModalWindow(clear) {
	$('#overlay').toggle();
	OpenedModal.toggle();
	if (clear == true) {
		resetFrom();
	}
	$().unbind();
	return false;
};

function resetFrom() {
	/*
	 * OpenedModal.find(':input').val('');
	 * OpenedModal.find('.active').removeClass('active');
	 * $('#noDeadline').trigger('click');
	 */
}

function showModal(modal_id) {
	OpenedModal = $(modal_id);
	OpenedModal.data('editId', null);
	$('#overlay').height($().height());
	$('#overlay').show();
	$('#overlay').click(hideModalWindow);
	$().keydown(hideWhenEscapePressed);
	OpenedModal.show();
	return false;
}