var sw_enablepersist="off" //Enable saving state of content structure using session cookies? (on/off)
var sw_memoryduration="7" //persistence in # of days

var sw_contractsymbol='imagens/bullet_lar.jpg' //Path to image to represent contract state.
var sw_expandsymbol='imagens/bullet_lar.jpg' //Path to image to represent expand state.

/////No need to edit beyond here //////////////////////////

function sw_getElementbyClass(rootobj, classname){
	var sw_temparray=new Array()
	var sw_inc=0
	var sw_rootlength=rootobj.length
	for (i=0; i<sw_rootlength; i++){
		if (rootobj[i].className==classname)
			sw_temparray[sw_inc++]=rootobj[i]
	}
	return sw_temparray
}

function sw_sweeptoggle(ec){
	var sw_inc=0
	while (ccollect[sw_inc]){
		ccollect[sw_inc].style.display=(ec=="contract")? "none" : ""
		sw_inc++
	}
	sw_revivestatus()
}


function sw_expandcontent(curobj, cid){
	if (ccollect.length>0){
		document.getElementById(cid).style.display=(document.getElementById(cid).style.display!="none")? "none" : ""
		curobj.src=(document.getElementById(cid).style.display=="none")? sw_expandsymbol : sw_contractsymbol
	}
}

function sw_revivecontent(){
	selectedItem=sw_getselectedItem()
	selectedComponents=selectedItem.split("|")
	for (i=0; i<selectedComponents.length-1; i++)
		document.getElementById(selectedComponents[i]).style.display="none"
}

function sw_revivestatus(){
	var sw_inc=0
	while (statecollect[sw_inc]){
		if (ccollect[sw_inc].style.display=="none")
			statecollect[sw_inc].src=sw_expandsymbol
		else
			statecollect[sw_inc].src=sw_contractsymbol
			sw_inc++
	}
}

function sw_get_cookie(Name) { 
	var sw_search = Name + "="
	var sw_returnvalue = "";
	if (document.cookie.length > 0) {
		offset = document.cookie.indexOf(sw_search)
		if (offset != -1) { 
			offset += sw_search.length
			end = document.cookie.indexOf(";", offset);
			if (end == -1) end = document.cookie.length;
				sw_returnvalue=unescape(document.cookie.substring(offset, end))
		}
	}
	return sw_returnvalue;
}

function sw_getselectedItem(){
	if (sw_get_cookie(window.location.pathname) != ""){
		selectedItem=sw_get_cookie(window.location.pathname)
		return selectedItem
	}
	else
		return ""
}

function sw_saveswitchstate(){
	var sw_inc=0, selectedItem=""
	while (ccollect[sw_inc]){
		if (ccollect[sw_inc].style.display=="none")
		selectedItem+=ccollect[sw_inc].id+"|"
		sw_inc++
	}
	if (sw_get_cookie(window.location.pathname)!=selectedItem){ //only update cookie if current states differ from cookie's
		var sw_expireDate = new Date()
		sw_expireDate.setDate(sw_expireDate.getDate()+parseInt(sw_memoryduration))
		document.cookie = window.location.pathname+"="+selectedItem+";path=/;expires=" + sw_expireDate.toGMTString()
	}
}

function do_onload(){
	uniqueidn=window.location.pathname+"firsttimeload"
	var sw_alltags=document.all? document.all : document.getElementsByTagName("*")
	ccollect=sw_getElementbyClass(sw_alltags, "switchcontent")
	statecollect=sw_getElementbyClass(sw_alltags, "showstate")
	if (sw_enablepersist=="on" && sw_get_cookie(window.location.pathname)!="" && ccollect.length>0)
		sw_revivecontent()
	if (ccollect.length>0 && statecollect.length>0)
		sw_revivestatus()
//	if (ccollect.length>0 && statecollect.length>0)
//		sw_sweeptoggle('contract')
}

if (window.addEventListener)
	window.addEventListener("load", do_onload, false)
else if (window.attachEvent)
	window.attachEvent("onload", do_onload)
else if (document.getElementById)
	window.onload=do_onload

if (sw_enablepersist=="on" && document.getElementById)
	window.onunload=sw_saveswitchstate

