var current = 2;
$(document).ready(function(){
	$('#flows').css('visibility','visible');
	if($('#flows').html() != undefined)
	{
		flow_effects();
	}
	$('.flow').parent().click(function(){
		return false;
	});
	$('.flow').each(function(index){
		$(this).click(function(){

			if($(this).hasClass('flow_current'))
			{
				self.location.href = $(this).parent().attr('href');
			}
			else
			{
				current = index;
				flow_effects();
			}
			return false;
		});
	});
});

function flow_effects()
{
	
	var flow_w = 461;
	var flow_y = 208;
	var flows = $('.flow');
	var count = flows.length;
	var width = 976;
	var half = width/2 - 461/2;
	//setting up spot
	var gap = 100;

	var center = (width-flow_w)/2;
	var onesidemax = 3;
	
	var zindex = 10;
	
	flows.each(function(){
		$(this).removeClass('flow_current');
	});
	
	//alert(current);
	for(var i=1;i<=current;i++)//process left hand side images
	{
		var flow = flows.eq(current-i);
		var width = flow_w * (0.9 - 0.15*i);
		var height = flow_y * (0.9 - 0.15*i);
		var top = (flow_y - height) / 2;
		var left = center - (i)*gap + 30*(i-1);
		if(i<=onesidemax)
		{
			flow.css('zIndex',zindex--).show().animate({'left':left, 'top': top, 'width':width, 'height':height}, 200);
		}
		else
		{
			flow.css('zIndex',zindex--).show().animate({'left':left	, 'top': top, 'width':width, 'height':height}, 100).fadeOut(100);
		}
		
	}
	
	for(var i=1;i<=count-1-current;i++)//process right hand side images
	{
		var flow = flows.eq(current+i);
		var width = flow_w * (0.9 - 0.15*i);
		var height = flow_y * (0.9 - 0.15*i);
		var top = (flow_y - height) / 2;
		var left = center + (i+1)*gap + 50*(i-1);
		if(i<=onesidemax)
		{
			flow.css('zIndex',zindex--).show().animate({'left':left, 'top': top, 'width':width, 'height':height}, 200);
		}
		else
		{
			flow.css('zIndex',zindex--).show().animate({'left':left, 'top': top, 'width':width, 'height':height}, 100).fadeOut(100);
		}

	}

	flows.eq(current).addClass('flow_current').css('zIndex',100).show().animate({'left':center, 'top':0, 'width':'461', height:'208'}, 400);	
}