// Imageresize jQuery Plugin
// Author: Adeel Ejaz (http://adeelejaz.com/)
// Version: 2.0.0
// License: Dual licensed under MIT or GPL licenses.
// change by David Hohl 24.07.2010
(function($) {
	$.fn.aeImageResize = function(options) {
		var params = jQuery.extend({
			height: 9,
			width: 9
		}, options);

		this.each(function() {
			var height = params.height,
				width = params.width,
				img_height = $(this).attr('height'),	// change to attr
				img_width = $(this).attr('width'),		// change to attr
				m_ceil = Math.ceil,
				m_floor = Math.floor;

			if (img_height >= img_width) {
				width = m_floor(m_ceil(img_width / img_height * height));
			} else {
				height = m_floor(m_ceil(img_height / img_width * width));
			}
			$(this).attr({
				'height': height,
				'width': width
			});
		});
	};
})(jQuery);

// overlay Loader
// Author: David hohl
// Version: 0.9.1
// License: Dual licensed under MIT or GPL licenses.
$(document).ready(function(){
	var overlay_counter = 1;
	$("a img[rel]").each(function() {
		$(this).attr('rel',$(this).attr('rel') + '_' + overlay_counter);
		var overlay_id = $(this).attr('rel');
		overlay_id = overlay_id.replace('#','');
		var parent = $(this).parent().get(0);
		if($('#'+overlay_id).length == 0) {
			var resize_image = '';
			 resize_image = 'width="'+$(this).attr('width')+'" height="'+$(this).attr('height')+'"';
			$('body').append($('<div />').attr({'class': 'apple_overlay', 'id': overlay_id}).html('<img src="'+$(parent).attr('href')+'" '+ resize_image+' class="resizeme" />'));
		}
		overlay_counter++;	
	});
	 $(".resizeme").aeImageResize({height: 350, width: 460});
	$("img[rel]").overlay({effect: 'apple', closeOnEsc: true, closeOnClick: true, load: false, fixed: true, speed: 'normal', top: '25%'});
});