/********************************************************
Name: Bush Accordion
Author: Terence Jefferies & Colin Goodman.
Business: Glow Creative
Version 2.0
Comments: This product was created by Terence Jefferies
for slick image viewing.
********************************************************/
$(function() {

	$('.slider-item').hover(function() {
	
		this.hovering = true;
		$(this).oneTime(300,function() {
			
			if(this.hovering)
			{
				minimizeAll(this);
				expand(this);
			}
			
		});

                
		
	
	},function() {
	
		this.hovering = false;
		maximizeAll(this);
		//$('.slider-description', this).animate({bottom:-150}, 'fast');
	
        });
	
	function minimizeAll(exclude)
	{
	
		var retractWidth = fetchRetract(exclude);
		$('.slider-item').each(function() {
		
			if(this != exclude)
			{
			
				$(this).animate({
				
					width:retractWidth
				
				},'fast');
			
			}
		
		});
	
	}
	
	function maximizeAll(retracting)
	{
	
		$('.slider-item').each(function() {
		
			$(this).animate({ width:137 },'fast');
			if(this == retracting)
			{
			
				var width = parseInt($('img',this).width());
				var moveTo = -(width / 2);
				$('img',this).animate({ left:(moveTo / 2) },'fast');
			
			}
		
		});
		
	}
	
	function fetchRetract(obj)
	{
	
		var width = parseInt($('img',obj).width());
		var retractWidth = (795 - width);
		var retractTo = (retractWidth / 5);
		return retractTo;
	
	}
	
	function expand(obj)
	{
	
		var changeto = parseInt($('img',obj).width());
		$(obj).animate({ width:changeto },'fast',function() { /*$('.slider-description', this).animate({bottom:0}, 'fast');*/ });
		$('img',obj).animate({ left:0 },'fast');	
	
	}

	function init()
	{
		$('.slider-item img').each(function() {
		
			var width = parseInt($(this).width());
			var moveTo = -(width / 2);
			$(this).css('position','relative');
			$(this).css('left',(moveTo / 2));
		
		});
		
		$('.slider-item').each(function() { this.hovering = false; });
	
	}
	
	init();

});
