﻿// jQuery centerXY 1.0 Plugin by John Terenzio (http://terenz.io)
jQuery.fn.centerXY = function(loaded, w, h) {
    //alert("loaded: " + loaded);
    var $self = jQuery(this);
    //get the dimensions using dimensions plugin
    var width = w; //300;
    var height = h; //200;
    //alert("height: " + height);  // returning 0 for some reason??
    //alert("width: " + width);
    if (!loaded) {
        //alert("window.height: " + $(window).height());
        //alert("window.width: " + $(window).width());
        $self.css('position', 'fixed');
        //$self.width(width);
        //$self.height(height);
        $self.css('top', $(window).height() / 2 - height / 2);
        $self.css('left', $(window).width() / 2 - width / 2);
        $self.css('height', height);
        $self.css('width', width);
        $(window).resize(function() { $self.centerXY(!loaded, h, w); });
    } else {
        $self.css('position', 'fixed');
        $self.css('height', height);
        $self.css('width', width);
        //$self.css('width', width);
        //$self.css('height', height);
        //$self.width(width);
        //$self.height(height);
        $self.stop();
        $self.animate({ top: $(window).height() / 2 - height / 2, left: $(window).width() / 2 - width / 2 }, 200, 'linear');
    }
};

