$(document).ready(function() {
	var imgHeight = $("#slideshow div:eq(0) img").height();
	$("#slideshow").css({"height" : imgHeight});
});


firstInt = setInterval(slideSwitch, 4000);
lastInt = '';

function slideSwitch() {
	var $active = $('#slideshow DIV.active');
	
	if ( $active.length == 0 ) $active = $('#slideshow DIV:last');

	var $next =  $active.next().length ? $active.next()
	: $('#slideshow DIV:first');

//	var $sibs  = $active.siblings();
//	var rndNum = Math.floor(Math.random() * $sibs.length );
//	var $next  = $( $sibs[ rndNum ] );

    $active.addClass('last-active');
	$next.css({opacity: 0.0})
		.addClass('active')
		.animate({opacity: 1.0}, 1000, function() {
			$active.removeClass('active last-active');
		});
		
		
	$('#slideshow').mouseover(function(){
		if(firstInt != '') {
			clearInterval(firstInt);
		}
		if(lastInt != '') {
			clearInterval(lastInt);
		}
	}).mouseout(function(){
		if(firstInt != '') {
			clearInterval(firstInt);
		}
		if(lastInt != '') {
			clearInterval(lastInt);
		}
		lastInt = setInterval(slideSwitch, 4000);
	});
}

/*
$(function() {
    setInterval("slideSwitch()", 4000);
});
*/

