////////////////////////////////////////////
//	Requies JQuery 1.3.2 or greater
//

//  To create your slideshow, add a div to your document that
//  contains imgs. You don't need anything special, just a div 
//  with some imgs you want to rotate:
//  <div id="yourSlideshowID">
//  	<img />
//  	<img />
//  	<img />
//  </div
//  
//	To use simply link to this file and add a call to this function 
//	in the head of your document. Wrap the call in 
//	JQuery syntax like so:
//
//	<script type="text/javascript">
//		$(document).ready(function() {
//			slideShow('yourSlideShowDivID',fadeTime,pauseTime);
//		});
//	</script>
//
//	If you don't pass a slideshow div id the function will
//	just look for a div called "slideshow" that contains imgs.
//	fadeTime and pauseTime are optional 
//	and default to 750ms and 2500ms respectively
//	If pause time is less than twice fadeTime, you may 
//	have wonky results. We could error check, but I'm not 
//	your mother.
//	To set pauseTime you must set fadeTime. Sorry, but JS is cumbersome
//	like that.
//
//	This function is released under a Your Own Risk license
// 	and you can do whatever you want with it. I make no claims of responsibility 
// 	for anything that it does and you use it at your own risk.
// 	Have a nice day.
///////////////////////////////////////////

function slideshow(theDiv,fadeTime,pauseTime){
	var td = !theDiv ? 'slideshow' : theDiv ;
	if($('#'+td)){
		var ft = !fadeTime ? 750 : fadeTime ;
		var pt = !pauseTime ? 2500 : pauseTime ;
		var pics = $('#'+td+' > img');
		
		if(pics.length > 1){
			var tallest = 0;
			for(var k=1; k < pics.length; k++){
				if (pics[tallest].height > pics[k].height){ 
					continue;
				}
				else {
					tallest = k;
				}
			}
	
			$('#'+td).css('height',pics[tallest].height);
			$('#'+td).css('position','relative');
			$(pics).css('position','absolute');
			
			for(var k=0; k < pics.length; k++){
				if (k == tallest){ 
					continue;
				}
				else {
					$(pics[k]).css('top',(pics[tallest].height - pics[k].height)/2);
				}
			}
			
		   	$('#'+td+' img:not(:first)').hide();
	
			var picsCount = pics.length-1;
			var i = 0;
			var j = 1;
			setInterval(function(){						
					$(pics[i]).fadeOut(ft,function(){$(pics[j]).fadeIn(ft);});
					j = j == picsCount ? 0 : j+1 ;
					i = i == picsCount ? 0 : i+1 ;
				},
				pt);
		}
	}
}

