function ScrollContent() {
	$.localScroll({
		target: $("#viewport"),
		axis:'xy',
		queue:true,
		duration:1200,
		hash:true,
		onBefore:function( e, anchor, $target ){
					this.isSection = function(id) {
				this.valid = false;
				this.id = id;
					$("#menu li a").each($.proxy(function(i, element) {
					if ($(element).attr("hash") == this.id)
						this.valid = true;
				}, this));
				return this.valid;
			};
			var currTarget = $(e.currentTarget);
			var id = "#" + currTarget.parent().parent().parent().parent().attr("id");
			
			if (this.isSection(id) && !currTarget.parent().hasClass("selected")) {
				this.target = $(id + " .section_content");
				
				$(id + " .section_menu li").each(function() {
					$(this).removeClass("selected");
				});
			currTarget.parent().addClass("selected");
			}
			else if ( !$("#menu a#" + currTarget.attr("id")).parent().hasClass("selected") ){
				this.target = $("#viewport");
				
				$("#menu li").each(function() {
					$(this).removeClass("selected");
				});
				
				$("#menu a#" + currTarget.attr("id")).parent().addClass("selected");
			}
			else
				return false;
		},
		onAfter:function( anchor, settings ){
		}
	});
}
function findTopMenuIdFromHref(href) {
    this.href = href;
    this.result = "";
    $("#menu li a").each($.proxy(function (i, element) {
        if ($(element).attr("href") == this.href) {
            this.result = $(element).attr("id");
            return;
        }
    }, this));

    return this.result;
}
$(document).ready(function () {
    var sC = new ScrollContent();
    // update menus to reflect current anchor
    // handles case of a page refresh
    this.anchor = $.url.attr("anchor");
    if (this.anchor) {
        this.topMenu = "";
        this.subMenu = "";
        this.anchor = '#' + this.anchor;
        this.topMenu = findTopMenuIdFromHref(this.anchor);
        if (this.topMenu) {
            $('#' + this.topMenu).click();
            return;
        }
        $(".section_menu li a").each($.proxy(function (i, element) {
            if ($(element).attr("href") == this.anchor) {
                var containerId = '#' + $(element).parent().parent().parent().parent().attr("id");
                this.topMenu = '#' + findTopMenuIdFromHref(containerId);
                $(this.topMenu).click();
                $(element).click();
                return;
            }
        }, this));
    }
});
