$(document).ready(function (){
	$(".dropdown-cases-more").click(function (){
		// Scan for large images and animate them down
		$(".dropdown-cases-image-large").parent().animate({width: "100px"},{duration: 1000, easing: 'swing', queue: false});
		$(".dropdown-cases-image-large").next().slideUp();
		$(".dropdown-cases-image-large").animate({width: "100px"}, 1000, 'swing', function(){
			// Hide the caption
			// Remove the large image identifier
			$(this).removeClass("dropdown-cases-image-large");
			// Animate the div.dropdown-cases-right back to default width
			$(this).parent().next().animate({width: "+=100px"}, 1500, 'swing', function(){
				// Slide content
				$(this).children(".dropdown-cases-ajax-full").slideUp("normal", function(){
					$(this).children(".dropdown-cases-ajax-long").hide();
					$(this).children(".dropdown-cases-more-more").show();
					$(this).removeClass("dropdown-cases-ajax-full");
					$(this).prev().slideDown();
				});
			});
		});
		
		// Animate div.dropdown-cases-right
		$(this).parent().parent().animate({width: "-=100px"}, 1000, 'swing', function(){
			// Add .dropdown-cases-image-large to the img in the same section
			$(this).prev().children('.dropdown-cases-image').addClass("dropdown-cases-image-large");
			// Animate the img 
			$(this).prev().animate({width: "200px"},{duration: 1000, easing: 'swing', queue: false});
			$(this).prev().children('.dropdown-cases-image').animate({width: "200px"}, 1000, 'swing', function(){
				// Animate the caption
				$caption = $(this).next();
				// Select the div.dropdown-cases-right and then the p.dropdown-cases-short
				$(this).parent().next().children(".dropdown-cases-short").slideUp("fast", function(){
					var url = $(this).children(".dropdown-cases-more").attr("href");
					// Select div.dropdown-cases-ajax, add class dropdown-cases-ajax-full
					$(this).next().addClass("dropdown-cases-ajax-full");
					$(this).next().children(".dropdown-cases-ajax-short").load(url, function(){
						$(this).parent().slideDown();
						$caption.slideDown();
					});
				});
			});
		});
		
		return false;
	});
	
	$(".dropdown-cases-more-more").click(function(){
		$(this).next().load($(this).attr("href"), function(){
			$(this).prev().hide();
			$(this).slideDown();
		});
		return false;
	});
	
	$(".case-list-header").click(function(){
		$(this).next().slideToggle("normal");
	});
	
	var hashArg = window.location.href;
	if(hashArg.lastIndexOf("#") > 0) {
		hashArg = hashArg.substring(hashArg.lastIndexOf("#") + 1, hashArg.length);
		$("#"+hashArg).trigger('click');
	}
});
