$(function() {
/////////////////////////////////////////////////////
/// ajax ///
/////////////////////////////////////////////////////
	// this displays ajax div
	$('.ajax').click(function(){
		var rel=$(this).attr('rel');
		$('#ajax').empty().load(rel).show();
		$('#ajax h2').append('<a href="#">Close</a>');
		return false;
	});
	// this closes the ajax div
	$('#ajax h2 a').live('click',function() {
		$('#ajax').hide();
		return false;
	});
/////////////////////////////////////////////////////
/// tab menu ///
/////////////////////////////////////////////////////
	$('.tabs-container').hide(0);
	$('.tabs-selected').show(0);
	$('.tabs-menu li a').live('click', function() {
		var selected = $(this).parent().attr('class');
		if(selected=="tab-selected"){
		} else {
			// this identifies any links not part of the tab structure
			if($(this).attr('target')=="_blank"){
			} else {
				$('.tabs-container').hide(0);
				$('.tabs-menu li').removeClass();
				var el = $(this).parent();
				var node = $(this).attr('href');
				$(el).addClass('tab-selected');
				$(node).show(0);
				return false;
			}
		}
	});
/////////////////////////////////////////////////////
/// innerfade ///
/////////////////////////////////////////////////////
	$('.slideshow').innerfade({ speed: 'slow', timeout: 4000, type: 'sequence', containerheight: 'auto' });
	$('#voucher-banner ul').innerfade({ speed: 'slow', timeout: 4000, type: 'sequence', containerheight: '32px' });
/////////////////////////////////////////////////////
});
/////////////////////////////////////////////////////
/// clear form ///
/////////////////////////////////////////////////////
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);
};
