
$(function() {
$('.venue-packages input').click(function(){
		var packageInfo = $(this).val();
		var arr = packageInfo.split('|');
		var package=arr[0];
		var price=arr[2];
		var packageID=arr[1];
		var venueID=arr[3];
		var activityID=arr[4];
		$('.enquiry a').attr('href','https://activitybooker.net/en/enquiry/goballistic.co.uk/pdID-'+packageID+'_oVenue-'+venueID+'_oVenAct-'+activityID+'');
		$('.book-online a').attr('href','https://activitybooker.net/en/booking/goballistic.co.uk/pdID-'+packageID+'_oVenue-'+venueID+'_oVenAct-'+activityID+'');
		//$('.package-details').empty().append('<input type="hidden" name="v_name[]" value="'+package+'"/><input type="hidden" name="packageID" value="'+packageID+'"/><input type="hidden" name="v_price[]" value="'+price+'"/><input type="hidden" name="subtotal" value="'+price+'"/><input class="price" type="hidden" name="total" value="'+price+'"/>');
	});
	//$('.venue-packages button').click(function(){
		//var buttonClass = $(this).parent().attr('class');
		//var packageID = $(".packageIDJS").val();
		//var packageName = $(".packageNameJS").val();
		//var packagePrice = $(".packagePriceJS").val();
		//var packageSubTotal = $(".packageSubTotalJS").val();
		//var packageTotal = $(".packageTotalJS").val();
		//var websiteID = $(".websiteIDJS").val();
		//var locationID = $(".locationIDJS").val();
		//if(buttonClass == "button book-online"){
		//	alert('hello');
		//	$.post('http://www.activitybooker.co.uk/packages/index.php', { packageID:packageID, v_name:packageName, v_price:packagePrice, subtotal:packageSubTotal, total:packageTotal, locationID:locationID},
		//	// database has been updated, email sent
		//	function(){
		//	
		//	document.location = 'https://www.activitybooker.co.uk/packages/?websiteID'+websiteID+'&enquiry=booking';	
		//	});
		//}
		//return false;
	//});
});
///////////////////////////////////////////
/// ajax ///
///////////////////////////////////////////
	$('.popup').livequery('click', function() {
		$('#footer #ajax').remove();
		var loadType = $(this).attr('name');
		var rel = $(this).attr('rel');
		// determine if ajax isset
		var bodyClass = $('body').attr('class');
		if(bodyClass != "ajaxed"){ $('body').addClass('ajaxed').append('<div id="overlay"></div><div id="ajax"></div>'); }
		// loads ajax
		$('body').append('<div id="loading"></div>');
		if(loadType=="href"){
			$('#ajax').fadeIn().append('<div id="iframe" class="plugin"><a href="#" class="ajax-close AJAXCLOSEjs">x</a><iframe src="'+rel+'" width="600px" height="400px" scrolling="no" frameborder="0"></iframe></div>');
		}else if(loadType=="contact"){
			$('#ajax').fadeIn().append('<div id="contact" class="plugin"><a href="#" class="ajax-close AJAXCLOSEjs">x</a><iframe src="'+rel+'" width="801px" height="594px" scrolling="no" frameborder="0"></iframe></div>');
		} else if(loadType=="tellafriend"){
			$('#ajax').fadeIn().append('<div id="tellafriend" class="plugin"><a href="#" class="ajax-close AJAXCLOSEjs">x</a><iframe src="'+rel+'" width="400px" height="594px" scrolling="no" frameborder="0"></iframe></div>');
		} else if(loadType=="hours"){
			$('#ajax').fadeIn().append('<div id="office-hours" class="plugin"><a href="#" class="ajax-close AJAXCLOSEjs">x</a><iframe src="'+rel+'" width="400px" height="325px" scrolling="no" frameborder="0"></iframe></div>');
		} else {
			$('#ajax').fadeIn().load(''+rel+'');
		}
		setTimeout( function() { $('#loading').fadeOut().remove(); }, 2500);
		return false;
	});
/////////////////////////////////////////////////////
	// this closes the specific ajax div
	$('.AJAXCLOSEjs').livequery('click',function() {
		$('#loading').remove();
		$('body').removeClass('ajaxed');
		$('#overlay').remove();
		$('#ajax').remove();
		$('#footer').append('<div id="ajax"></div>');
		return false;
	});
	// this closes all ajax related divs
	$('#overlay').livequery('click',function() {
		$('#loading').remove();
		$('body').removeClass('ajaxed');
		$('#overlay').remove();
		$('#ajax').remove();
		$('#footer').append('<div id="ajax"></div>');
		return false;
	});
