onLoad(function(){
	var tg=document.getElementById('toggle_guide');
	var el = document.getElementById('ministry_guide');
	var est = el.style;
	var nowH = est.height;
	est.height = '';
	var to = sparo.getTrueHeight(el);
	est.height = nowH;
	if(to) {
		tg.onclick=showMinistries;
	} else {
		tg.onclick=toggleIE;
	}
	disableSelection(tg);
	emailObfuscate('(delete_this)');
	initHoverMenu('navMenu');
});
function showMinistries(){
	document.getElementById('ministry_arrow').className='arrowDown';
	expandV(document.getElementById('ministry_guide'), 20);
	document.getElementById('toggle_guide').onclick=hideMinistries;
	return false;
}
function hideMinistries(){
	document.getElementById('ministry_arrow').className='arrowUp';
	collapseV(document.getElementById('ministry_guide'), 20);
	document.getElementById('toggle_guide').onclick=showMinistries;
	return false;
}
function toggleIE() {
	var el = document.getElementById('ministry_guide');
	if(el.style.height === '0px') {
		el.style.height = '';
		document.getElementById('ministry_arrow').className='arrowDown';
	} else {
		el.style.height = '0px';
		document.getElementById('ministry_arrow').className='arrowUp';
	}
}
function siteSearch(){
	var f=document.getElementById('searchForm');
	f.q.value="site:friendlyavenue.com "+f.searchField.value;
}

/*
 *
 * Hover Menu
 *
 */
sparo.hovMenu = {};
sparo.hovMenu.isOpen = false;
sparo.hovMenu.defer;
function initHoverMenu(p) {
	var p = typeof p === 'string' ? document.getElementById(p) : p;
	var els = getElementsByClass('hasMenu');
	var elsLen = els.length;
	var holdLIs = [];
	var holdLen = 0;
	var tmp;
	var offFn;
	for(var i=0;i<elsLen;i++){
		tmp = els[i].childNodes[0];
		tmpRef = tmp.childNodes[0].data;
		offFn = (function(a){
								return function(){
									hoverOff(a);
								};
							})(tmpRef);
		tmp.onclick = offFn;
		tmp.onmouseover = (function(a){
								return function(){
									hoverOn(a);
								};
							})(tmpRef);
		tmp.onmouseout = offFn;
		sparo.hovMenu[tmp.childNodes[0].data] = { hov: tmp.parentNode.childNodes[2] };
		holdLIs = els[i].getElementsByTagName('LI');
		holdLen = holdLIs.length;
		for(var j=0;j<holdLen;j++){
			if(holdLIs[j].parentNode === els[i].childNodes[2]){
			holdLIs[j].onclick = navTo;
			holdLIs[j].onmouseover = (function(a){
											return function(){
												hoverOn(a);
											};
										})(tmpRef);
			holdLIs[j].onmouseout = (function(a){
											return function(){
												hoverOff(a);
											};
										})(tmpRef);
			}
		}
	}
}
function hoverOn(ref) {
	var ref = sparo.hovMenu[ref],
		ul = ref.hov,
		f;
	if(ul.style.display !== 'block') {
		f = openMenu(ul);
		if(sparo.hovMenu.isOpen){
			sparo.hovMenu.defer = f;
		} else {
			ref.timer = setTimeout(f, 400);
		}
	} else {
		if(ref.timer){
			clearTimeout(ref.timer);
			ref.timer = null;
		}
	}
}
function openMenu(a) {
	return function(){
		a.style.height = '0px';
		a.style.display = 'block';
		expandV(a, 25);
		sparo.hovMenu.isOpen = true;
	};
}
function hoverOff(ref) {
	var ref = sparo.hovMenu[ref],
		ul = ref.hov,
		f;
	if(ul.style.display !== 'block') {
		if(ref.timer){
			clearTimeout(ref.timer);
			ref.timer = null;
		}
	} else {
		f = closeMenu(ul);
		ref.timer = setTimeout(f, 500);
	}
	sparo.hovMenu.defer = null;
}
function closeMenu(a) {
	return function(){
		collapseV(a, 30);
	};
}
function nowClosed() {
	sparo.hovMenu.isOpen = false;
	if(sparo.hovMenu.defer) { sparo.hovMenu.defer(); }
}
function navTo(e) {
	var evt = e || event;
	if (evt && evt.stopPropagation) { evt.stopPropagation(); } else { evt.cancelBubble = true; }
	
	var url = evt.target || evt.srcElement;
	if(url.nodeName === 'A'){
		return;
	} else if(url.parentNode.parentNode.className === 'hasMenu'){
		url = url.childNodes[0];
	} else {
		url = url.parentNode.parentNode.childNodes[0];
	}
	window.location = url;
}


