$(document).ready(function()
{
	var options = {
		toShow: null,
		toHide: null,
		autoHeight: true,
		down: false,
		duration: 500,
		complete: completed
	};
	
	var levelImageCount =  $('div.levelImage').length;
	var rand = Math.floor((levelImageCount)*Math.random())
	$('div.levelImage').eq(rand).slideDown(0);
	var isAnimating = false;
	$("#accordion h2.accordionHeading").mouseover(function()
    {
		if(!isAnimating){
			isAnimating = true;
			//$(this).prev("div.levelImage").slideDown(1000, function(){ isAnimating = false;}).siblings("div.levelImage").slideUp("slow");
			options.toShow = $(this).next("div.levelImage").filter(':hidden');
			options.toHide = $(this).siblings('div.levelImage').filter(':visible');
			
			if(options.toShow.size() && options.toHide.size())
				animation(options);
			else
				isAnimating = false;
		}
	});
	
	function animation(options,additions){
		
		if ( !options.toHide.size() ) {
			options.toShow.animate({height: "show"}, options);
			return;
		}		
		var hideHeight = options.toHide.height(),
			showHeight = options.toShow.height(),
			difference = showHeight / hideHeight;
		options.toShow.css({ height: 0, overflow: 'hidden' }).show();
		options.toHide.animate({height:"hide"},{
			step: function(now) {				
				var current = (hideHeight - now) * difference;
				if ($.browser.msie || $.browser.opera) {
					current = Math.ceil(current);
				}
				options.toShow.height( current );
			},
			duration: options.duration,
			complete: function() {
				if ( !options.autoheight ) {
					//options.toShow.css("height", "auto");
				}
				options.complete();
			}
		});	
	}
	
	function completed(){
		isAnimating = false;
	}
});
