jQuery.fn.center = function (absolute) {
	return this.each(function () {
		var t = jQuery(this);

		t.css({
			position:	absolute ? 'absolute' : 'fixed',
			left:		'50%',
			top:		'50%',
		}).css({
			marginLeft:	'-' + (t.outerWidth() / 2) + 'px',
			marginTop:	'-' + (t.outerHeight() / 2) + 'px'
		});

		if (absolute) {
			t.css({
				marginTop:	parseInt(t.css('marginTop'), 10) + jQuery(window).scrollTop(),
				marginLeft:	parseInt(t.css('marginLeft'), 10) + jQuery(window).scrollLeft()
			});
		}
	});
};

function launchWindow(id) {

		//Get the screen height and width
		var maskHeight = $(document).height();
		var maskWidth = $(window).width();

		//Set heigth and width to mask to fill up the whole screen
		$('#mask').css({'width':maskWidth,'height':maskHeight});

		//transition effect
		//$('#mask').fadeIn(500);
		$('#mask').fadeTo("fast",0.6);

		//Get the window height and width
		//var winH = $(window).height();
		//var winW = $(window).width();
        $(id).center(true);
		//Set the popup window to center
		//$(id).css('top',  winH/2-$(id).height());
		//$(id).css('left', winW/2-$(id).width()/2);

		//transition effect
		$(id).fadeIn(700);
}

function hide()
{
 $('#mask').hide();
 $('.window').hide();
}

$(document).ready(function(){
    $('#FormSporocilo').delegate("#close","click",function (e) {
	  e.preventDefault();
		$('#mask').hide();
		$('.window').hide();
        return false;
	});

	//if mask is clicked
	$('#mask').click(function () {
		$(this).hide();
		$('.window').hide();
	});

  $("#newssign").click(function(){
      var n = $(".epodrocje:checked").length;
      var e = $("#enoviceemail").val();
      if ((n>0) && ( e.length > 0 && e != "Vaš email naslov..." ))
      {
          var seria = $("form#enoviceform").serialize();
          $.post('model/_ajax.newssign.model.php',seria, function(data) {
               $('#FormSporocilo').html(data);
               launchWindow('#FormSporocilo');
                $('input.epodrocje').attr('checked', false);
                $('input#enoviceemail').attr('value','');
          });

      }

      return false;

  });
});