/*
 *
 *  EMAIL
 *
 */
function emailObfuscate(remove) {
	var lnks = document.getElementsByTagName('A'),
		lnksLen = lnks.length,
		mail;
	for(var i=0;i<lnksLen;i++){
		mail = lnks[i].href.toString();
		if(mail.indexOf('mailto:') !== -1){
			mail = mail.replace(remove,'');
		}
		lnks[i].href = mail;
	}
}


/*
 *
 *
 *  AJAX
 *
 *
 */
sparo.aj_jaxData = [];

function ajax(url, target, oncomplete){
	if (target) {
		if (typeof target === 'string') {
			target = document.getElementById(target);
		}
		else {
			if (typeof target !== 'object') {
				target = null;
			}
		}
	}
	if (typeof url === 'string') {
		sparo.aj_singleRequest(url, target, oncomplete);
	}
	else 
		if (typeof url === 'object') {
			var start = 0;
			var total = url.length;
			var color = '#999999';
			if (url[0].indexOf('color:') === 0) {
				color = url[0].substring(6);
				start = 1;
				total--;
			}
			if (target) {
				sparo.aj_fill(target, '<table border="0" cellspacing="0" cellpadding="0" style="font-family:Arial, Helvetica, sans-serif;font-size:11px;letter-spacing:0.1em;"><tr><td style="padding-right:5px;">Loading...</td><td><div align="left" style="width:75px;height:8px;overflow:hidden;background-color:#DDDDDD;border:#CCCCCC 1px solid;"><div id="AJAX_prgBar" style="width:1px;height:8px;background-color:' + color + ';"></div></div></td><td style="padding-left:5px;"><span id="AJAX_prgText">0%</span></td></tr></table>');
			}
			for (var i = start; i < url.length; i++) {
				sparo.aj_multipleRequest(i - start, total, url[i], target, oncomplete);
			}
		}
		else {
			sparo.aj_fill(target, 'Error: Invalid Arguments');
		}
}

