var bln_cms_access = false;

$( document ).ready ( function ( )
{
	// Kick off any jcarousels in the page. They MUST be initialised
	// before the tabs otherwise they'll produce a javascript error
	$( '#mycarousel' ).jcarousel ({
		scroll: 3
	});
	
	if (document.location.hash == '#sn') {
		scrollto = document.location.hash;
		setTimeout ( "$.scrollTo('#terNav', 800)", 500 ); 
		document.location.hash = '';
	}
	
	// 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
	}

	// Replace any 'Y' or 'N' in tables with a tick or a cross
	$( 'table tbody tr' ).find ( 'td' ).each ( function ( )
	{
		str_text	= $( this ).text ( );
		
		if ( str_text == 'Y' )
		{
			$( this ).html ( '<img src="/i/icon-tick.gif" alt="Yes" />' );
		}
		else if ( str_text == 'N' )
		{
			$( this ).html ( '<img src="/i/icon-cross.gif" alt="No" />' );
		}
		
	});

	var options = {
			navigation: 'permanent',
			direction: 	'left',
			opacity: 		'0.5'
	}
	if ($('.ppy').length) $('.ppy').popeye(options);

	// Randomly rotate any polariod images in a gallery
	$( 'div.jcarousel-skin-gallery div.polaroid' ).each ( function ( i )
	{
		var flt_rotate	= ( Math.random ( ) * 4 ) - 2;
		$(this).css ( '-webkit-transform', 'rotate(' + flt_rotate + 'deg)' );
		$(this).css ( '-moz-transform', 'rotate(' + flt_rotate + 'deg)' );
		$(this).css ( 'transform', 'rotate(' + flt_rotate + 'deg)' );
	});
	
	if ($.fancybox)
	{
		$( '.polaroid a' ).fancybox ({
			'type' : 'image',
			'padding' : 15,
			'transitionIn' : 'Elastic',
			'transitionOut' : 'Elastic',
			'overlayOpacity' : 0.2,
			'titlePosition' : 'inside'
		});
	}

});


