// JavaScript Document

hrefString = document.location.href ? document.location.href : document.location;
var url = document.location.href;
var pos = url.lastIndexOf('/');
var posAnn = url.lastIndexOf('?');
var path = url.slice(0, pos + 1);
var fileName = url.slice(pos +1);
var fileNameAnn = url.slice(pos + 1, posAnn);

$(document).ready(function(){
	$('#nav > ul > li:first-child').css('background', 'url(/images/menu_left.png)');
	$('#nav > ul > li:last-child').css('background', 'url(/images/menu_right.png) right');
	$('#nav > ul > li:first-child:').hover(function(){
		$(this).css('background', 'url(/images/menu_left_hover.png)');},
		function(){
		$(this).css('background', 'url(/images/menu_left.png)');
	});
	$('#nav > ul > li:last-child:').hover(function(){
		$(this).css('background', 'url(/images/menu_right_hover.png) right');},
		function(){
		$(this).css('background', 'url(/images/menu_right.png) right');
	});
	
	$('a[href$="' + fileName + '"]').parent().addClass('selected');
	
	$('#nav > ul > li').hover(function(){
		var width = $(this).children('ul').width();
		$('.subMenu', this).width(width);
		$('.subMenu', this).css('display', 'block');},
		function(){
		$('.subMenu', this).css('display', 'none');
	});
	
	$('#nav li').each(function(){
		var text = $(this).children('a').text();
		$(this).attr('title', text);
	});
	
	$('#nav > ul > li').each(function(){
		var text = $(this).children('a').text().replace(/ /g,'');
		var title = text.replace(text.charAt(0), text.charAt(0).toLowerCase());
		$(this).attr('id', title);
	});
	
	$('#nav .subMenu > li').each(function(){
		var text = $(this).children('a').text().replace(/ /g,'');
		var pId = $(this).parents('li').attr('id');
		$(this).attr('id', pId + text);
	});
});