//-------------------------------------
//  Subnav
//-------------------------------------

		// adds in the toggle html.
		$(document).ready(function(){
		$("#subnav li.sub-level-1").parent().parent().find("a:first").after("<div class=\"toggle togglevis\"></div>");
		});
		
		$(document).ready(function(){
			$('#subnav li.sub-level-0').hover(
			function(){ $(this).find("div").removeClass('togglevis') },
			function(){ $(this).find("div").addClass('togglevis') }
			)
		});
		
		// makes active item's toggle visible
		$(document).ready(function(){
			$('#subnav li.active').find('div').addClass('togglevis2')
		});
		
		$(document).ready(function(){
			$('#subnav li div.toggle').click(
			function(){ $(this).toggleClass('togglevis2'); }
			)
		});
		
		//this allows smoother scrolling...test on other browsers!
		$(document).ready(function(){
			$('#subnav li ul').css('padding', '0px');
			$('#subnav li ul').find('li:first').css('padding-top', '10px');
			$('#subnav li ul').find('li:last').css('padding-bottom', '10px');
		});
		
		//scroll code
		function initMenu() {
		  $('#subnav li div.toggle').click(
			function() {
				$(this).next().slideToggle('normal');	
			  }
			);
		  }
		$(document).ready(function() {initMenu();});
		


//-------------------------------------
//  content expander toggles
//-------------------------------------

$(document).ready(function(){

	//Hide (Collapse) the toggle containers on load
	$(".toggle_container").hide(); 

	//Switch the "Open" and "Close" state per click
	$("h2.trigger").toggle(function(){
		$(this).addClass("active");
		}, function () {
		$(this).removeClass("active");
	});

	//Slide up and down on click
	$("h2.trigger").click(function(){
		$(this).next(".toggle_container").slideToggle("slow");
	});

});


//-------------------------------------
//  club list expander toggles
//-------------------------------------

$(document).ready(function(){

	//Hide (Collapse) the toggle containers on load
	$(".details").hide(); 

	//Switch the "Open" and "Close" state per click
	$("a.trigger").toggle(function(){
		$(this).addClass("active");
		}, function () {
		$(this).removeClass("active");
	});

	//Slide up and down on click
	$("a.trigger").click(function(){
		$(this).parent().next(".details").slideToggle("fast");
	});

});




//-------------------------------------
// promo fader
//-------------------------------------

function slideSwitch() {
    var $active = $('#promotion a.active');

    if ( $active.length == 0 ) $active = $('#promotion a:last');

    var $next =  $active.next().length ? $active.next()
        : $('#promotion a:first');

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

$(function() {
    setInterval( "slideSwitch()", 12000 );
});








//-------------------------------------
// Live scores ticker
//-------------------------------------

		/*!
		 * liScroll 1.0 updated by @davetayls
		 * Examples and documentation at: 
		 * http://www.gcmingati.net/wordpress/wp-content/lab/jquery/newsticker/jq-liscroll/scrollanimate.html
		 * 2007-2009 Gian Carlo Mingati
		 * Version: 1.0.1 (07-DECEMBER-2009)
		 * Dual licensed under the MIT and GPL licenses:
		 * http://www.opensource.org/licenses/mit-license.php
		 * http://www.gnu.org/licenses/gpl.html
		 * Requires:
		 * jQuery v1.2.x or later
		 * 
		 */
		jQuery.fn.liScroll = function(settings) {
			settings = jQuery.extend({
				travelocity: 0.05,
				showControls: false
			}, settings);
			return this.each(function() {
				var strip = this;
				var $strip = jQuery(strip);
				$strip.addClass("liScroll-ticker")
				$stripItems = $strip.find("li");
				var stripWidth = 0;
				var $mask = $strip.wrap("<div class='liScroll-mask'></div>");
				var $tickercontainer = $strip.parent().wrap("<div class='liScroll-container'></div>").parent();
				var paused = false;
				var containerWidth = $strip.parent().parent().width(); //a.k.a. 'mask' width
		
				var currentItemIndex = function() {
					var index = 0;
					var currentLeft = parseInt($strip.css("left"));
					var accumulatedWidth = 0;
					if (currentLeft > 0) {
						return 0;
					} else {
						$strip.find("li").each(function(i) {
							if (currentLeft == (0 - accumulatedWidth)) {
								index = i;
								return false;
							}
							accumulatedWidth += jQuery(this).width();
							if (currentLeft > (0 - accumulatedWidth)) {
								index = i;
								return false;
							}
							return true;
						});
					}
					return index;
				};
				var next = function() {
					pause();
					var index = currentItemIndex();
					if (index >= $stripItems.length - 1) {
						$strip.css("left", "0px");
					} else {
						var $itm = $stripItems.eq(index + 1);
						$strip.css("left", (0 - $itm.position().left) + "px");
					}
				};
				var pause = function() {
					$strip.stop();
					$tickercontainer
						.removeClass("liScroll-playing")
						.addClass("liScroll-paused");
					paused = true;
				};
				var previous = function() {
					pause();
					var index = currentItemIndex();
					var $itm = null;
					if (index == 0) {
						$itm = $stripItems.eq($stripItems.length - 1);
					} else {
						$itm = $stripItems.eq(index - 1);
					}
					$strip.css("left", (0 - $itm.position().left) + "px");
				};
				var play = function() {
					var offset = $strip.offset();
					var residualSpace = offset.left + stripWidth;
					var residualTime = residualSpace / settings.travelocity;
					scrollnews(residualSpace, residualTime);
					$tickercontainer
						.addClass("liScroll-playing")
						.removeClass("liScroll-paused");
					paused = false;
				};
				var togglePlay = function() {
					if (paused) {
						play();
					} else {
						pause();
					}
				};
		
				if (settings.showControls) {
					var $prev = $("<div class='liScroll-prev'>&lt;</div>")
						.appendTo($tickercontainer)
						.click(function() { previous.call(strip); });
					var $pause = $("<div class='liScroll-play'>Pause</div>")
						.appendTo($tickercontainer)
						.click(function() { togglePlay.call(strip); });
					var $next = $("<div class='liScroll-next'>&gt;</div>")
						.appendTo($tickercontainer)
						.click(function() { next.call(strip); });
				}
		
		
				$stripItems.each(function(i) {
					stripWidth += jQuery(this, i).width();
				});
				$strip.width(stripWidth);
		
				var totalTravel = stripWidth + containerWidth;
				var defTiming = totalTravel / settings.travelocity; // thanks to Scott Waye		
		
		
				function scrollnews(spazio, tempo) {
					$strip.animate({ left: '-=' + spazio }, tempo, "linear", function() { $strip.css("left", containerWidth); scrollnews(totalTravel, defTiming); });
				}
				scrollnews(totalTravel, defTiming);
				$tickercontainer.addClass("liScroll-playing")
				$strip.hover(pause, play);
			});
		};
		
		//-----------------------
		
		
			$().ready(function(){
				$("ul#ticker").liScroll();
			});



//-------------------------------------
// Fancybox
//-------------------------------------

	$(document).ready(function() {
		/* This is basic - uses default settings */
		$("a[rel=thumbpic]").fancybox();
		/* Using custom settings */
		$("a#inline").fancybox({
			'hideOnContentClick': true
		});
		$("a.group").fancybox({
			'speedIn'		:	600, 
			'speedOut'		:	200, 
			'overlayShow'	:	false
		});
	});





//-------------------------------------
// Enquiry form
//-------------------------------------


	$(function()
	{
		$('.date-pick').datePicker();

	});




