$(document).ready(function () {

	loadPreferences();
	savePreferences();
	
	$(".form_background").bind('click',function(){
		updateBackground(this.value);		
	});
	
	$(".form_masthead").bind('click',function(){
		updateMasthead(this.value);		
	});
	
	$(".form_photo").bind('click',function(){
		updatePhoto(this.value);		
	});
	
	$("#saveprefs").bind('click', function () {
	
		savePreferences();
	
		if($.cookie('prefs_navclick') !== null) {
			//alert('Your preferences have been saved.');
			window.location.hash = '';
			window.location.reload(true);
			//self.close();
		} else {
			alert('You must enable cookies in order to save your site preferences.');
		}
		return false;
	});
});

function savePreferences()
{
	$.cookie('prefs_navclick', $(".form_navclick:checked").val(), {expires: 365});
	$.cookie('prefs_accordion', $(".form_accordion:checked").val(), {expires: 365});
	$.cookie('prefs_search', $(".form_search:checked").val(), {expires: 365});
	$.cookie('prefs_email', $(".form_email:checked").val(), {expires: 365});
	$.cookie('prefs_masthead', $(".form_masthead:checked").val(), {expires: 365});
	$.cookie('prefs_photo', $(".form_photo:checked").val(), {expires: 365});
	$.cookie('prefs_background', $(".form_background:checked").val(), {expires: 365});
}

function loadPreferences()
{
	if ($.cookie('prefs_navclick') !== null && $.cookie('prefs_navclick') != '') {
		$(".form_navclick:eq(" + $.cookie('prefs_navclick') + ")").attr("checked","checked");
	} else {
		$(".form_navclick:eq(0)").attr("checked","checked");
	}

	if ($.cookie('prefs_accordion') !== null && $.cookie('prefs_accordion') != '') {
		$(".form_accordion:eq(" + $.cookie('prefs_accordion') + ")").attr("checked","checked");
	} else {
		$(".form_accordion:eq(0)").attr("checked","checked");
	}

	if ($.cookie('prefs_search') !== null && $.cookie('prefs_search') != '') {
		$(".form_search:eq(" + $.cookie('prefs_search') + ")").attr("checked","checked");
	} else {
		$(".form_search:eq(0)").attr("checked","checked");
	}

	if ($.cookie('prefs_email') !== null && $.cookie('prefs_email') != '') {
		$(".form_email:eq(" + $.cookie('prefs_email') + ")").attr("checked","checked");
	} else {
		$(".form_email:eq(0)").attr("checked","checked");
	}

	if ($.cookie('prefs_masthead') !== null && $.cookie('prefs_masthead') != '') {
		$(".form_masthead:eq(" + $.cookie('prefs_masthead') + ")").attr("checked","checked");
		updateMasthead($(".form_masthead:eq(" + $.cookie('prefs_masthead') + ")")[0].value);
	} else {
		$(".form_masthead:eq(flash)").attr("checked","checked");
	}

	if ($.cookie('prefs_photo') !== null && $.cookie('prefs_photo') != '') {
		$(".form_photo:eq(" + $.cookie('prefs_photo') + ")").attr("checked","checked");
		updatePhoto($(".form_photo:eq(" + $.cookie('prefs_photo') + ")")[0].value);
	} else {
		$(".form_photo:eq(flash)").attr("checked","checked");
	}

	if ($.cookie('prefs_background') !== null && $.cookie('prefs_background') != '') {
		$(".form_background:eq(" + $.cookie('prefs_background') + ")").attr("checked","checked");
		updateBackground($(".form_background:eq(" + $.cookie('prefs_background') + ")")[0].value);
	} else {
		$(".form_background:eq(0)").attr("checked","checked");
	}
}

function updateBackground(id)
{
	var imageNumber = 0;	

		if(id == 0){
			imageNumber = 1;
		}else if(id == 1){
			imageNumber = 3;
		}else if(id == 2){
			imageNumber = 4;
		}else if(id == 3){
			imageNumber = 5;
		}else if(id == 4){
			imageNumber = 11;
		}else if(id == 5){
			imageNumber = 7;
		}else if(id == 6){
			imageNumber = 8;
		}
		
	$("#page").css('background-image','url(http://virginia.edu/virginia/images/bg/page-'+imageNumber+'.png)');
}

