$(document).ready(function() {
	
	var $pointer = $('#pointer');
	
	// IE 6 fixes
	if ($.browser.msie && $.browser.version < 7) {
		// topNav width problem
		$('#topNav li div').each(function(){$(this).css('width',$(this).parent().width())});
		// topNav png fix
		$('#header img[src$=png]').each(function() {
			var span = '<span style="position:relative;white-space:pre-line;display:inline-block;background:transparent;'
				+ 'width:' + $(this).width() + 'px;' + 'height:' + $(this).height() + 'px;'
 				+ 'filter:progid:DXImageTransform.Microsoft.AlphaImageLoader' + '(src=\'' + $(this).attr('src') + '\', sizingMethod=\'scale\');'
 				+ '"></span>';
			$(this).hide().after(span);
		});
		// pointer png fix
		$pointer.css('filter', 'progid:DXImageTransform.Microsoft.AlphaImageLoader'+'(src=\''+$pointer.attr('src')+'\',sizingMethod=\'scale\')').attr('src', webroot+'img/clear.gif');
	}
	
	// topNav bg opacity
	$('#topNav').find('li div, li:first, li:last').css('opacity', 0.6);
	
	// rightNav
	$('#rightNav a').bind('mouseenter', function(e) {
		$toShow = $(this);
		if ($toShow.hasClass('active')) return;
		$toHide = $('#rightNav a').not($toShow).removeClass('active').css('backgroundPosition', '0 -122px').each(function(){$(this).data('height', $(this).height())});
		$toShow.addClass('active').css('backgroundPosition', '0 0');
		$toHide.animate({height: 67}, {queue: false, duration: 200, step: function(now) {
			$.data(this, 'height', parseInt(now));
			var current = 0;
			$toHide.each(function(){current += $(this).data('height')});
			current = 256 - current;
			$toShow.height(current);
		}})
	}).bind('mouseleave', function(e) {
		if ($(e.target).is('#rightNav a')) {
			if ($('#rightNav:has(li.active)').length > 0) $('#rightNav li.active a').triggerHandler('mouseenter');
			else $('#rightNav a').removeClass('active').css('backgroundPosition', '0 -122px').animate({height: 85}, 200);
		}
	}).find('span').css($.browser.msie ? 'visibility' : 'display', $.browser.msie ? 'hidden' : 'none');
	if ($('#rightNav:has(li.active)').length == 0) $('#rightNav a').css('height', 85);
	
	// subNav interactive pointer
	$('#subNav a').click(function() {
		var $this = $(this).blur();
		var x = $this.offset().left + (($this.width() + 20) / 2) - $('#subNav').offset().left - ($pointer.width() / 2);
		$('#subNav li.active').removeClass('active');
		if ($pointer.is(':hidden')) {
			$pointer.css('marginLeft', x).show();
			$this.parent().addClass('active');
		} else $pointer.animate({marginLeft: x}, {duration: 300, complete: function() {
			$this.parent().addClass('active');
			window.location = $this.attr('href');
		}});
		return false;
	});
	$('#subNav li.active a').triggerHandler('click');
	
	// remove margin-top from first H2 on page
	$('body h2:first').addClass('nt');
	
	// setup button hover effect
	$('.button').css('opacity', 0.7).hover(function() {
		$(this).css('opacity', 1);
	}, function() {
		$(this).css('opacity', 0.7);
	});
	
});