
	// Controls if the Edit in CMS link is display.
	// Some later code will set this to true if the user has access
	var bln_cms_access = false;
	
	//JQuery show/hide - Tanya Stovold 31/03/2010 ->
	$("#tabs").livequery(function() {
		//JQuery Tabs - Tanya Stovold 26/03/2010
		$("#tabs").tabs(); 
	});	
	
	$(document).ready(function() {
		//Show all the toggle triggers
		$('a[class^=toggle_trigger]').show();
		
		//Hide all the elements by default
		$('a[class^=toggle_trigger]').each(function(index) {
			var toggle_element = $(this).attr("id") + "_element";													  					
			$("#"+toggle_element).hide();
        });
			
		//On toggle, show and hide			
		$('a[class^=toggle_trigger]').toggle(function() {
			//Show the element													  			
			var toggle_element = $(this).attr("id") + "_element";													  						
			$("#"+toggle_element).show("slow");			
			$(this).empty();
			$(this).append('<img alt="Hide" src="/i/minus.png" class="show_hide" />'); 

			return false;			
		}, function() {
			//Hide the element													  
			var toggle_element = $(this).attr("id") + "_element";													  					
			$("#"+toggle_element).hide("slow");
			$(this).empty();
			$(this).append('<img alt="Show" src="/i/plus.png" class="show_hide" />'); 
			return false;			
		});						   
	});
	//JQuery show/hide - Tanya Stovold 31/03/2010	

	$(document).ready(function()
	{		
		sfHover = function() {
			var sfEls = document.getElementById("priNav").getElementsByTagName("LI");
			for (var i=0; i<sfEls.length; i++) {
				sfEls[i].onmouseover=function() {
					this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
					this.className=this.className.replace(new RegExp(" sfnohover\\b"), "");
					this.className+=" sfhover";
				}
				sfEls[i].onmouseout=function() {
					this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
					this.className=this.className.replace(new RegExp(" sfnohover\\b"), "");
					this.className+=" sfnohover";
				}
			}
		}
		if (window.attachEvent) window.attachEvent("onload", sfHover);

		
		/*
		$('#priNav li').hover(function() {
			jQuery.browser.version = jQuery.browser.msie &&	parseInt(jQuery.browser.version) == 6 && window['XMLHttpRequest'] ?	'7.0' :	jQuery.browser.version;
			if (jQuery.browser.version >= '7.0') $('#priNav li').removeClass('sfhover');
						
			$(this).removeClass('sfnohover');
			$(this).addClass('sfhover');			
			},
			function() {$(this).removeClass('sfhover');
			$(this).addClass('sfnohover');}
		);
		*/
		
		// Vertically align the product header against the image
		$(window).load(function() {
			$('.productTemplate .productHeader').each(function(i) {
				$mainheight = $(this).innerHeight();
				$leftlink		= false;
				$(this).children('p').each(function() {
					if ($(this).attr('class') == 'leftimage') $leftlink = true;
					if ($leftlink && $(this).outerHeight(true) < $mainheight)	{
						var top = ($mainheight - $(this).outerHeight(true) ) / 2;
						$(this).css('margin-top', top);
					}	
				});
			});
		});

		// If an element is given a valign class, vertically
		// align it within it's container 
		$( window ).load ( function ( )
		{
			$( '.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 );
			});
		});

		// If an element is given a fullheight class,
		// maximise it's height within it's container 
		$( window ).load ( function ( )
		{
			$( '.fullheight' ).each ( function ( i )
			{
				// Calculate how much padding the element has
				var str_elPadTop				= $(this).css ( 'padding-top' );
				var str_elPadBot				= $(this).css ( 'padding-bottom' );
				str_elPadTop						= str_elPadTop.substring ( 0, str_elPadTop.length - 2 );
				str_elPadBot						= str_elPadBot.substring ( 0, str_elPadBot.length - 2 );
				// Calculate how much border the element has
				var str_elBorderTop			= $(this).css ( 'border-top-width' );
				var str_elBorderBot			= $(this).css ( 'border-bottom-width' );
				str_elBorderTop					= str_elBorderTop.substring ( 0, str_elBorderTop.length - 2 );
				str_elBorderBot					= str_elBorderBot.substring ( 0, str_elBorderBot.length - 2 );
				// The padding and border must be deducted from
				// the element height to calculate how tall it should be
				var int_elPadding				= parseInt ( str_elPadTop ) + parseInt ( str_elPadBot )
				var int_elBorder				= parseInt ( str_elBorderTop ) + parseInt ( str_elBorderBot )
				var int_containerHeight	= $(this).parent().height() - int_elPadding - int_elBorder;
				// Set the new height of teh container
				$(this).css ( 'height', int_containerHeight );
			});
		});

		var position = $('#csma-club-logo').position();
	//$('#csma-club-logo-dots').width(position.left).height($('#csma-club-logo').height()).css("top",position.top).css("margin-top",0);		
		$('#csma-club-logo-dots').width(position.left).height($('#csma-club-logo').height());		
		
		$('a.counter').click(function()
		{
			link_counter($(this).attr('href'));
		});
		
		var str_default_search_meg		= 'Search term';		
		var bln_default_search_replace		= false;
		var str_default_email_meg			= 'Your e-mail address';
		var str_default_password_meg	= 'Your login password';

		// Default the search form inout text and colour
		if ( $('#search_text').val() == '' )
		{
			$('#search_text').attr( 'value', str_default_search_meg );
			$('#search_text').css( 'color', '#BBB' );
			bln_default_search_replace		= true;
		}
		// Default the login e-mail address inout text and colour
		if ( $('#lg_email').val() == '' )
		{
			$('#lg_email').attr( 'value', str_default_email_meg );
			$('#lg_email').css( 'color', '#BBB' );
		}
		
		// Default the login lg_password inout text and colour
		if ( $('#lg_password').val() == '' )
		{			
			$('#lg_password').hide();
			$("#lg_password").after('<label id="lg_password_dummy_label" for="lg_password_dummy" class="accessibility">Password <span class="required_info">*</span></label><input type="text" class="text" name="lg_password_dummy" id="lg_password_dummy" maxlength="20" value="'+str_default_password_meg+'" />');
			$('#lg_password_dummy').css( 'color', '#BBB' );
		}
		
		$('#search_text').focus(function()
		{
			if ( bln_default_search_replace && $('#search_text').val() == str_default_search_meg )
			{
				$('#search_text').attr( 'value', '' );
				$('#search_text').css( 'color', '#555' );				
				bln_default_search_replace		= false;
			}
		});

		$('#search_text').blur(function()
		{
			if ( $('#search_text').val() == '' )
			{
				$('#search_text').attr( 'value', str_default_search_meg );
				$('#search_text').css( 'color', '#bbb' );				
				bln_default_search_replace		= true;
			}
		});
		
		$('#search_form').submit(function()
		{
			if (bln_default_search_replace || $('#search_text').val() == '') return false;
			/*if ( bln_default_search_replace && $('#search_text').val() == str_default_search_meg )
			{
				$('#search_text').attr( 'value', '' );
				$('#search_text').css( 'color', '#555' );				
				bln_default_search_replace		= false;
			}*/
		});

		$('#lg_email').focus(function()
		{
			if ( $('#lg_email').val() == str_default_email_meg )
			{
				$('#lg_email').attr( 'value', '' );
				$('#lg_email').css( 'color', '#555' );
			}
		});


		$('#lg_email').blur(function()
		{
			if ( $('#lg_email').val() == '' )
			{
				$('#lg_email').attr( 'value', str_default_email_meg );
				$('#lg_email').css( 'color', '#bbb' );
			}
		});
		
		$('#lg_password_dummy').focus(function()
		{
			$('#lg_password_dummy').hide();
			$('#lg_password_dummy_label').hide();
			$('#lg_password').show();
			$('#lg_password').focus();
		});


		$('#lg_password').blur(function()
		{
			if ( $('#lg_password').val() == '' )
			{
				$('#lg_password').hide();
				$('#lg_password_dummy').show();
			}
		});
		
		
		$( '#bannerFadeTop' ).innerFade (
		{ 
			startPause: 2500, animSpeed: 1000, frameDuration: 5000, frameType: 'sequence', containerHeight: '176px' 
		}); 
		
		$( '#bannerFadeBottom' ).innerFade (
		{ 
			animSpeed: 1000, frameDuration: 5000, frameType: 'sequence', containerHeight: '176px' 
		}); 

		$( '#bannerFadeLinked' ).innerFadePlus (
		{ 
			animSpeed: 1000, frameDuration: 5000, frameType: 'sequence', containerHeight: '176px' 
		}); 

	}); // end document ready
	
	function link_counter(url) {
		$.get("/counter.php", { 'redirectto': url, 'ajax': true } );
	}
	
	// timeout function
	$.fn.idle = function(time)
  {
      var o = $(this);
      o.queue(function()
      {
         setTimeout(function()
         {
            o.dequeue();
         }, time);
      });
      return this;              //****
  }
  
