var USERNAME = get_username();
$(document).ready(function () {
	//**show_edit**//					   
	init_labelshows('header_t');
	//**menu**//
	$('#topnav li>dl').hide();
	//$("#topnav li:first").addClass('over');
	$("#topnav li").each(function () {
		$(this).hover(
			function () {
				$('#topnav li>dl').hide();
				$(this).addClass('active');
				$(this).find('dl').show().css({
					top: parseInt($(this).position().top+33) + 'px',
					left: parseInt($(this).position().left) + 'px',
					//width: $(this).find('dt').size() * 38 + 'px'
					width: '200px'
				});
			},
			function () {
			    $('#topnav li').removeClass('active');
			    $(this).find('dl').hide();
			}
  		)
	});

});

$(function () {
    window.nav = {};

    String.prototype.endWith = function (str) {
        if (str == null || str == "" || this.length == 0 || str.length > this.length)
            return false;
        if (this.substring(this.length - str.length) == str)
            return true;
        else
            return false;
        return true;
    }

    nav.setActiveMainNav = function (activeUrl) {
        activeUrl = activeUrl || (location + "");
        if (activeUrl.endWith("-page-2.shtml")) {
            activeUrl = activeUrl.substring(0, activeUrl.length - 13);
        }
        if (activeUrl.endWith("###")) {
            activeUrl = activeUrl.substring(0, activeUrl.length - 3);
        }
        $("#topnav a").each(function () {
            if (activeUrl.endWith($(this).attr("href")) || $(this).attr("href").endWith(activeUrl)) {
                $(this).attr("class", "active");
                if ($(this).parent().parent().attr("tagName") == "DL" || $(this).parent().parent().attr("tagName") == "UL") {
                    $(this).parent().parent().prev().attr("class", "active");
                    if ($(this).parent().parent().parent().parent().attr("tagName") == "DL" || $(this).parent().parent().attr("tagName") == "UL") {
                        $(this).parent().parent().parent().parent().prev().attr("class", "active");
                    }
                }
            }
        })
    }

    nav.createLeftMenu = function () {
        $("#topnav a[class='active']:first").each(function () {
            $("#leftMenu .leftMenuTitle").html($(this).html());
            $(this).parent().find("dl > dt > a").each(function () {
                var item = $("<li></li>");
                $("#leftMenu > ul").append(item.append($("<a></a>").html($(this).html()).attr("href", $(this).attr("href")).attr("class", $(this).attr("class")).attr("target", $(this).attr("target"))));
                if ($(this).attr("class") == "active") {
                    var item1 = $("<ul></ul>");
                    item.append(item1);
                    $(this).parent().find("ul > li > a").each(function () {
                        item1.append($("<li class=\"li2\"></li>").append($("<a></a>").html($(this).html()).attr("href", $(this).attr("href")).attr("class", $(this).attr("class")).attr("target", $(this).attr("target"))));
                    });
                }
            });
        })
    }

    nav.createNavPath = function () {
        var lastItem = $("#navPath a:first");
        $("#topnav a[class='active']:first").each(function () {
            var item = $("<span>&nbsp;&gt;&nbsp;</span>");
            lastItem.after(item);
            lastItem = item;
            item = $("<a></a>").html($(this).html()).attr("href", $(this).attr("href")).attr("class", $(this).attr("class")).attr("target", $(this).attr("target"));
            lastItem.after(item);
            lastItem = item;
            $(this).parent().find("dl a[class='active']").each(function () {
                var item = $("<span>&nbsp;&gt;&nbsp;</span>");
                lastItem.after(item);
                lastItem = item;
                item = $("<a></a>").html($(this).html()).attr("href", $(this).attr("href")).attr("class", $(this).attr("class")).attr("target", $(this).attr("target"));
                lastItem.after(item);
                lastItem = item;
                $(this).parent().find("dl a[class='active']").each(function () {
                    var item = $("<span>&nbsp;&gt;&nbsp;</span>");
                    lastItem.after(item);
                    lastItem = item;
                    item = $("<a></a>").html($(this).html()).attr("href", $(this).attr("href")).attr("class", $(this).attr("class")).attr("target", $(this).attr("target"));
                    lastItem.after(item);
                    lastItem = item;
                });
            });
        })
    }
});
