/*
Programmer: Darryl Ballard
Date created: 2008-10-07
Last updated: 2008-12-23
Version: 1.0.0

Requires:
	Prototype 1.6
	
Version History:
*/

var GST_Click_Boxes = {
	class_to_activate:"GST_Click_Box",
	
	class_for_hiding_child_link:"hide_link",
	
	activate:function()
	{
		var all_links = $$("a");
		
		for (var i = 0; i < all_links.length; i++) {
			var click_box_parent = all_links[i].up("." + GST_Click_Boxes.class_to_activate);
			
			if (click_box_parent != undefined) {
				// Optionally hide the link
				if (click_box_parent.hasClassName(GST_Click_Boxes.class_for_hiding_child_link)) {
					all_links[i].hide();
				}
				
				// Disable the click event of the link
				all_links[i].observe("click", function(e) {
					e.preventDefault();
					return false;
				});
				
				// Give the click box some behavior
				click_box_parent.observe("click", function() {
					var child_link = this.down("a");
					
					if (child_link != undefined) {
						//alert("Should I go to " + child_link.href);
						
						// Check for offsite link behavior
						if (typeof GST_External_Links == "undefined") {
							// Open in current tab/window
							window.location = child_link.href;
						} else {
							// Ask GST_External_Links to handle it
							GST_External_Links.trigger(child_link);
						}
						
						/*
						if (this.hasClassName("offsite")) {
							// Open in a new tab/window
							window.open(child_link.href, "externalWindow");
						} else {
							// Open in current tab/window
							window.location = child_link.href;
						}
						*/
					}
				});
			}
		} // end for(i)
	} // end activate()
};

// Require that Prototype is available
if (typeof Prototype == "undefined") {
	alert("GST Click Boxes 1.0 requires the Prototype javascript framework.\n\nPlease check that it is included.");
} else {
	//Event.observe(window, 'load', GST_Click_Boxes.activate);
	document.observe("dom:loaded", GST_Click_Boxes.activate);
}
