// vertical positioning in the viewport

(function($) {
    $.fn.vCenter = function(options) {

        var offset = 0;
        if (options != null) {
            offset = options;
        }

        var pos = {
            sTop: function() {
                return window.pageYOffset || document.documentElement && document.documentElement.scrollTop || document.body.scrollTop;
            },
            wHeight: function() {
                return window.innerHeight || document.documentElement && document.documentElement.clientHeight || document.body.clientHeight;
            }
        };


        return this.each(function(index) {
            if (index == 0) {
                var $this = $(this);

                //get the dimensions using dimensions plugin
                var width = $this.width();
                var height = $this.height();
                //get the paddings
                var paddingTop = parseInt($this.css("padding-top"));
                var paddingBottom = parseInt($this.css("padding-bottom"));
                //get the borders

                ////Commented out b/c IE returns "medium" or a string
                //var borderTop = parseInt($this.css("border-top-width"));
                //var borderBottom = parseInt($this.css("border-bottom-width"));


                //get the media of padding and borders
                //var mediaBorder = (borderTop + borderBottom) / 2;
                var mediaPadding = (paddingTop + paddingBottom) / 2;

                //get the type of positioning
                var positionType = $this.parent().css("position");

                // get the half minus of width and height
                var halfWidth = (width / 2) * (-1);
                var halfHeight = ((height / 2) * (-1)) - mediaPadding;
                

                var elHeight = $this.height();
                var elTop = pos.sTop() + (pos.wHeight() / 2) - (elHeight / 2) - mediaPadding - offset;
                $this.css({
                    position: 'absolute',
                    marginTop: 0,
                    top: elTop

                });


            }
        });
    };

})(jQuery);



