var _tmp_scrolling = [];
var _tmp_scrolling_count;


$(document).ready(function(){
	
	$('div.scrollingHotSpotRight').click(function() {
		$('div#portfolioScroll div.home_portfolio_item').each(function(i)
		{
			_tmp_scrolling [i] = $(this).css('display');
		});
		action_portfolio('right');
	});
	
	$('div.scrollingHotSpotLeft').click(function() {
		$('div#portfolioScroll div.home_portfolio_item').each(function(i)
		{
			_tmp_scrolling [i] = $(this).css('display');
		});
		action_portfolio('left');
	});

});

function action_portfolio( action )
{
	_tmp_scrolling_count = _tmp_scrolling.length - 1;

	if ( action == 'right' )
	{
		if ( _tmp_scrolling[_tmp_scrolling_count] == 'none' )
		{
			for (var i = 0; i <= _tmp_scrolling_count-3; i++)
			{
				if ( _tmp_scrolling[i] != 'none' && _tmp_scrolling[i] != 'show' )
				{
					if ( i+3 <= _tmp_scrolling_count )
					{
						_tmp_scrolling[i] = 'none';
						_tmp_scrolling[i+3] = 'show';
					}
				}
			}
		}
		else
		{
			for (var i = 0; i <= _tmp_scrolling_count; i++)
			{
				if ( i < 3 )
				{
					_tmp_scrolling[i] = 'show';
				}
				else
				{
					_tmp_scrolling[i] = 'none';
				}
			}
		}
	}
	else if ( action == 'left' )
	{
		if ( _tmp_scrolling[0] == 'none' )
		{
			for (var i = _tmp_scrolling_count; i >= 3; i--)
			{
				if ( _tmp_scrolling[i] != 'none' && _tmp_scrolling[i] != 'show' )
				{
					if ( i-3 <= _tmp_scrolling_count )
					{
						_tmp_scrolling[i] = 'none';
						_tmp_scrolling[i-3] = 'show';
					}
				}
			}
		}
		else
		{
			for (var i = 0; i <= _tmp_scrolling_count; i++)
			{
				if ( i > _tmp_scrolling_count-3 )
				{
					_tmp_scrolling[i] = 'show';
				}
				else
				{
					_tmp_scrolling[i] = 'none';
				}
			}
		}
	}

	$('div#portfolioScroll div.home_portfolio_item').each(function(i)
	{
		if ( _tmp_scrolling [i] == 'none' && $(this).css('display') != 'none' )
		{
			$(this).find('div.home_portfolio_item_title').css('display','none');
			$(this).css('display','none');

		}
		else if ( _tmp_scrolling [i] == 'show' )
		{
			if ( action == 'right' )
			{
				$('div.scrollableArea').css('float','right');
			}
			else if ( action == 'left' )
			{
				$('div.scrollableArea').css('float','left');
			}

			$(this).find('div.home_portfolio_item_title').css('display','none');
			$(this).show('1000');
			$(this).find('div.home_portfolio_item_title').css('display','');
		}
	});

	_tmp_scrolling = [];
}