// wrap to avoid global namespace
(function(){
	sparo.aj_loadContent = function aj_loadContent(target, oncomplete){
		if (target) {
			sparo.aj_fill(target, sparo.aj_jaxData.join(''));
		}
		if (oncomplete) {
			if (typeof oncomplete === 'function') {
				oncomplete();
			}
			else 
				if (typeof oncomplete === 'object') {
					for (var i = 0; i < oncomplete.length; i++) {
						oncomplete[i]();
					}
				}
		}
	};
	var aj_loadContent = null;
	
	sparo.aj_fill = function aj_fill(target, data){
		if (target.nodeName == 'TEXTAREA' || target.nodeName == 'INPUT') {
			target.value = data;
		}
		else {
			target.innerHTML = data;
		}
	};
	var aj_fill = null;
	
	
	// ---------------SINGLE-------------- //
	sparo.aj_singleRequest = function aj_singleRequest(url, target, oncomplete){
		var httpRequest;
		if (window.XMLHttpRequest) { // Mozilla, Safari, ...
			httpRequest = new XMLHttpRequest();
			if (httpRequest.overrideMimeType) {
				httpRequest.overrideMimeType('text/xml');
			}
		}
		else 
			if (window.ActiveXObject) { // IE
				try {
					httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
				} 
				catch (e) {
					try {
						httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
					} 
					catch (e) {
					}
				}
			}
		if (!httpRequest) {
			sparo.aj_fill(target, 'Cannot create XMLHTTP instance');
			return false;
		}
		httpRequest.onreadystatechange = function(){
			sparo.aj_duringRequest(httpRequest, target, oncomplete);
		};
		try {
			httpRequest.open('GET', url, true);
		} 
		catch (e) {
			sparo.aj_fill(target, 'Cannot Access File');
		}
		httpRequest.send(null);
	};
	var aj_singleRequest = null;
	
	sparo.aj_duringRequest = function aj_duringRequest(httpRequest, target, oncomplete){
		try {
			if (httpRequest.readyState === 4) {
				if (httpRequest.status === 200) {
					sparo.aj_jaxData[0] = httpRequest.responseText;
					sparo.aj_loadContent(target, oncomplete);
				}
				else {
					sparo.aj_fill(target, 'Error: Problem with Request');
				}
			}
		} 
		catch (e) {
			sparo.aj_fill(target, 'Exception: ' + e.description);
		}
	};
	var aj_duringRequest = null;
	
	
	// ---------------MULTIPLE-------------- //
	sparo.aj_multipleRequest = function aj_multipleRequest(indx, tot, url, target, oncomplete){
		var httpRequest;
		if (window.XMLHttpRequest) { // Mozilla, Safari, ...
			httpRequest = new XMLHttpRequest();
			if (httpRequest.overrideMimeType) {
				httpRequest.overrideMimeType('text/xml');
			}
		}
		else 
			if (window.ActiveXObject) { // IE
				try {
					httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
				} 
				catch (e) {
					try {
						httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
					} 
					catch (e) {
					}
				}
			}
		if (!httpRequest) {
			sparo.aj_fill(target, 'Cannot create XMLHTTP instance');
			return false;
		}
		httpRequest.onreadystatechange = function(){
			sparo.aj_duringMultiple(httpRequest, indx, tot, target, oncomplete);
		};
		try {
			httpRequest.open('GET', url, true);
		} 
		catch (e) {
			sparo.aj_fill(target, 'Cannot Access File');
		}
		httpRequest.send(null);
	};
	var aj_multipleRequest = null;
	
	sparo.aj_duringMultiple = function aj_duringMultiple(httpRequest, indx, tot, target, oncomplete){
		try {
			if (httpRequest.readyState === 4) {
				if (httpRequest.status === 200) {
					sparo.aj_jaxData[indx] = httpRequest.responseText;
					if (sparo.aj_jaxData.length == tot) {
						sparo.aj_loadContent(target, oncomplete);
					}
					else {
						var perc = (indx + 1) / tot;
						document.getElementById('AJAX_prgBar').style.width = Math.round(perc * 75) + 'px';
						document.getElementById('AJAX_prgText').innerHTML = Math.round(perc * 100) + '%';
					}
				}
				else {
					sparo.aj_fill(target, 'Error: Problem with Request');
				}
			}
		} 
		catch (e) {
			sparo.aj_fill(target, 'Exception: ' + e.description);
		}
	};
	var aj_duringMultiple = null;
})();




/*
 *
 *
 *  ANIMATION
 *
 *
 */

sparo.queue = []; // holds functions to be executed
sparo.timer = null;

sparo.startTimer = function(){
    if (!sparo.timer) {
        sparo.timer = setInterval(sparo.execute, 20);
    }
};
sparo.stopTimer = function(){
    if (!sparo.timer) {
        return false;
    }
    clearInterval(sparo.timer);
    sparo.timer = null;
    var q = sparo.queue;
    for (var m = 0; m < q.length; m++) {
        q.splice(0, q.length);
    }
};
// gets called every 20ms, executes any fn in sparo.queue
sparo.execute = function(){
    var allNull = true;
    var q = sparo.queue;
    var qLen = q.length;
    for (var n = 0; n < qLen; n++) {
        if (q[n] !== null && q[n][2] && typeof(q[n][2]) === 'function') {
            q[n][2]();
            allNull = false;
        }
    }
    if (allNull) {
        sparo.stopTimer();
    }
};
sparo.inQueue = function(el, animType){
    var qLen = sparo.queue.length;
    for (var i = 0; i < qLen; i++) {
        var q = sparo.queue[i];
        if (q && q[0] === el && q[1] === animType) {
            return i;
        }
    }
    return -1;
};
sparo.init = function(el){
	if (!el.sparo) {
		el.sparo = {};
	}
	if (!el.sparo.size) {
		var es = el.style;
		var pT = parseInt(es.paddingTop, 10) || 0;
		var pR = parseInt(es.paddingRight, 10) || 0;
		var pB = parseInt(es.paddingBottom, 10) || 0;
		var pL = parseInt(es.paddingLeft, 10) || 0;
		el.sparo.size = {
			bdrT: parseInt(es.borderTopWidth, 10) || 0,
			bdrR: parseInt(es.borderRightWidth, 10) || 0,
			bdrB: parseInt(es.borderBottomWidth, 10) || 0,
			bdrL: parseInt(es.borderLeftWidth, 10) || 0,
			padT: pT,
			padR: pR,
			padB: pB,
			padL: pL,
			w: parseInt(es.width, 10) || (el.clientWidth - pL - pR),
			h: parseInt(es.height, 10) || (el.clientHeight - pT - pB)
		};
	}
	if (!el.sparo.pos) {
		el.sparo.pos = {
			x: parseInt(es.left, 10) || 0,
			y: parseInt(es.top, 10) || 0,
			vel: 0
		};
	}
};


