var GDirs = 
{
	baseUrl: null,
	dBox: null,
	originalText: null,
	addyBox: null,

	init: function()
	{
		GDirs.baseUrl = location.protocol + '//' + location.hostname + '/';
		var url = location.pathname;
		if (location.hostname == 'devsys2.gaslightmedia.com') {
			var urlParts = url.split('/');
			GDirs.baseUrl += urlParts[1] + '/';
		} else if (location.hostname == 'kanga.acrewoods.com') {
			var site = location.pathname.split('/');
			var urlParts = url.split('/');
			GDirs.baseUrl += urlParts[1] + '/' + site[2] + '/';
		}

		GDirs.addyBox = $('#toaddress');
		GDirs.originalText = GDirs.addyBox.val();
		GDirs.dBox = $('#google-div');
		GDirs.dBox.before('<!-- <a href="#"> -->' +
			'<div id="google-map-link">Get Driving Directions</div> <!-- <img class="member-button" src="'+ GDirs.baseUrl +'assets/buttons/directions.gif" alt="Get Driving Directions" title="Get Driving Directions" id="google-map-link"> -->' +
		  '<!-- </a> -->');
		GDirs.dBox.hide();
		$('#google-map-link').bind('click', GDirs.toggleBox);
		$('#GDirs').bind('submit', GDirs.submitForm);
		GDirs.addyBox.bind('focus', GDirs.clearForm);
		GDirs.addyBox.bind('blur', GDirs.fillForm);
	},

	toggleBox: function(event)
	{
		event.preventDefault();
		GDirs.dBox.slideToggle('normal');
	},

	submitForm: function(event)
	{
		if (GDirs.addyBox.val() == GDirs.originalText || GDirs.addyBox.val() == '') {
			event.preventDefault();
			alert('Please fill in your Address');
		}
	},

	clearForm: function(event)
	{
		if (GDirs.addyBox.val() == GDirs.originalText) {
			GDirs.addyBox.val('');
		}
	},

	fillForm: function(event)
	{
		if (GDirs.addyBox.val() == '') {
			GDirs.addyBox.val(GDirs.originalText);
		}
	}
};

var Imgs = 
{
	init: function()
	{
		$('.member-img-s').bind('click', Imgs.updateImage);
	},

	updateImage: function(event)
	{
		$(this).effect('transfer', {to: "#member-img-1"}, 300);
		$(this).queue(function() {
			$('#member-img-1').attr('src', $(this).attr('id'));
			$('#photo-caption').text($(this).attr('alt'));
			$(this).dequeue();
		});
	}
};

$(document).ready(GDirs.init);
$(document).ready(Imgs.init);

