window.onload = function()
{
	var elements_to_replace = new Array();
	elements_to_replace[0] = 'h2';
	elements_to_replace[1] = 'h3';

	imgreplace(elements_to_replace);

	if(document.getElementById("index-page"))
	{
		applyCutlery();
	}

	if(document.getElementById && document.all)
	{
		doHovers();
	}
}

function imgreplace(elements)
{
	var i;
	for(i=0; i<elements.length; i++)
	{
		var lmnts = document.getElementsByTagName(elements[i]);
		var j;
		for(j=0; j<lmnts.length; j++)
		{
			var txt = '';
			var size = '';
			var width = '';
			var height = '';

			// should add support for links and all kinds of elements
			txt = lmnts[j].innerHTML.replace(/&amp;/, "och");

			// Get font attributes
		//	size = lmnts[j].style.fontSize;
		//	width = lmnts[j].style.pixelWidth;
		//	height = lmnts[j].style.pixelHeight;

			// Rubbish temp solution
			if(elements[i] == 'h2')
			{
				size = 26;
			}
			if(elements[i] == 'h3')
			{
				size = 18;
				height = 30;
			}
			if(lmnts[j].className.indexOf('dont-replace') == -1)
			{
			/*	lmnts[j].className = lmnts[j].className +' image-replace';
				lmnts[j].style.background = 'url(css/gfx/btn-contact.jpg) left top no-repeat;'; //__nice-heading.php?str=' +txt +'&size=' +size +'&width=' +width +'&height=' +height +'
				lmnts[j].style.width = width +'px;';
				lmnts[j].style.height = height +'px;';
*/
				lmnts[j].innerHTML = '<img src="__nice-heading.php?str=' +txt +'&amp;size=' +size +'&amp;width=' +width +'&amp;height=' +height +'" alt="' +txt +'" />';
			}
		}
	}
}

function applyCutlery()
{
	var cutlery = document.createElement("div");
	cutlery.setAttribute("id", "cutlery");
	document.getElementById("wrapper").appendChild(cutlery);
}

function doHovers()
{
	var lis = document.getElementById("header").getElementsByTagName("li");
	var i;

	for(i=0; i<lis.length; i++)
	{	
		lis[i].onmouseover = function()
		{
			this.className = "hover";
		}
		lis[i].onmouseout = function()
		{
			this.className = "";
		}
	}
	
	var uls = document.getElementsByTagName("ul");
	var i;

	for(i=0; i<uls.length; i++)
	{
		if(uls[i].className == "sub-nav")
		{
			var spans = uls[i].getElementsByTagName("span");
			var j;

			for(j=0; j<spans.length; j++)
			{	
				spans[j].onmouseover = function()
				{
					this.className = "hover";
				}
				spans[j].onmouseout = function()
				{
					this.className = "";
				}
			}
		}
	}
}