$(document).ready(function($) {
	$('#main').sliderHome();
});


(function($) {
	$.fn.sliderHome = function(options) {
		var opts = {
			delta: 0
		};
		
		return this.each(function() {
			if (options) {
				$.extend(opts, options);
			}
			var $this = $(this),
			$image = $this.find('img');
			var iWidth = $image.attr('width'),
				iHeight = $image.attr('height');
			
			var setItemSize = function() {
				var dHeight = $(window).height();
				var dWidth = $(window).width();
				while (iHeight>dHeight || iWidth>dWidth) {
					iHeight--;
					iWidth--;
				}
				while (iHeight<dHeight || iWidth<dWidth) {
					iHeight++;
					iWidth++;
				}
				
				$image.data('width', iWidth);
				$image.data('height', iHeight);
				$image.css({
					width: iWidth + 'px',
					height: iHeight + 'px',
					/*top: (iHeight - dHeight > 0 ? -1 * Math.floor((iHeight - dHeight) / 2) : 0) + 'px',*/
					left: (iWidth - dWidth > 0 ? -1 * Math.floor((iWidth - dWidth) / 2) : 0) + 'px'
				});
				
				opts.delta = dWidth;
			}
			
			setItemSize();
			$(window).resize(function() {
				setItemSize();
			});
		});
	}
})(jQuery);
