// slideshow
jQuery(document).ready(function ($) {

	jQuery.isset = function(name) {
		return (typeof(window[name]) !== 'undefined') ? true : false;
	};

	var ecoThumbs = {
		init: function (thumb) {

			var thumbs = $(thumb);
			
			var status = typeof(window['ide_thumb_captions']) != 'undefined' ? ide_thumb_captions : 0;

			$(thumbs).find('img').each(function() {
				$(this).attr('title', '');
			});
			
			$(thumbs).find('.caption').each(function() {
				$(this).css('opacity', 0.8 ).
					width( $(this).parent().width() ).
					height( 30 );
					
					
					if(status < 2)
						$(this).css('top', $(this).parent().height() );
			});

			if(status == 1) {
				$(thumbs).hover(function() {
					var c = $(this).find('.caption');
					
					$(c).stop().animate({top: $(this).height() - $(c).height()  },{queue:false,duration:200});
				}, function() {
					$(this).find('.caption').stop().animate({top: $(this).height() },{queue:false,duration:200});
				});
			}

		}
	};

	// initialize the slides
	ecoThumbs.init('#thumbgallery .thumb');


	// try to auto-resize large blog post images so that they don't overflow
	if($.isset('ide_img_resize') && ide_img_resize) {
		$('.widget_links img').each(function() {
			$(this).parent().parent().parent().addClass('widgetbanners');
		});				

		$('.post .text').each(function() {
			var maxWidth = $(this).outerWidth();
			var maxHeight = $(this).outerHeight();

			$(this).find('img').each(function() {
			
				var width = $(this).width();
				var height = $(this).height();

				var ratio = height / width;
				if(width >= maxWidth){
					width = maxWidth;
					height = width * ratio;
				} else if(height >= maxHeight){
					height = maxHeight;
					width = height / ratio;
				}
				
				$(this).css('width', width);
				$(this).css('height', height);
			});
		});
	}
	
});

