
$( document ).ready ( function ( )
{
	// Kick off any jcarousels in the page. They MUST be initialised
	// before the tabs otherwise they'll produce a javascript error
	$( '#insideShop #mycarousel' ).jcarousel ({
		scroll: 6
	});
	$( '#history #mycarousel, .pg_section-leisureRetreats #mycarousel, .pg_section-shop #mycarousel' ).jcarousel ({
		scroll: 3
	});
	$( '#headBanner #mycarousel' ).jcarousel ({
		scroll: 1
	});
	
	// Initialise any tabs in the page
	var tabs = $( "#jqTabs" ).tabs ( );
	
	// pre-select a tab for anchors within tab content
	// the rel attribute of the link specifies the tab to load
	$('#secContent .section ul a[href^=#]').click(function() {
		tabs.tabs('select', '#' + $(this).attr('rel'));
	});
	// pre-select a tab for anchors within tab content
	// the rel attribute of the link specifies the tab to load
	$('#jqTabs div a[href^=#]').click(function() {
		if ( $('#jqTabs .ui-tabs-nav a[href^=' +$(this).attr('href')+ ']').length > 0 )
		{
			tabs.tabs('select', $(this).attr('href'));
			return false;
		}
	});

	// Vertical align content
	$( '.valign' ).each ( function ( i )
	{
		var int_imgHeight				= $(this).height();
		var int_containerHeight	= $(this).parent().height();
		var int_valign					= ( int_containerHeight - int_imgHeight ) / 2;

		$(this).css ( 'margin-top', int_valign );
	});

	// IE 6 specific javascript
	if ($.browser.msie && jQuery.browser.version.substr(0,1) == '6') {
		// fix monster tabs
		$('#priNav li').hover(function () {			
			$(this).addClass('hover');
		},
		function () {
			$(this).removeClass('hover');
		});
		$('#priNav li').unbind('hover');
		// end monster tabs
	}

	if ( $('#indexShop') != 'undefined' )
	{
		// Hide the shop content
		$( '#indexShop .insideShopProduct' ).hide ( );
		// ...but show the first shop content
		$('#indexShop div[id$=-index].insideShopProduct:first').show ( );
		// Set the current content is
	
		$( '#indexShop a.shop_action' ).live('click', function ( )
		{
			$( '#indexShop .insideShopProduct' ).hide ( );
			str_content_id = $( this ).attr ( 'href' );
			$( $( this ).attr ( 'href' ) ).show ( );
			return false;
		});
		
	}
	
	if ($.fancybox)
	{
		$( '.polaroid a' ).fancybox ({
			'type' : 'image',
			'padding' : 15,
			'transitionIn' : 'Elastic',
			'transitionOut' : 'Elastic',
			'overlayOpacity' : 0.2,
			'titlePosition' : 'inside'
		});
	}
	
	if ( $('.pollParent form') != 'undefined')
	{
		$(".pollParent form input[type=submit]").click(function()
		{
			parentDiv = $(this).closest('.pollParent');
			parentForm = $(this).closest('form');
			// Send the form data as a GET to the validation script
			$.get("/p/inc.polls.php", parentForm.serializeArray(),
			// When the result from the validation script is returned
			// execute the following. The result is passed in str_data
			function(str_data)
			{
				parentDiv.html(str_data);
			});

			return false;
		});
	}

	var input = null;

	$("#pollForm input[type='radio']").change(function() {
		var self = $(this);

		if(self.hasClass("other")) {
			// create
			if(!input) {
				input = $("<input />").attr({
					type: "text",
					name: "_other_"
				});

				$(this).parent().append(input);
			}

			input.css("display", this.checked ? 'inline' : 'none');
		}
		else if(input && !input.val())
			input.css("display", 'none');
	});
});


