﻿$(document).ready(function() {

    var zIndexNumber = 1000;
    $('div').each(function() {
        $(this).css('zIndex', zIndexNumber);
        zIndexNumber -= 10;
    });


    var projectType;

    //----------------------------
    // Navigation
    //----------------------------

    var path = location.pathname.substring(1);
    var ontheboards = getQueryString('ontheboards');

    var check = path.substring(0, 6);
    if (check == "miles/") {
        path = path.substring(6);
    }

    if (path != "") {
        $('#mainmenu a[href="' + path + '"]').addClass('active');
        $('#subnav a[href="' + path + '"]').addClass('active');
    }
    if (path == "profile.aspx" || path == "history.aspx" || path == "teamapproach.aspx" || path == "clients.aspx") {
        $("#practiceLink").addClass('active');
        $(".submenu").hide("fast");
        $("#practiceSubMenu").show("fast");
        $('#practiceSubMenu a[href="' + path + '"]').addClass('active');
    }

	if (path == "team.aspx" || path == "teamcorp.aspx" || path == "teampro.aspx" || path == "team-budmiles.aspx") {
        $("#leadershipLink").addClass('active');
        $(".submenu").hide("fast");
        $("#leadershipSubMenu").show("fast");
        $('#leadershipSubMenu a[href="' + path + '"]').addClass('active');
    }
	
    else if (path == "architecture.aspx" || path == "masterplanning.aspx" || path == "programming.aspx" || path == "projectmanagement.aspx"
            || path == "interiordesign.aspx" || path == "facilitiesassessment.aspx" || path == "digitalcommunication.aspx" || path == "developmentstrategies.aspx") {
        $("#practiceLink").addClass('active');
        $(".submenu").hide("fast");
        $("#practiceSubMenu").show("fast");
        $('#practiceSubMenu a[id="servicesLink"]').addClass('active');
    }
    else if (path == "clients-oklahomacity.aspx" || path == "clients-tulsa.aspx" || path == "clients-dallas.aspx" || path == "clients-houston.aspx") {
        $("#practiceLink").addClass('active');
        $(".submenu").hide("fast");
        $("#practiceSubMenu").show("fast");
        $('#practiceSubMenu a[id="clientsLink"]').addClass('active');
    }
    else if (path == "career-detail.aspx") {
        $("#careersLink").addClass('active');
        $(".submenu").hide("fast");
    }
    else if (path == "team-budmiles.aspx") {
        $("#teamLink").addClass('active');
        $(".submenu").hide("fast");
    }
    else if (path == "projects.aspx") {
        var queryString = window.location.search.substring(1);
        
        $("#projectsLink").addClass('active');
        $(".submenu").hide("fast");
        $("#"+PROJECTSUBMENUID).show("fast");
        
        var index = queryString.indexOf("categoryid=");
        if (index > -1){
            var catId = queryString.substring(index+11);
            $("#catLink_" + catId).addClass('active');
        }
    }
    else if (path == "projects-details.aspx") {
        var queryString = window.location.search.substring(1);
        var split = queryString.split("&");
        var queryString = split[0];

        var ontheboardsQS = getQueryString("ontheboards");

        if (ontheboardsQS == 1) {
            $("#onTheBoardLink").addClass('active');
        }
        else {
            $("#projectsLink").addClass('active');
            $(".submenu").hide("fast");
            $("#"+PROJECTSUBMENUID).show("fast");
            
            var catId = CATEGORYID;
            if (catId != null && catId.length > 0){
                $("#catLink_" + catId).addClass('active');
            }
        }
    }
    else if (path == "awards.aspx") {
        $("#inTheNewsLink").addClass('active');
        $(".submenu").hide("fast");
        $("#inTheNewsSubMenu").show("fast");
        $("#awardsLink").addClass('active');
    }
    else if (path == "pressRelease.aspx") {
        $("#inTheNewsLink").addClass('active');
        $(".submenu").hide("fast");
        $("#inTheNewsSubMenu").show("fast");
        $("#pressReleaseLink").addClass('active');
    }
    else if (path == "studio-dallas.aspx") {
        $("#footerSubNav").hide("fast");
        $(".submenu").hide("fast");
        $("#studiosLink").addClass("active");
        $("#studiodallasLink").addClass("active");
        $("#studiosSubMenu").show("fast");
    }
    else if (path == "studio-houston.aspx") {
        $("#footerSubNav").hide("fast");
        $(".submenu").hide("fast");
        $("#studiosLink").addClass("active");
        $("#studiohoustonLink").addClass("active");
        $("#studiosSubMenu").show("fast");
    }
    else if (path == "studio-oklahomacity.aspx") {
        $("#footerSubNav").hide("fast");
        $(".submenu").hide("fast");
        $("#studiosLink").addClass("active");
        $("#studiookLink").addClass("active");
        $("#studiosSubMenu").show("fast");
    }
    else if (path == "studio-tulsa.aspx") {
        $("#footerSubNav").hide("fast");
        $(".submenu").hide("fast");
        $("#studiosLink").addClass("active");
        $("#studiotulsaLink").addClass("active");
        $("#studiosSubMenu").show("fast");
    }


    //----------------------------
    // Click functions
    //----------------------------
    $(".menuToggle").click(function() {
        $(".menuToggle").removeClass("active");
        $(this).addClass("active");
        $(".submenu").hide("fast");
        //$("#" + $(this).attr("mysub")).show("fast");
        
        var subMenu = null;
        var menuId = $(this).attr("id");
        switch (menuId){
            case "practiceLink":
                subMenu = $("#practiceSubMenu");
                break;
			case "leadershipLink":
                subMenu = $("#leadershipSubMenu");
                break;
            case "projectsLink":
                subMenu = $("#"+PROJECTSUBMENUID);
        }
        
        if (subMenu != null)
            $(subMenu).show("fast");
    });

    $(".subMenuToggle").click(function() {
        $(".subMenuToggle").removeClass("active");
        $(this).addClass("active");
    });

    $("#inTheNewsLink").click(function() {
        $("#studiosLink").removeClass("active");
        $(this).addClass("active");
        $("#inTheNewsSubMenu").hide("fast");
        $("#studiosSubMenu").hide("fast");
        $("#footerSubNav").show("fast");
        $("#inTheNewsSubMenu").show("fast");
    });

    $("#studiosLink").click(function() {
        $("#inTheNewsLink").removeClass("active");
        $(this).addClass("active");
        $("#inTheNewsSubMenu").hide("fast");
        $("#footerSubNav").hide("fast");
        $("#studiosSubMenu").hide("fast");
        $("#studiosSubMenu").show("fast");
    });

    //----------------------------
    // Scrolling
    //----------------------------    
    $("#btnDown").mousedown(function() {
        setTimeout(function() {
            scrollDown();
        }, 50);
    }).mouseup(function() {
        $("#container").stop();
    });

    $("#btnUp").mousedown(function() {
        setTimeout(function() {
            scrollUp();
        }, 50);
    }).mouseup(function() {
        $("#container").stop();
    });

    // Toggle feature removed Oct 29 2009
    //    $("#toggleButton").click(function() {
    //        $("#projectHolder").slideToggle("fast");
    //    });


//    $('#contentPane').jScrollPane({ scrollbarWidth: 8, scrollbarMargin: 10, showArrows: false, scrollbarOnLeft: true });



    //----------------------------
    // Set column opacity to 80%
    //----------------------------
    $("#contentHolder").css("opacity", "0.85");
    $("#projectHolder").css("opacity", "0.85");
    $("#topWhiteBox").css("opacity", "0.50");
    $("#bottomWhiteBox").css("opacity", "0.50");
});


function getQueryString(ji) {
    hu = window.location.search.substring(1);
    gy = hu.split("&");
    for (i = 0; i < gy.length; i++) {
        ft = gy[i].split("=");
        if (ft[0] == ji) {
            return ft[1];
        }
    }
}

function scrollUp() {    
    $("#container").stop().animate({
        scrollTop: 0
    }, 1000);
}

function scrollDown() {    
    $("#container").stop().animate({
        scrollTop: $("#scrollContent").height()
    }, 3000);
}


/*Scrolling*/
function ScrooUpBtnPress()
{
    $("#btnDown").mousedown(function() {
        setTimeout(function() {
            scrollDown();
        }, 50);
    }).mouseup(function() {
        $("#container").stop();
    });

    $("#btnUp").mousedown(function() {
        setTimeout(function() {
            scrollUp();
        }, 50);
    }).mouseup(function() {
        $("#container").stop();
    });
}
