(function($) {
	$.fn.casestudyLoad = function(options) {
	
		var defaults = {}
		var options = $.extend(defaults, options);
						 
		return this.each(function() {

			var obj = $(this);			
			var isActive = false;
			
			obj.children().each(function() {

				$(this).bind('click', function(event) {
					event.preventDefault();
					if(isActive == false) {
						isActive = true;					
						var clicked = $(this);
						var temp = $(this).attr('id').split('-');
						var currentActive = $('.logoactive').attr('id');
						var activeTemp = currentActive.split('-');

						$('#'+currentActive).find('img').attr('src', '/images/work/large-'+activeTemp[0]+'-grey.gif');
						$('#'+currentActive).removeClass('logoactive');

						$(clicked).find('img').attr('src', '/images/work/large-'+temp[0]+'.gif');
						$(clicked).addClass('logoactive');

						$('.infoactive').fadeOut('slow', function() {
							var oldCase = $(this).attr('id').split('-');
							$(this).removeClass('infoactive');						
							$('#'+temp[0]+'-info').fadeIn('slow', function() {
								$('#'+temp[0]+'-info').addClass('infoactive');
								$('#'+oldCase[0]+'-caseimage').animate({
									width: '0px'
									}, { duration: 400, complete: function() {
										$('#'+temp[0]+'-caseimage').animate({
										width: '456px'	
										}, {duration: 400}, function() {	
							
										});
									
									}
								});
								isActive = false;
							});
						});
					}

				});
				
				$(this).hover(function() {
					var temp = $(this).attr('id').split('-');
					$(this).find('img').attr('src', '/images/work/large-'+temp[0]+'.gif');
				} , function() {
					var temp = $(this).attr('id').split('-');
					if(!$('#'+temp[0]+'-logo').hasClass('logoactive')) {
						$(this).find('img').attr('src', '/images/work/large-'+temp[0]+'-grey.gif');					
					}
				});

			});
	

		});

	}
})(jQuery);