// The table #hover-container contains a cell #hover-display containing an image within a link.
// The table #hover-links contains anchors when mouseovered trigger the contents of #hover-display to change.

// General functions

function addLoadEvent (func) 
{
	var oldonload = window.onload;
	if (typeof window.onload != 'function') 
	{
		window.onload = func;
	}
	else 
	{
		window.onload = function() 
		{
			oldonload();
			func();
		}
	}
}

function setDisplay (whichpic, link, title) 
{
	if (!document.getElementById || !document.createElement) return false;
	if (!document.getElementById('hover-display')) return true;
	var destination = document.getElementById('hover-display');
	// Create link to band
	var display = document.createElement('a');
	display.setAttribute('href',link);
	display.setAttribute('rel','nofollow');
	display.setAttribute('title',title);
	// Create image for within link
	var img = document.createElement('img');
	img.setAttribute("src",whichpic);
	img.setAttribute("alt",title);
	img.setAttribute("width",400);
	img.setAttribute("height",268);
	// Add band image to link
	display.appendChild(img);
	// Add the new elements to destination
	while (destination.hasChildNodes())
	{
		destination.removeChild(destination.lastChild);
	}
	destination.appendChild(display);
	return false;
}

function prepareHoverLinks ()
{
	if (!document.getElementById || !document.getElementsByTagName) return false;
	if (!document.getElementById('hover-links'))	return false;
	var links = document.getElementById('hover-links').getElementsByTagName('a');
	for (var i=0; i < links.length; i++) 
	{
		links[i].onmouseover = function() 
		{
			var style = this.className;
			var whichpic = '/scripts/category-rollovers/'+style+'.jpg';
			var link = getLink(style);
			var title = getTitle(style);
			setDisplay(whichpic, link, title);
		};
	}
}

function getLink (style)
{
	// Build array of styles and links
	var styles = Array();
	styles['a-z-bands'] = 'backbeat-beatles-tribute-band_liverpool-wedding-band.htm';
	styles['ceilidh-band'] = 'burdock-band_birmingham-ceilidh-band.htm';
	styles['classical-ensemble'] = 'mancini-string-quartet_london-wedding-band.htm';
	styles['jazz-band'] = 'charleston-charlies_manchester-jazz-band.htm';
	styles['pop-band'] = 'amberlights_london-wedding-band.htm';
	styles['world-band'] = 'jalikunda_african-drums-bristol.htm';
	styles['blues-country'] = 'blazing_saddles.htm';
	// Return link
	return '/'+styles[style];
}

function getTitle (style)
{
	// Build array of styles and titles
	var styles = Array();
	styles['a-z-bands'] = 'Backbeat Beatles Tribute Band';
	styles['ceilidh-band'] = 'The Burdock Ceilidh Band';
	styles['classical-ensemble'] = 'Hop Till You Drop! &mdash; A wedding music agency dedicated to providing live music for weddings, family birthday and anniversary parties and corporate events';
	styles['jazz-band'] = 'The Charleston Charlies Jazz Band';
	styles['pop-band'] = 'The Amberlights Pop Band';
	styles['world-band'] = 'Jalikunda African Band';
	styles['blues-country'] = 'Blazing Saddles Line Dance Band';
	// Return title
	return styles[style];
}

addLoadEvent(prepareHoverLinks);