/* 
* jQuery bgScale v0.0.1
*/
(function($){
	jQuery.fn.bgScale = function(_options){    
		// defaults options	    
		var _options = jQuery.extend({		
			scale:'both'
		},_options);
		
		return this.each(function(){
			var _img = $(this),
				_winHeight, _winWidth, _imgWidth = _img.get(0).width, _imgHeight = _img.get(0).height,
				_thisK = _imgWidth/_imgHeight;
				
			function windowSize (){
				if (window.innerHeight) {
					_winHeight = window.innerHeight;
					_winWidth = window.innerWidth;
				} else {
					_winHeight = document.documentElement.clientHeight;
					_winWidth = document.documentElement.clientWidth;
				}
				if (_winWidth < 950)  _winWidth = 950;
			};
			
			function setBgSize(){
				windowSize();
				_img.css({
					'marginTop':0,
					'marginLeft':0,
					'width':'auto',
					'height':'auto'
				});
				if (_winWidth/_winHeight < _thisK) {
					_img.css({
						'height':_winHeight
					});
					_img.css({
						'marginLeft':-(_img.width()-_winWidth)/2
					});
				} else {
					_img.css({
						'width':_winWidth
					});
					_img.css({
						'marginTop':-(_img.height()-_winHeight)/2
					});
				}
			};
			setBgSize();
			
			$(window).resize(function(){
				setBgSize();
			});				
		});
	}
})(jQuery)





