var currentHash;
var currentColumn;

$(document).ready(function() {
	
	SWFAddress.onChange = function() {
	
		if(window.location.hash != "") {
				
				// the column we requested
				currentHash = window.location.hash;
				//alert(currentHash);
				currentColumn = $(currentHash);
			
				// show requested column
				showColumn();
				
				// bind hash links
				bindLinks();
				
			} else {
				
				// hide all photo galleries
				$('.photos').fadeOut(500);
	
				setTimeout(function() {
					// slide off all columns
					$('#sportboat').animate({left:'0px'}, 500);
					$('#runabout').animate({left:'316px'}, 500);
					$('#racer').animate({left:'632px'}, 500);
					$('#custom').animate({left:'948px'}, 500);
				}, 500);
	
				return false;
				
		}
				
	};
	
	$('a.backbtn').click(function() {
		
		// hide all photo galleries
		$('.photos').fadeOut(500);
		
		setTimeout(function() {
			// slide off all columns
			$('#sportboat').animate({left:'0px'}, 500);
			$('#runabout').animate({left:'316px'}, 500);
			$('#racer').animate({left:'632px'}, 500);
			$('#custom').animate({left:'948px'}, 500);
		}, 500);
		
		window.location.hash = '';
		
		return false;
	});
	
});

function showColumn() {
	
	//console.log("fired");
	
	// hide all photo galleries
	$('.photos').fadeOut(500);
	
	// slide off all columns
	$('.column').animate({left:'-300px'}, 500);
	
	// show requested column
	currentColumn.animate({left:'0px'}, {duration:500, queue:false});
	
	// show requested column's photos
	setTimeout(function() {
		$(currentHash + '_photos').fadeIn(500);
		
		// bind hash links
		bindLinks();
	}, 500);
}

function bindLinks()
{
	$('a.viewphotos').click(function() {
		// unbind hash links
		$('a.viewphotos').unbind('click');
		
		// the column we clicked
		currentHash = $(this).attr('href');
		currentColumn = $(currentHash);
		
		//window.location.hash = currentHash;
		
		return false;
	});
}
