/* =========================================================

// jquery.innerfade.js

// Datum: 2007-01-29
// Firma: Medienfreunde Hofmann & Baldes GbR
// Autor: Torsten Baldes
// Mail: t.baldes@medienfreunde.com
// Web: http://medienfreunde.com

// based on the work of Matt Oakes http://portfolio.gizone.co.uk/applications/slideshow/

// Modifications specific to wisinski testimonials made here

// ========================================================= */


(function($) {

$.fn.innerfade = function(options) {

	this.each(function(){ 	
		
		var settings = {
			animationtype: 'fade',
			speed: 'normal',
			timeout: 2000,
			type: 'sequence',
			containerheight: 'auto',
			runningclass: 'innerfade'
		};
		
		if(options)
			$.extend(settings, options);
		
		var elements = $(this).children();
		
	
	
		if (elements.length > 1) {
		
			$(this).css('position', 'relative');
			$(this).css('height', settings.containerheight);
			
			$(this).addClass(settings.runningclass);
			
			for ( var i = 0; i < elements.length; i++ ) {
				$(elements[i]).css('z-index', String(elements.length-i)).css('position', 'absolute');
				$(elements[i]).hide();
			};
		
			if ( settings.type == 'sequence' ) {
				setTimeout(function(){
					$.innerfade.next(elements, settings, 1, 0);
				}, settings.timeout);
				$(elements[0]).show();
				
				// added by mdesign, specific to testimonials
			 //   var moomoo2 = $(elements[0]).height();
			 //   var padThai2 = Math.floor((((230 - moomoo2)/2)-5));
			 //   $(elements[0]).css('padding-top', padThai2);
			
			// added by mdesign, specific to testimonials
		
		if ( !(jQuery.browser.msie && jQuery.browser.version < 7)) { // take away IE6 	
				var topad = $(elements[0]).find('div.fwrap');
				var moomoo2 = topad.height();
				var padThai2 = Math.floor((((230 - moomoo2)/2)-5));
				topad.css('padding-top', padThai2);
			}	
				//alert("height: " + moomoo2 + " pixels; padding:"+padThai2);
				
				
			} else if ( settings.type == 'random' ) {
				setTimeout(function(){
					do { current = Math.floor ( Math.random ( ) * ( elements.length ) ); } while ( current == 0 )
					$.innerfade.next(elements, settings, current, 0);
				}, settings.timeout);
				$(elements[0]).show();
			}	else {
				alert('type must either be \'sequence\' or \'random\'');
			}
			
		}
		
	});
};


$.innerfade = function() {}
$.innerfade.next = function (elements, settings, current, last) {

	if ( settings.animationtype == 'slide' ) {
		$(elements[last]).slideUp(settings.speed, $(elements[current]).slideDown(settings.speed));
	} else if ( settings.animationtype == 'fade' ) {
		$(elements[last]).fadeOut(settings.speed);
		$(elements[current]).fadeIn(settings.speed);
		
		// added by mdesign, specific to testimonials
		//var moomoo = $(elements[current]).height();
		//var padThai = Math.floor((((230 - moomoo)/2)-5));
	//	$(elements[current]).css('padding-top', padThai);
		
	if ( !(jQuery.browser.msie && jQuery.browser.version < 7)) { // take away IE6 		
		
		var topad2 = $(elements[current]).find('div.fwrap');
				var moomoo3 = topad2.height();
				var padThai3 = Math.floor((((230 - moomoo3)/2)-5));
				topad2.css('padding-top', padThai3);
	
	}			
		//alert("height: " + moomoo3 + " pixels; padding:"+padThai3);
		
		
		// added by mdesign, specific to testimonials
		
		//var moomoo3 = $(elements[current]).children().eq(2).height();
		
		//var moomoo3 = $(elements[current]).children().find('p.desc').height();
		//var moomoo3 = $(elements[current]).sibling().height();
		
		//var moomoo3 = $(elements[current]).parent();
		
		//var moomoo4 = moomoo3.children().eq(2).height();

		
		//var moomoo3 = $(this > ".feature_testimonial").height();
		
		//var padThai3 = Math.floor((((250 - moomoo4)/2)-5));
		//$(".feature_testimonial").css('padding-top', padThai3);
		
		
		//alert("height: " + moomoo3 + " pixels; padding:"+padThai3);
		
		
		
		//alert("padding-top: " + padThai3 + "pixels");

		
		
	} else {
		alert('animationtype must either be \'slide\' or \'fade\'');
	};
	
	if ( settings.type == 'sequence' ) {
		if ( ( current + 1 ) < elements.length ) {
			current = current + 1;
			last = current - 1;
		} else {
			current = 0;
			last = elements.length - 1;
		};
	}	else if ( settings.type == 'random' ) {
		last = current;
		while (	current == last ) {
			current = Math.floor ( Math.random ( ) * ( elements.length ) );
		};
	}	else {
		alert('type must either be \'sequence\' or \'random\'');
	};
	setTimeout((function(){$.innerfade.next(elements, settings, current, last);}), settings.timeout);
};
})(jQuery);
