// make me more generic
var Location = function(baseName) {
	var self = this;
	this.baseName = baseName;
	this.container = $('#' + baseName);
	this.tab = $('#' + baseName + '_link');
	this.map_link = $('#' + baseName + '_map_link');
	this.photo_link = $('#' + baseName + '_photos_link');
	this.map_container = $('#' + baseName + '_map_container');
	this.photo_container = $('#' + baseName + '_photos_container');
};
Location.setMap = function(location) {
	location.map_link.addClass('selected');
	location.photo_link.removeClass('selected');
	location.map_container.removeClass('left-9999');
	location.photo_container.addClass('left-9999');
};
Location.setPhoto = function(location) {
	location.photo_link.addClass('selected');
	location.map_link.removeClass('selected');
	location.photo_container.removeClass('left-9999');
	location.map_container.addClass('left-9999');
};
Location.prototype = {
	isSelected : function() {
		return this.tab.hasClass('selected');
	},
	select : function() {
		this.container.removeClass('left-9999');
		this.tab.addClass('selected');
	},
	clear : function() {
		this.container.addClass('left-9999');
		this.tab.removeClass('selected');
	},
	clearLinks : function() {
		this.map_link.removeClass('selected');
		this.photo_link.removeClass('selected');
	},
	isMap : function() {
		return this.map_link.hasClass('selected');
	},
	isPhoto : function() {
		return this.photo_link.hasClass('selected');
	}
}
$(function() {
	var homer_glen = new Location('homer_glen');
	var joliet = new Location('joliet');
	
	homer_glen.tab.click(function(event) {
		event.preventDefault();
		if (!homer_glen.isSelected()) {
			homer_glen.select();
			joliet.clear();
			if (joliet.isMap()) {
				joliet.clearLinks();
				Location.setMap(homer_glen);
			}
			else {
				joliet.clearLinks();
				Location.setPhoto(homer_glen);
			}
		}
	});
	joliet.tab.click(function(event) {
		event.preventDefault();
		if (!joliet.isSelected()) {
			joliet.select();
			homer_glen.clear();
			if (homer_glen.isMap()) {
				homer_glen.clearLinks();
				Location.setMap(joliet);
			}
			else {
				homer_glen.clearLinks();
				Location.setPhoto(joliet);
			}
		}
	});
	homer_glen.map_link.click(function(event) {
		event.preventDefault();
		if (!homer_glen.isMap()) {
			Location.setMap(homer_glen);
		}
	});
	homer_glen.photo_link.click(function(event) {
		event.preventDefault();
		if (!homer_glen.isPhoto()) {
			Location.setPhoto(homer_glen);
		}
	});
	joliet.map_link.click(function(event) {
		event.preventDefault();
		if (!joliet.isMap()) {
			Location.setMap(joliet);
		}
	});
	joliet.photo_link.click(function(event) {
		event.preventDefault();
		if (!joliet.isPhoto()) {
			Location.setPhoto(joliet);
		}
	});
	joliet.clear();
	homer_glen.select();
	Location.setMap(homer_glen);
});
