var June = {
	ajax: {
		ajaxParamName: "ajax",
		ajaxParamValue: "true",
		get: function(url, id, script) {
	        if (url.indexOf("?") >= 0) {
	            url += "&";
	        } else {
	            url += "?";
	        }
	        url += "rnd=" + new Date().getTime();
	        if (this.ajaxParamName != null && this.ajaxParamName.length > 0) {
				url += "&" + this.ajaxParamName;
		        if (this.ajaxParamValue != null && this.ajaxParamValue.length > 0) {
					url += "=" + this.ajaxParamValue;
				}
			}
			try {
	            YAHOO.util.Connect.asyncRequest("GET", url, this._getCallBack(id, script));
	        } catch(e) {}
	    },
		post: function(form, id, script) {
	        if (this.ajaxParamName != null && this.ajaxParamName.length > 0) {
				if (!form.elements[this.ajaxParamName]) {
					var input = document.createElement("input");
					input.type = "hidden";
					input.name = this.ajaxParamName;
			        if (this.ajaxParamValue != null && this.ajaxParamValue.length > 0) {
						input.value = this.ajaxParamValue;
					}
					form.appendChild(input);
				}
			}
	        YAHOO.util.Connect.setForm(form);
	        try {
	            YAHOO.util.Connect.asyncRequest("POST", form.action, this._getCallBack(id, script));
	        } catch(e) {}
	    },
	    _successHandler: function(o) {
			if (o.responseText !== undefined) {
	            if (o.argument.id != null) {
	                var obj = document.getElementById(o.argument.id);
	                if (obj != null) {
	                    obj.innerHTML = o.responseText;
	                }
					if (o.argument.script) {
						eval(o.argument.script);
					}
	            }
	        }
	    },
	    _getCallBack: function(id, script) {
	        return {
	            success: this._successHandler,
	            argument: { id: id, script: script}
	        };
	    }
	},
	Expander: function(name, clickId, objId, objClasses) {
		this.isLoaded = false;
		this.isActive = false;
		this.isTweening = false;
		this.animIn = null;
		this.animOut = null;
		this.name = name;
		this.clickId = clickId;
		this.objId = objId;
		this.objClasses = objClasses;
	},
	expanders: Array(),
	expanderQueue: Array(),
	init: function() {
		June.sitemap = new June.Expander("June.sitemap", "toSitemap", "sitemap", "sitemap wideBox");
		June.sitemap.init();
		June.search = new June.Expander("June.search", "toSearch", "search", "searchFields wideBox");
		June.search.init();
		var subMenu;
		if(subMenu = document.getElementById("submenu")) {
			var subMenuHeight = subMenu.clientHeight;
			var contentArea = document.getElementById("content");
			var contentAreaHeight = contentArea.clientHeight;
			if (contentAreaHeight < subMenuHeight) {
				contentArea.style.height = subMenuHeight + "px";
			}
		}
	}
}
June.Expander.prototype.init = function () {
	var clickTarget = document.getElementById(this.clickId);
	if (clickTarget) {
		YAHOO.util.Event.on(this.clickId, "click", function(e) {
			if (!this.isTweening) {
				if (this.isLoaded) {
					if (this.isActive) {
						this.hide();
					} else {
						this.show();
					}
				} else {
					var obj = document.createElement("div");
					obj.id = this.objId;
					obj.className = this.objClasses;
					obj.style.visibility = "hidden";
					document.getElementById("services").appendChild(obj);
					June.ajax.get(clickTarget.href, this.objId, this.name + ".activate()");
				}
			}
		    YAHOO.util.Event.stopEvent(e);
	    }, this, true);
		June.expanders.push(this);
	}
	var obj = document.getElementById(this.objId);
	if (obj) {
		this.activate();
	}
}
June.Expander.prototype.activate = function() {
	var objHeight = document.getElementById(this.objId).clientHeight + 50;
    this.animOut = new YAHOO.util.Anim("services", { height: { to: objHeight } }, .5, YAHOO.util.Easing.easeOutStrong);
	this.animOut.onComplete.subscribe(function() { this.isTweening = false; this.isActive = true; document.getElementById("services").style.height = (document.getElementById(this.objId).clientHeight + 50) / 13 + "em"; }, this, true);
    this.animIn = new YAHOO.util.Anim("services", { height: { to: 17 } }, .5, YAHOO.util.Easing.easeOutStrong);			
	this.animIn.onComplete.subscribe(function() { document.getElementById(this.objId).style.display = "none"; this.isTweening = false; this.isActive = false; this.showNext(); }, this, true);
	this.isLoaded = true;
	this.show();
}
June.Expander.prototype.show = function() {
	for (var i = 0; i < June.expanders.length; i++) {
		if (June.expanders[i] != this) {
			if (June.expanders[i].isActive) {
				June.expanders[i].hide();
				June.expanderQueue.push(this);
				return;
			}
		}	
	}
	this.isTweening = true;
	var obj = document.getElementById(this.objId);
	obj.style.visibility = "visible";
	obj.style.display = "block";
	this.animOut.animate();
}
June.Expander.prototype.hide = function() {
	this.isTweening = true;
	this.animIn.animate();
}
June.Expander.prototype.showNext = function() {
	if (June.expanderQueue.length > 0) {
		June.expanderQueue.shift().show();
	}
}
June.init();


function hideDocumentElement(id) {
    var el = document.getElementById(id);
    if (el) el.style.display = 'none';
}

function showDocumentElement(id) {
    var el = document.getElementById(id);
    if (el) el.style.display = 'block';
}
