isAfterFirstSWFAddress = false;
swfAddressSection = 0;
SWFAddress.addEventListener(SWFAddressEvent.CHANGE, onHashAddressChange);
function onHashAddressChange( e ){
	// Define vars. //
	var pathNames = SWFAddress.getPathNames();
	var theContent = pathNames[0];
	
	if( location.search == '?ref=features' ){
		if( !theContent ) theContent = 0;
		if( isAfterFirstSWFAddress ){
			$('.featureContent').fadeOut();
			$('#features'+theContent).fadeIn();
		}else{
			isAfterFirstSWFAddress = true;
			if( theContent != 0 ){
				$('.featureContent').fadeOut();
				$('#features'+theContent).fadeIn();
			}
		}
		
		$('#features .altPanel a').removeClass('selected');
		$('#features .altPanel a[rel^="'+theContent+'"]').addClass('selected');
		
		theContentHeight = $('#features'+theContent).innerHeight();
		theContentHeight < 400 ? theContentHeight = 400 : null;
		
		$('.contentWrapper').animate({height:theContentHeight+'px'},{duration:300});
	}else if( location.search == '?ref=home' ){
		if( !theContent ) theContent = 'safetyBox';
		if( isAfterFirstSWFAddress ){
			$('.contentTxt').fadeOut();
			$('#'+theContent+'_div').fadeIn();
		}else{
			isAfterFirstSWFAddress = true;
			$('.contentTxt').hide();
			$('#'+theContent+'_div').show();
		}
		$('a.tabNav').removeClass('selected');
		$('a.tabNav[rel="'+theContent+'"]').addClass('selected');
	}else if( location.search == '?ref=tour' ){
		if( !theContent ) theContent = 1;
		var theNum = theContent-1;
		swfAddressSection = theContent;
		$('.navBar .selector').animate({left:(theNum*209)+'px'},{duration:300});
		$('.navBar .selector .curItem').animate({backgroundPosition:'(-'+(theNum*209)+'px 0px)'},{duration:280});
		$('.infoWrapper').animate({left:'-'+(theNum*836)+'px'},{duration:300});
		
		theContentHeight = $('#infoPanel'+(theNum+1)).innerHeight() + 30;
		
		if(theNum < 3) $('.theNextBut').removeClass('disabled');
		else $('.theNextBut').addClass('disabled');
		if(theNum > 0) $('.thePrevBut').removeClass('disabled');
		else $('.thePrevBut').addClass('disabled');
		$('.tourInfoPanel').animate({height:theContentHeight+'px'},{duration:300});
	}
	
}
	
	
$(function(){
	$.localScroll();

	$('a.tabNav').click(function( event ){
		event.preventDefault();
		var theNumber = $(this).attr('rel');
		SWFAddress.setValue(theNumber);
	})
	
	$('.navBar a').click(function( event ){
		event.preventDefault();
		var relArray = $(this).attr('rel').split(',');
		var theNumber = relArray[0];
		var theName = relArray[1];
		SWFAddress.setValue(theNumber+'/'+theName);
	})
	
	$('.theNextBut').click(function( event ){
		event.preventDefault();
		if( $(this).hasClass('disabled') ) return false;
		var theNumber = Number(swfAddressSection)+1;
		var theName = $('.navBar a').eq(theNumber-1).attr('rel').split(',')[1];
		SWFAddress.setValue(theNumber+'/'+theName);
	});
	$('.thePrevBut').click(function( event ){
		event.preventDefault();
		if( $(this).hasClass('disabled') ) return false;
		var theNumber = swfAddressSection-1;
		var theName = $('.navBar a').eq(theNumber-1).attr('rel').split(',')[1];
		SWFAddress.setValue(theNumber+'/'+theName);
	});
	
	/* features effect for info display */
	
	$('#features .altPanel a, #features .overviewSummary a').click(function( event ){
		event.preventDefault();
		var relArray = $(this).attr('rel').split(',');
		var theNumber = relArray[0];
		var theName = relArray[1];
		SWFAddress.setValue(theNumber+'/'+theName);
	})
	
	/* color change effect for auto scroll */
	
	var prevHeading = "";
	$('#faqs .faq a, #services .services a, #security .security a').click(function(){
		var nextHeading = $(this).attr("href");
		if(prevHeading != "") {
			$(prevHeading).animate({color:"#154A60"},500);
		}
		$(nextHeading).animate({color:"#7DB305"},2000);
		prevHeading = nextHeading;
	})
	
	
		setTimeout(function() { $('.errorMsg span').fadeOut(); }, 2000);
	
	
})