function updateMasthead(id)
{
	if(id == 0) {
		$(".mast").removeClass("alt");
	} else {
		$(".mast").addClass("alt");
	}
	
}

function updatePhoto(id)
{
	var imgSrc = "http://virginia.edu/virginia/images/photos/";
	var showFlash = false;

		if(id == 0){
			// add flash
			showFlash = true;
		}else if(id == 1) {
			imgSrc += "01.jpg";
		}else if(id == 2){
			imgSrc += "nbm2.jpg";
		}else if(id == 3){
			imgSrc += "snowa.jpg";
		}else if(id == 4){
			imgSrc += "health-building.jpg";
		}else if(id == 5){
			imgSrc += "athletics-flags.jpg";
		}else if(id == 6){
			imgSrc += "lawn-fall.jpg";
		}else if(id == 7){
			imgSrc += "cville-icepark.jpg";
		}else if(id == 8){
			imgSrc += "athletics-flag.jpg";
		}else if(id == 9){
			imgSrc += "scenic-books.jpg";
		}
		
	var main = $("#main-photo");
	var selected = $("#selected-photo");

	if(showFlash)	{
		main.show();
		selected.hide();
	} else {
	
		// check for img
		var selectedImage = $("#selected-photo img");
		if(selectedImage.length == 0) {
			// add img tag
			selected.html('<img src="'+imgSrc+'"/>');
		} else {
			selectedImage[0].src = imgSrc;
		}
	
		main.hide();
		selected.show();
	}
}

function closePrefsPanel() { 
	loadPreferences();
	$(".prefs").removeClass("active");
}

// JavaScript Document
var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();


var tmr;
var t;
var obj;

function sFa() {
	obj = gObj();
	sLft();
	shw(true);
	t = 0;
	sTmr();
}

function hFa() {
	t = -100;
	sTmr();
	return false;
}

function sTmr() {
	tmr = setInterval("fd()",20);
}

function fd() {
	var amt = Math.abs(t+=10);
	if(amt == 0 || amt == 100) clearInterval(tmr);
	amt = (amt == 100)?99.999:amt;
  	
	obj.style.filter = "alpha(opacity:"+amt+")";
	obj.style.KHTMLOpacity = amt/100;
	obj.style.MozOpacity = amt/100;
	obj.style.opacity = amt/100;
	
	if(amt == 0) shw(false);
}

function sLft() {
	var w = 200;	// set this to 1/2 the width of the faw div defined in the style sheet 
			// there's not a reliable way to retrieve an element's width via javascript!!
					
	var l = (document.body.innerWidth)? document.body.innerWidth / 2:document.body.offsetWidth / 2;

	obj.style.left = (l - w)+"px";
}

function gObj() {
	return document.getElementById("faw");	
}

function shw(b) {
	(b)? obj.className = 'show':obj.className = '';	
}

/*javascript for Bubble Tooltips by Alessandro Fulciniti
- http://pro.html.it - http://web-graphics.com */

function enableTooltips(id){
var links,i,h;
if(!document.getElementById || !document.getElementsByTagName) return;
h=document.createElement("span");
h.id="btc";
h.setAttribute("id","btc");
h.style.position="absolute";
document.getElementsByTagName("body")[0].appendChild(h);
if(id==null) links=document.getElementsByTagName("a");
else links=document.getElementById(id).getElementsByTagName("a");
for(i=0;i<links.length;i++){
    Prepare(links[i]);
    }
}

function Prepare(el){
var tooltip,t,b,s,l;
t=el.getAttribute("title");
if(t==null || t.length==0) t="link:";
el.removeAttribute("title");
tooltip=CreateEl("span","tooltip");
s=CreateEl("span","top");
s.appendChild(document.createTextNode(t));
tooltip.appendChild(s);
b=CreateEl("b","bottom");
l=el.getAttribute("href");
if(l.length>30) l=l.substr(0,27)+"...";
b.appendChild(document.createTextNode(l));
tooltip.appendChild(b);
setOpacity(tooltip);
el.tooltip=tooltip;
el.onmouseover=showTooltip;
el.onmouseout=hideTooltip;
el.onmousemove=Locate;
}

