$(function() {

	// alert($.browser.version);
	
	$("a[href^='http']").livequery(function() {$(this).attr('target','_blank');});
	$("a.external").livequery(function() {$(this).attr('target','_blank');});
	
	var index = $("#accordion h3.header.current").attr('rel')-0;
	$("div#navigation div#accordion").accordion({
		header: 'h3.header',
		active: index,
		changestart: function(event, ui) {
			var newheader = ui.newHeader;
			var ahref = $(newheader).find('a');
			var url = $(ahref).attr('href')+'?ajax';
			$.post(url, function(data) {
				$("div#content").append(data).hide().fadeIn(200);
			});
			$("div#content > div").fadeOut(100, function() {
				$(this).remove();
			});
			$("div.header-image.ui-corner-all").attr('class', "header-image ui-corner-all "+$(ahref).html())
			var newHeader = ui.newHeader;
			console.debug($(newHeader));
			$(newHeader).next().find('li a').removeClass('ui-state-active');
			$(newHeader).next().find('li:first a').addClass('ui-state-active');
			
		}
	});
	
	
	/* default-value */
	var active_color = '#000'; // Colour of user provided text
	var inactive_color = '#ccc'; // Colour of default text

	$("input.default-value").css("color", inactive_color);
	var default_values = new Array();
	$("input[default-value]").each(function() {
			if (!default_values[this.id]) {
				default_values[this.id] = $(this).attr('default-value');
			}
			if (this.value == '' || this.value==default_values[this.id]) {
				this.style.color = inactive_color;
				this.value = default_values[this.id];
			}
		}).focus(function() {
		if (!default_values[this.id]) {
			default_values[this.id] = $(this).attr('default-value');
		}
		if (this.value == default_values[this.id]) {
			this.value = '';
			this.style.color = active_color;
		}
		$(this).blur(function() {
			if (this.value == '') {
				this.style.color = inactive_color;
				this.value = default_values[this.id];
			}
		});
	});
	
	$("form").submit(function() {
		$("input[default-value]").each(function() {
				if (!default_values[this.id]) {
					default_values[this.id] = $(this).attr('default-value');
				}
				if (this.value==default_values[this.id]) {
					this.style.color = active_color;
					this.value = '';
				}
			});
			
		return true;
	});
	/* end default-value */
	
	
	// $("#accordion h3.header").hoverIntent(function() {
	// 	console.debug('hover');
	// 	$(this).trigger('click');
	// }, function(){});
	
	// $("div#navigation div#accordion a").click(function() {
	// 	return false;
	// })
});

$(window).bind("load",function(){ 

	  // wrap our new image in jQuery, then: 
	var img = new Image(); 	
	$(img).attr('src', 'tradeshow/img/headers/WhoShouldAttend.jpg');
	var img = new Image(); 
	$(img).attr('src', 'tradeshow/img/headers/sightseeing.jpg');
	var img = new Image(); 
	$(img).attr('src', 'tradeshow/img/headers/AreYouReady.jpg');
	var img = new Image(); 
	$(img).attr('src', 'tradeshow/img/headers/registration.jpg');
	var img = new Image(); 
	$(img).attr('src', 'tradeshow/img/headers/WhoShouldExhibit.jpg');
	var img = new Image(); 
	$(img).attr('src', 'tradeshow/img/headers/Hotel-Travel-Banner-LongBeach.jpg');
	
});
