/**
 * smenu data loader for Joomla
 *
 * @package smenu
 * @version 1.0.0.20070504
 * @copyright Creative Pulse Ltd 2007
 * @link http://www.creativepulse.eu/goto/smenu
 */

function getChild(node)
{
	if (node) {
		var node = node.firstChild;
		while (node && node.nodeType != 1) {
			node = node.nextSibling;
		}
	}
	return node;
}

function smenu_load_joomla(imgpath)
{
	var li = document.getElementById('pos_user9');
	if (!li) {
		alert('Animated menu position not found');
		return;
	}

	li = getChild(getChild(li));
	if (!li) {
		alert('Animated menu not found');
		return;
	}
	else if (li.nodeName != 'LI') {
		alert('Animated menu is invalid. (Perhaps not a flat list?)');
		return;
	}

	var i = 1;
	smenu.data['smenu' + i] = {
		content: '',
		bgcolor: '',
		bgimg: imgpath + 'menuLeft.jpg',
		width: 16,
		link: ''
	}
	
	var init = false;
	while (li) {
		if (init) {
			i++;
			smenu.data['smenu' + i] = {
				content: '',
				bgcolor: '',
				bgimg: imgpath + 'menuSplitter.jpg',
				width: 9,
				link: ''
			}
		}
		else {
			init = true;
		}

		var img = getChild(li);
		if (img.nodeName != 'IMG') {
			alert('Menu image not found. (Perhaps -Show Menu Icons- has a -No- value?)');
			return;
		}

		var lnk = img.nextSibling;
		while (lnk && lnk.nodeType != 1 && lnk.nodeName != 'A') {
			lnk = lnk.nextSibling;
		}
		if (!lnk) {
			alert('Menu URL not found');
			return;
		}

		i++;
		smenu.data['smenu' + i] = {
			content: '',
			bgcolor: '',
			bgimg: img.src,
			width: 0,
			link: lnk.href,
			title: lnk.firstChild.nodeValue
		}

		li = li.nextSibling;
	}

	i++;
	smenu.data['smenu' + i] = {
		content: '',
		bgcolor: '',
		bgimg: imgpath + 'menuRight.jpg',
		width: 14,
		link: ''
	}

	smenu.height = 95;

	smenu.h_onload('smenu');
	smenu.timer_id = setInterval('smenu.ontimer()', smenu.interval);
}

