///////////////////////////////////
// package search //
///////////////////////////////////
$(function(){
	 $('.search a').click(function() {
    	$('.search div').empty().append('<label id="your-town"><input name="city" value="" /><span>Select A Town</span></label>');
		return false;
   	}); 
	$('#details').hide();
    $('.tablesorter a').click(function() {
		var
		td = $(this).parent();
		tr =$(td).parent();
    	$('.tablesorter tr').removeClass('current');
		$(tr).addClass('current');
		$('.tablesorter td').removeClass('selected');
		$(td).addClass('selected');
		$('#wrapper').ScrollTo('slow');
		setTimeout("$('#details').slideDown();", 1000);
    	$('#details').empty().load($(this).attr('rel')).show();
		return false;
   	}); 
	
	$('.tablesorter td').hover(function() {
		var
		tr = $(this).parent();
    	$('.tablesorter tr').removeClass('selected');
		$(tr).addClass('selected');
		return false;
   	}); 
	
	$.delegate('#details .close','click',function() {
		$('#details').hide();
		return false;
	 });
	
    $.delegate('.venuedetails','click',function() {
		var
		parent = $(this).parent();
		$('#wrapper').ScrollTo('slow');
    	$('#details').empty().load($(parent).attr('rel')).show();
		return false;
   	}); 
});
///////////////////////////////////
// play movie //
///////////////////////////////////
$(function(){
$('.play-flash').click(function() {
	$('.play-flash').load('/flash/movie.htm');
	return false;
});
} );
///////////////////////////////////
// discounts //
///////////////////////////////////
$(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;
	});

});
/*///////////////////////////////////////*/
/*/ 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();
		return false;
	}
	// this closes the ajax div
	$('#ajax h2 a').livequery('click',function() {
		close_ajax();
	});
	$('#overlay').livequery('click',function() {
		close_ajax();
	});
});
/*///////////////////////////////////////*/
/*/ innerfade /*/
/*///////////////////////////////////////*/
$(function(){
$('#slideshow').innerfade({ speed: 'slow', timeout: 4000, type: 'sequence', containerheight: '240px' });
} );
/*///////////////////////////////////////*/
/*/ 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;
	});

});
/*///////////////////////////////////////*/
/*/ 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;
   	});
	 
} );
/*///////////////////////////////////////*/
/*/ 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);
};


$(function(){

  $('div#search form#search').submit(function(){
    townsearch();
    return false;
  });

});

/*///////////////////////////////////////*/
/*/ tabs /*/
/*///////////////////////////////////////*/
$(function(){
$('#tab-menu').tabs();
} );