/*------------------------------------*/
/* Collapsible boxes on club handbook */
/*------------------------------------*/
$(document).ready(function(){

 $('#handbookList ul ul').css( 'display','none');
 $('#handbookList ul ul.first').css( 'display','block');
 $('.less').hide();
	
	$(".trigger").toggle(function(){
		$(this).addClass("more");
		}, function () {
		$(this).removeClass("more");
	});
	
	$(".trigger").click(function(){
		$(this).next().slideToggle("fast");
	});
	
	 $(".triggerFirst").toggle(function(){
		$(this).removeClass("more");
		}, function () {
		$(this).addClass("more");
	});
	
	$(".triggerFirst").click(function(){
		$(this).next().slideToggle("fast");
	});
 
 });

/*------------------------------------*/
/* History timeline scrolling				  */
/*------------------------------------*/

$(document).ready(function() {
	$('div.scrollable').scrollable();	
});

/*------------------------------------------*/
/* Rounded Corners - 'Great Deal Club'			*/
/*------------------------------------------*/

$(document).ready(function(){ 
	
      $('#quoteBox').cornerz({radius: 8})
			$('#phoneCTA').cornerz({radius: 6})
			$('.voucherBox').cornerz({radius: 6})
			$('#bgCards').cornerz({radius: 5})

	});


