﻿var current_url = window.location.pathname;
var current_bg;
var slide_show = false;
var slide_delay = 2000;
var slide_speed = 1000;

if (current_url.substr(-1) == "/") {
    current_url = current_url + 'default.aspx';
}

var a = current_url.split("/");
switch (a.length) {
    case 2:
        current_bg = ['/assets/images/backgrounds/home-6.jpg', '/assets/images/backgrounds/home-1.jpg', '/assets/images/backgrounds/home-7.jpg', '/assets/images/backgrounds/home-8.jpg', '/assets/images/backgrounds/home-5.jpg', '/assets/images/backgrounds/home-4.jpg', '/assets/images/backgrounds/home-9.jpg', '/assets/images/backgrounds/home-10.jpg'];
        slide_show = true;
        slide_delay = 5000;
        break;
    case 3:
        current_bg = ["/assets/images/backgrounds/" + a[1] + ".jpg"];
        break;
    case 4:
        if (a[2].toLowerCase() == "map") {
            current_bg = ["/assets/images/backgrounds/" + a[1] + "-" + a[2] + ".jpg"];
        } else {
            current_bg = ["/assets/images/backgrounds/" + a[2] + ".jpg"];
        }
        break;
    default:
        current_bg = ["/assets/images/backgrounds/conservation.jpg"];
        break;
}

$(function () {
    $(document).bgStretcher({
        images: current_bg,
        imageWidth: 2031,
        imageHeight: 847,
        slideShow: slide_show,
        nextSlideDelay: slide_delay,
        slideShowSpeed: slide_speed
    });

    //NAVIGATION
    var current_url = window.location.pathname;
    var root_segment;
    var current_segment;
    var segments = current_url.substring(1).split("/");

    switch (segments.length) {
        case 2:
            root_segment = segments[0];
            break;
        case 3: //secondary level
            root_segment = segments[0];
            current_segment = segments[1];
            break;
        default:
            break;
    }

    //let's get the menu to "stick".
    if (typeof (root_segment) != "undefined") {
        var img = $("#topnav").find("." + root_segment).find("img:first");
        if (img.attr("src")) {
            img.attr("src", img.attr("src").replace("-off", "-on"));
        }

        if (typeof (current_segment) != "undefined") {
            //$("#topnav").find("." + root_segment).stop().animate({ height: '270px' }, { queue: false, duration: 600, easing: 'linear' });
            $("." + root_segment).find("#" + current_segment + " img:last").css("z-index", "11");
        }
    }

    //main menu hover.
    $("#topnav > li").each(function () {
        var li_id = $(this).attr("class");
        $(this).append("<div class=\"subnavitem " + li_id + "-hover\"></div>");
    });

    $("#topnav > li").hover(function () {
        $(this).stop();
        $(this).children("div").fadeIn("1000");
    }, function () {
        $(this).stop();
        $(this).children("div").fadeOut("1000");
    });

    //slide the subnav down.
    $("#topnav li.mainnav").hover(function () {
        $(this).stop().animate({ height: '270px' }, { queue: false, duration: 600, easing: 'linear' });
    }, function () {
        $(this).stop().animate({ height: '58px' }, { queue: false, duration: 600, easing: 'linear' });
    });

    //animate the subnav hrefs.
    $("img.off").hover(
    function () {
        $(this).stop().animate({ "opacity": "0" }, 600);
    },
    function () {
        $(this).stop().animate({ "opacity": "1" }, 600);
    });


    //contact div.
    $("body").click(function () {
        $("#contactcontainer").hide();
        $("#sitecontainer").css("z-index", "2");
    });

    $("#contacticon, #contactcontainer").click(function (event) {
        $("#contactcontainer").show();
        $("#sitecontainer, #contactcontainer").css("z-index", "999");
        event.stopPropagation();
    });

    //disable right click.
    $(this).bind("contextmenu", function (e) {
        e.preventDefault();
    });
});

