function trace(s) {
  if (this.console && typeof console.log != "undefined")
    console.log(s);
}


$().ready(function(){
	
	insertBanner()
		
		
	$('.nav-menu').each(function()
		{
			$(this).data('height', $(this).height() ).css('height', '100px').css('opacity', 0);
		})

	$('#navbar>li')
	.hover(function()
		{
			$(this).find('>a').stop().animate({marginTop:-3},300 ).css('z-index', 20)
			menu = $(this).find('.nav-menu')
			menu.stop().animate({opacity: 1, height: menu.data('height') }, 300).css('z-index', 50)
			//$(this).stop().animate({top:-3},300 ).css('z-index', 20).find('.nav-menu').fadeIn();
		},
		function()
		{
			$(this).find('>a').stop().animate({marginTop:0},300 ).css('z-index', 40)
			menu = $(this).find('.nav-menu')
			menu.stop().animate({opacity: 0, height: 100}, 200, function(){
				$('.nav-menu:visible').hide()
			})
			//$(this).stop().animate({top:-3},300 ).css('z-index', 20).find('.nav-menu').fadeOut();
			
		})
	
	syncNavigation()
		
})



function syncNavigation() // sync sidebar nav based on filename
{
path = location.href
dot = path.lastIndexOf('.')
slash = path.lastIndexOf('/')
filename = path.substr( (slash +1), (dot - slash -1) ) // start,length

folderPath = path.substr(0,slash)
folderSlash = folderPath.lastIndexOf('/')
folderName = folderPath.substr(folderSlash +1 , folderPath.length)


//add arrow indicator to subnav
if(filename.length > 0)
{
	$('.subnav a[href*=' + filename + ']').addClass('active');
}

// .active adds arrow indicator, .active-menu indents menu items to align with arrow-indicator

var itemFound = false;
$('.nav-menu a').each(function()
	 {
		 if( (filename.length > 0) && (itemFound == false) )
		 	{
				if( ($(this).attr('href').indexOf(filename) > -1 ) || ($(this).attr('href').indexOf(folderName) > -1 ) )
				{
					$(this).addClass('active').parent().parent().addClass('active-menu')
					itemFound = true; // stop matching when first item is found
				}
			}
	 })
}


//Zoom Maps
function initMap()
{
	$('#map').jqzoom({ 
	'zoomWidth' :640, 'zoomHeight': 250 , 'title':false, 'position':'top', 'xOffset':0, 'yOffset':0,
	'showEffect':'fadein', 'hideEffect':'fadeout', 
	'fadeinSpeed':'medium', 'fadeoutSpeed': 'medium'
	});
}


/*Flash Embed*/
function insertBanner(){ 

var banner
if( banner = document.getElementById('banner') )
	{
	currentFolder = getFolderName(location.href)
	prevFolder = getFolderName(top.window.name)
	
	if((currentFolder != prevFolder) || 
	   (window.flashBanner) ||
	   (location.href == top.window.name)
	   )
	{
		moviePath = banner.getAttribute('data-swf') // movie path embedded into container <div> "data-swf" attribute
		flashembed('banner', {src:moviePath, version:[8], wmode:'opaque', background:'none'});
		}
	}
	
	top.window.name = location.href
	
} 


function getFolderName(link)
{
path = link
slash = path.lastIndexOf('/')
folderPath = path.substr(0,slash)
folderSlash = folderPath.lastIndexOf('/')
folderName = folderPath.substr(folderSlash +1 , folderPath.length)
return folderName
}

