/* ------------------------------- */
/* FUNCTIONS for OVERRIDING STYLES */
/* ------------------------------- */

var useragent = navigator.userAgent.toLowerCase();

if(useragent.indexOf('safari')!=-1) {
 document.write('<link rel="stylesheet" type="text/css" href="/includes/trinity-safari.css" />');
}
else if(useragent.indexOf('msie 6')!=-1 || useragent.indexOf('msie 5')!=-1) {
 document.write('<link rel="stylesheet" type="text/css" href="/includes/trinity-ie.css" />');
}
else if(useragent.indexOf('msie 7')!=-1) {
 document.write('<link rel="stylesheet" type="text/css" href="/includes/trinity-ie7.css" />');
}

/* ------------- */
/* BROWSER SNIFF */
/* ------------- */

function checkBrowser(){
	this.ver=navigator.appVersion
	this.dom=document.getElementById?1:0
	this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom)?1:0;
	this.ie4=(document.all && !this.dom)?1:0;
	this.ns5=(this.dom && parseInt(this.ver) >= 5) ?1:0;
	this.ns4=(document.layers && !this.dom)?1:0;
	this.bw=(this.ie5 || this.ie4 || this.ns4 || this.ns5)
	return this
}

bw=new checkBrowser()

/* ----------------------------- */
/* ONLOAD (NOT INCLUDING IMAGES) */
/* ----------------------------- */

searchdom = 0;
function checkload() {
 if(document.getElementById('footer-area')) {
  clearTimeout(searchdom);
  olqueue();
 }
 else {
  searchdom = setTimeout("checkload()",100); 
 }
}
checkload();

function olqueue() {
 initMenuEvents();
}


/* ----------------------------- */
/* FUNCTIONS for MAIN NAVIGATION */
/* ----------------------------- */

openmenu = 0;
killmenu = 0;
topmenu = 0;
function om() {
 sm();
 cm();
 m = parseInt(this.id.charAt(1));
 if(m) document.getElementById('navMenu' + m).style.display = 'block';
 this.className = 'navItemHover';
 if(m>7 && document.all && document.getElementById('explore-menu')) {
  document.getElementById('explore-menu').style.visibility = 'hidden';
 }
 topmenu = this;
 openmenu = m;
}
function km() {
 killmenu = setTimeout('cm()',200);
}
function sm() {
 if(killmenu) clearTimeout(killmenu);
 killmenu = 0;
}
function cm() {
 if(openmenu) {
  document.getElementById('navMenu' + openmenu).style.display = 'none';
  if(document.getElementById('explore-menu'))
   document.getElementById('explore-menu').style.visibility = 'visible';
 }
 if(topmenu) topmenu.className = 'navItem';
 topmenu = 0;
 openmenu = 0;
}

function newEvent(el,ev,fn) {
 if (el.addEventListener) el.addEventListener(ev,fn,false);
 else el['on' + ev] = fn;
}

function initMenuEvents() {
 var navmenus = document.getElementsByTagName('div');
 for(i=0; i<navmenus.length; i++) {
  if(navmenus[i].className == 'navMenus') {
   newEvent(navmenus[i],'mouseover',sm);
   newEvent(navmenus[i],'mouseout',km);
  }
 }
 var navitems = document.getElementsByTagName('a');
 for(j=0; j<navitems.length; j++) {
  if(navitems[j].className == 'navItem') {
   newEvent(navitems[j],'mouseover',om);
   newEvent(navitems[j],'mouseout',km);
  }
 }
}

/* -------------------------------------------- */
/* FUNCTIONS for RETRIEVING and SETTING COOKIES */
/* -------------------------------------------- */

function setCookie(name, value, expires, path, domain, secure) {
	var curCookie = name + "=" + escape(value) +
	((expires) ? "; expires=" + expires.toGMTString() : "") +
	((path) ? "; path=" + path : "") +
	((domain) ? "; domain=" + domain : "") +
	((secure) ? "; secure" : "");
	document.cookie = curCookie;
}

