// JavaScript Document

/********************************************\
	FN : MAGevListener
	Description : Multi Browser Event Listener

\********************************************/

function MAGevListener(obj,evt,fn,cpt) {
	if(!cpt) {
		cpt = false;
	}
	if(obj.addEventListener) {
		obj.addEventListener(evt,fn,cpt);
		eCache.add(obj,evt,fn);
	}
	else if(obj.attachEvent) {
		obj["e"+evt+fn] = fn;
		obj[evt+fn] = function() { obj["e"+evt+fn]( window.event ); }
		obj.attachEvent("on"+evt,obj[evt+fn] );
		eCache.add(obj,evt,fn);
	}
	else {
		obj["on"+evt] = obj["e"+evt+fn];
	}
}

var eCache = function(){
	var eList = [];
	return {
		listEvents : eList,

		add : function(node,sEventName,fHandler){
			eList.push(arguments);
		},

		flush : function(){
			var i, item;
			for(i=eList.length - 1; i>=0; i=i-1){
				item = eList[i];
				if(item[0].removeEventListener){
					item[0].removeEventListener(item[1], item[2], item[3]);
				};
				if(item[1].substring(0, 2) != "on"){
					item[1] = "on" + item[1];
				};
				if(item[0].detachEvent){
					item[0].detachEvent(item[1], item[2]);
				};
				item[0][item[1]] = null;
			};
		}
	};
}();

MAGevListener(window,'unload',eCache.flush);
MAGevListener(window,'load',function(e) {
	var lC,rC,lCh,rCh,newHeight;
	lC = document.getElementById("siteNav");
	rC = document.getElementById("bodyContent");
	lCh = lC.offsetHeight;
	rCh = rC.offsetHeight;
	if(lCh > rCh) {
		var cHh,cFh;
		cHh = document.getElementById("contentHead").offsetHeight;
		cFh = document.getElementById("contentFoot").offsetHeight;
		pANDm = 20; //Padding and Margin calculations
		newHeight = lCh - cHh - cFh - pANDm;
		document.getElementById("contentBody").style.height = newHeight+"px";
	}
	else if (rCh > lCh) {
		var nBh,siteNav,botSpacer,siteNavOH,botSpacerOH;
		siteNav = document.getElementById("siteNav");
		botSpacer = document.getElementById("navSpacerBot");
		siteNavOH = siteNav.offsetHeight;
		botSpacerOH = botSpacer.offsetHeight;
		pANDm = 2; //Padding and Margin calculations
		newHeight = rCh - siteNavOH - pANDm + botSpacerOH;
		botSpacer.style.height = newHeight+"px";
	}
});


$(document).ready(function() {
	$(".iFrameDonation").fancybox({
		'padding'			: 0,
		'width'				: '80%',
		'height'			: '90%',
		'autoScale'			: false,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe'
	});
	$(".iFrameYouTube").fancybox({
		'padding'			: 5,
		'width'				: 480,
		'height'			: 390,
		'autoScale'			: false,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe'
	});

	$(".swfPopin").fancybox({
		'padding'			: 0,
		'autoScale'			: false,
		'opacity'			: true,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'swf'							: {wmode:'transparent'}
	});
});
