﻿jQuery(document).ready(function() {

    var path = jQuery.url.attr("path");
    var high_l = 0;
    var item;
    var s;
    var ss;
    var i;

    jQuery("a[rhtNEType='IMG']").each(function() { rhtNEIMGRollover(this); });

    jQuery("a[href='" + path + "']").each(function() {
        var xl = jQuery(this).attr("rhtNELevel");
        var l;

        if (!xl) {
            l = 1;
        }
        else {
            l = parseInt(xl);
        }

        if (l > high_l) {
            item = this;
            high_l = l;
        }
    });

    s = jQuery(item).attr("rhtNESet");
    ss = jQuery(item).attr("rhtNESubSet");
    rhtNE(item, s, high_l);

    for (i = high_l - 1; i >= 1; i--) {
        if (i == 1) ss = null;
        if (!ss) {
            jQuery("a[rhtNESet='" + s + "'][rhtNELevel='" + i + "']").each(function() { rhtNE(this, s, i); });
        }
        else {
            jQuery("a[rhtNESet='" + s + "'][rhtNELevel='" + i + "'][rhtNESubSet='" + ss + "']").each(function() { rhtNE(this, s, i); });
        }
    }

});

function rhtNE(item, s, l) {
	var t = jQuery(item).attr("rhtNEType");
	if (!t) t = "LINK";
	if (t == "IMG") rhtNEIMG(item, s, l);
	if (t == "LINK") rhtNELINK(item, s, l);
}


function rhtNELINK(item, s, l) {
	jQuery(item).attr("class", "current");
	return;

	var href = jQuery(item).attr("href");
	jQuery(item).attr("class", "");

	if (path.indexOf(href) == 0) {
		if (href.length == 1) {
			if (href == path) jQuery(item).attr("class", "current");
		}
		else {
			if (href.length == path.length) jQuery(item).attr("class", "current");
		}
	}
}


function rhtNEIMG(item, s, l) {
	var href = jQuery(item).attr("href");
	var i = jQuery(item).children().eq(0);
	var src = jQuery(i).attr("src");
	var srcDown = src.replace(".gif", "-down.gif").replace(".jpg", "-down.jpg");

	jQuery(i).unbind();
	jQuery(i).attr("src", srcDown);
}


function rhtNEIMGRollover(item) {
	var i = jQuery(item).children().eq(0);
	var src = jQuery(i).attr("src");
	var srcOver = src.replace(".gif", "-over.gif").replace(".jpg", "-over.jpg");
	var srcDown = src.replace(".gif", "-down.gif").replace(".jpg", "-down.jpg");

	jQuery(i).unbind();
	jQuery(i).hover(
				function() { jQuery(i).attr("src", srcOver); }
				, function() { jQuery(i).attr("src", src); }
				);
}