/* 
 * 
 *   invectorwetrust.com
 *   /2011
 * 
 *   Robert Schulke
 *   heartshapedwork.com
 *
 */


    
(function($){

	$.fn.resizer = function(options) {
		
		function resizeMe(el,natW,natH) {

			el = $(el);

			ratio = natW/natH;

			if ($(window).width() / $(window).height() > ratio)
			{
				// Breitformat
				newWidth = $(window).width();
				newHeight = $(window).width()/ratio;
			} else {
				// Hochformat
				newHeight = $(window).height();
				newWidth = $(window).height()*ratio;
			}

			
			
			// Positionierung
			newX = $(window).width()/2 - newWidth/2;
			newY = $(window).height()/2 - newHeight/2;

			newX = Math.round(newX);
			newY = Math.round(newY);

			$('#container').css('height', $(window).height()-100);
			$('.contentback').css('height', $(window).height()).css('width', $(window).width());

			// update scroll element
			if ($('#copy').length > 0) {

						$('.viewport').css('height', $(window).height()-130);
						$('.track').css('height', $(window).height()-130);
						$('.overview').css('height', $('#copy').height());
						$('#scrollbar1').tinyscrollbar_update();

			}

			el
				.css("width", newWidth)
				.css("height", newHeight)
				.css("left", newX)
				.css("top", newY);

		}

// --------------------------------------------------------

	    return this.each(function() {

			if (this.nodeName == 'IMG') {

				var $this = $(this);
				var $natW = this.naturalWidth;
				var $natH = this.naturalHeight


//				http://ditio.net/2010/01/02/jquery-image-resize-plugin/
  				if(!$natW || !$natH) {
					// Ooops you are an IE user, let's fix it.
					var img = document.createElement('img');
					img.src = this.src;
					
					$natW = img.width;
					$natH = img.height;
				}


				$(window).bind('resize', function() {
					resizeMe($this, $natW, $natH);
				});

				resizeMe($this, $natW, $natH);

		    }
		});

// --------------------------------------------------------

	}

})(jQuery);