function showTooltip(e){
document.getElementById("btc").appendChild(this.tooltip);
Locate(e);
}

function hideTooltip(e){
var d=document.getElementById("btc");
if(d.childNodes.length>0) d.removeChild(d.firstChild);
}

function setOpacity(el){
el.style.filter="alpha(opacity:99)";
el.style.KHTMLOpacity="0.99";
el.style.MozOpacity="0.99";
el.style.opacity="0.99";
}

function CreateEl(t,c){
var x=document.createElement(t);
x.className=c;
x.style.display="block";
return(x);
}

function Locate(e){
var posx=0,posy=0;
if(e==null) e=window.event;
if(e.pageX || e.pageY){
    posx=e.pageX; posy=e.pageY;
    }
else if(e.clientX || e.clientY){
    if(document.documentElement.scrollTop){
        posx=e.clientX+document.documentElement.scrollLeft;
        posy=e.clientY+document.documentElement.scrollTop;
        }
    else{
        posx=e.clientX+document.body.scrollLeft;
        posy=e.clientY+document.body.scrollTop;
        }
    }
document.getElementById("btc").style.top=(posy+10)+"px";
document.getElementById("btc").style.left=(posx+0)+"px";
}

var tmr;
var t;
var obj;

function sFa() {
	obj = gObj();
	sLft();
	shw(true);
	t = 0;
	sTmr();
}

function hFa() {
	t = -100;
	sTmr();
	return false;
}

function sTmr() {
	tmr = setInterval("fd()",20);
}

function fd() {
	var amt = Math.abs(t+=10);
	if(amt == 0 || amt == 100) clearInterval(tmr);
	amt = (amt == 100)?99.999:amt;
  	
	obj.style.filter = "alpha(opacity:"+amt+")";
	obj.style.KHTMLOpacity = amt/100;
	obj.style.MozOpacity = amt/100;
	obj.style.opacity = amt/100;
	
	if(amt == 0) shw(false);
}

function sLft() {
	var w = 200;	// set this to 1/2 the width of the faw div defined in the style sheet 
			// there's not a reliable way to retrieve an element's width via javascript!!
					
	var l = (document.body.innerWidth)? document.body.innerWidth / 2:document.body.offsetWidth / 2;

	obj.style.left = (l - w)+"px";
}

function gObj() {
	return document.getElementById("faw");	
}

function shw(b) {
	(b)? obj.className = 'show':obj.className = '';	
}

/*javascript for Bubble Tooltips by Alessandro Fulciniti
- http://pro.html.it - http://web-graphics.com */

function enableTooltips(id){
var links,i,h;
if(!document.getElementById || !document.getElementsByTagName) return;
h=document.createElement("span");
h.id="btc";
h.setAttribute("id","btc");
h.style.position="absolute";
document.getElementsByTagName("body")[0].appendChild(h);
if(id==null) links=document.getElementsByTagName("a");
else links=document.getElementById(id).getElementsByTagName("a");
for(i=0;i<links.length;i++){
    Prepare(links[i]);
    }
}

function Prepare(el){
var tooltip,t,b,s,l;
t=el.getAttribute("title");
if(t==null || t.length==0) t="link:";
el.removeAttribute("title");
tooltip=CreateEl("span","tooltip");
s=CreateEl("span","top");
s.appendChild(document.createTextNode(t));
tooltip.appendChild(s);
b=CreateEl("b","bottom");
l=el.getAttribute("href");
if(l.length>30) l=l.substr(0,27)+"...";
b.appendChild(document.createTextNode(l));
tooltip.appendChild(b);
setOpacity(tooltip);
el.tooltip=tooltip;
el.onmouseover=showTooltip;
el.onmouseout=hideTooltip;
el.onmousemove=Locate;
}

function showTooltip(e){
document.getElementById("btc").appendChild(this.tooltip);
Locate(e);
}

function hideTooltip(e){
var d=document.getElementById("btc");
if(d.childNodes.length>0) d.removeChild(d.firstChild);
}

function setOpacity(el){
el.style.filter="alpha(opacity:99)";
el.style.KHTMLOpacity="0.99";
el.style.MozOpacity="0.99";
el.style.opacity="0.99";
}

