(function($) {

	$(document).ready(function() {

		// START Quicksearch

		// when the artist or town field is selected, and it has artist or town as the current value, blank it out
		$("form.quicksearch input[name='town']").focus(function() {
			if ($(this).val() == 'town') {
				$(this).val('');
			}
		});
		$("form.quicksearch input[name='artist']").focus(function() {
			if ($(this).val() == 'artist or event') {
				$(this).val('');
			}
		});

		
		// when the artist or town field is defocused, and it's blank, reset to the default values
		// trigger this event once it's setup to set the default values.
		$("form.quicksearch input[name='town']").blur(function() {
			if ($(this).val() == '') {
				$(this).val('town');
			}
		}).blur();
		$("form.quicksearch input[name='artist']").blur(function() {
			if ($(this).val() == '') {
				$(this).val('artist or event');
			}
		}).blur();

		
		// Setup the search form submit action
		// only an artist, then go to the artist page directly
		// only a town, then go to the town page directly
		// else submit the form to the search page
		$('form.quicksearch').submit(function() {
			var artist = $("input[name='artist']", this).val();
			var town = $("input[name='town']", this).val();
			if ((artist == 'artist or event' || artist == '') && ( town == '' || town == 'town')) {
				return false; 
			} else if ((artist != 'artist or event') && (town == '' || town == 'town')) {
				location.href = '/tickets/' + artist.replace('/','%5c');
				return false;
			} else if ((town != 'town') && (artist == '' || artist == 'artist or event')) {
				location.href = '/towns/' + town;
				return false;
			} else {
				return true;
			}
		});

		// END Quicksearch



		// START Tabs
		$('div.clickTabs').each(function () {
			var tabContainers = $('> div', this);
			var tabs = $('> ul.tabNavigation li a', this);
			$('ul.tabNavigation a', this).click(function () {
				tabContainers.hide().filter(this.hash).show();
				tabs.removeClass('selected');
				$(this).addClass('selected');
				return false;
			}).filter(':first').click();
		});		
		// END Tabs

	});
})(jQuery);


function acceleratorSupported() {
	return (typeof (window.external.AddService) != "undefined");
}	
