confirmLoad = function() {
    $("#viewport").addClass("is-loaded");
}

$(document).ready(
	function()
	{
	    confirmLoad();
	    attachAnchorBehaviour();
	}
);

rolloverSubNav = function()
{
    var selector = $("#navigation-outer");
    selector.removeClass("default").addClass("drop-down-active");
}

rolloutSubNav = function()
{
    var selector = $("#navigation-outer");
    //selector.className = "default";
    selector.removeClass("drop-down-active").addClass("default");
}

attachAnchorBehaviour = function()
{
    $("a[href^='http://'], a[href^='https://']").each(function(index) {
        var titleValue = "(Opens in new window/tab)";
        this.title = titleValue;
    }).click(function(event) {
        openWindow(this.href);
        return false;
    });
    $("a[rel]").each(function(index) {
        switch (this.rel) {
            case 'external':
                this.title = "Link launches in new window";
                break;
        }
    }).click(function(event) {
        switch (this.rel) {
            case 'nofollow': case 'external': case 'nonWebDocument':
                openWindow(this.href);
                return false;
                break;

            case 'within-page':
                scrollToSelector(this.href);
                return false;
                break;
        }
    });
}

// ----------------------------------------------
scrollToSelector = function(href)
{
    var modifiedHref = href.substring(href.indexOf("#")+1);
    var targetOffset = $("#" + modifiedHref).offset().top;

    $("html,body").animate(
    {
    	scrollTop: targetOffset
    },1000);
}

// ----------------------------------------------
openWindow = function(href)
{    
	var attributes = "scrollbars=yes,toolbar=yes,menubar=yes,status=yes,directories=no,location=yes,resizable=yes";
	var windowOrTab = window.open(href,"",attributes);
	if (windowOrTab != null)
	{
	    windowOrTab.focus();
	}
	else
	{
	    window.location.href = href;
	}	   
}

// ----------------------------------------------
showFeedback = function(button_container, processing)
{
    if (processing)
    {
        $("#" + button_container).css("display", "none");
        $("#" + button_container + "Container").append("<div id='processing'><image src='/_images/indicators/default.gif' />");
    }
    else
    {
        $("#" + button_container).css("display", "block");
        $("#processing").remove();
    }
}