function CreateEl(t,c){
var x=document.createElement(t);
x.className=c;
x.style.display="block";
return(x);
}

function Locate(e){
var posx=0,posy=0;
if(e==null) e=window.event;
if(e.pageX || e.pageY){
    posx=e.pageX; posy=e.pageY;
    }
else if(e.clientX || e.clientY){
    if(document.documentElement.scrollTop){
        posx=e.clientX+document.documentElement.scrollLeft;
        posy=e.clientY+document.documentElement.scrollTop;
        }
    else{
        posx=e.clientX+document.body.scrollLeft;
        posy=e.clientY+document.body.scrollTop;
        }
    }
document.getElementById("btc").style.top=(posy+10)+"px";
document.getElementById("btc").style.left=(posx+0)+"px";
}

function setCookie(c_name, value, expiredays)
{
    var exdate=new Date();
    exdate.setDate(exdate.getDate() + expiredays);
    document.cookie = c_name + "=" + encodeURI(value) + ((expiredays === null) ? "" : ";expires=" + exdate.toGMTString());
}

function getCookie(c_name)
{
    var c_start = -1;
    var c_end = -1;

    if (document.cookie.length > 0)
    {
        c_start = document.cookie.indexOf(c_name);

        if (c_start != -1)
        {
            c_start = c_start + c_name.length + 1;
            c_end = document.cookie.indexOf(";", c_start);

            if (c_end == -1)
			{
                c_end = document.cookie.length;
			}

            return decodeURI(document.cookie.substring(c_start, c_end));
        }
    }
    return null;
}

function resetCookie()
{
	var cookie = document.cookie;
	var cookies = cookie.split(';');
	for (var i = 0; i < cookies.length; i++)
	{
		var cookieName = cookies[i].split('=', 1);
		for (var j = 0; j < cookieName.length; j++)
		{
			setCookie(cookieName[j], null, 0);
		}
	}
	
	window.location.reload();
}

function setActiveStyleSheet(title)
{
	if (title === undefined)
	{
		title = getCookie('style');
		if (title === null)
		{
			title = '';
		}
	}
	
	var i, a;

	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;
				setCookie('style', title, 365);
			}
		}
	}
}

function setDefaultPhoto(photo, targetDiv)
{
	if (photo === undefined || targetDiv === undefined)
	{
		photo = getCookie('defaultPhoto');
		if (photo === null)
		{
			return;
		}
		else
		{
			targetDiv = getCookie('targetDiv');
			if (targetDiv === null)
			{
				targetDiv = "selected-photo";
			}
		}
	}
	
	$("#main-photo").hide();

	var html = "<img src='images/photos/" + photo + "'>";
	$("#" + targetDiv).html(html);
	$("#" + targetDiv).show();
	
	setCookie('defaultPhoto', photo, 365);
	setCookie('targetDiv', targetDiv, 365);
}

function stripURL(url)
{
	var expression = /(\w{4}\:\/\/((\w|\d)*\.)*(\w)*(\:)*(\d)*(\/){1}){0,1}((\w)*\/)*/;
	var clean = url.replace(expression, '');
	return clean;
}

function writeFragment(dirName, bodyName, linksName)
{
	$.ajax({
		url: dirName,
		cache: false,
		success: function(html)
		{
			$("#parking").append(html);
			
			href = getCookie(bodyName);
			
			if (href !== null && href !== undefined)
			{
				$("#" + bodyName).load(dirName + "/" + stripURL(href));
			}
			else
			{
				href = $("#parking a").filter(":contains('feature')").filter(":first").attr('href');
				$("#" + bodyName).load(dirName + "/" + stripURL(href));
		 	}
		
			$("#parking a").filter(":contains('feature')").each(function(i)
			{
				var href = stripURL($(this).attr('href'));
				var link = $('<a />');
				link.attr("href", "");
				link.click(function() {
					$("#" + bodyName).load(dirName + "/" + href);
					$("#" + linksName + " .on").removeClass("on");
					$(this).addClass("on");
					setCookie(bodyName, href, 365);
					return false;
				});
				link.text(i + 1);
				link.attr("name", href);
				
				link.appendTo($("#" + linksName));
			});
			
			$("#" + linksName + " a").wrap("<li />");
			$("#" + linksName + " li").wrapAll("<ul />");
			
			$("#" + linksName + " a").each(function(j)
			{
				if ($(this).attr("name") == href)
				{
					$(this).addClass("on");
				}
			});
			
			$("#parking").empty();
		}
	});
}