/**
 * Fade In/Out
 */
function fadeIn(el, speed){
    if (typeof el === 'string') {
        el = document.getElementById(el);
    }
    if (!el.style) {
        return;
    }
	if (!speed || (speed <= 0)) {
		speed = 10;
	}
    var already = sparo.inQueue(el, 'fade');
    var f;
    if (already != -1) {
        f = (function(a, b, c, d){
					return function(){
						sparo.doFade(a, b, c, d);
					};
				})(el, 100, already, speed);
        sparo.queue[already][2] = f;
    }
    else {
		f = (function(a, b, c, d){
					return function(){
						sparo.doFade(a, b, c, d);
					};
				})(el, 100, sparo.queue.length, speed);
        sparo.queue.push([el, 'fade', f]);
    }
    sparo.startTimer();
}

function fadeOut(el, speed){
    if (typeof el === 'string') {
        el = document.getElementById(el);
    }
    if (!el.style) {
        return;
    }
	if (!speed || (speed <= 0)) {
		speed = 10;
	}
    var already = sparo.inQueue(el, 'fade');
    var f;
    if (already != -1) {
        f = (function(a, b, c, d){
					return function(){
						sparo.doFade(a, b, c, d);
					};
				})(el, 0, already, speed);
        sparo.queue[already][2] = f;
    }
    else {
		f = (function(a, b, c, d){
					return function(){
						sparo.doFade(a, b, c, d);
					};
				})(el, 0, sparo.queue.length, speed);
        sparo.queue.push([el, 'fade', f]);
    }
    sparo.startTimer();
}

function fadeTo(el, to, speed){
    if (typeof el === 'string') {
        el = document.getElementById(el);
    }
    if (!el.style) {
        return;
    }
	if (!speed || (speed <= 0)) {
		speed = 10;
	}
    var already = sparo.inQueue(el, 'fade');
    var f;
    if (already != -1) {
        f = (function(a, b, c, d){
					return function(){
						sparo.doFade(a, b, c, d);
					};
				})(el, to, already, speed);
        sparo.queue[already][2] = f;
    }
    else {
		f = (function(a, b, c, d){
					return function(){
						sparo.doFade(a, b, c, d);
					};
				})(el, to, sparo.queue.length, speed);
        sparo.queue.push([el, 'fade', f]);
    }
    sparo.startTimer();
}

sparo.doFade = function(el, to, ndx, spd){
	var op;
	var curOp = sparo.getStyle(el,'opacity') * 100;
	if (curOp > to) {
		op = curOp - spd;
		if (op < to) {
			op = to;
		}
		sparo.setStyle(el, 'opacity', op / 100);
		return;
	}
	else 
		if (curOp < to) {
			op = curOp + spd;
			if (op > to) {
				op = to;
			}
			sparo.setStyle(el, 'opacity', op / 100);
			return;
		}
	sparo.queue[ndx] = null;
};


/**
 * Resize
 */
