$(function(){
	$('ul.paneltabs li').hover(function() {
		anchor = $(this).find('a:first-child');
		var pos = $(anchor).position();
		$(anchor).clone()
			.addClass('temp')
			.css({top: pos.top, left: pos.left})
			.insertAfter(anchor)
			.animate({opacity: 0.8}, 'slow');
	}, function() {
		$('a.temp', this).stop(true).animate({opacity: 0}, function(){$(this).remove()});
	});
	$('ul.paneltabs a, #nav a.tour').live('click',function() {
		var hash = this.hash.substring(1);
		if ($('a#tab-'+hash).get(0)) {
			animateTour(hash);
		}
		$(this).blur();
	});
	
	// set content to #hash on page load
	var hash = document.location.hash.substring(1);
	if (hash && $('a#tab-'+hash).get(0)) {
		$('#hero li.active').removeClass('active');
		$('#hero li.' + hash).addClass('active');
		$('ul.paneltabs a#tab-' + hash).addClass('active');
	}
	// ajax forms
	$('form.ajax').submit(function(e) {
		e.preventDefault();
		$('.inputerror',this).removeClass('inputerror');
		var dirty = false;
		$('.required').each(function(){
			if ($(this).val() == '') {
				$(this).addClass('inputerror');
				dirty = true;
			}
		});
		if (dirty) {
			return false;
		};
		$('input[type=text], label, textarea', this).animate({'opacity': 0.7});
		$('button[type=submit]', this).after('<img src="/images/ajax-loader.gif" class="throbber"/>');
		$('button[type=submit] span', this).text('Please Wait...');
		$(this).ajaxSubmit();
	});
});

function animateTour(hash) {
	$('#tour-left li.active').animate({'left': '-400px'}, 400, function(){
		$('#tour-left li.active').removeClass('active');
		$('#tour-left li.' + hash).css({'left': -400}).addClass('active').animate({'left': 0}, 400);
	});
	$('#tour-right li.active').animate({'right': '-300px'}, 400, function(){
		$('#tour-right li.active').removeClass('active');
		$('#tour-right li.' + hash).css({'right': -300}).addClass('active').animate({'right': 0}, 400);
	});
	$('ul.paneltabs a.active').removeClass('active');
	$('a#tab-' + hash).addClass('active');
}

/* taconite extensions */
$.fn.replaceAndFadeIn = function(newContentElements) { 
    return this.each(function() { 
        $(this).empty().hide().append(newContentElements).fadeIn('slow'); 
    }); 
};
