(function($)
{
	$.fn.SteawAccordion = function() 
	{
		var slideWrapper 	= $(this),									// element that holds the slides
			slides			= slideWrapper.find('.photo').css('display','block'),				// the slides
			slide_count 	= slides.length,							// number of slides
			slide_width		= slideWrapper.width() / slide_count		// width of the slides
			expand_slide 	= slides.width(),							// size of a slide when expanded
			minimized_slide	= (slideWrapper.width() - expand_slide) / (slide_count - 1), // remaining width is shared among the non-active slides
			overlay_modifier = 100,					//increases the size of the minimized image div to avoid flickering
			interval = '',
			current_slide = 0;
		
		//iterate each slide and set new base values, also set positions for acitve and inactive states and event handlers
		slides.each(function(i)
		{
			var this_slide = $(this);// current slide element
											
			this_slide.data( //save data of each slide via jquerys data method
			'data',
			{
				this_slides_position: i * slide_width,							// position if no item is active
				pos_active_higher: i * minimized_slide,							// position of the item if a higher item is active
				pos_active_lower: ((i-1) * minimized_slide) + expand_slide		// position of the item if a lower item is active
			});
				
			//set base properties	
			this_slide.css({zIndex:i+1, left: i * slide_width, width:slide_width + overlay_modifier});
							
			//set mouseover or click event
			this_slide.bind('mouseover', function(event)
			{	
				var objData = this_slide.data( 'data' );
				//on mouseover expand current slide to full size and fadeIn real content
				this_slide.stop().animate({	width: expand_slide + (overlay_modifier * 1.2), 
											left: objData.pos_active_higher},
											300);
				this_slide.find('.photo-excerpt').stop().fadeTo(200,1.0);
									
				//set and all other slides to small size
				slides.each(function(j){
					if (i !== j)
					{	
						var this_slide = $(this),
							objData = this_slide.data( 'data' ),
							new_pos = objData.pos_active_higher;
							
						if(i < j) { new_pos = objData.pos_active_lower; }
						this_slide.stop().animate({left: new_pos, width:minimized_slide + overlay_modifier},300);
						this_slide.find('.photo-excerpt').stop().fadeTo(200,0.0);
					}
				});
			});
		});
		
		//set mouseout event: expand all slides to no-slide-active position and width
		slideWrapper.bind('mouseleave', function()
		{
			slides.each(function(i)
			{
				var this_slide = $(this),
					objData = this_slide.data( 'data' ),
					new_pos = objData.this_slides_position;
					this_slide.stop().animate({left: new_pos, width:slide_width + overlay_modifier},300);
					this_slide.find('.photo-excerpt').stop().fadeTo(200,0.0);
			});
		});	
	};
})(jQuery);
