var $j = jQuery.noConflict();
var in_queue = null;

$j(function () {

	var links  = $j("div.swapimg_links a");
	var images = $j("div.swapimg_images img");
	var on_top = $j("div.swapimg_images img:first");
	
	images.each( function() {
		if ($j(this).css("z-index") != "2") {
			$j(this).fadeOut(1);
		}
	});
	
	links.each( function() {
		$j(this).mouseenter( function () {
			if (in_queue) {
				in_queue = $j(this);
			} else {
				show_img($j(this).attr("class"));
			}
		});
	});
	
	function show_img(class_name) {
	    $j("animated").fadeOut(1);
		var img_to_show = $j("img."+class_name);
		if (img_to_show.css("z-index") != "2") {
			img_to_show.css("z-index", "2");
			on_top.css("z-index", "1");
			on_top.css("z-index", "0").fadeOut(1);
			on_top = img_to_show;
			img_to_show.fadeIn(500, function () {
				
				
				if (in_queue && in_queue.attr("class") == class_name) {
					in_queue = null;
				} else if (in_queue) {
					show_img(in_queue.attr("class"));
				}
			});
		}
	}
});