//** Ajax Tabs Content script v2.0- © Dynamic Drive DHTML code library (http://www.dynamicdrive.com)
//** Updated Oct 21st, 07 to version 2.0. Contains numerous improvements
//** Updated Feb 18th, 08 to version 2.1: Adds a public "tabinstance.cycleit(dir)" method to cycle forward or backward between tabs dynamically. Only .js file changed from v2.0.
//** Updated April 8th, 08 to version 2.2:
//   -Adds support for expanding a tab using a URL parameter (ie: http://mysite.com/tabcontent.htm?tabinterfaceid=0) 
//   -Modified Ajax routine so testing the script out locally in IE7 now works 

var ddajaxtabssettings={}
ddajaxtabssettings.bustcachevar=1  //bust potential caching of external pages after initial request? (1=yes, 0=no)
ddajaxtabssettings.loadstatustext="Loading..." 


////NO NEED TO EDIT BELOW////////////////////////

function ddajaxtabs(tabinterfaceid, contentdivid){
	this.tabinterfaceid=tabinterfaceid //ID of Tab Menu main container
	this.tabs=document.getElementById(tabinterfaceid).getElementsByTagName("a") //Get all tab links within container
	this.enabletabpersistence=true
	this.hottabspositions=[] //Array to store position of tabs that have a "rel" attr defined, relative to all tab links, within container
	this.currentTabIndex=0 //Index of currently selected hot tab (tab with sub content) within hottabspositions[] array
	this.contentdivid=contentdivid
	this.defaultHTML=""
	this.defaultIframe='<iframe src="about:blank" marginwidth="0" marginheight="0" frameborder="0" vspace="0" hspace="0" class="tabcontentiframe" style="width:100%; height:auto; min-height: 100px"></iframe>'
	this.defaultIframe=this.defaultIframe.replace(/<iframe/i, '<iframe name="'+"_ddajaxtabsiframe-"+contentdivid+'" ')
this.revcontentids=[] //Array to store ids of arbitrary contents to expand/contact as well ("rev" attr values)
	this.selectedClassTarget="link" //keyword to indicate which target element to assign "selected" CSS class ("linkparent" or "link")
}

ddajaxtabs.connect=function(pageurl, tabinstance){
	var page_request = false
	var bustcacheparameter=""
	if (window.ActiveXObject){ //Test for support for ActiveXObject in IE first (as XMLHttpRequest in IE7 is broken)
		try {
		page_request = new ActiveXObject("Msxml2.XMLHTTP")
		} 
		catch (e){
			try{
			page_request = new ActiveXObject("Microsoft.XMLHTTP")
			}
			catch (e){}
		}
	}
	else if (window.XMLHttpRequest) // if Mozilla, Safari etc
		page_request = new XMLHttpRequest()
	else
		return false
	var ajaxfriendlyurl=pageurl.replace(/^http:\/\/[^\/]+\//i, "http://"+window.location.hostname+"/") 
	page_request.onreadystatechange=function(){ddajaxtabs.loadpage(page_request, pageurl, tabinstance)}
	if (ddajaxtabssettings.bustcachevar) //if bust caching of external page
		bustcacheparameter=(ajaxfriendlyurl.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime()
	page_request.open('GET', ajaxfriendlyurl+bustcacheparameter, true)
	page_request.send(null)
}

ddajaxtabs.loadpage=function(page_request, pageurl, tabinstance){
	var divId=tabinstance.contentdivid
	document.getElementById(divId).innerHTML=ddajaxtabssettings.loadstatustext //Display "fetching page message"
	if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1)){
		document.getElementById(divId).innerHTML=page_request.responseText
		ddajaxtabs.ajaxpageloadaction(pageurl, tabinstance)
	}
}

ddajaxtabs.ajaxpageloadaction=function(pageurl, tabinstance){
	tabinstance.onajaxpageload(pageurl) //call user customized onajaxpageload() function when an ajax page is fetched/ loaded
}

