/* DomReady Event fires when all Elements are ready, but not images. */
window.addEvent('domready', function() {
	// Remove the time from all day events
	var fixthis = $('FixSide').innerHTML;
	$('FixSide').innerHTML = fixthis.replace(/, 12?am/g,'');
	// Preload Mouseover Images
   img1 = new Image();
   img2 = new Image();
   img3 = new Image();
   img1.src = "/img/visionover.gif";
   img2.src = "/img/buildingover.gif";
   img3.src = "/img/campaignover.gif";
});

window.onload = function() {
	// On the building drawings page, hack nextgen gallery to expand thumbnails
	if (window.location == 'http://futuregrace.gccnashville.org/the-building/drawings/'){
		var b = getElementsByClassName('ngg-gallery-thumbnail', 'div');
		for (var i=0;i<b.length;i++) {
			b[i].style.width = '220px';
		}
	
		var imgs = $('ngg-gallery-2').getElementsByTagName('img');
		for (var i=0;i<imgs.length;i++)
  		{ 
  			imgs[i].style.height = '150px';
  			imgs[i].style.width = '200px';
  		}
	}
	
	if (window.location == 'http://futuregrace.gccnashville.org/the-vision/videos/' || window.location == 'http://futuregrace.gccnashville.org/the-vision/videos/#'){
		new Ajax('http://futuregrace.gccnashville.org/custom/videoplayer.html', {			method: 'get',			update: $('fgVideo'),
			onComplete: extendDropShadow,
			evalScripts: true		}).request();
	
	}
	
	extendDropShadow();

	//Disable Thickbox if it's IE6... this version doesn't currently work, and switching it out isnn't worth the trouble.
	if (window.external && typeof window.XMLHttpRequest == "undefined") {
		var IEout = document.getElementsByName('IEnogo');

		for (var i=0;i<IEout.length;i++)
  		{ 
  			IEout[i].className = null;
  		}
	}
}

function extendDropShadow() {
	// Extend the drop shadow divs
	var h = $('midBox').offsetHeight;
	$('leftVine').style.height = h +'px';
	$('rightVine').style.height = h +'px';
	$('leftVine').style.maxHeight = h +'px';
	$('rightVine').style.maxHeight = h +'px';	
}

function getElementsByClassName(className, tag, elm){
	var testClass = new RegExp("(^|\\\\s)" + className + "(\\\\s|$)");
	var tag = tag || "*";
	var elm = elm || document;
	var elements = (tag == "*" && elm.all)? elm.all : elm.getElementsByTagName(tag);
	var returnElements = [];
	var current;
	var length = elements.length;
	for(var i=0; i<length; i++){
		current = elements[i];
		if(testClass.test(current.className)){
			returnElements.push(current);
		}
	}
	return returnElements;
}

// Nav Bar swaps
function SwapOver(str) {
	var thisOne = $(str);
	if (thisOne.src.search(/over.gif/) === -1) thisOne.src = '/img/' + str + 'over.gif';
	else thisOne.src = '/img/' + str + '.gif';
}	
