/*///////////////////////////////////////*/
/*/ add to basket /*/
/*///////////////////////////////////////*/
$(function(){
	$('a.add-to-basket').livequery('click',function() {
		$('#basket').empty().load($(this).attr('rel'));
		return false;
	});
});
/*///////////////////////////////////////*/
/*/ buy a balloon /*/
/*///////////////////////////////////////*/
$(function() {
	// this opens the balloon section
	$('#choose-a-balloon').hide(0);
	$('a.buy-with-balloon').click(function(){
		var
		href=$(this).attr('rel');
		$('#choose-a-balloon').fadeIn('slow').load(href);
		$('#top').ScrollTo('slow');
		return false;
	});
	// this opens the category menus
	$('#balloons li ul').livequery(function(){ $(this).hide(0)});
	$('#balloons li a').livequery('click', function(){
		var
		el = this,
		node = $(this).next();
		
		$('#balloons li ul').each(function(){
			if( $(this).is(':visible') && $(this).get(0) != $(node).get(0) )
				$(this).hide();
		});
			
		$(node).is(":hidden") ?
		$(node).show(0) && $(el).addClass('expanded') :
		$(node).hide(0) && $(el).removeClass('expanded') ;
	});
	// this loads the category images
	$('#balloons li a').livequery('mouseover',function() {
		var
		rel=$(this).attr('rel');
		$('#balloon').empty().load(rel);
		return false;
	});
	// this loads the balloon images
	$('#balloons li ul li a').livequery('mouseover',function() {
		var
		rel=$(this).attr('rel');
		$('#balloon').empty().load(rel);
		return false;
	})
	// this loads the balloon details
	$('#balloons li ul li a').livequery('click',function() {
		var
		href=$(this).attr('href');
		$('#balloon-details').empty().load(href).show();
		
		return false;
	});
	// this closes the balloon details
	$('#balloon-details a.close').livequery('click',function() {
		var
		href=$(this).attr('href');
		$('#balloon-details').hide();
		
		return false;
	});
});

/*///////////////////////////////////////*/
/*/ 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();
}
//////////////////////////////////
/* region map */
//////////////////////////////////
$(function(){
	$('#hover').hide();
	
	$('.hover').hover(function() {  
		var name = $(this).attr('id');
		var selector = "#hover span#reg-"+name;
    	$('#hover span').hide();
		$(selector).show();
		$('#hover').removeClass().addClass(name).show();
		
		return false;
		
   	}, function(){});
	
});
//////////////////////////////////
/* get url */
//////////////////////////////////
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;
}
//////////////////////////////////
/* packages */
//////////////////////////////////
$('.package').each(function(){
										
	var
	formatID = getURLVar("formatID");
		
	if(formatID == "" ) {
	} else {
		if($(this).attr('rel') != "format-" + formatID) {
			$(this).hide(0);
		}
	}
});
//////////////////////////////////
/* package list */
//////////////////////////////////
$(function(){

	$('#package-list ul').hide(0);
	
	/* if there is a formatID set, the corresponding ul will stay open */
	
	$('#package-list ul').each(function(){
										
		var
		formatID = getURLVar("formatID");
		
		if( $(this).attr('class') == "format" + formatID )
			$(this).slideDown('slow');
	});

	$('#package-list li a.expand').click(function()
	{
		var
		el = this,
		node = $(this).next();

		$('#package-list li a.expand').each(function(){
			$(this).removeClass('expanded');
		});
		
		$('#package-list ul').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;
		
	});
	
/*/ package selected /*/
	$('#package-list li ul li a').click(function()
	{
		var
		el = $(this).attr('href');

		$('.package').hide(0);
		$(el).show(0);
		return false;

	});

});
//////////////////////////////////
/* buy as voucher */
//////////////////////////////////
$(function(){

	$('.expandable dl').hide(0);
	$('.expandable .redeem').hide(0);

	$('.expandable .expand').click(function()
	{
		var
		el = this,
		node = $(this).next();

		$('.expandable .expand').each(function(){
			$(this).removeClass('expanded');
		});

		$(node).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;
	});

});
//////////////////////////////////
/* faqs */
//////////////////////////////////
$(function(){

	$('.faqs p').hide(0);
	$('.faqs h3').css('cursor', 'pointer');

	$('.faqs h3').click(function()
	{
		var
		el = this,
		node = $(this).next();

		$('.faqs h3').each(function(){
			$(this).removeClass('expanded');
		});

		$('.faqs p').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') }) ;
	});

});
//////////////////////////////////
/* venue details */
//////////////////////////////////
$(function(){

	$('#venue-details .venue-details').hide(0);
	$('#venue-details #selected').show(0);
	$('#venue-details h3').css('cursor', 'pointer');

	$('#venue-details h3').click(function()
	{
		var
		el = this,
		node = $(this).next();

		$('#venue-details h3').each(function(){
			$(this).removeClass('expanded');
		});

		$('#venue-details .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') }) ;
	});

});
//////////////////////////////////
/* clear input */
//////////////////////////////////
function clearText(thefield){
if (thefield.defaultValue==thefield.value)
thefield.value = ""
}
//////////////////////////////////
/* innerfade */
//////////////////////////////////
$(function(){
$('#description div').innerfade({ speed: 'slow', timeout: 4000, type: 'sequence', containerheight: '250px' });
$('#venue-gallery').innerfade({ speed: 'slow', timeout: 6000, type: 'sequence', containerheight: '180px' });
$('#quotes').innerfade({ speed: 'slow', timeout: 6000, type: 'sequence', containerheight: '50px' });
} ); 
//////////////////////////////////
/* 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();
});
