﻿dojo.addOnLoad(function() {
	// Initialize the Orange Buttons
	dojo.query(".te-orange-btn").forEach(function(o) {
		new ButtonControl({
			"link" : o
		});
	});
});

// Controls the classnames of the orange buttons
// forces behavioral consistency across all browsers
function ButtonControl(cfg) {
	this.link = dojo.byId(cfg.link);
	dojo.connect(this.link, "onmouseover", this, function() { dojo.addClass(this.link, "te-orange-btn-hover"); });
	dojo.connect(this.link, "onmouseout", this, function() { dojo.removeClass(this.link, "te-orange-btn-hover"); });
	dojo.connect(this.link, "onmousedown", this, function() { dojo.addClass(this.link, "te-orange-btn-active"); });
	dojo.connect(this.link, "onmouseup", this, function() { dojo.removeClass(this.link, "te-orange-btn-active"); });
}

// Fix for IE since there's no CSS display : table-cell property
// forces divs to be the same height at the bottom of the homepage
function ForceConsistentHeight(cfg) {
	this.nodes = cfg.nodes;
	this.maxHeight = 0;
	this.fixed = true;
	this.updateMaxHeight();
	this.applyNewHeights();
	this.checkHeights();
	if(!this.fixed) {
		this.offset = 0;
		this.getOffset();
		this.fixHeights();
	}
};
ForceConsistentHeight.prototype.updateMaxHeight = function() {
	var h = 0;
	dojo.forEach(this.nodes, function(o) {
		h = dojo.coords(o).h;
		this.maxHeight = h > this.maxHeight ? h : this.maxHeight;
	}, this);
	this.applyNewHeights();
};
ForceConsistentHeight.prototype.applyNewHeights = function() {
	var h = 0;
	dojo.forEach(this.nodes, function(o) {
		h = dojo.coords(o).h;
		if(this.maxHeight > h) {
			dojo.style(o, {
				"height" : this.maxHeight + "px"
			});
		}
	}, this);
};
ForceConsistentHeight.prototype.checkHeights = function() {
	dojo.every(this.nodes, function(o) {
		if(dojo.coords(o).h != this.maxHeight && this.fixed) {
			this.fixed = false;
		}
	}, this);
};
ForceConsistentHeight.prototype.getOffset = function() {
	var h = 0;
	dojo.forEach(this.nodes, function(o) {
		h = dojo.coords(o).h;
		if(this.maxHeight > h) {
			this.offset = this.maxHeight - h;
		}
	}, this);
};
ForceConsistentHeight.prototype.fixHeights = function() {
	var h = 0;
	dojo.forEach(this.nodes, function(o) {
		h = dojo.coords(o).h;
		if(h == this.maxHeight) {
			dojo.style(o, {
				"height" : this.maxHeight + this.offset + "px"
			});
		}
	}, this);
};

