/*///////////////////////////////////////*/
/*/ get querystring variables /*/
/*///////////////////////////////////////*/
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;   
}
/*///////////////////////////////////////*/
/*/ add to basket /*/
/*///////////////////////////////////////*/
$(function(){
	$('a.add-to-basket').livequery('click',function() {
		$('#basket').empty().load($(this).attr('rel'));
		return false;
	});
});
/*///////////////////////////////////////*/
/*/ ajax /*/
/*///////////////////////////////////////*/
$(function() {
	// this displays ajax div
	$('.ajax').livequery('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;
	});
});
/*///////////////////////////////////////*/
/*/ 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;
	});
});
/*///////////////////////////////////////*/
/*/ map /*/
/*///////////////////////////////////////*/
$(function(){
	$('#hover').hide();
	
	$('.hover').hover(function() {  
		var name = $(this).attr('id');
    	$('#hover').removeClass().addClass(name).show();
		return false;
   	});
	
	$("#tapcontent").css({
		"marginTop":"0px"
	}).hide().remove();

	$("#smcontent").css({
		"marginTop":"0px"
	}).hide().remove();
	
} );
/*///////////////////////////////////////*/
/*/ expandable menu /*/
/*///////////////////////////////////////*/
$(function(){

	$('.activity-menu ul.menu').hide(0);
	$('.activity-menu h3').css('cursor', 'pointer');

	$('.activity-menu h3').click(function()
	{

		var
			el = this,
			node = $(this).next();

		$('.activity-menu h3').each(function(){
			$(this).removeClass('expanded');
		});

		$('.activity-menu 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;
	});
	
	    $('.activity-menu ul li a').each(function()
    {
        if( $(this).attr('href') == location.pathname+location.hash+location.search ||
            $(this).attr('href') == window.location
        )
        {
            var el = $(this).parents().get(1).previousSibling;
            while( el.nodeType != 1 )
            {
                el = el.previousSibling;
            }
            $(el).trigger('click');
            navigationopen = true;
            return;
        }
    });
   
});
/*///////////////////////////////////////*/
/*/ gallery /*/
/*///////////////////////////////////////*/
$(function() {
$('.image1').hover(function() {
$('.img1').fadeIn('normal');
},function(){
$(".img1").fadeOut('normal');
});
$('.image2').hover(function() {
$('.img2').fadeIn('normal');
},function(){
$(".img2").fadeOut('normal');
});
$('.image3').hover(function() {
$('.img3').fadeIn('normal');
},function(){
$(".img3").fadeOut('normal');
});
$('.image4').hover(function() {
$('.img4').fadeIn('normal');
},function(){
$(".img4").fadeOut('normal');
});
$('.image5').hover(function() {
$('.img5').fadeIn('normal');
},function(){
$(".img5").fadeOut('normal');
});
$('.image6').hover(function() {
$('.img6').fadeIn('normal');
},function(){
$(".img6").fadeOut('normal');
});
$('.image7').hover(function() {
$('.img7').fadeIn('normal');
},function(){
$(".img7").fadeOut('normal');
});
$('.image8').hover(function() {
$('.img8').fadeIn('normal');
},function(){
$(".img8").fadeOut('normal');
});
$('.image9').hover(function() {
$('.img9').fadeIn('normal');
},function(){
$(".img9").fadeOut('normal');
});
$('.image10').hover(function() {
$('.img10').fadeIn('normal');
},function(){
$(".img10").fadeOut('normal');
});
$('.image11').hover(function() {
$('.img11').fadeIn('normal');
},function(){
$(".img11").fadeOut('normal');
});
$('.image12').hover(function() {
$('.img12').fadeIn('normal');
},function(){
$(".img12").fadeOut('normal');
});
$('.image13').hover(function() {
$('.img13').fadeIn('normal');
},function(){
$(".img13").fadeOut('normal');
});
$('.image14').hover(function() {
$('.img14').fadeIn('normal');
},function(){
$(".img14").fadeOut('normal');
});
$('.image15').hover(function() {
$('.img15').fadeIn('normal');
},function(){
$(".img15").fadeOut('normal');
});
$('.image16').hover(function() {
$('.img16').fadeIn('normal');
},function(){
$(".img16").fadeOut('normal');
});
});
/*///////////////////////////////////////*/
/*/ innerfade /*/
/*///////////////////////////////////////*/
$(function(){
$('#intro-images').innerfade({ speed: 'slow', timeout: 4000, type: 'sequence', containerheight: '240px' });
$('#intro').innerfade({ speed: 'slow', timeout: 4000, type: 'sequence', containerheight: '169px' });
$('#voucher-banner ul').innerfade({ speed: 'slow', timeout: 4000, type: 'sequence', containerheight: '23px' });
} ); 
/*///////////////////////////////////////*/
/*/ 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);
};
/*///////////////////////////////////////*/
/*/ clear form /*/
/*///////////////////////////////////////*/
function clearText(thefield){
if (thefield.defaultValue==thefield.value)
thefield.value = ""
}
/*///////////////////////////////////////*/
/*/ tabs /*/
/*///////////////////////////////////////*/
$(function(){
$('#tab-menu').tabs();
} );