var slide =
{
	eachWidth: function(){
		
		
		if($("#home_video").length > 0) {
			return 428;
		} else { 
			return 296; 
		}
	}, //change to 391 when the new home goes live
	currDir: 'left',
	duration: 750,
	navObj: null,
	q: $({}),
	
	init: function(){
		
		slide.navObj = $('#home_slideshow_inner');
		
		// Move this into css
		var totalWidth = slide.eachWidth() * $('#home_slideshow_inner img').length;
		slide.navObj.css('width', totalWidth);
	},
	
	move: function(dir){	
		
		// Clear queue if direction is reversed
		if (slide.currDir != dir)
		{
			while( slide.q.queue().length > 1)
			{slide.q.queue().pop();}
		}
					
		// Skip if queue is already at 4 actions
		if ( slide.q.queue().length < 4 )
		{
			// Move last item to front
			if(dir == 'left')
			{
				slide.q.queue(function(next){
					
					// Detach last item, move to front
					var last = $('#home_slideshow_inner a:last').detach();
					$('#home_slideshow_inner').css('marginLeft','-'+slide.eachWidth()+'px').prepend(last);
					$('#home_slideshow_inner').animate({marginLeft: 0}, slide.duration, next);
					
				});
			}
			else
			{
				slide.q.queue(function(next){
					
					// Detach first item, move to back
					$('#home_slideshow_inner').animate({marginLeft: '-'+slide.eachWidth()+'px'}, slide.duration, function(){
						var first = $('#home_slideshow_inner a:first').detach();
						$('#home_slideshow_inner').css('marginLeft','0px').append(first);
						next();
					});
					
				});
			}
			
			slide.currDir = dir;
		}
	}
};

function swapHomeBox(div)
{
	$('#home_topbox_content').animate({marginLeft: '-700px'}, 300);
	setTimeout(function(){
		$('#home_topbox_content').html($('#' + div).html()).animate({marginLeft: '0px'}, 300, function(){
			/*if($('#home_topbox_content .tb_inner_content').height() < 120)
			{
				$('#topbox_arrows').fadeOut("medium");
			}
			else
			{
				$('#topbox_arrows').fadeIn("medium");
			}*/
		});
	}, 300);
}

function moveHomebox(dir)
{
	if(dir == 'up')
	{
		$('#home_topbox_content .tb_inner_content').animate({marginTop: '0px'}, 300);
	}
	else
	{
		$('#home_topbox_content .tb_inner_content').animate({marginTop: '-100px'}, 300);
	}
}