function resizeTo(el, w, h, speed){
	if (typeof el === 'string') {
		el = document.getElementById(el);
	}
	if (!el.style) {
		return;
	}
	if (w !== null) {
        if (w < 0) {
			w = 0;
		}
        if (w > 10000) {
			w = 10000;
		}
    }
	if (h !== null) {
        if (h < 0) {
			h = 0;
		}
        if (h > 10000) {
			h = 10000;
		}
    }
	if (!speed || (speed <= 0)) {
		speed = 10;
	}
	if (el.style.display === 'none') {
		el.style.display = '';
	}
	sparo.init(el);
	var already = sparo.inQueue(el, 'resize');
    var f;
    if (already != -1) {
        f = (function(a, b, c, d, e){
					return function(){
						sparo.doResize(a, b, c, d, e);
					};
				})(el, already, w, h, speed);
        sparo.queue[already][2] = f;
    }
    else {
		f = (function(a, b, c, d, e){
					return function(){
						sparo.doResize(a, b, c, d, e);
					};
				})(el, sparo.queue.length, w, h, speed);
        sparo.queue.push([el, 'resize', f]);
    }
    sparo.startTimer();
}
function restore(el, speed){
	if (typeof el === 'string') {
		el = document.getElementById(el);
	}
	if (!el.sparo.size) {
		return false;
	}
	if (!speed || (speed <= 0)) {
		speed = 10;
	}
	if (el.style.display === 'none') {
		el.style.display = '';
	}
	var already = sparo.inQueue(el, 'resize');
    var f;
    if (already != -1) {
        f = (function(a, b, c, d, e){
					return function(){
						sparo.doResize(a, b, c, d, e);
					};
				})(el, already, el.sparo.size.w, el.sparo.size.h, speed);
        sparo.queue[already][2] = f;
    }
    else {
		f = (function(a, b, c, d, e){
					return function(){
						sparo.doResize(a, b, c, d, e);
					};
				})(el, sparo.queue.length, el.sparo.size.w, el.sparo.size.h, speed);
        sparo.queue.push([el, 'resize', f]);
    }
    sparo.startTimer();
}
sparo.doResize = function(el, ndx, w, h, sp){
	var est = el.style;
	var adjusting = false;
	if (w !== null && w !== undefined) {
		var x;
		var curW = parseInt(est.width, 10);
		if (!curW) {
			curW = el.clientWidth - (parseInt(est.paddingLeft, 10) || 0) - (parseInt(est.paddingRight, 10) || 0);
		}
		if (curW < w) {
			x = sparo.smoothSize(el, curW, w);
			if (x > w) {
				x = w;
			}
			if (x < 0) {
				x = 0;
			}
			est.width = x + 'px';
			adjusting = true;
		}
		else 
			if (curW > w) {
				x = sparo.smoothSize(el, curW, w);
				if (x < w) {
					x = w;
				}
				est.width = x + 'px';
				adjusting = true;
			}
	}
	if (h !== null && h !== undefined) {
		var y;
		var curH = parseInt(est.height, 10);
		if (!curH) {
			curH = el.clientHeight - (parseInt(est.paddingTop, 10) || 0) - (parseInt(est.paddingBottom, 10) || 0);
		}
		if (curH < h) {
			y = sparo.smoothSize(el, curH, h);
			if (y > h) {
				y = h;
			}
			est.height = y + 'px';
			adjusting = true;
		}
		else 
			if (curH > h) {
				y = sparo.smoothSize(el, curH, h);
				if (y < h) {
					y = h;
				}
				est.height = y + 'px';
				adjusting = true;
			}
	}
    if (adjusting) {
		return;
	}
	if (w + h <= 0) {
		est.display = 'none';
	}
	sparo.queue[ndx] = null;
};


/**
 * Collapse
 */
