// Define site file extension here : html, php, asp...
template_fileExt = 'html';

// Template setup
$(document).ready(function()
{
	// Highlight
	$('#highlights li').hover(function()
	{
		$(this).css('background-position', '0 0').animate({backgroundPosition:'0 -300px'}, 500);
	}, function()
	{
		$(this).css('background-position', '0 -300px').animate({backgroundPosition:'0 0'}, 500);
	});

	
	// Detection of current page if none specified
	var current = nav.find('.current');
	if (current.length == 0)
	{
		// Detects from current url, with hash
		var selection = navElements.find('a');
		var href = document.location.href;
		if (href.substr(-1, 1) == '#')
		{
			href = href.substr(0, href.length-1);
		}
		if ($.browser.safari)
		{
			href = href.replace(' ', '%20');			// Webkit leaves spaces unencoded in document.location	
		}
		var found = template_markLinks(selection, href);
		if (!found)
		{
			// If hash, remove it
			if (document.location.hash && document.location.hash.length > 0)
			{
				href = document.location.href.substr(0,  document.location.href.length-document.location.hash.length);
				found = template_markLinks(selection, href);
			}
		}
		if (!found)
		{
			// If folder, search with index.html
			if (document.location.pathname.substr(-1, 1) == '/')
			{
				found = template_markLinks(selection, href+'index.'+template_fileExt);
			}
		}
		
		// Reload selection
		if (found)
		{
			current = nav.find('.current');
		}
	}
	
	// If current
	if (current.length > 0)
	{
		current.each(function(i)
		{
		  	// Check level
			var element = $(this);
			var parent = element.parent().parent();
			if (parent.get(0).nodeName.toLowerCase() == 'li')
			{
				element = parent;
			}
			element.children('a').click();
		});
	}
});


