
// AISPIRE LIGHTBOX SIMPLE GALLERY
var currSlideNumber=0;
var numberOfSlides=0;
var intervalHandle="";
function advanceSlide() {
	// Hide old slide and, asynchronously...
	$('#slideshowSlide'+currSlideNumber).css({opacity:1}).stop().animate(
		{ opacity:0.0 },
		2000,
		function() { $(this).hide(); }
	).css({'z-index':'0'});
	currSlideNumber+=1;
	// ... show new slide
	currSlideNumber%=numberOfSlides;
	$('#slideshowSlide'+currSlideNumber).css({opacity:0}).show().stop().animate(
		{ opacity:1.0 },
		2000,
		function() { }
	).css({'z-index':'1000'});
	// ... and show the titles for one second
	//$('#slideshowPage'+currSlideNumber+' span.slideshowItemName').slideDown(1000, function() { hideTitles(); });
}
function startSlides(numberOfSlides) {
	$('.slideshowSlide').hide(); // initially hide all slides
	currSlideNumber = numberOfSlides-1; // last slide, so we'll start by advancing to first slide
	advanceSlide();
	intervalHandle = setInterval(advanceSlide,5000);
}
// END LIGHTBOX GALLERY


function loadGalleryImages(year) {

		// remove bolding class from all year spans
		$('.galleryYear').removeClass('bold')
		// add bolding class to this year's span
		$('.galleryYear[title='+year+']').addClass('bold');

		$('#gallery').html("");							 // Remove any existing images from the DOM
		var data = {'action':'getGallery', 'year':year}; // Start with no year
		$.ajax({										 // Get the correct images
			url:'assets/php/fbto.php',
			type:"POST",
			data:data,
			success:function(r){
				$('#gallery').html(r);
				$('.gallery-thumb-image').unbind('click');
				$('.gallery-thumb-image').click(function(){
					var small = this;
					var f = $(this).attr('title');
					var big = $("<img class='bigGalleryImage' src='"+f+"' alt='Folk by the Oak' />");
					big.hide();
					big.load(function() { 
						ml = -big.width()/2;
						big.css({'top':'10%', 'left':'50%', 'margin-left':ml}).show();					
					});
					$('body').append(big);
					$('body').append("<div id='galleryBGHaze'></div>");
					$('body').append("<img id='gallerySpinner' src='assets/images/spinner4.gif' alt='spinner' />");
					$('body').append("<div id='galleryControls'><span class='galleryButton' id='galleryPrev'>&lt;</span><span class='galleryButton' id='galleryQuit'> X </span><span class='galleryButton' id='galleryNext'>&gt;</span></div>");
					$('#galleryBGHaze').css({'opacity':'0.75'});
/*
					$('.bigGalleryImage').click(function(){
						$(this).remove();
						$('#galleryBGHaze').remove();
						$('#galleryControls').remove();
					});
*/
					$('#galleryQuit').click(function(){
						big.remove();
						$('#galleryBGHaze').remove();
						$('#galleryControls').remove();
						$('#gallerySpinner').remove();
					});
					$('#galleryNext').click(function(){
						var nextF = $(small).parent().next().find('img').attr('title');
						if (typeof(nextF)=="undefined") { return false; }
						$('.bigGalleryImage').remove();
						small = $(small).parent().next().find('img').eq(0);
						big = $("<img class='bigGalleryImage' src='"+nextF+"' alt='Folk by the Oak' />");
						big.hide();
						big.load(function() { 
							ml = -big.width()/2;
							big.css({'top':'10%', 'left':'50%', 'margin-left':ml}).show();					
						});
						$('body').append(big);					
					});
					$('#galleryPrev').click(function(){
						var nextF = $(small).parent().prev().find('img').attr('title');
						if (typeof(nextF)=="undefined") { return false; }
						$('.bigGalleryImage').remove();
						small = $(small).parent().prev().find('img').eq(0);
						big = $("<img class='bigGalleryImage' src='"+nextF+"' alt='Folk by the Oak' />");
						big.hide();
						big.load(function() { 
							ml = -big.width()/2;
							big.css({'top':'10%', 'left':'50%', 'margin-left':ml}).show();					
						});
						$('body').append(big);					
					});
				});
			}
		});		
}


