// vertical positioning in the viewport

(function($){
  $.fn.smartCenter = function(params) {
    var pos = {
      sTop : function() {
        return window.pageYOffset || document.documentElement && document.documentElement.scrollTop ||	document.body.scrollTop;
      },
	  sLeft : function() {
        return window.pageXOffset || document.documentElement && document.documentElement.scrollLeft ||	document.body.scrollLeft;
      },
      wHeight : function() { 
        return window.innerHeight || document.documentElement && document.documentElement.clientHeight || document.body.clientHeight;
      },
	  wWidth : function() { 
        return window.innerWidth || document.documentElement && document.documentElement.clientWidth || document.body.clientWidth;
      }
    };
	var options = {
			easeIn:false,
			wOffsetWidth:0

		}
	op = jQuery.extend(options, params);

    return this.each(function(index) {
      if (index == 0) {
        var $this = $(this);
        var elHeight = $this.height();
		var elTop = pos.sTop() + (pos.wHeight() / 2) - (elHeight / 2);
		
		var elWidth = $this.width();
		var elLeft = pos.sLeft() + (pos.wWidth() / 2) - (elWidth / 2);
	    
		//document.write(elLeft);
		
		//take into consideration padding
		elLeft = elLeft + 10;//op.wOffsetWidth;
		
		//document.write(elLeft);
		
		if(elTop < 0)elTop=0;
		if(elLeft < 0)elLeft=0;
		
		/*$this.animate({
		  "top": elTop,
		  "left": elLeft
		}, "slow");*/
		
        /*$this.css({
          position: 'absolute',
          marginTop: '0',
          top: elTop,
		  left: elLeft
        });*/
		
		
		if(op.easeIn){
			$this.css({
			  position: 'absolute'
			});	
			
			$this.animate({
			  top:elTop,
			  left:elLeft
			}, "fast");
		}
		else{
			$this.css({
			  position: 'absolute',
			  marginTop: '0',
			  top: elTop,
			  left: elLeft
			});
		}
			


      }
    });
  };

})(jQuery);


