/* Copyright (c) 2009 Rudie Schaaphuizen, Gillz http://www.gillz.nl
 * Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
 * jQuery Thumcropper
 * Version: 1.0 (September 11, 2009)
 * Requires: jQuery 1.3+
 */

(function($){  
 $.fn.thumbcrop = function(options) {  
   
	var defaults = {  
		thumbwidth: 182,
		thumbheight: 80
	};  
	var options = $.extend(defaults, options);
	var size = Array;
   
	return this.each(function() {
		//var images = $('img');
		//images.each(function() {
			$(this).replaceWith('<div class="getEdit greenlined"><img src="'+$(this).attr('src')+'" class="'+$(this).attr('class')+'"/></div>');
			var obj = $('.getEdit'); $(obj).removeClass('getEdit');
			
			// de grootte van de afbeelding ophalen
			size['height'] = $('img', obj).height();
			size['width'] = $('img', obj).width();
			
			// rescale image
			size['ratio'] = size['width'] / options.thumbwidth;
			size['width'] = options.thumbwidth;
			size['height'] = size['height'] / size['ratio'];
			
			// de margin-top berekenen
			size['margin'] = (size['height'] - options.thumbheight) / 2;
			
			// de maten aan de afbeelding en de div meegeven
			$('img', obj).css({'height': size['height'],'width': size['width'], 'marginTop': '-'+size['margin']+'px'});
			$(obj).css({'height': options.thumbheight,'width': options.thumbwidth, 'overflow': 'hidden'});
		//});
	});  
 };  
})(jQuery); 