function CategoryImage(img, id)
{
active = (webshop_category_active[id]) ? '' : '_bright';
src = img.src;
src = src.replace('_bright', '');
if (src.indexOf('.gif') > -1)
{
ext = '.gif';
src = src.replace('.gif', '');
}
if (src.indexOf('.jpg') > -1)
{
ext = '.jpg';
src = src.replace('.jpg', '');
}
img.src = src + active + ext;
img.style.cursor = 'pointer';
add_event_handler(img, 'click', CategoryImageClick);
add_event_handler(img, 'mouseover', CategoryImageOver);
add_event_handler(img, 'mouseout', CategoryImageOut);
}

function CategoryImageOver(e)
{
if (!e) e = window.event;
if (!e) return;
	if (e.target)
	{
		img = e.target;
	}
	else if (e.srcElement)
	{
		img = e.srcElement;
	}

id = img.alt.substr(9);
if (parseInt(id) == id)
{
     src = img.src;
     src = src.replace('_bright', '');
     if (src.indexOf('.gif') > -1)
     {
     ext = '.gif';
     src = src.replace('.gif', '');
     }
     if (src.indexOf('.jpg') > -1)
     {
     ext = '.jpg';
     src = src.replace('.jpg', '');
     }
     img.src = src + '' + ext;
}
}

function CategoryImageClick(e)
{
if (!e) e = window.event;
if (!e) return;
	if (e.target)
	{
		img = e.target;
	}
	else if (e.srcElement)
	{
		img = e.srcElement;
	}
id = img.alt.substr(9);
if (parseInt(id) == id)
{
document.location.href = '/site//Webshop/products/category/' + id;
}
}

function CategoryImageOut(e)
{
if (!e) e = window.event;
if (!e) return;
	if (e.target)
	{
		img = e.target;
	}
	else if (e.srcElement)
	{
		img = e.srcElement;
	}

id = img.alt.substr(9);
if (parseInt(id) == id)
{
     active = (webshop_category_active[id]) ? '' : '_bright';
     src = img.src;
     src = src.replace('_bright', '');
     if (src.indexOf('.gif') > -1)
     {
     ext = '.gif';
     src = src.replace('.gif', '');
     }
     if (src.indexOf('.jpg') > -1)
     {
     ext = '.jpg';
     src = src.replace('.jpg', '');
     }
     img.src = src + active + ext;
}
}

function CategoryImageInit()
{
	// Henter billeder
	if (document.getElementById)
	{
		images = document.getElementsByTagName('img');
	}
	else if (document.all)
	{
		images = document.all['mouseovers'].all.tags('IMG');
	}
	else
	{
		return;
	}
	
	// Gennemløber billeder på siden
	for (var i = 0; i < images.length; i++)
	{
		img = images.item(i);
		src = img.src;
		if (img.alt.indexOf('category_') > -1)
		{
                                      id = img.alt.substr(9);
                                      if (parseInt(id) == id)
                                      {
                                            CategoryImage(img, id);
                                      }
		}
	}
}

function add_event_handler(obj, event, func)
{
	if (obj.addEventListener)
	{
		obj.addEventListener(event, func, true);
	}
	else if (obj.attachEvent)
	{
		obj.attachEvent("on" + event, func);
	}
}

onload = CategoryImageInit;