function collapseV(el, speed){
	if (typeof el === 'string') {
		el = document.getElementById(el);
	}
	if (!el.style) {
		return;
	}
	if (!speed || (speed <= 0)) {
		speed = 10;
	}
	sparo.init(el);
	var already = sparo.inQueue(el, 'resize');
    var f;
    if (already != -1) {
        f = (function(a, b, c){
					return function(){
						sparo.doCollapseV(a, b, c);
					};
				})(el, already, speed);
        sparo.queue[already][2] = f;
    }
    else {
		f = (function(a, b, c){
					return function(){
						sparo.doCollapseV(a, b, c);
					};
				})(el, sparo.queue.length, speed);
        sparo.queue.push([el, 'resize', f]);
    }
    sparo.startTimer();
}
sparo.doCollapseV = function(el, ndx, sp){
	var est = el.style;
	var h = parseInt(est.borderBottomWidth, 10);
	if (h) {
		h = h - sp;
		if (h < 0) {
			h = 0;
		}
		est.borderBottomWidth = h + 'px';
		return;
	}
	h = parseInt(est.paddingBottom, 10);
	if (h) {
		h = h - sp;
		if (h < 0) {
			h = 0;
		}
		est.paddingBottom = h + 'px';
		return;
	}
	var cur = parseInt(est.height, 10);
	if (!cur) {
		cur = el.clientHeight - (parseInt(est.paddingTop, 10) || 0) - (parseInt(est.paddingBottom, 10) || 0);
	}
	if (cur > 0) {
		h = cur - sp;
		if (h < 0) {
			h = 0;
		}
		est.height = h + 'px';
		return;
	}
	h = parseInt(est.paddingTop, 10);
	if (h) {
		h = h - sp;
		if (h < 0) {
			h = 0;
		}
		est.paddingTop = h + 'px';
		return;
	}
	h = parseInt(est.borderTopWidth, 10);
	if (h) {
		h = h - sp;
		if (h < 0) {
			h = 0;
		}
		est.borderTopWidth = h + 'px';
		return;
	}
	est.display = '';
	sparo.queue[ndx] = null;
	nowClosed();
};
function collapseH(el, speed){
	if (typeof el === 'string') {
		el = document.getElementById(el);
	}
	if (!el.style) {
		return;
	}
	if (!speed || (speed <= 0)) {
		speed = 10;
	}
	sparo.init(el);
	var already = sparo.inQueue(el, 'resize');
    var f;
    if (already != -1) {
        f = (function(a, b, c){
					return function(){
						sparo.doCollapseH(a, b, c);
					};
				})(el, already, speed);
        sparo.queue[already][2] = f;
    }
    else {
		f = (function(a, b, c){
					return function(){
						sparo.doCollapseH(a, b, c);
					};
				})(el, sparo.queue.length, speed);
        sparo.queue.push([el, 'resize', f]);
    }
    sparo.startTimer();
}
sparo.doCollapseH = function(el, ndx, sp){
	var est = el.style;
	var h = parseInt(est.borderRightWidth, 10);
	if (h) {
		h = h - sp;
		if (h < 0) {
			h = 0;
		}
		est.borderRightWidth = h + 'px';
		return;
	}
	h = parseInt(est.paddingRight, 10);
	if (h) {
		h = h - sp;
		if (h < 0) {
			h = 0;
		}
		est.paddingRight = h + 'px';
		return;
	}
	var cur = parseInt(est.width, 10);
	if (!cur) {
		cur = el.clientWidth - (parseInt(est.paddingRight, 10) || 0) - (parseInt(est.paddingLeft, 10) || 0);
	}
	if (cur > 0) {
		h = sparo.smoothSize(el, cur, 0);
		if (h < 0) {
			h = 0;
		}
		est.width = h + 'px';
		return;
	}
	h = parseInt(est.paddingLeft, 10);
	if (h) {
		h = h - sp;
		if (h < 0) {
			h = 0;
		}
		est.paddingLeft = h + 'px';
		return;
	}
	h = parseInt(est.borderLeftWidth, 10);
	if (h) {
		h = h - sp;
		if (h < 0) {
			h = 0;
		}
		est.borderLeftWidth = h + 'px';
		return;
	}
	est.display = 'none';
	sparo.queue[ndx] = null;
};


/**
 * Expand
 */
sparo.getTrueHeight = function(el){
	var est = el.style;
	return el.clientHeight - (parseInt(est.paddingTop, 10) || 0) - (parseInt(est.paddingBottom, 10) || 0);
};
sparo.getTrueWidth = function(el){
	var est = el.style;
	return el.clientWidth - (parseInt(est.paddingLeft, 10) || 0) - (parseInt(est.paddingRight, 10) || 0);
};

