var path = document.location.pathname;
if ( path.charAt(path.length-1) != '/' ) path = path+'/';

$(document).ready(init);

var buf = path.split('/');
buf.shift();
var section = buf[0];
var sub_section = buf[1];

function init() {
	$(".lightbox").lightbox();

	$("#menu td").hover(
		function () {
			var id = $(this).attr("id");
			$(this).addClass("selected");
			$("#"+id+" + th").addClass(id);
		},
		function () {
			var id = $(this).attr("id");
			$(this).removeClass("selected");
			$("#"+id+" + th").removeClass(id);	

			hlCurrentItem();
		}
	);

    $("#services a").hover (
        function () { $(this).parent().addClass($(this).attr("id")); },
        function () { $(this).parent().removeClass($(this).attr("id")) }
    );
    
    if ( path != '/' ) {         
        $("#header").addClass(section).addClass(sub_section);        
        hlCurrentItem();
        hlCurrentMenuItem();
        $("#menu p").hide();
        //$("#menu em").hide();
        $("#content").addClass(section).addClass(sub_section);
        
        try { $("#"+$("#submenu").attr("class")).addClass("selected"); } catch (e) {} 
    }
    
}

function hlCurrentItem() {
	$("#"+section).addClass("selected");
	$("#"+section+" + th").addClass(section);
}

function hlCurrentMenuItem() {
    $("#menu a").each(
        function() {
            var href = $(this).attr("href").replace('http://'+document.domain,'');
            if ( href.charAt(href.length-1) != '/' ) href = href+'/';
                        
            if ( path == href ) {
                $(this).addClass("selected");
            }
        }
    );
}
