// JavaScript Document
$(document).ready(function() {
	
	var _expanders = new Array;
	
	_expanders[0] = {id:"1",openHeight:150, isOpen:false};
	_expanders[1] = {id:"2",openHeight:100, isOpen:false};
	_expanders[2] = {id:"3",openHeight:180, isOpen:false};
	
	// toggle expanders open status
	function findObject(tglId) {
		for (x in _expanders) {
			if (_expanders[x].id == tglId) {
				return _expanders[x];
			}
		}
		return false;
	}
	
	function setOpenStatus(tglId, theStatus) {
		for (x in _expanders) {
			if (_expanders[x].id == tglId) {
					_expanders[x].isOpen = theStatus;
			}
		}
	}
	
	function isOpen(tglId) {
		var _thisPanel = findObject(tglId);
		return _thisPanel.isOpen;
	}
	
	function panelOpen(tglId) {
		var _thisPanel = findObject(tglId);
		var _thisNewHeight = _thisPanel.openHeight+"px";

		setOpenStatus(tglId,true);
		$(".expd-"+tglId+"-panel").animate({height:_thisNewHeight},500);
		$(".expd-"+tglId+"-leftArrow").addClass('hidden');
		$(".expd-"+tglId+"-downArrow").removeClass('hidden');
	}
	
	function panelClose(tglId) {
		var _thisPanel = findObject(tglId);
		
		setOpenStatus(tglId,false);
		$(".expd-"+tglId+"-panel").animate({height:40},500);
		$(".expd-"+tglId+"-leftArrow").removeClass('hidden');
		$(".expd-"+tglId+"-downArrow").addClass('hidden');
	}

	// process the navigation active anchors first
	if (typeof _pageInfo !== undefined) {
		_linkName = ".navLink-"+_pageInfo.pageName;
		$(_linkName).addClass("activePage");
		if (typeof _pageInfo.expander !== undefined) {
			panelOpen(_pageInfo.expander);
		}
	}
	
	// assign all of the valid expander controls
	$(".expd").each(function(index) {
		var _idBreakout = this.id.split("-");
		var _myId = _idBreakout[1];
		$(this).click(function() {
			if (isOpen(_myId)) {
				panelClose(_myId);
			} else {
				panelOpen(_myId);
			}
		});
	});
		
});