function expandV(el, speed){
	if (typeof el === 'string') {
		el = document.getElementById(el);
	}
	if (!el.style) {
		return;
	}
	if (!speed || (speed <= 0)) {
		speed = 10;
	}
	if (el.style.display === 'none') {
		el.style.display = '';
	}
	sparo.init(el);
	var est = el.style;
	var shown = est.display;
	if (shown === 'none') {
		est.display = '';
	}
	var nowH = est.height;
	est.height = '';
	var to = sparo.getTrueHeight(el);
	est.height = nowH;
	if (shown === 'none') {
		est.display = shown;
	}
	var already = sparo.inQueue(el, 'resize');
    var f;
    if (already != -1) {
        f = (function(a, b, c, d){
					return function(){
						sparo.doExpandV(a, b, c, d);
					};
				})(el, already, to, speed);
        sparo.queue[already][2] = f;
    }
    else {
		f = (function(a, b, c, d){
					return function(){
						sparo.doExpandV(a, b, c, d);
					};
				})(el, sparo.queue.length, to, speed);
        sparo.queue.push([el, 'resize', f]);
    }
    sparo.startTimer();
}

// c = current value
// d = desired value
sparo.doExpandV = function(el, ndx, h, sp){
	var est = el.style;
	var c = parseInt(est.borderTopWidth, 10);
	var d = el.sparo.size.bdrT;
	if (d && c < d) {
		c = c + sp;
		if (c > d) {
			c = d;
		}
		est.borderTopWidth = c + 'px';
		return;
	}
	c = parseInt(est.paddingTop, 10);
	d = el.sparo.size.padT;
	if (d && c < d) {
		c = c + sp;
		if (c > d) {
			c = d;
		}
		est.paddingTop = c + 'px';
		return;
	}
	var cur = parseInt(est.height, 10);
	if (!cur) {
		cur = sparo.getTrueHeight(el);
	}
	if (cur < h) {
		c = cur + sp;
		if (c > h) {
			c = h;
		}
		est.height = c + 'px';
		return;
	}
	c = parseInt(est.paddingBottom, 10);
	d = el.sparo.size.padB;
	if (d && c < d) {
		c = c + sp;
		if (c > d) {
			c = d;
		}
		est.paddingBottom = c + 'px';
		return;
	}
	c = parseInt(est.borderBottomWidth, 10);
	d = el.sparo.size.bdrB;
	if (d && c < d) {
		c = c + sp;
		if (c > d) {
			c = d;
		}
		est.borderBottomWidth = c + 'px';
		return;
	}
	sparo.queue[ndx] = null;
};
function expandH(el, speed){
	if (typeof el === 'string') {
		el = document.getElementById(el);
	}
	if (!el.style) {
		return;
	}
	if (!speed || (speed <= 0)) {
		speed = 10;
	}
	if (el.style.display === 'none') {
		el.style.display = '';
	}
	sparo.init(el);
	var est = el.style;
	var shown = est.display;
	if (shown === 'none') {
		est.display = '';
	}
	var nowW = est.width;
	var nowPL = est.paddingLeft;
	var nowPR = est.paddingRight;
	var nowBL = est.borderLeftWidth;
	var nowBR = est.borderRightWidth;
		est.width = '';
		est.paddingLeft = el.sparo.size.padL;
		est.paddingRight = el.sparo.size.padR;
		est.borderLeftWidth = el.sparo.size.bdrL;
		est.borderRightWidth = el.sparo.size.bdrR;
	var to = sparo.getTrueWidth(el);
		est.width = nowW;
		est.paddingLeft = nowPL;
		est.paddingRight = nowPR;
		est.borderLeftWidth = nowBL;
		est.borderRightWidth = nowBR;
	if (shown === 'none') {
		est.display = shown;
	}
	var already = sparo.inQueue(el, 'resize');
    var f;
    if (already != -1) {
        f = (function(a, b, c, d){
					return function(){
						sparo.doExpandH(a, b, c, d);
					};
				})(el, already, to, speed);
        sparo.queue[already][2] = f;
    }
    else {
		f = (function(a, b, c, d){
					return function(){
						sparo.doExpandH(a, b, c, d);
					};
				})(el, sparo.queue.length, to, speed);
        sparo.queue.push([el, 'resize', f]);
    }
    sparo.startTimer();
}
sparo.doExpandH = function(el, ndx, w, sp){
	var est = el.style;
	var c = parseInt(est.borderLeftWidth, 10);
	var d = el.sparo.size.bdrL;
	if (d && c < d) {
		c = c + sp;
		if (c > d) {
			c = d;
		}
		est.borderLeftWidth = c + 'px';
		return;
	}
	c = parseInt(est.paddingLeft, 10);
	d = el.sparo.size.padL;
	if (d && c < d) {
		c = c + sp;
		if (c > d) {
			c = d;
		}
		est.paddingLeft = c + 'px';
		return;
	}
	var cur = parseInt(est.width, 10);
	if (!cur) {
		cur = sparo.getTrueWidth(el);
	}
	if (cur < w) {
		c = cur + sp;
		if (c > w) {
			c = w;
		}
		est.width = c + 'px';
		return;
	}
	c = parseInt(est.paddingRight, 10);
	d = el.sparo.size.padR;
	if (d && c < d) {
		c = c + sp;
		if (c > d) {
			c = d;
		}
		est.paddingRight = c + 'px';
		return;
	}
	c = parseInt(est.borderRightWidth, 10);
	d = el.sparo.size.bdrR;
	if (d && c < d) {
		c = c + sp;
		if (c > d) {
			c = d;
		}
		est.borderRightWidth = c + 'px';
		return;
	}
	sparo.queue[ndx] = null;
};


