var strapIndex = getCookie('strapIndex');
var index = parseInt(Math.floor(Math.random() * 3)); // RWP: changed the case count to 3
var color = '';

$(function () {
    if (strapIndex != "" && strapIndex != null && strapIndex != false) {
        index = parseInt(strapIndex);
    }
    else {
        setCookie('strapIndex', index, null);
    }
    switch (index) {
        case 0: $('body').attr('id', 'blue'); color = 'blue'; break;
		case 1: $('body').attr('id', 'green'); color = 'green'; break;
		case 2: $('body').attr('id', 'red'); color = 'red'; break;
		//case 3: $('body').attr('id', 'purple'); color = 'purple'; break; // RWP: commented the 'purple' option out
		default: $('body').attr('id', ''); color = 'default'; // RWP: changed this from 'green' to 'default' 18-August-2011
    }
    setActiveStyle();
    setActiveStyleSheet(color);

});            /****End onload functions*******/


//$(document).ready(function () {

	function getCookie(c_name) {
		if (document.cookie.length > 0) {
			var i, x, y, ARRcookies = document.cookie.split(";");
			for (i = 0; i < ARRcookies.length; i++) {
				x = ARRcookies[i].substr(0, ARRcookies[i].indexOf("="));
				y = ARRcookies[i].substr(ARRcookies[i].indexOf("=") + 1);
				x = x.replace(/^\s+|\s+$/g, "");
				if (x == c_name) {
					return unescape(y);
				}
			}
		}
		return false;
	}
	
	function setCookie(c_name, value, expiredays) {
		var exdate = new Date();
		exdate.setDate(exdate.getDate() + expiredays);
		document.cookie = c_name + "=" + escape(value) +
		((expiredays == null) ? ";path=/" : ";expires=" + exdate.toUTCString()); +"path=/";
	}
	
	
	function setActiveStyleSheet(title) {
		var i, a, main;
	
		for (i = 0; (a = document.getElementsByTagName("link")[i]); i++) {
			if (a.getAttribute("rel").indexOf("Style") != -1 && a.getAttribute("title")) {
				a.disabled = true;
				if (a.getAttribute("title") == title) a.disabled = false;
			}
		}
	}
	
	function setActiveStyle() {
		var i, a, main;
	
		for (i = 0; (a = document.getElementsByTagName("link")[i]); i++) {
			if (a.getAttribute("href").indexOf("blue") != -1) {
				a.setAttribute('title', 'blue');
				a.setAttribute('media', 'screen');
				a.setAttribute('rel', 'Alternate Stylesheet');
			}
			if (a.getAttribute("href").indexOf("green") != -1) {
				a.setAttribute('title', 'green');
				a.setAttribute('media', 'screen');
				a.setAttribute('rel', 'Alternate Stylesheet');
			}
			if (a.getAttribute("href").indexOf("red") != -1) {
				a.setAttribute('title', 'red');
				a.setAttribute('media', 'screen');
				a.setAttribute('rel', 'Alternate Stylesheet');
			}
			if (a.getAttribute("href").indexOf("purple") != -1) {
				a.setAttribute('title', 'purple');
				a.setAttribute('media', 'screen');
				a.setAttribute('rel', 'Alternate Stylesheet');
			}
		}
	}
//});
