function loadMap(){
	var latlng = new google.maps.LatLng(38.205793,-85.551358);
	var myOptions = {
		zoom: 12,
		center: latlng,
		mapTypeId: google.maps.MapTypeId.ROADMAP
	};
	var logo = 'images/logo_small.png';
	
	var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
	var marker = new google.maps.Marker({
		position: latlng,
		map: map,
		title: 'Gordon-Darby, Inc.',
		icon: logo
	});
}
// executes when HTML-Document is loaded and DOM is ready
$(document).ready(function() {
	var speed = 600;
	var menuBusy = false;
	var menuLastLink, menuHover, lastHashVal;
	var lastNav, lastNavParam, navHover;
	
	function getExtras(hashVal){
		// populate dynamic extras to build per page
		switch (hashVal){
		case 'Home':
			extrasArray = ['cycle'];
			break;
		case 'News':
			extrasArray = ['navpage','contentlinks'];
			break;
		case 'History':
			extrasArray = ['navpage','expandlist'];
			break;
		case 'Contact_Us':
			extrasArray = ['map'];
			break;
		case 'Sitemap':
			extrasArray = ['expandlist','contentlinks'];
			break;
		case 'Links':
			extrasArray = ['expandlist'];
			break;
		default:
			extrasArray = ['navpage'];
		}
		return extrasArray;
	}
	function buildExtras(extrasArray){
		for(i=0;i<extrasArray.length;i++){
			switch (extrasArray[i]){
			case 'navpage':
				// rewrite navlinks and pagelinks as hashVal=navParam
				$('a.navlink,a.pagelink').each(function(){
					$(this).attr('href','#'+hashVal+'='+$(this).attr('id').split('-')[1]);
				});
				// rewrite .html navhoplinks and hoplinks to anchors
				$('a.navhoplink,a.hoplink').each(function(){
					$(this).attr('href','#'+$(this).attr('id').split('-')[1]);
				});
				break;
			case 'contentlinks':
				// rewrite .html contentlinks to anchors
				$('a.contentlink').each(function(){
					$(this).attr('href','#'+$(this).attr('id').split('-')[1]);
				});
				break;
			case 'expandlist':
				// prepare expand links and hide expand lists
				$('.expand').prev().before('<span class="expandlink"><img class="expandlink" src="images/icons/toggle-small-expand.png"></img></span>');
				$('.expand').hide();
				break;
			case 'map':
				// map
				var script = document.createElement("script");
				script.type = "text/javascript";
				script.src = "http://maps.googleapis.com/maps/api/js?sensor=false&callback=loadMap";
				document.body.appendChild(script);
				break;
			case 'cycle':
				$('#slideshow').cycle({
					fx:    'fade', 
					speed:  2500 
				 });
				break;
			default:
			}
		}
	}
	// menuClick function called on hashchange event
	function menuClick(link) {
		$('ul#topnav li ul').hide();
		$('ul#topnav li a').css({'color':'#ffffff'});
		$(link).css({'color':'#cccccc'});
		if($(link).parent('li').is('li.top')){
			// click on top-level menu item
			menuLastLink = $(link).attr('id');
			$(link).next('ul').show();
		
		}else{
			// click on sub-level menu item
			menuLastLink = $(link).parent('li').parent('ul').prev('a').attr('id');
			$(link).parent('li').parent('ul').show();
			$(link).parent('li').parent('ul').prev('a').css({'color':'#cccccc'});
		}
	}
	// navClick function called on hashchange event
	function navClick(link){
		$('a.navlink,a.pagelink,a.navhoplink,a.hoplink').css({'color':'#5083C4'});
		$(link).css({'color':'#cccccc'});
		$(link).next('a').css({'color':'#cccccc'});
		blockid = link.split('-')[1];
		if(blockid !=lastNav && blockid != navHover){
			$('#page').fadeOut(speed,function(){
				$('.navblock').next().hide();
				$('#'+blockid).next().show();
				$('#page').fadeIn(speed);
			});
		}
		lastNav = blockid;
	}
	// live menu hover handler
	$('ul#topnav li.top').live('hover',function(event) {
		menuHover = $(this).find('a').attr('id');
		if (event.type == 'mouseenter') {
			if(menuLastLink == $(this).find('a').attr('id')){
				// keep current sub-menu shown
			}else{
				// hide last sub-menu and show this (where they exist)
				$('#'+menuLastLink).next('ul').hide();
				$(this).find('ul').show();
			}	
			/* if(menuLastLink == $(this).find('a').attr('id')){
				// keep current sub-menu shown
			}else{
				if($('#'+menuLastLink).parent('li').children('span').length == 0){
					$('#'+menuHover).next('span').hide().fadeIn(speed);
				}else{
					$('#'+menuLastLink).next('span').show().fadeOut(speed,function(){
						$('#'+menuHover).next('span').hide().fadeIn(speed);
					});
				}
			} */
		}else{
			/* if(menuLastLink == $(this).find('a').attr('id')){
				// keep current sub-menu shown
			}else{
				if($('#'+menuHover).parent('li').children('span').length == 0){
					$('#'+menuLastLink).next('span').hide().fadeIn(speed);
				}else{
					$('#'+menuHover).next('span').show().fadeOut(speed,function(){
						$('#'+menuLastLink).next('span').hide().fadeIn(speed);
					});
				}
			} */
			if(menuLastLink == $(this).find('a').attr('id')){
				// keep current sub-menu shown
			}else{
				// hide this sub-menu and show last (where they exist)
				$(this).find('ul').hide();
				$('#'+menuLastLink).next('ul').show();
			}
		}
	});
	// live nav hover handler
	$('ul.navlist li span').live('hover',function(event) {
		blockid = $(this).find('a').attr('id').split('-')[1];
		if (event.type == 'mouseenter') {
			navHover = blockid;
			if(blockid != lastNav){
				$('#page').fadeOut(speed,function(){
					$('.navblock').next().hide();
					$('#'+blockid).next().show();
					$('#page').fadeIn(speed);
				});
			}
		} else {
			navHover = null;
			if(blockid != lastNav){
				$('#page').fadeOut(speed,function(){
					$('.navblock').next().hide();
					$('#'+lastNav).next().show();
					$('#page').fadeIn(speed);
				});
			}
		}	
	});
	// live expandlink click handler
	$('span.expandlink').live('click',function() {
		if($(this).next().next('.expand').is(':hidden')){
			$(this).parent('li').parent('div').parent('ul').find('.expand').slideUp(speed);
			$(this).parent('li').parent('div').parent('ul').find('span.expandlink').children().attr('src','images/icons/toggle-small-expand.png');
			$(this).next().next('.expand').slideDown(speed);
			$(this).children().attr('src','images/icons/toggle-small.png');
		}else{
			$(this).next().next('.expand').slideUp(speed);
			$(this).children().attr('src','images/icons/toggle-small-expand.png');
		}
	});
	// hashchange handler
	$(window).hashchange( function(){
		fullHash = location.hash.split('#')[1];
		if(fullHash == undefined){
			hashVal = 'Home';
			navParam = undefined;
		}else{
			hashVal = fullHash.split('=')[0];
			navParam = fullHash.split('=')[1];
		}
		//alert ('hashVal:'+hashVal+',navParam:'+navParam+'\nlastHashVal:'+lastHashVal+',lastNav:'+lastNav);
		if(hashVal != lastHashVal){
			menuClick('#menu-'+hashVal);
			$('#content-pane').fadeOut(speed,function(){
				$('#content').load(hashVal+'.html #-'+hashVal,function(){
					buildExtras(getExtras(hashVal));
					// set page title to match loaded content
					document.title = 'Gordon-Darby, Inc. - '+hashVal.replace(/_/g," ");
					if(navParam === undefined){
						navParam = $('.navdefault').attr('id');
					}
					navClick('#nav-'+navParam);
					lastNav = navParam;
					// reveal content-pane
					$('#content-pane').fadeIn(speed);
				})
			});
			lastHashVal = hashVal;
		}else{
			if(navParam === undefined){
				navParam = $('.navdefault').attr('id');
			}
			navClick('#nav-'+navParam);
		}
	});
	$(window).hashchange();
	// rewrite .html menulinks to anchors
	$('a.menulink').each(function(){
		$(this).attr('href','#'+$(this).attr('id').split('-')[1]);
	});
});
// Ajax activity indicator bound to ajax start/stop document events
$(document).ajaxSend(function(){
		//$('#ajaxload').fadeIn(speed);
	}).ajaxStart(function(){
	}).ajaxStop(function(){
		//$('#ajaxload').fadeOut(speed);
	}).ajaxSuccess(function(){
	}).ajaxError(function(){
		
});
// executes when complete page is fully loaded, including all frames, objects and images
$(window).load(function() {
});

