// Styleswitcher loosely based on <http://www.alistapart.com/stories/alternate/styleswitcher.js>,
// with a whole lot of updating - thanks to Dori Smith http://backupbrain.com/. 
// updated 2006-10-16 thanks. :-)
function setActiveStyleSheet(title) {
	linksFound = document.getElementsByTagName("link")
	for (i=0; i<linksFound.length; i++) {
		thisLink = linksFound[i]
    	if (thisLink.getAttribute("rel").indexOf("style") > -1 && thisLink.getAttribute("title")) {
			thisLink.disabled = true
			if (thisLink.getAttribute("title") == title) {
				thisLink.disabled = false
			}
		}
	}
}
function getActiveStyleSheet() {
	linksFound = document.getElementsByTagName("link")
	for (i=0; i<linksFound.length; i++) {
		thisLink = linksFound[i]
    	if (thisLink.getAttribute("rel").indexOf("style") > -1 && thisLink.getAttribute("title") && !thisLink.disabled) {
			return thisLink.getAttribute("title")
		}
	}
}
function getPreferredStyleSheet() {
	linksFound = document.getElementsByTagName("link")
	for (i=0; i<linksFound.length; i++) {
		thisLink = linksFound[i]
		if (thisLink.getAttribute("rel").indexOf("style") > -1 && thisLink.getAttribute("rel").indexOf("alt") == -1 && thisLink.getAttribute("title")) {
		 	return thisLink.getAttribute("title")
		}
	}
}
function cookieVal(cookieName) {
	thisCookie = document.cookie.split("; ")
	for (i=0; i<thisCookie.length; i++) {
		if (cookieName == thisCookie[i].split("=")[0]) {
			return thisCookie[i].split("=")[1]
		}
	}
	return ""
}
window.onunload = function() {
	expireDate = new Date
	expireDate.setYear(expireDate.getFullYear()+1)
	document.cookie = "style="+getActiveStyleSheet()+"; expires="+expireDate.toGMTString()+"; path=/"
}

// added 2006-10-16 via Dori email
window.onload = function () {
	// Style sheet changer
	var thisCookie = cookieVal("style");
	var title = (thisCookie) ? thisCookie : getPreferredStyleSheet();
  setActiveStyleSheet(title);
	
// Preload any images not already loaded - upd 061023.2046pm
preloadImages('/img/bgb1/wrap.jpg','/img/bgb1/ft.png','/img/bgb1/tmbtm.png','/img/bgb1/tnavbtm.png','/img/bgb/dsblue.gif','/img/bgb/dsblue2.gif','/img/iconsbg1/caltop1b.gif','/img/bgb1/corner.gif','/img/bgb1/snav.png');
    
// If in a frame, kick out of it
        if (top.location != self.location) {
            top.location.replace(self.location);
        }
}// END 2006-10-16 additions
// ---------------------------
// Show Hide menus - see Designing with Web Standards, by Jeffrey Zeldman, Chapter 15
function toggleMenu(currMenu) {
	if (document.getElementById) {
		thisMenu = document.getElementById(currMenu).style
		if (thisMenu.display == "block") {
			thisMenu.display = "none"
		}
		else {
			thisMenu.display = "block"
		}
		return false
	}
	else {
		return true
	}
}
// ---------------------------
// AutoBlink
// Puts Google's Autolink on the Blink :)
// (c) 2005 Chris Ridings   http://www.searchguild.com
// Redistribute at will but leave this message intact
var linkcount;
function checklinks() {
	if (!(linkcount==document.links.length)) {
		// Something changed the links!
		// Iterate for an id of _goog
		for (i=0; i < document.links.length; i++) {
			if (document.links[i].id.substring(0,5)=="_goog") {
				// If we find an id of _goog then remove the link!
				var tr = document.links[i].parentTextEdit.createTextRange();
				tr.moveToElementText(document.links[i]);
				tr.execCommand("Unlink",false);
				tr.execCommand("Unselect",false);
			}
		}
	}
		setTimeout("checklinks()",500);
}
if (document.getElementById && document.createElement) {
	linkcount=document.links.length;
	setTimeout("checklinks()",500);
}
// --------------------------------------------------
// Image Preloader  v1.0.1
// documentation: http://www.dithered.com/javascript/image_preloader/
// license: http://creativecommons.org/licenses/by/1.0/
// code by Chris Nott (chris[at]dithered[dot]com)
function preloadImages() {
	if (document.images) {
		for (var i = 0; i < preloadImages.arguments.length; i++) {
				(new Image()).src = preloadImages.arguments[i];
		}
	}
}
