jQuery.noConflict();
$navigation = function(jEl) {
    var self = this;
    this.options = {
        event : arguments[1] && arguments[1].event ? arguments[1].event : 0,
        showDuration : 500,
        hideDuration : 300,
        defaultActiveSections : jEl.find("li.Active")
    };

    this.navigation = jEl;
    this.navigation.find("li").each(function() {
        var o = jQuery(this);

        if (o.find("> ul").length > 0) {
            o.addClass("HasChild");
        }

		/*
		// duy.thanh add : fix issue #1966
		*/
		if (o.hasClass("Level1") && o.find("> a").outerHeight() > 32) {
			if(jQuery.browser.msie && (parseFloat(jQuery.browser.version) >7)) {
				if(o.hasClass("Active")) {
				o.find("> a").css({'padding' : '0px 11px 6px 8px', 'line-height': '11px'});
				} else {
					o.find("> a").css({'padding' : '0px 11px 1px 8px', 'line-height': '11px'});
				}
			} else {
				if(o.hasClass("Active")) {
					o.find("> a").css({'padding' : '1px 11px 6px 8px'});
				} else {
					o.find("> a").css({'padding' : '1px 11px 1px 8px'});
				}
			}
        }
		// end 
		
        o.bind(self.options.event, function(evt) {
            o.parent().find("> li.Active > ul:first").hide(self.options.hideDuration);
            o.parent().find("> li.Active").removeClass("Active");

            if (o.hasClass("Active")) {
            	o.removeClass("Active");
            	o.find("> ul:first").hide(self.options.hideDuration);
            } else {
            	o.addClass("Active");
                o.find("> ul:first").show(self.options.showDuration);
            }

            evt.stopPropagation();
        });
    });

    this.refresh = function(evt) {
    	// hold default active sections
    	var activeSections = self.options.defaultActiveSections;
        for (i = 0; i < activeSections.length; i++) {
            var activeSection = jQuery(activeSections[i]);
            activeSection.addClass("Hilite");
        }

        var leaf = null;
        this.navigation.find("li.Active").each(function() {
            var o = jQuery(this);
            if (o.find("li.Active").length <= 0) {
                leaf = o;
            }
        });

        while (leaf != null && leaf.hasClass("Active")) {
            if (!leaf.hasClass("Hilite")) {
                leaf.find("> ul:first").hide(self.options.hideDuration);
            }
            leaf.removeClass("Active");
            leaf = leaf.parent().parent();
        }
    };
    
    jQuery(document).bind(self.options.event, function(evt) {
        if (self.navigation.find("li.Active").length > 0) {
            self.refresh(self.options.event);
        }

        self.navigation.find('li.Hilite').each(function() {
            jQuery(this).find("> ul:first").show(self.options.showDuration);
        });

        evt.stopPropagation();
    });
};

jQuery.fn.extend( {
    addNavigation : function() {
        var options = arguments[0];
        this.each(function() {
            new $navigation(jQuery(this), options);
        });
    }
});

