/**
	* @preserve Travel Website JavaScript
	* @author Robin Bolton <robin@parcommarketing.com>
	* @version 20101122.1655
	* 
	* TODO Write instructions
	*/
SITEACTIONS = {
	// GLOBAL
	common: {
		init: function() {

			/** Add placeholder text to relevant form elements **/
			$('form input').h5Placeholder();

		}
	},

	// HOME PAGE
	home: {
		init: function() {

			/** Rotating Banners **/
			$('div#banner>div.inner')
				.scrollable({
					circular: true,
					easing: 'easeInQuart',
					items: '.banner-items',
					speed: 600,
					vertical: true})
				.autoscroll({interval: 5000})
				.navigator({
					indexed: true,
					navi: 'div.banner-thumbs'});

			/** Search Box Tabs **/
			$('ul.svTabs>li>a').click(function (evt) {
				var svWrap = $(this).closest('div.svWrap, div.svWideWrap');
				var iframe = svWrap.find('iframe');
				var items = svWrap.find('ul.svTabs>li');
				var currentItem = $(this).parent();

				// Indicate current tab
				items.removeClass('current');
				currentItem.addClass('current');

				// Class the frame by determining which tab was clicked
				var frameClass = currentItem.attr('class').split(' ', 1)[0].replace('Tab', 'Frame');
				iframe.removeClass();
				iframe.addClass(frameClass);
			});

		}
	},
		
	// CONTACT PAGE
	contact: {
		init: function() {

			// Contact form validation
			if (jQuery().validate) { $('#contactForm').validate(); }

		}
	}
};


UTIL = {
	exec: function( controller, action ) {
		var ns = SITEACTIONS,
				action = ( action === undefined ) ? "init" : action;

		if ( controller !== "" && ns[controller] && typeof ns[controller][action] == "function" ) {
			ns[controller][action]();
		}
	},

	init: function() {
		var body = document.body,
				controller = body.getAttribute( "data-controller" ),
				action = body.getAttribute( "data-action" );

		UTIL.exec( "common" );
		UTIL.exec( controller );
		UTIL.exec( controller, action );
	}
};

$(document).ready(UTIL.init);

