﻿/*
 * Sets the footer to align with the bottom of the page
 */
setMainPageHeight = function(offset, contentOrigHeight) {
	if (window.getHeight() > 0) {
		var contentElement = $('content');
		
		var contentHeight = contentElement.offsetHeight;
		var headerHeight = $('header').offsetHeight;
		var footerHeight = $('footer').offsetHeight;
		
		var origHeight = contentOrigHeight + footerHeight + headerHeight;
		var diff = window.getHeight() - origHeight - offset;
		
		(diff < 0) ? (diff = 0) : true;
				
		contentElement.style.height = (contentOrigHeight + diff) + "px";
		
	}
}

/*
ToggleController.js
Jason Tang June 2007

This script adds an "expand/compress" button to each element with the ID controlPrefix, and toggles between display:none and display:block
for each element with the ID contentPrefix.

Each element used in the main page should have an ID either controlPrefix or contentPrefix,
followed immediately by a number (starting at 0) -- if the number of items is more than 1

This script REQUIRES either mooTools, an Microsoft AJAX ScriptManager, or something that implements the $ function supplied by these libraries.
Example Usage:

<script>
    var t_controller = new ToggleController("t_controller","button","content",3);
    
    //optional
    t_controller.expandContentSymbol = " [+] EXPAND ";
    t_controller.hideContentSymbol = " [-] HIDE ";
    t_controller.expandCssClass = "buttonClass";
    t_controller.hideCssCass = "buttonClass2";
    t_controller.Initialize();
</script>
<div id="button1"></div>
<div id="button2"></div>
<div id="button3"></div>
<div id="content1"></div>
<div id="content2"></div>
<div id="content3"></div>
--------OR--------

<div id="button"></div>
<div id="content"></div>
<script>
    var t_controller = new ToggleController("t_controller","button","content");
    t_controller.Initialize();
</script>
------------------
*/

function ToggleController(reference, controlPrefix, contentPrefix, numItems) {
	this.reference = reference; //reference is a STRING that, when eval()'d, returns this instance of ToggleController

	if (numItems > -1) this.numItems = numItems;
	else this.numItems = 1;

	this.controlPrefix = controlPrefix;
	this.contentPrefix = contentPrefix;
}
 
ToggleController.prototype = {

	reference : "",
	controlPrefix : "",
	contentPrefix : "",
	expandContentSymbol : "[+]",
	hideContentSymbol : "[-]",
	expandCssClass : "",
	hideCssClass : "",
	postToggle : null,
	postToggleParams : "",
	numItems : 0,
	callback : null,
	state : null,

	Initialize : function() {
		if (!this.state) this.state = new Array(this.numItems);
		this.Refresh();
	},
 
	Refresh : function() {
		for (var i=0; i< this.numItems; i++)
			this.RefreshControl(i);    
	},

	RefreshControl : function(index) {
		if (this.state[index]) {
			$(this.controlPrefix + ((this.numItems>1)?index:"") ).innerHTML = "<a href=\"javascript:" + this.reference + ".Toggle(" + index + ");\" class=\"" + this.expandCssClass + "\">" + this.expandContentSymbol + "</a>";
			//do the transition here:
			$(this.contentPrefix + ((this.numItems>1)?index:"") ).style.display = "none";
		} else {
			$(this.controlPrefix + ((this.numItems>1)?index:"") ).innerHTML = "<a href=\"javascript:" + this.reference + ".Toggle(" + index + ");\" class=\"" + this.hideCssClass + "\">" + this.hideContentSymbol + "</a>";
			//do the transition here:
			$(this.contentPrefix + ((this.numItems>1)?index:"") ).style.display = "block";
		}
	},

	Toggle : function(index) {
		this.state[index] = !this.state[index];
		this.RefreshControl(index);

		if (this.postToggle) eval(this.postToggle + '(' + this.postToggleParams + ');');
	}
}