/*
 * @example
 * $("element").center({
 *
 * 		vertical: true,
 *      horizontal: true
 *
 * });
 * @obs With no arguments, the default is above
 * @param bool vertical, bool horizontal
 *
 */
$.fn.center = function(params) {

		var options = {

			vertical: true,
			horizontal: true

		}
		op = jQuery.extend(options, params);

        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;
          },
          wWidth : function() {            
            return document.documentElement.clientWidth;            
          }
        };

   return this.each(function(){
		
        var $this = $(this);		
		var cssProp = {
			position: 'absolute',
			marginTop: '0'
		};
        
		if(op.vertical) {
            var elHeight = $this.height();
	    	var elTop = pos.sTop() + (pos.wHeight() / 2) - (elHeight / 2);
			cssProp.top = elTop;
		}
				
		if(op.horizontal) {
			cssProp.left =  pos.wWidth() / 2 - $this.width() / 2;			

		}

		//check the current position
        /*
		if(positionType == 'static') {
			$self.parent().css("position","relative");
		}
        */
		//aplying the css
		$this.css(cssProp);
   });
};