var switchColor = function() {

    // Main colors
    colors = new Array(4);
    colors[0] = "#7BAF4C"; // green
    colors[1] = "#992B1E"; // red
    colors[2] = "#c47700"; // gold
    colors[3] = "#668092"; // blue

    // Lighter version of colors
    lcolors = new Array(4);
    lcolors[0] = "#BDD7A6"; // lighter green
    lcolors[1] = "#CC958F"; // lighter red
    lcolors[2] = "#E2BB80"; // lighter gold
    lcolors[3] = "#B3C0C9"; // lighter blue

    // Array of colors to attach to body tag for CSS styling
    strColors = [];
    strColors[0] = "green";
    strColors[1] = "red";
    strColors[2] = "gold";
    strColors[3] = "blue";
  
    currentColor = Math.floor(Math.random() * colors.length);
    return currentColor;
}
var switchLogo = function () {
	var path = document.location.pathname.toLowerCase();
	if (/default.aspx/.test(path) || path == "/") {
		logos = [];
		logos[0] = "OV";
		logos[1] = "OA";
	} else {
		logos = [];
		logos[0] = "OV";
		logos[1] = "OA";
		logos[2] = "AO";
	}
	currentLogo = Math.floor(Math.random() * logos.length);
	return currentLogo;
}
$(document).ready(function() {
    var path = document.location.pathname.toLowerCase();
    switchColor();
    var color = colors[currentColor];
    var lcolor = lcolors[currentColor];

    if (!/lab.aspx/.test(path)) {
        $("body").attr("class", strColors[currentColor]);
    } else {
        $("body").attr("class", "gray");
        color = "#939999";
        lcolor = "#D2D5D5";
    }
    switchLogo();
    var logo = logos[currentLogo];
    if (/default.aspx/.test(path) || path == "/") {
        logo += "_Home";
    }
    var ext = ".png";
    var logoFileName = color.slice(1, color.length) + "_" + logo + ext;
    if ((navigator.appName == "Microsoft Internet Explorer" && navigator.appVersion.indexOf("MSIE 7.0") >= 0) || (navigator.appName != "Microsoft Internet Explorer")) {
        if (path != "/default.aspx" && path != "/") {
            logoFileName = "FFFFFF_" + logo + ext;
        }
    }
    var pageName = path.slice(1, path.indexOf("."));
    var titleFileName = "images/titles/";
    titleFileName += pageName + "_" + color.slice(1, color.length) + ext;
    var introFileName = "images/intros/";
    if (/default.aspx/.test(path) || path == "/") {
        introFileName += "Intro_home_" + color.slice(1, color.length) + ext;
    } else {
        introFileName += "Intro_" + pageName + "_" + color.slice(1, color.length) + ext;
    }
    var subtitleFileName = "images/home/";
    subtitleFileName += color.slice(1, color.length) + ext;

    // apply styles for all pages
    $("#logo").css("background-image", "url(images/logo/" + logoFileName + ")");
    if (/lab.aspx/.test(path)) {
        if (navigator.appName == "Microsoft Internet Explorer" && navigator.appVersion.indexOf("MSIE 6.0") > 0) {
            window.document.getElementById("crosshair").src = "images/projects/circle_plus.gif";
            $("#intro").css("margin-bottom", "-25px");
            $("#intro").css("margin-left", "158px");
        }
    }
    if (/default.aspx/i.test(path) || path == "/") {
        $("body").addClass("default");
        window.document.getElementById("subtitle").src = subtitleFileName;
        $("#intro").css("height", "50px");
    } else {
        if (navigator.appName == "Microsoft Internet Explorer" && MSIEVersion() < 7) {
            document.getElementById("pageTitle").outerHTML = "<br><br><br><br><div style=\"width:" + document.getElementById("pageTitle").width
              + "px;height:" + document.getElementById("pageTitle").height
              + "px;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
              + "(src=\'" + document.getElementById("pageTitle").src + "\');\"></div>";
        } window.document.getElementById("intro").src = introFileName;
        if (document.getElementById("intro")) {
            var introElem = document.getElementById("intro");
            introElem.src = "/images/intro.ashx?text=" + escape(introElem.alt) + "&width=" + introElem.width + "&height=" + introElem.height + "&color=" + escape(color);
        }
    }
    function MSIEVersion() {
        var version = -1; // Return value assumes failure.
        if (navigator.appName == 'Microsoft Internet Explorer') {
            var regExp = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
            if (regExp.exec(navigator.userAgent) != null) {
                version = parseFloat(RegExp.$1);
            }
        }
        return version;
    }
});

