var countTry = 0;

function redrawCAPTCHA() {
	countTry++;
	$('.captchaIMG').css( 'background-image', 'URL(/images/captcha.php?try='+countTry+')' );
}

function showItem( itemID ) {
	$('#contactPlaceholder .contactItem').hide();
	$('.subnav li').removeClass('lit');
	$('#show' + itemID).addClass('lit');
	$('#' + itemID).show();
	$("#contactPlaceholder").css( 'height', ($('#' + itemID).height() + 20) + "px" );
}

// Prepare jQuery-enabled contact form functions
$(document).ready(function() {
	
	if ( $('#contactPlaceholder .contactItem').length ) {
		
		var arrayItems = new Array();
		var htmlControls = '<div class="subnav"><ul class="subnav">';
		
		$('#contactPlaceholder .contactItem').each(function() {
			var thisID = $(this).attr('id');
			arrayItems[arrayItems.length] = thisID;
			htmlControls += '   <li id="show' + thisID + '"><a href="#' + thisID + '">' + $('#' + thisID + ' h2').html()  + '</a></li>';
			$('#' + thisID + ' tr.title').css( 'display', 'none' );
		});
		
		htmlControls += '</ul></div>';
		
		$('#contactPlaceholder').prepend(htmlControls);
		
		for ( var i = 0; i < arrayItems.length; i++ ) {
			$('#show' + arrayItems[i]).click(function() {
				var showID = $(this).attr('id');
				showID = showID.replace(/show/, '');
				showItem( showID );
			});
		}
		
		
		$(".contactItem").css("border","solid 1px #C0C0C0");
		$(".contactItem").css("border-width","0 1px 1px 1px");
		
		var thisPage = '';
		var showPage = '';
		
		if ( self.document.location.hash ) {
			thisPage = self.document.location.hash.replace(/#/, '');
			for ( var i = 0; i < arrayItems.length; i++ ) {
				if ( thisPage == arrayItems[i] ) {
					showPage = thisPage;
				}
			}
		}
		
		if ( !showPage ) {
			showPage = 'office';
		}
		
		showItem( showPage );
		
	}
	
	if ( $('#contactPlaceholder .captchaRedraw').length ) {
		$('#contactPlaceholder .captchaRedraw').each(function() {
			$(this).append( '<br /><a href="#" onclick="redrawCAPTCHA()">[REDRAW]</a>' );
		});
	}
	
});

