/* 
	JS for main Remembrance Wall site - to add link behaviour to blocks containing links.

	Requires glow.dom (uses simple event handling without glow.events at present).

	created: 2008-10-03 <a href="mailto:Michael.Taylor1@bbc.co.uk">Mike Taylor</a>
*/

(function(){

// MAINTAINED VARIABLES:
	var dbg = false; // set true to open only one at a time

// CODE TO EXECUTE:
	glow.ready(function() {
		addLinks('blockLink', 'blockLinkHover');
	});


// FUNCTIONS:
/* 
	addLinks: enhancement to add link behaviour to whole block containing the link.
	Search for all blocks with the given class. 
	Find the first link in the block, save the target and set the onclick 
	event handler for the block to respond by navigating to that link.
*/
	function addLinks(
		sWrapperSelector /* selector for wrapping elements containing link */
		, sHoverClass /* class added here to block to simulate link-hover */
	) 
	{
		var ns_wrappers = glow.dom.get('.' + sWrapperSelector) 
			;

		ns_wrappers.each(function(i) {

			var ns_block = ns_wrappers.slice(i,i+1) // containing block
				, ns_a = ns_block.get('a') // first anchor in block
				;

			if (!ns_a.length) return;

			this.linkTarget = ns_a.attr('href');

			// simulate link behaviour on wrapper
			this.onclick = function() { window.location = this.linkTarget };
			this.onmouseover = function() { glow.dom.get(this).addClass(sHoverClass) };
			this.onmouseout = function() { glow.dom.get(this).removeClass(sHoverClass) };

		});
	}
	//-----


})(); // call immediately

// end of script