function getCookie(name) {
	var dc = document.cookie;
	var prefix = name + "=";
	var begin = dc.indexOf("; " + prefix);
	if (begin == -1) {
		begin = dc.indexOf(prefix);
		if (begin != 0) return null;
	} else
		begin += 2;
	var end = document.cookie.indexOf(";", begin);
	if (end == -1)
		end = dc.length;
	return unescape(dc.substring(begin + prefix.length, end));
}

function deleteCookie(name, path, domain) {
	if (getCookie(name)) {
		document.cookie = name + "=" +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		"; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
}


/* ------------------------------ */
/* FUNCTIONS for FONT SIZE CHANGE */
/* ------------------------------ */

function modRule(x){
	if (!document.styleSheets) return;
	var mycss = new Array();
	if (document.styleSheets[0].cssRules)
		mycss = document.styleSheets[0].cssRules;
	else
		mycss = document.styleSheets[0].rules;
		mycss[0].style.fontSize = x + 'px';
}

getsize = getCookie("size")||10;
size = parseInt(getsize);


function changeTextSize() {
 size = (size < 13) ? (size+1) : 10;
 modRule(size);
 setCookie("size",size,"","/");
}

if(getCookie("size")) modRule(getCookie("size"));


/* -------------------------- */
/* FUNCTION for NO-SPAM EMAIL */
/* -------------------------- */

function email(a,b,c){
	if(!b) b="trinitywallstreet.org";
	if(c) c="?subject="+c; else c="";
	document.location="mailto:"+a+"@"+b+c;
}


/* ------------------------- */
/* FUNCTIONS for NEW WINDOWS */
/* -------------------------- */

function openWindow(url, name, params) {
 if(params == undefined) params = 'width=520,height=500,scrollbars=yes,resizable=yes';
 popupWin = window.open(url, name, params);
 window.popupWin.focus();
}

function centerWindow(u,n,w,h,p) {
	if(!p) p="scrollbars=no,menubars=no,resizeable=no,toolbar=no,directories=no,status=no";
	wl=(screen.width-w)/2;
	wt=(screen.height-h)/2;
	pr="width="+w+",height="+h+",left="+wl+",top="+wt+","+p;
	win=window.open(u,n,pr);
	if(parseInt(navigator.appVersion) >= 4) win.window.focus();
}

function launchWebcast(u) {
	centerWindow(u,"webcast","615","520");
}

/* ------------------------- */
/* FUNCTIONS for SEARCH WIDGET */
/* -------------------------- */

function changeSelection(i,v,m,f,g){
	eval("document."+f+".value='"+v+"'");
	//hide(m);
}

function ddSet(ddId, tgt) {
	if((elem = document.getElementById(ddId)) != undefined) {
		max = elem.options.length;
		for(i=0;i<max;++i) 
			if(elem.options[i].value == tgt)
				elem.selectedIndex = i;
	}
	return;
}


/* ------------------------------- */
/* FUNCTIONS for DISPLAYING LAYERS */
/* ------------------------------- */
function showHide(div,nest){
	obj=bw.dom?document.getElementById(div).style:bw.ie4?document.all[div].style:bw.ns4?nest?document[nest].document[div]:document[div]:0;
	if(obj.visibility=='visible' || obj.visibility=='show') obj.visibility='hidden'
	else obj.visibility='visible'
}

function show(div,nest){
	obj=bw.dom?document.getElementById(div).style:bw.ie4?document.all[div].style:bw.ns4?nest?document[nest].document[div]:document[div]:0;
	obj.visibility='visible'
}

function hide(div,nest){
	obj=bw.dom?document.getElementById(div).style:bw.ie4?document.all[div].style:bw.ns4?nest?document[nest].document[div]:document[div]:0;
	obj.visibility='hidden'
}


function launchSlides(ss){
		if(ss=="treasures") centerWindow('/photos/images/slideshows/treasures/treasures.html','slideshow',600,350);
		else if(ss=="tour") centerWindow('/photos/images/slideshows/tour/intro.html','slideshow',700,537);
		else if(ss=="brown") centerWindow('/photos/images/slideshows/brown/popup.html','slideshow',560,430);
		else if(ss=="stpauls") centerWindow('/photos/images/slideshows/stpaul/index.html','slideshow',600,490);
  	else centerWindow('/photos/images/slideshows/'+ss+'/'+ss+'.html','slideshow',685,456);
}