/*------------------------------------------*/
/* Playing Card Anim - 'Great Deal Club'		*/
/*------------------------------------------*/
var cardSet = 1;
var currSet = null;
var lastSet = null;
var dealSets = 0;

$(document).ready(function(){
						   
	function dealCards () {	

		cardEle = $('#dealSet .cardSet:nth-child('+cardSet+')');

		$('#mainSet h2').html(cardEle.children('h2').html());

		if (lastSet != null) {
			lastEle = $('#dealSet .cardSet:nth-child('+lastSet+')');
			lastEle.children('div').css( 'left', '50em' );
		}
		lastSet = currSet;
		if (currSet != null) {
			thisEle = $('#dealSet .cardSet:nth-child('+currSet+')');
			thisEle.children('div.card1').animate({left: '-20em' }, {queue:false, duration:600, easing:'easeOutBack'});
			thisEle.children('div.card2').animate({left: '-20em' }, {queue:false, duration:615, easing:'easeOutBack'});
			thisEle.children('div.card3').animate({left: '-20em' }, {queue:false, duration:635, easing:'easeOutBack'});
			thisEle.children('div.card4').animate({left: '-20em' }, {queue:false, duration:650, easing:'easeOutBack'});
		}
		currSet = cardSet;
		cardEle.children('div.card1').animate({left: '-3em' }, {queue:false, duration:600, easing:'easeOutBack'});
		cardEle.children('div.card2').animate({left: '6.5em' }, {queue:false, duration:615, easing:'easeOutBack'});
		cardEle.children('div.card3').animate({left: '16em' }, {queue:false, duration:635, easing:'easeOutBack'});
		cardEle.children('div.card4').animate({left: '25.5em' }, {queue:false, duration:650, easing:'easeOutBack'});

	}

	if ($('#playingCards').length) {

		var cardSet = 1;
		var currSet = null;
		var lastSet = null;
		var dealSets = $('#dealSet .cardSet').length;

		$('#dealSet .cardSet').each(function(i) {
			if (!$(this).hasClass('hiddenSet')) {
				$(this).addClass('hiddenSet');
				cardSet = i+1;
			}
		});
		$('#dealSet').before('<div id="mainSet" class="cardSet"><h2></h2></div>');
		dealCards ();
		
		$('#deal').attr('href','#');
		
		$('#deal').click(function(event) {
								  
			if(cardSet < dealSets) {
				cardSet++;
			} else {
				cardSet = 1;
			}			
			dealCards ();
			
			return false;
		});
	} // end if
});

/* NNEDS SOME INVESGIGATION AS HOW TO PICK UP THEJS
   FOR PHPLIVE (THE FUNCTION NAMES ARE MONDIFIED WITH
   AND IDENIFIER WHICH CHANGES ON EACH PAGE LOAD)
// Start Live Help prompt
setTimeout ( 'live_help_prompt ( )', 5000 ); 

function live_help_prompt ( )
{
	
	$(document).ready(function()
	{													 
		alert ( $( '#live-help' ).attr ( 'src' ) );
		$( this ).htmlLightBox ( { contentURL: '/p/inc.live-help-prompt.php', closeElement: '#htmlLightboxClose' }); 
	});
}

*/