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 clearMe(formfield)
{
  if (formfield.defaultValue==formfield.value)
  formfield.value = "";
}

function restoreMe(formfield)
{
  if (""==formfield.value)
  formfield.value = formfield.defaultValue;
}

function hide()
{
 $('#mask').hide();
 $('.window').hide();
}

$(document).ready(function() {

	//Put in the DIV id you want to display
	//launchWindow('#FormSprocilo');

	//if close button is clicked
	$('.window #close').click(function (e) {
	  e.preventDefault();
	  alert("bugabuga");
		$('#mask').hide();
		$('.window').hide();
        return false;
	});

	//if mask is clicked
	$('#mask').click(function () {
		$(this).hide();
		$('.window').hide();
	});

});


$(function() {
  // prikaz za spodnji blok 3 narocil
    $("form .poslji").click(function() {
        var form = $(this).parents('form:first');
        $.ajax({
            type: "GET",
            url: "_povprasevanje.php?"+form.serialize(),
            dataType: "html",
            error: function(){
                alert('Error loading XML document');
            },
            success: function(data){
                $('#FormSporocilo').html(data);
                launchWindow('#FormSporocilo');
            }
      });
    });
  // prikaz za servis na frameu-desno
    $("form .naroci").click(function() {
        var form = $(this).parents('form:first');
        $.ajax({
            type: "GET",
            url: "_povprasevanje.php?"+form.serialize(),
            dataType: "html",
            error: function(){
                alert('Error loading XML document');
            },
            success: function(data){
                $('#FormSporocilo').html(data);
                launchWindow('#FormSporocilo');
            }
      });
    });
    //narocienovice Narocilo e novice
     $("form .narocienovice").click(function() {
        var form = $(this).parents('form:first');
        $.ajax({
            type: "GET",
            url: "_enovice_prijava.php?"+form.serialize(),
            dataType: "html",
            error: function(){
                alert('Error loading XML document');
            },
            success: function(data){
                $('#FormSporocilo').html(data);
                launchWindow('#FormSporocilo');
            }
      });
    });
    // Narocilo katalogov
     $("form .narocikatalog").click(function() {
        var form = $(this).parents('form:first');
        $.ajax({
            type: "GET",
            url: "_katalogi.php?"+form.serialize(),
            dataType: "html",
            error: function(){
                alert('Error loading XML document');
            },
            success: function(data){
                $('#FormSporocilo').html(data);
                launchWindow('#FormSporocilo');
            }
      });
    });
    // Pošiljanje vprašanja
     $("form .posljivprasanje").click(function() {
        var form = $(this).parents('form:first');
        $.ajax({
            type: "GET",
            url: "_vprasanje.php?"+form.serialize(),
            dataType: "html",
            error: function(){
                alert('Error loading XML document');
            },
            success: function(data){
                $('#FormSporocilo').html(data);
                launchWindow('#FormSporocilo');
            }
      });
    });
});

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);
}