ddajaxtabs.getCookie=function(Name){ 
	var re=new RegExp(Name+"=[^;]+", "i"); //construct RE to search for target name/value pair
	return ""
}

ddajaxtabs.setCookie=function(name, value){
	document.cookie = name+"="+value+";path=/" //cookie value is domain wide (path=/)
}

ddajaxtabs.prototype={

	expandit:function(tabid_or_position){ //PUBLIC function to select a tab either by its ID or position(int) within its peers
		this.cancelautorun() //stop auto cycling of tabs (if running)
		var tabref=""
		try{
			if (typeof tabid_or_position=="string" && document.getElementById(tabid_or_position).getAttribute("rel")) //if specified tab contains "rel" attr
				tabref=document.getElementById(tabid_or_position)
			else if (parseInt(tabid_or_position)!=NaN && this.tabs[tabid_or_position].getAttribute("rel")) //if specified tab contains "rel" attr
				tabref=this.tabs[tabid_or_position]
		}
		catch(err){alert("Invalid Tab ID or position entered!")}
		if (tabref!="") //if a valid tab is found based on function parameter
			this.expandtab(tabref) //expand this tab
	},

	cycleit:function(dir, autorun){ //PUBLIC function to move foward or backwards through each hot tab (tabinstance.cycleit('foward/back') )
		if (dir=="next"){
			var currentTabIndex=(this.currentTabIndex<this.hottabspositions.length-1)? this.currentTabIndex+1 : 0
		}
		else if (dir=="prev"){
			var currentTabIndex=(this.currentTabIndex>0)? this.currentTabIndex-1 : this.hottabspositions.length-1
		}
		if (typeof autorun=="undefined") //if cycleit() is being called by user, versus autorun() function
			this.cancelautorun() //stop auto cycling of tabs (if running)
		this.expandtab(this.tabs[this.hottabspositions[currentTabIndex]])
	},

	setpersist:function(bool){ //PUBLIC function to toggle persistence feature
			this.enabletabpersistence=bool
	},

	loadajaxpage:function(pageurl){ //PUBLIC function to fetch a page via Ajax and display it within the Tab Content instance's container
		ddajaxtabs.connect(pageurl, this)
	},

	loadiframepage:function(pageurl){ //PUBLIC function to fetch a page and load it into the IFRAME of the Tab Content instance's container
		this.iframedisplay(pageurl, this.contentdivid)
	},

	setselectedClassTarget:function(objstr){ //PUBLIC function to set which target element to assign "selected" CSS class ("linkparent" or "link")
		this.selectedClassTarget=objstr || "link"
	},

	getselectedClassTarget:function(tabref){ //Returns target element to assign "selected" CSS class to
		return (this.selectedClassTarget==("linkparent".toLowerCase()))? tabref.parentNode : tabref
	},

	urlparamselect:function(tabinterfaceid){
		var result=window.location.search.match(new RegExp(tabinterfaceid+"=(\\d+)", "i")) //check for "?tabinterfaceid=2" in URL
		return (result==null)? null : parseInt(RegExp.$1) //returns null or index, where index (int) is the selected tab's index
	},

	onajaxpageload:function(pageurl){ //PUBLIC Event handler that can invoke custom code whenever an Ajax page has been fetched and displayed
		//do nothing by default
	},

	expandtab:function(tabref){
		var relattrvalue=tabref.getAttribute("rel")
		//Get "rev" attr as a string of IDs in the format ",john,george,trey,etc," to easy searching through
		var associatedrevids=(tabref.getAttribute("rev"))? ","+tabref.getAttribute("rev").replace(/\s+/, "")+"," : ""
		if (relattrvalue=="#default")
			document.getElementById(this.contentdivid).innerHTML=this.defaultHTML
		else if (relattrvalue=="#iframe")
			this.iframedisplay(tabref.getAttribute("href"), this.contentdivid)
		else
			ddajaxtabs.connect(tabref.getAttribute("href"), this)
		this.expandrevcontent(associatedrevids)
		for (var i=0; i<this.tabs.length; i++){ //Loop through all tabs, and assign only the selected tab the CSS class "selected"
			this.getselectedClassTarget(this.tabs[i]).className=(this.tabs[i].getAttribute("href")==tabref.getAttribute("href"))? "selected" : ""
		}
		if (this.enabletabpersistence) //if persistence enabled, save selected tab position(int) relative to its peers
			ddajaxtabs.setCookie(this.tabinterfaceid, tabref.tabposition)
		this.setcurrenttabindex(tabref.tabposition) //remember position of selected tab within hottabspositions[] array
	},

	iframedisplay:function(pageurl, contentdivid){
		if (typeof window.frames["_ddajaxtabsiframe-"+contentdivid]!="undefined"){
			try{delete window.frames["_ddajaxtabsiframe-"+contentdivid]} //delete iframe within Tab content container if it exists (due to bug in Firefox)
			catch(err){}
		}
		document.getElementById(contentdivid).innerHTML=this.defaultIframe
		window.frames["_ddajaxtabsiframe-"+contentdivid].location.replace(pageurl) //load desired page into iframe
	},


	expandrevcontent:function(associatedrevids){
		var allrevids=this.revcontentids
		for (var i=0; i<allrevids.length; i++){ //Loop through rev attributes for all tabs in this tab interface
			//if any values stored within associatedrevids matches one within allrevids, expand that DIV, otherwise, contract it
			document.getElementById(allrevids[i]).style.display=(associatedrevids.indexOf(","+allrevids[i]+",")!=-1)? "block" : "none"
		}
	},

	setcurrenttabindex:function(tabposition){ //store current position of tab (within hottabspositions[] array)
		for (var i=0; i<this.hottabspositions.length; i++){
			if (tabposition==this.hottabspositions[i]){
				this.currentTabIndex=i
				break
			}
		}
	},

	autorun:function(){ //function to auto cycle through and select tabs based on a set interval
		this.cycleit('next', true)
	},

	cancelautorun:function(){
		if (typeof this.autoruntimer!="undefined")
			clearInterval(this.autoruntimer)
	},

	init:function(automodeperiod){
		var persistedtab=ddajaxtabs.getCookie(this.tabinterfaceid) //get position of persisted tab (applicable if persistence is enabled)
		var selectedtab=-1 //Currently selected tab index (-1 meaning none)
		var selectedtabfromurl=this.urlparamselect(this.tabinterfaceid) //returns null or index from: tabcontent.htm?tabinterfaceid=index
		this.automodeperiod=automodeperiod || 0
		this.defaultHTML=document.getElementById(this.contentdivid).innerHTML
		for (var i=0; i<this.tabs.length; i++){
			this.tabs[i].tabposition=i //remember position of tab relative to its peers
			if (this.tabs[i].getAttribute("rel")){
				var tabinstance=this
				this.hottabspositions[this.hottabspositions.length]=i //store position of "hot" tab ("rel" attr defined) relative to its peers
				this.tabs[i].onclick=function(){
					tabinstance.expandtab(this)
					tabinstance.cancelautorun() //stop auto cycling of tabs (if running)
					return false
				}
				if (this.tabs[i].getAttribute("rev")){ //if "rev" attr defined, store each value within "rev" as an array element
					this.revcontentids=this.revcontentids.concat(this.tabs[i].getAttribute("rev").split(/\s*,\s*/))
				}
				if (selectedtabfromurl==i || this.enabletabpersistence && selectedtab==-1 && parseInt(persistedtab)==i || !this.enabletabpersistence && selectedtab==-1 && this.getselectedClassTarget(this.tabs[i]).className=="selected"){
					selectedtab=i //Selected tab index, if found
				}
			}
		} //END for loop
		if (selectedtab!=-1) //if a valid default selected tab index is found
			this.expandtab(this.tabs[selectedtab]) //expand selected tab (either from URL parameter, persistent feature, or class="selected" class)
		else //if no valid default selected index found
			this.expandtab(this.tabs[this.hottabspositions[0]]) //Just select first tab that contains a "rel" attr
		if (parseInt(this.automodeperiod)>500 && this.hottabspositions.length>1){
			this.autoruntimer=setInterval(function(){tabinstance.autorun()}, this.automodeperiod)
		}
	} //END int() function

} //END Prototype assignment