/**
 * Move
 */
function moveTo(el, x, y, speed){
	if (typeof el === 'string') {
		el = document.getElementById(el);
	}
	if (!el.style) {
		return;
	}
	if (x !== null) {
        if (x < -100000) {
			x = -100000;
		}
        if (x > 100000) {
			x = 100000;
		}
    }

	if (y !== null) {
        if (y < -100000) {
			y = -100000;
		}
        if (y > 100000) {
			y = 100000;
		}
    }
	var est = el.style;
	if (!est.position || est.position === 'inherit') {
		est.position = 'relative';
	}
	else 
		if (est.position === 'fixed') {
			est.position = 'absolute';
		}
	sparo.init(el);
	var already = sparo.inQueue(el, 'move');
    var f;
    if (already != -1) {
        f = (function(a, b, c, d, e){
					return function(){
						sparo.doMove(a, b, c, d, e);
					};
				})(el, already, x, y, speed);
        sparo.queue[already][2] = f;
    }
    else {
		f = (function(a, b, c, d, e){
					return function(){
						sparo.doMove(a, b, c, d, e);
					};
				})(el, sparo.queue.length, x, y, speed);
        sparo.queue.push([el, 'move', f]);
    }
    sparo.startTimer();
}


// http://www.arc.id.au/JsAnimation.html
sparo.doMove = function(el, ndx, x, y, sp){
	var est = el.style;
	var curX = parseInt(est.left, 10) || 0;
	var curY = parseInt(est.top, 10) || 0;
	var slope = (y - curY) / (x - curX);
	var newX = (x || x === 0) ? sparo.smoothSize(el, curX, x, sp) : curX;
	var newY = (x === null || x === undefined || x === curX) ? sparo.smoothSize(el, curY, y, sp) : Math.round( slope * (newX - curX) + curY );
	var adj = 0;
	if ((x || x === 0)) {
		est.left = newX + 'px';
		if (newX !== x) {
			adj = 1;
		}
	}
	if ((y || y === 0)) {
		est.top = newY + 'px';
		if (newY !== y) {
			adj = 1;
		}
	}
	if (!adj) {
		el.sparo.pos.vel = 0;
		sparo.queue[ndx] = null;
	}
};

// http://safalra.com/web-design/javascript/smooth-movement/
sparo.smoothSize = function(el, at, to, accel){
	at = Math.round(at);
	to = Math.round(to);
	if (at === to) {
		return at;
	}
	spd = el.sparo.pos.vel || 0;
	if (!accel || accel <= 0) {
		accel = 1;
	}
	var was = at;
	at += spd;
	if (was < to && at > to) {
		at = to;
	}
	if (was > to && at < to) {
		at = to;
	}
    if (spd < 0){
      if (at - spd * (spd  - 1) / 2 < to){
        spd+=accel;
      }else if (at - (spd - 1) * (spd - 2) / 2 >= to){
        spd-=accel;
      }
    }else{
      if (at + spd * (spd + 1) / 2 > to){
        spd-=accel;
      }else if (at + (spd + 1) * (spd + 2) / 2 <= to){
        spd+=accel;
      }
    }
	el.sparo.pos.vel = spd;
    return at;
};




