﻿function redirect() {

    if (document.referrer.indexOf("http://www.google") == -1) {
        var url = document.location.toString();
        if (url.indexOf("-") >= 0) {
            if (url.indexOf("Jobs") >= 0) {
                var hashtag = "#&&";
                hashtag += "category=jobs";
                var baseUrl = url.substring(0, url.lastIndexOf("/"));
                if (url.indexOf("#&&") == -1) {
                    var linkPart = url.substring(url.lastIndexOf("/") + 1, url.lastIndexOf("."));
                    var linkParts = linkPart.split("-");

                    hashtag += "&title=" + linkParts[1];
                } else {
                    hashtag = url.substring(url.indexOf("#"), url.length);
                }
                window.location = baseUrl + "/Content.aspx" + hashtag;
            } else if (url.indexOf("Work") >= 0) { 
                var hashtag = "#&&";
                hashtag += "category=work";
                var baseUrl = url.substring(0, url.lastIndexOf("/"));
                if (url.indexOf("#&&") == -1) {
                    var linkPart = url.substring(url.lastIndexOf("/") + 1, url.lastIndexOf("."));
                    var linkParts = linkPart.split("-");

                    hashtag += "&client=" + linkParts[0];
                    hashtag += "&case=" + linkParts[1];
                } else {
                    hashtag = url.substring(url.indexOf("#"), url.length);
                }
                window.location = baseUrl + "/Content.aspx" + hashtag;
            } else if (url.indexOf("Work") >= 0) { 
                var hashtag = "#&&";
                hashtag += "category=contact";
                window.location = baseUrl + "/Content.aspx" + hashtag;
            } else if (url.indexOf("About") >= 0) {
                var hashtag = "#&&";
                hashtag += "category=about";
                var baseUrl = url.substring(0, url.lastIndexOf("/"));
                if (url.indexOf("#&&") == -1) {
                    var linkPart = url.substring(url.lastIndexOf("/") + 1, url.lastIndexOf("."));
                    var linkParts = linkPart.split("-");

                    hashtag += "&title=" + linkParts[1];
                } else {
                    hashtag = url.substring(url.indexOf("#"), url.length);
                }
                window.location = baseUrl + "/Content.aspx" + hashtag;
            }
        }
    }
}

redirect();
window.onresize = resizeFlashWindow;

function resizeFlashWindow()
{
	if(document.getElementById("banner") && document.getElementById("banner").resizeOnMaximize)
	{
		document.getElementById("banner").resizeOnMaximize();
	}
}

function checkMenu() {
    var url = document.location.toString();
    var client = "";
    var clientCase = "";

    if (url.indexOf("#&&") == -1) {
        if (url.indexOf("-") >= 0) {
            var linkPart = url.substring(url.lastIndexOf("/") + 1, url.lastIndexOf("."));
            var linkParts = linkPart.split("-");

            client = linkParts[0];
            clientCase = linkParts[1];
        }
    } else {
        var hashtag = url.substring(url.indexOf("#") + 3, url.length);
        var hashParts = hashtag.split("&");
        client = hashParts[0].split("=")[1];
        clientCase = hashParts[1].split("=")[1];
    }

  //  if (client != "")
    //    toggleMenu("client" + client);
}

function viewPort() {
    var h = window.innerHeight || document.documentElement.clientHeight || document.getElementsByTagName('body')[0].clientHeight;
    var w = window.innerWidth || document.documentElement.clientWidth || document.getElementsByTagName('body')[0].clientWidth;

    return { width: w, height: h }
}

function openWindowSWF(title, path, width, height) {
    var view = viewPort();
    if (width > view.width)
        width = view.width;
    if (height > view.height)
        height = view.height;

    tb_show(title, "FlashContainer.aspx?path=" + path + "&itemheight=" + height + "&itemwidth=" + width + "&KeepThis=true&TB_iframe=true&height=" + height + "&modal=true&width=" + width + "&autoheight=true&autowidth=true");
}

function openWindowImage(title, path, width, height, mediaTypeId) {
    var view = viewPort();
    if (width > view.width)
        width = view.width;
    if (height > view.height)
        height = view.height;

    tb_show(title, "ImageContainer.aspx?path=" + path + "&mediaTypeId=" + mediaTypeId + "&KeepThis=true&TB_iframe=true&TB_iframe=true&height=100&modal=true&width=200&autoheight=true&autowidth=true");
}

function navigate(category) {
    document.getElementById('hfCategory').value = category;
    __doPostBack('rapContent', '');
}

function ReplaceAll(value, org, rep) {
    var oldValue = "";
    while (value != oldValue) {
        oldValue = value;
        value = value.replace(org, rep);
    }
    return value;
}

function Filter(value) {
    if (value == null)
        return "";

    value = ReplaceAll(value, " ", "_");
    value = ReplaceAll(value, "&", "_");
    value = ReplaceAll(value, "/", "_");
    value = ReplaceAll(value, "__", "_");

    while (value.charAt(value.length - 1) == "_")
        value = value.substr(0, value.length - 1);

    return value;
}

