﻿$(document).ready(function () {

});

function maskScreen(showLoader) {
    var box = $("#modalBox");
    box.css("height", $(document).height());
    box.css("width", $(document).width());

    box.children().hide();
    box.fadeIn("slow");

    if (showLoader)
        showLoading();
}

function showLoading() {
    var box = $("#modalBox");

    if (showLoading)
        box.children().fadeIn("fast");
}

function hideLoading() {
    var box = $("#modalBox");
    box.children().fadeOut("fast");
}

function unmaskScreen() {
    var box = $("#modalBox");
    box.fadeOut("slow");
}

function CenterInWindow(element) {
    var eWidth = DetermineWidth(element);
    var eHeight = DetermineHeight(element);

    var windowHeight = $(window).height();
    var windowWidth = $(window).width();

    element.css("position", "absolute");

    if (windowHeight < eHeight)
        element.css("top", $(window).scrollTop());
    else
        element.css("top", ((windowHeight - eHeight) / 2) + $(window).scrollTop());

    if (windowWidth < eWidth)
        element.css("left", 0);
    else
        element.css("left", (windowWidth - eWidth) / 2);
}



function DetermineWidth(element) {
    var total = element.width();

    var pad = parseInt(element.css("padding-left"), 10) + parseInt(element.css("padding-right"), 10);
    var mar = parseInt(element.css("margin-left"), 10) + parseInt(element.css("margin-right"), 10);
    var bor = parseInt(element.css("borderLeftWidth"), 10) + parseInt(element.css("borderRightWidth"), 10);

    if (!isNaN(pad))
        total += pad;

    if (!isNaN(mar))
        total += mar;

    if (!isNaN(bor))
        total += bor;

    return total;
}

function DetermineHeight(element) {
    var total = element.height();

    var pad = parseInt(element.css("padding-top"), 10) + parseInt(element.css("padding-bottom"), 10);
    var mar = parseInt(element.css("margin-top"), 10) + parseInt(element.css("margin-bottom"), 10);
    var bor = parseInt(element.css("borderTopWidth"), 10) + parseInt(element.css("borderBottomWidth"), 10);

    if (!isNaN(pad))
        total += pad;

    if (!isNaN(mar))
        total += mar;

    if (!isNaN(bor))
        total += bor;

    return total;
}

var tipHandle;

function loadTip(element) {
	var tipText = "";

	if (element.text() == "Regional Land Use Plan")
	    tipText = "A collective statement about how to use and manage land and resources within a geographic area. In Yukon, Regional Planning Commissions prepare land use plans for consideration by affected governments, which include Yukon and First Nation governments.";
	else if (element.text() == "sustainable development")
	    tipText = "Beneficial socio-economic change that does not undermine the ecological and social systems upon which communities and societies are dependent (Source: Yukon Umbrella Final Agreement).";
	else if (element.text() == "moderated")
	    tipText = "All feedback and opinions are welcome, but the website moderator will not post offensive, racist, sexist or abusive responses.";
	else if (element.text() == "Special Management Areas")
	    tipText = "An area identified and established within a Traditional Territory pursuant to Chapter 10 of the First Nation Final Agreements and may include a) National wildlife areas; b) National parks, territorial parks, or national park reserves, and extensions thereof, and national historic sites; c) Special Wildlife or Fish management areas; d) Migratory bird sanctuaries or a wildlife sanctuary; e) Designated Heritage sites; f) Watershed protection areas; and g) Such other areas as a Yukon First Nation and Government agree from time to time. (Source: Yukon Umbrella Final Agreement)";
	else if (element.text() == "watershed")
	    tipText = "The region or area drained by a river or stream system, divided from other drainage basins by a height of land.";
	else if (element.text() == "Landscape Management Units")
	    tipText = "Land that has identifiable and repeating patterns of landform and vegetation (i.e. a landscape) that forms a logical area for consideration as one planning entity within the regional plan. LMU borders are usually drawn around rivers, roads, existing special management areas, or other identifiable features.";
	else if (element.text() == "Landscape Management Unit")
	    tipText = "Land that has identifiable and repeating patterns of landform and vegetation (i.e. a landscape) that forms a logical area for consideration as one planning entity within the regional plan. LMU borders are usually drawn around rivers, roads, existing special management areas, or other identifiable features.";
	else if (element.text() == "ecological integrity")
	    tipText = "The degree to which the physical, chemical, and biological components of a natural community are present, functioning, and capable of self-renewal.";
	else if (element.text() == "ecosystem services")
	    tipText = "Collective benefits provided to humankind by natural resources and processes, for example, production of food, control of climate change, and spiritual and recreational benefits.";
	else if (element.text() == "Integrated Management Areas")
	    tipText = "A land use category where a range of mineral, oil and gas development and other industrial activities are permissible (subject to applicable laws and regulations).";
	else if (element.text() == "watershed")
	    tipText = "The region or area drained by a river or stream system, divided from other drainage basins by a height of land.";




	$("#tipBox div").text(tipText);
	$("#tipBox").css("top", element.offset().top + 17);
	$("#tipBox").css("left", element.offset().left + (DetermineWidth(element) / 2) - ($("#tipBox").width() / 2));
	$("#tipBox").fadeIn();

	if (tipHandle != null)
	    window.clearTimeout(tipHandle);

	tipHandle = window.setTimeout(CloseTip, 5000);
}

function CloseTip() {
    $("#tipBox").fadeOut();
    tipHandle = null;
}
