// JavaScript Document

// Preload Backgrounds

function preLoad() {

	if (document.images)
	{
	pic1= new Image(15,30); 
	pic1.src="../_images/btn/btn_on.gif";
	}
	
}

// rollover effects

function initImgRollovers() {
	if (!document.getElementById) return
	
	var aPreLoad = new Array();
	var sTempSrc;
	var aImages = document.getElementsByTagName('img');

	for (var i = 0; i < aImages.length; i++) {		
		if (aImages[i].className == 'imgover') {
			var src = aImages[i].getAttribute('src');
			var ftype = src.substring(src.lastIndexOf('.'), src.length);
			var hsrc = src.replace(ftype, '_o'+ftype);
			
			hsrc = hsrc.replace('_a_o.','_o.'); // account for active section tabs
			
			aImages[i].setAttribute('hsrc', hsrc);			
			aPreLoad[i] = new Image();
			aPreLoad[i].src = hsrc;
			
			aImages[i].onmouseover = function() {
				sTempSrc = this.getAttribute('src');
				this.setAttribute('src', this.getAttribute('hsrc'));
			}	
			
			aImages[i].onmouseout = function() {
				if (!sTempSrc) sTempSrc = this.getAttribute('src').replace('_o'+ftype, ftype);
				this.setAttribute('src', sTempSrc);
			}
		}
	}
}

function imgOver(obj,clsname) {
	var src = obj.getAttribute('src');
	var ftype = src.substring(src.lastIndexOf('.'), src.length);
	var hsrc = src.replace(ftype, '_o'+ftype);
	obj.setAttribute('src', hsrc);
	Element.addClassName(obj,clsname);
	obj.onmouseout = function() {obj.setAttribute('src', src);Element.removeClassName(obj,clsname);}
}

function hilite(obj,clsname) {
	Element.addClassName(obj,clsname);
	obj.onmouseout = function() {Element.removeClassName(obj,clsname);}
	//obj.className = clsname;
	//obj.onmouseout = function() {obj.className = '';}
}

function hideSelects(navmenu) {
	var IE6 = false /*@cc_on || @_jscript_version < 5.7 @*/;
	if(IE6) {
		var navbar = document.getElementById(navmenu);
		var selects = document.getElementsByTagName("SELECT");
		navbar.onmouseover=function() {
			for (var n=0; n<selects.length; n++) {
				selects[n].className+=" hidden";
			}
		}
		navbar.onmouseout=function() {
			for (var n=0; n<selects.length; n++) {
				selects[n].className = selects[n].className.replace(new RegExp(" hidden\\b"), "");
			}
		}
	}
}

// Form button highliter

function cls(obj,cls)
{
	obj.className=cls;
}

// Page Re-directs
function navTo(pageid)
{
	window.top.document.location=pageid; return false;
}

function navToFrame(pageid)
{
	window.location=pageid; return false;
}

function navToBlank(pageid)
{
	window.open(pageid,"NewWin000"); return false;
}


// Opens window and builds page for large view

var winStatus = 0;

function showPic(dir,imgSrc,picWidth,picHeight,caption) {

	var pos_right = 13;
	var pos_btm = 13;
	// var caption = 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Integer odio volutpat.';
	
	if (winStatus == 1) {		
		newWindow.close();
	}
	
	winWidth = picWidth + 20;
	winHeight = picHeight + 20;
	
	if(caption){
		pos_btm = 24;
		winHeight = winHeight + 11;
	} else {
		caption = "";
	}

	var x = (screen.width) ? (screen.width-winWidth)/2 : 0;
	var y = (screen.height) ? (screen.height-winHeight)/2 : 0;	

	tmpStr = 'location=no,menubar=no,directories=no,toolbar=no,status=no,personalbar=no,titlebar=no,scrollbars=no,dependent=yes,resizable=no,width='+winWidth+',height='+winHeight+',top='+y+',left='+x;
	
	newWindow=window.open('_images/spacer.gif','newWin',tmpStr);
	newWindow.document.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html><head><title>Large View<\/title><style type="text/css" media="screen">@import url("_css/fbcas_pop.css");<\/style><\/head><body style="background-image:url('+dir+'/'+imgSrc+'.jpg); background-repeat:no-repeat; background-position:10px 10px;"><div id="caption" style="width:'+picWidth+'px;">'+caption+'</div><input type="button" name="close" value="Close" title="Close this window" class="btn" style="right:'+pos_right+'px; bottom:'+pos_btm+'px;" onclick="window.close();"><\/body><\/html>');
	
	winStatus = 1;
	
	newWindow.document.close();
	newWindow.focus();
}


// POP-UP DIV HANDLERS