/*///////////////////////////////////////*/
/*/ ajax /*/
/*///////////////////////////////////////*/
$(function() {
	// this displays ajax div
	$('.ajax').click(function(){
		var
		rel=$(this).attr('rel');
		$('#ajax').empty().load(rel).show();
		//$('body').append('<div id="overlay"></div>');
		return false;
	});
	function close_ajax(){
		$('#ajax').hide();
		$('#overlay').remove();
	}
	// this closes the ajax div
	$('#ajax h2 a').livequery('click',function() {
		close_ajax();
		return false;
	});
	$('#overlay').livequery('click',function() {
		close_ajax();
		return false;
	});
});
///////////////////////////////////
// vouchers //
///////////////////////////////////
$(function(){
	$('#products div.menu').hide(0);
	$('#products div.package').css('cursor', 'pointer');

	$('#products div.package').click(function()
	{

		var
			el = this,
			node = $(this).next();

		$('#products div.package').each(function(){
			$(this).removeClass('expanded');
		});

		$('#products div.menu').each(function(){
			if( $(this).is(':visible') && $(this).get(0) != $(node).get(0) )
				$(this).slideUp('slow');
		});

		$(node).is(':hidden') ?
		$(node).slideDown('slow', function(){ $(el).addClass('expanded') }) :
		$(node).slideUp('slow', function(){ $(el).removeClass('expanded') }) ;
 return false;
	});

});
/*///////////////////////////////////////*/
/*/ play movie /*/
/*///////////////////////////////////////*/
$(function(){
$('.play-flash').click(function() {
	$('.play-flash').load('/flash/movie.htm');
	return false;
});
} );
/*///////////////////////////////////////*/
/*/ gallery /*/
/*///////////////////////////////////////*/
$(function(){
		   
	$('#packages-loading-gif').hide();
	$('.static-image').hide();
   
    $('a.ajaximage').click(function() {
    	$('#slideshow').hide();
    	$('#packages-loading-gif').show();
		setTimeout("$('#packages-loading-gif').fadeOut('normal');", 1000);
    	$('.static-image').empty().load($(this).attr('href')).show();
		return false;
   	});
	 
} );
/*///////////////////////////////////////*/
/*/ venue details /*/
/*///////////////////////////////////////*/
$(function(){
	$('.venue-details').hide(0);
	$('#overview').show(0);
	$('#column1 h3').css('cursor', 'pointer');

	$('#column1 h3').click(function()
	{

		var
			el = this,
			node = $(this).next();

		$('#column1 h3').each(function(){
			$(this).removeClass('expanded');
		});

		$('.venue-details').each(function(){
			if( $(this).is(':visible') && $(this).get(0) != $(node).get(0) )
				$(this).slideUp('slow');
		});

		$(node).is(':hidden') ?
		$(node).slideDown('slow', function(){ $(el).addClass('expanded') }) :
		$(node).slideUp('slow', function(){ $(el).removeClass('expanded') }) ;
 return false;
	});

});
/*///////////////////////////////////////*/
/*/ get querystring /*/
/*///////////////////////////////////////*/
function getURLVar(urlVarName) {
 var urlHalves = String(document.location).split('?');
 var urlVarValue = '';
 if(urlHalves[1]){
  var urlVars = urlHalves[1].split('&');
  for(i=0; i<=(urlVars.length); i++){
   if(urlVars[i]){ 
    var urlVarPair = urlVars[i].split('=');
    if (urlVarPair[0] && urlVarPair[0] == urlVarName) {
     urlVarValue = urlVarPair[1];
    }
   }
  }
 }
 return urlVarValue;   
}
/*///////////////////////////////////////*/
/*/ innerfade /*/
/*///////////////////////////////////////*/
$(function(){
	$('#venue-gallery').innerfade({ speed: 'slow', timeout: 4000, type: 'sequence', containerheight: '193px' });
}); 
/*///////////////////////////////////////*/
/*/ mapscroll /*/
/*///////////////////////////////////////*/
function map_options(func_id)
{
	switch(func_id) 
	{
		case 'left':
				document.getElementById("x").value = parseFloat(document.getElementById("x").value) - 80 ;
				break ;
		case 'centre':
				document.getElementById("x").value = 0 ;
				document.getElementById("y").value = 0 ;
				break ;
		case 'right':
				document.getElementById("x").value = parseFloat(document.getElementById("x").value) + 80 ;
				break ;
		case 'up':
				document.getElementById("y").value = parseFloat(document.getElementById("y").value) - 80 ;
				break ;
		case 'down':
				document.getElementById("y").value = parseFloat(document.getElementById("y").value) + 80 ;
				break ;
		case 'in':
			if (parseFloat(document.getElementById("zoom").value) > 100)
				document.getElementById("zoom").value = parseFloat(document.getElementById("zoom").value) - 100 ;
				break ;
		case 'out':
			if (parseFloat(document.getElementById("zoom").value) < 400)
				document.getElementById("zoom").value = parseFloat(document.getElementById("zoom").value) + 100 ;
				break ;
		case 'change_map':
				if (document.getElementById("mapstyle").value == 'road')
					document.getElementById("mapstyle").value = 'county' ;
				else
					document.getElementById("mapstyle").value = 'road' ;
				break ;
		case 'change_page':
				if (document.getElementById("page").value == 'console')
					document.getElementById("page").value = 'multiactivity' ;
				else
					document.getElementById("page").value = 'console' ;
				break ;
	}
	document.map_hidden_form.submit();
}
/*///////////////////////////////////////*/
/*/ faqs /*/
/*///////////////////////////////////////*/
$(function(){
	$('#faqs h3').css('cursor', 'pointer');

	$('#faqs h3').click(function()
	{
		var
		el = this,
		node = $(this).next();

		$('#faqs h3').each(function(){
			$(this).removeClass('expanded');
		});

		$(node).is(':hidden') ?
		$(node).slideDown('slow', function(){ $(el).addClass('expanded') }) :
		$(node).slideUp('slow', function(){ $(el).removeClass('expanded') }) ;
	});
	
	$('#faqs dd').hide(0);
	$('#faqs dt').css('cursor', 'pointer');

	$('#faqs dt').click(function()
	{
		var
		el = this,
		node = $(this).next();

		$('#faqs dt').each(function(){
			$(this).removeClass('expanded');
		});

		$('#faqs dd').each(function(){
			if( $(this).is(':visible') && $(this).get(0) != $(node).get(0) )
				$(this).slideUp('slow');
		});

		$(node).is(':hidden') ?
		$(node).slideDown('slow', function(){ $(el).addClass('expanded') }) :
		$(node).slideUp('slow', function(){ $(el).removeClass('expanded') }) ;
	});
	
	$('#expand-all').click(function(){
		$('#faqs dd').show( 0 );return false;
	});
	
	$('#close-all').click(function(){
		$('#faqs dd').hide( 0 );return false;
	});

});
/*///////////////////////////////////////*/
/*/ clear form input /*/
/*///////////////////////////////////////*/
function clearText(thefield){
if (thefield.defaultValue==thefield.value)
thefield.value = ""
}
/*///////////////////////////////////////*/
/*/ innerfade /*/
/*///////////////////////////////////////*/
$.fn.innerfade = function(options) {
return this.each(function(){ 
						   
var settings = {
speed: 'normal',
timeout: 2000,
type: 'sequence',
containerheight: 'auto'
}

if(options)
$.extend(settings, options);

var elements = $(this).children().get();

if (elements.length > 1) {

$(this).parent().css('position', 'relative');

$(this).css('height', settings.containerheight);

for ( var i = 0; i < elements.length; i++ ) {
$(elements[i]).css('z-index', elements.length - i).css('position', 'absolute');
$(elements[i]).hide();
}

if ( settings.type == 'sequence' ) {
setTimeout(function(){
$.innerfade.next(elements, settings, 1, 0);
}, settings.timeout);
$(elements[0]).show();
}
else if ( settings.type == 'random' ) {
setTimeout(function(){
do { current = Math.floor ( Math.random ( ) * ( elements.length ) ); } while ( current == 0 )
$.innerfade.next(elements, settings, current, 0);
}, settings.timeout);
$(elements[0]).show();
}
else {
alert('type must either be \'sequence\' or \'random\'');
}

}

});
};

$.innerfade = function() {}
$.innerfade.next = function (elements, settings, current, last) {

$(elements[last]).fadeOut(settings.speed);
$(elements[current]).fadeIn(settings.speed);

if ( settings.type == 'sequence' ) {
if ( ( current + 1 ) < elements.length ) {
current = current + 1;
last = current - 1;
}
else {
current = 0;
last = elements.length - 1;
}
}
else if ( settings.type == 'random' ) {
last = current;
while (current == last ) {
current = Math.floor ( Math.random ( ) * ( elements.length ) );
}
}
else {
alert('type must either be \'sequence\' or \'random\'');
}
setTimeout((function(){$.innerfade.next(elements, settings, current, last);}), settings.timeout);
};
/*///////////////////////////////////////*/
/*/ tabs /*/
/*///////////////////////////////////////*/
$(function(){
$('#tab-menu').tabs();
} );