function showTicketWarning() {
	// define warning popup
/*
	$("body").append("<div id='finishedBG'></div>");
	$("body").append("<div id='finishedFG' class='popup'><span style='font-size:18px;font-weight:bold;'>PLEASE NOTE: Tickets purchased now for this event will NOT be posted. At the concert, make your way to the ‘Box Office’ ticket marquee at the entrance.</span><br><br>Please present a printout of your ‘Payment Successful’ page / your Order Reference number, along with the payment card used during booking, to collect your tickets.<br><br>If you are unable to print, please be sure to note your order reference number and bring your card.<br><br><span class='closePopup' style='font-size:18px;font-weight:bold;text-decoration:underline;'>Continue with my ticket booking &gt;&gt;&gt;</span></div>");
	$('#finishedFG').corner("10px");
	// enable popup dismiss
	$('.closePopup').click(function(){
		$('#finishedBG').remove();
		$('#finishedFG').remove();
	});
*/
	
	alert("PLEASE NOTE: Tickets purchased now for this event will NOT be posted.\n\nAt the concert, make your way to the ‘Box Office’ ticket marquee at the entrance.\n\nPlease present a printout of your ‘Payment Successful’ page / your Order Reference number, along with the payment card used during booking, to collect your tickets.\n\nIf you are unable to print, please be sure to note your order reference number and bring your card.\n\nContinue with my ticket booking >");
}

$(document).ready(function() {

	// Start new slideshow
	numberOfSlides = $('.slideshowSlide').length;
	if (numberOfSlides>0) {
		startSlides(numberOfSlides);
	}

	// Make the WHOLE logo clickable, not just the text
	$('#logo2').click(function(){
		location.href = "index";
	});
	// Make the WHOLE CTA clickable, not just the text
	$('#CTA, #CTA2, #CTA3').click(function(){
		location.href = "buy-tickets";
	});

/*
	$('#CTA').corner("7px");
	$('#CTA2').corner("7px");
	$('#CTA3').corner("7px");
*/
	$('input[name=Submit]').corner("7px");
	$('#getPricesButton').corner("7px");
	
	$('a img').css({'border':'none'});
	$('a img').parent().css({'border':'none'}); // remove borders on IE

	// GALLERY //
	if ($('#gallery').length>0) {
		loadGalleryImages("2011");
//		$('#galleryGeneral').click(function(){ loadGalleryImages("2011"); });
		$('#gallery2011').click(function(){ loadGalleryImages("2011"); });
		$('#gallery2008').click(function(){ loadGalleryImages("2008"); });
		$('#gallery2009').click(function(){ loadGalleryImages("2009"); });
		$('#gallery2010').click(function(){ loadGalleryImages("2010"); });
	}
	


	// Check to see if the venue is past its date (and popup message if it is, or delete it from the list)
	var d = new Date(); // e.g. "Thu Jun 09 2011 21:39:18 GMT+0100 (BST)"
	var dateBits = (""+d).split(" ");
	var dateNum   = parseInt( $.trim(dateBits[2]), 10 );
	var dateMonth = $.trim(dateBits[1]);
	var dateYear  = $.trim(dateBits[3]);
	var simpleDate = dateBits[1]+" "+dateBits[2]+" "+dateBits[3];

	if (dateYear === "2011" && dateMonth === "Jul" && dateNum >= 18 && dateNum < 24 && 
		location.href=="http://www.folkbytheoak.com/buy-tickets" ) {
		showTicketWarning();
		
	} else if (dateYear === "2011" && dateMonth === "Jul" && dateNum === 24 ) {
		alert("Advance booking has now ended for Folk by the Oak\n\nTickets will be available to purchase at the event gate at £37 per adult and £15 per child.\n\nPLEASE NOTE: Cash only on gate.\n\nGates Open 1pm.");
	
	} // else do nothing

});


