// JavaScript Document

function centerTaxWindow(){
	var w = $('#tax-window');
	var l = ($(window).width() - w.width() ) /2;
	var t = ( ($(window).height() - w.height() ) /2) + $(window).scrollTop();
	if( l < 0) l = 0;
	if( t < 0 ) t = 0;
	w.css({ 'left' : l, 'top' : t});
}

$(document).ready( function(){

	$('#tax-button').click( function(){
			$('#tax-window').before( $('<div id="overlay"></div>') );	
			$('#overlay').css({ 'opacity':0, 'display':'block', 'height': $(document).height()}).animate({'opacity':0.7});
			$('#tax-window').fadeIn();
			$('#stock-strip-inner').attr('paused', 'yes');
			S.endSlideshow();
	});
	
	$('#tax-window-close').click( function(){
			$('#overlay').animate({'opacity':0}, {complete:removeOverlay});
			$('#tax-window').fadeOut();	
			$('#stock-strip-inner').attr('paused', 'no');
			S.beginSlideshow();
	});

	function removeOverlay(){
		$('#overlay').remove();	
	}
	
	
	
	$('.subnav').hide();
	
	
	$('#left-nav .active').parent().children('.subnav').show();
	$('#left-nav .active').parent().children('.expand_btn').addClass('expanded');
	
	

	$('#left-nav .active').parent().parent().prev().addClass('expanded');
	$('#left-nav .active').parent().parent().prevAll('a').addClass('active');
	
	$('.subnav a').each( function(){
		
		if( this.href == window.location.href ){
			$(this).parents('.subnav').show();
			$(this).parents('.subnav').prev().children('.expand').addClass('expanded');
		}
	});
	
	
	$('.expand_btn').click( function(e){
		e.preventDefault();			
		$(this).next('.subnav').slideToggle();
		$(this).toggleClass('expanded');
	});
	
	
	
	$('.normal').css({'background-image':'none'});
	
	
	
	$('form[validate]').bind('validationPassed', function(){
		this.submit();
	});

});










$(window).load( centerTaxWindow ).resize( centerTaxWindow ).scroll( centerTaxWindow );