function showPop(id) {
	var popScrn = top.document.getElementById('popScrn');
	var popFrame = top.document.getElementById('popFrame');
	var popDiv = top.document.getElementById(id);
	
	var winWidth = top.document.documentElement.clientWidth;
	var winHeight = top.document.documentElement.clientHeight;
	var scrollTop = top.document.documentElement.scrollTop;
	var scrollHeight = top.document.documentElement.scrollHeight;
	
	popFrame.style.display = 'block';
	popFrame.style.height = scrollHeight+'px';
	
	popScrn.style.display = 'block';
	if (winHeight <= scrollHeight) {
		popScrn.style.height = scrollHeight+'px';
	} else {
		popScrn.style.height = winHeight+'px';
	}
	
	popDiv.style.display = 'block';
	
	xPos = (winWidth - popDiv.offsetWidth)/2;
	yPos = (winHeight - popDiv.offsetHeight)/2 + scrollTop;

	popDiv.style.left = xPos + 'px';
	popDiv.style.top = yPos + 'px';
}

function showPhoto(id,path,caption) {
	var popScrn = top.document.getElementById('popScrn');
	var popFrame = top.document.getElementById('popFrame');
	var popDiv = top.document.getElementById(id);

	var popCaption = top.document.getElementById('popCaption');
	var imgLarge = top.document.getElementById('largeImg');
	
	var winWidth = top.document.documentElement.clientWidth;
	var winHeight = top.document.documentElement.clientHeight;
	var scrollTop = top.document.documentElement.scrollTop;
	var scrollHeight = top.document.documentElement.scrollHeight;
	
	popFrame.style.display = 'block';
	popFrame.style.height = scrollHeight+'px';
	
	popScrn.style.display = 'block';
	if (winHeight <= scrollHeight) {
		popScrn.style.height = scrollHeight+'px';
	} else {
		popScrn.style.height = winHeight+'px';
	}
	
	imgLarge.src = path;
	popDiv.style.display = 'block';
	popCaption.innerHTML = caption;
	
	xPos = (winWidth - popDiv.offsetWidth)/2;
	yPos = (winHeight - popDiv.offsetHeight)/2 + scrollTop;

	popDiv.style.left = xPos + 'px';
	popDiv.style.top = yPos + 'px';
}

function hidePop(id) {
	if (!id) {
		id = 'popDiv';
	}
	top.document.getElementById('largeImg').src = '/_images/placeholder.gif';
	top.document.getElementById('popFrame').style.display='none';
	top.document.getElementById('popScrn').style.display='none';
	top.document.getElementById(id).style.display = 'none';
}


//this fix circumvents the "click to view" hotfix implements for Windows XP and Windows 2003 server users with IE6
function flash_write(file, width, height) {
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="'+width+'" height="'+height+'" id="movie" ><param name="movie" value="'+file+'" /><param name="wmode" value="transparent" /><param name="menu" value="false" /><param name="bgcolor" value="#FFFFFF" /><param name="wmode" value="transparent" /><param name="menu" value="false" /><embed width="'+width+'" height="'+height+'" align="middle" wmode="transparent" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" bgcolor="#ffffff" quality="high" src="'+file+'"/></object>');
}


// TREE TOGGLER

function doBranch(node) {

	if(node.parentNode.className == "closed") {
		node.parentNode.className = "open";
	}
	
	else if (node.parentNode.className == "open") {
		node.parentNode.className = "closed";
	}
}

// IMAGE SOURCE SWAPPER

function swapSrc(largePic,smallPic,caption) {
	var thumb = document.getElementById(smallPic);
	var src = thumb.getAttribute('src');
	var fileName = src.substring(src.lastIndexOf('/'), src.length);
	var path = '/media/gallery'+fileName;
	document.getElementById(largePic).src = path;
	document.getElementById('caption').innerHTML = caption;
}

// DIV SWAPPER

function showDIV(divName){
	document.getElementById(divName).style.display = 'block';
	document.getElementById(divName).style.visibility = 'visible';
}

function hideDIV(divName){
	document.getElementById(divName).style.visibility = 'hidden';
	document.getElementById(divName).style.display = 'none';
}

// GOOGLE MAP FUNCTIONS

function createMarker(point) {
	var icon = new GIcon();
	icon.image = "http://www.firstaltamonte.org/_images/map_icon.png";
	icon.shadow = "http://www.firstaltamonte.org/_images/map_icon_shadow.png";
	icon.iconSize = new GSize(18, 24);
	icon.shadowSize = new GSize(32, 24);
	icon.iconAnchor = new GPoint(9, 20);
	icon.infoWindowAnchor = new GPoint(9, 1);
	var info = "<b>First Baptist Church of Altamonte Springs</b><br />900 North Street<br />Longwood, FL 32750<br />(407) 339-8961";
	var marker = new GMarker(point,icon);
	GEvent.addListener(marker, "click", function() {
	marker.openInfoWindowHtml(info);
	});
	return marker;
}

function loadmap() {
	if (GBrowserIsCompatible()) {
	// Create our "tiny" marker icon
	var map = new GMap2(document.getElementById("googlemap"));
	var point = new GLatLng(28.6836, -81.3568);
	map.setCenter(point, 15);
	//map.setCenter(new GLatLng(28.6840, -81.3516), 15);
	map.addControl(new GSmallMapControl());
	map.addOverlay(createMarker(point));
	}
}