/*
 *  Modal window by Gurduza Oleg
 */

jQuery.fn.center = function () {
    this.css("position","absolute");
    this.css("top", ( $(window).height() - this.height() ) / 2+$(window).scrollTop() + "px");
    this.css("left", ( $(window).width() - this.width() ) / 2+$(window).scrollLeft() + "px");
    return this;
}


$(function(){


     $('a[name=openmodal]').click(function(e){e.preventDefault();
         var id = $(this).attr('href');
         //Get the window height and width
       //  var winH = $(window).height();
       //  var winW = $(window).width();
         //Set the popup window to center
         if($("#"+id).height()>0)$('#windowcontent').css('height', $("#"+id).height()+'px');
         if($('#'+id).width()>0) $('#windowcontent').css('width',$('#'+id).width()+'px');

         //transition effect
         $('#windowcontent').html($("#"+id).html());
         $("#window").center();
         $('#window').fadeIn(500);
         
      });
      $('.close').click(function(e){e.preventDefault();
         //transition effect
         $('#window').fadeOut(500);
         $('#windowcontent').html('');
      });

      openmodal = function(id, address , type){
        type = (type==''?"html":type);
        if(id==''){
            $.ajax({type: 'POST', url: address,dataType: type ,data:{},
              success: function(data){
                 // alert(data.content +' '+data.width+' '+data.height)
                  
                  $('#windowcontent').html(data.content);
                  $('#windowcontent').css({'width':data.width+'px','height':data.height+'px'});
              }
            });
        }
        else $('#windowcontent').html($("#"+id).html());
        $("#window").center();//position({my: "center",at: "center",of: window});
        $('#window').fadeIn(500);

      }


    



});
