$(document).ready(function() { DoDocReady(); });

function DoDocReady() {
	var cookie = readCookie("style");
	var title = cookie ? cookie : getPreferredStyleSheet();
	setActiveStyleSheet(title);
	setUpStyleSwitch();
	setUpBookMark();
	externalLinks();
	$("#tabs").tabs({ fx: { opacity: 'toggle' } });
}
jQuery.noConflict();

jQuery(function(){

Cufon.replace('h1,h2,h3,h4,h5,h6,#tagLine,.imgTitle,th');

// jQuery("ul.images li:nth-child(3n)").addClass("nm");

});

window.onunload = function(e) {
		var title = getActiveStyleSheet();
		if (title != '' && title != null) {
	        createCookie("style", title, 365);
	    }
	     else{
	        createCookie("style", "normal", 365);
	    }
}

var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);

// Clears input values
function clearDefault(objInput,strDefaultText) {
	if (objInput.value==strDefaultText) objInput.value = '';
}

// Restores the default text, if the input box is empty
function restoreDefault(objInput,strDefaultText) {
	if (objInput.value=='') objInput.value = strDefaultText;
}

// This is for the AAA links, top right
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 getActiveStyleSheet() {
		var i, a;
		for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
				if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
		}
		return null;
}

function getPreferredStyleSheet() {
		var i, a;
		for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
				if(a.getAttribute("rel").indexOf("style") != -1
				   && a.getAttribute("rel").indexOf("alt") == -1
				   && a.getAttribute("title")
				   ) return a.getAttribute("title");
		}
		return null;
}

function createCookie(name,value,days) {

		if (days) {
				var date = new Date();
				date.setTime(date.getTime()+(days*24*60*60*1000));
				var expires = "; expires="+date.toGMTString();
		}
		else expires = "";
		document.cookie = name+"="+value+expires+"; path=/";


}

function deleteCookie(name) {
document.cookie = name +
'=; expires=Thu, 01-Jan-70 00:00:01 GMT;';
}

function readCookie(name) {
		var nameEQ = name + "=";
		var ca = document.cookie.split(';');
		for(var i=0;i < ca.length;i++) {
				var c = ca[i];
				while (c.charAt(0)==' ') c = c.substring(1,c.length);
				if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
		}
		return null;
}

function setUpStyleSwitch() {
	// Does "styleswitch" exist?
	if (document.getElementById('styleswitch')) {
		// Writes the HTML
		document.getElementById('styleswitch').innerHTML = 'Text size: <a href="#" onclick="setActiveStyleSheet(\'Normal\');" title="Normal text size">A<span> (normal text size)</span></a><a href="#" onclick="setActiveStyleSheet(\'Large\');" title="Large text size" class="large">A<span> (large text size)</span></a><a href="#" onclick="setActiveStyleSheet(\'Extra-large\');" title="Extra-large text size" class="xl">A<span> (Extra-large text size)</span></a>';
	}
}
// End AAA functions

// This adds the bookmark link, if the browser supports it
function setUpBookMark() {
	// Does "bkmrk" exist?
	if (document.getElementById('bkmrk')) {
		objBook = document.getElementById('bkmrk');
		if (window.external && !window.sidebar) objBook.innerHTML = '<a href="#" onclick="window.external.AddFavorite(location.href, document.title);return false;">Bookmark This Page</a>';
	    // Gekko bookmark
	    if (window.sidebar) objBook.innerHTML = '<a href="#" onclick="window.sidebar.addPanel(document.title, location.href, \'\');return false;">Bookmark This Page</a>';
	}
}

// Converts links with an attribute of rel="external" to target="_blank"
function externalLinks() {
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) {
			var anchor = anchors[i];
			if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") {
				 anchor.target = "_blank";
				 anchor.title = "This link will open in a new window.";
		}
	}
}
