var position = function occur(str, pattern)
{
  return str.lastIndexOf(pattern);
}

// checks and sets active menu state
onload = function ()
{
	var id = window.location.pathname;
	var pos = position(id, "/");
	var clean = id.substring(pos+1, position(id, "."));
	var find_el;
	if (find_el = document.getElementById(clean))
		if (find_el.className != 'act')
		{
			var li = find_el.parentNode.childNodes;
			for (var i=0; i<li.length; i++)
			{
				if(li[i].nodeName == "LI");
					li[i].className = "";
			}

			find_el.className = 'act';
		}
}

// page-switcher
function goto(page)
{
	window.location.href = page+".html";
}

// dynamically included menu
document.write("<li id='index' class='act' onclick=\"goto('index')\"></li><li id='entgrauer' class='' onclick=\"goto('entgrauer')\"></li><li id='kraftreiniger' onclick=\"goto('kraftreiniger')\" class=''></li><li id='pflege_emulsion' onclick=\"goto('pflege_emulsion')\" class=''></li><li id='mehrzwecktuecher' onclick=\"goto('mehrzwecktuecher')\" class=''></li><li id='haendler' onclick=\"goto('haendler')\" class=''></li><li id='presse' onclick=\"goto('presse')\" class=''></li><li id='faq' onclick=\"goto('faq')\" class=''></li><li id='kontakt' onclick=\"goto('kontakt')\" class=''></li>");


var scroll_init = function has_scrollbar(elem_id)
{
 elem = document.getElementById(elem_id);
 // Window height is lower than scrollbar height if it is there
 if (elem.clientHeight < elem.scrollHeight)
 	document.getElementById('footer').style.marginLeft = "-497px";
 else
 	document.getElementById('footer').style.marginLeft = "-489px";
}

// Run scroll_init after page is rendered
if(window.attachEvent)
{
    window.attachEvent('onload', scroll_init('layout'));
}
else
{
    if(window.onload)
    {
        var curronload = window.onload;
        var newonload = function()
        {
            curronload();
            scroll_init('layout');
        };
        window.onload = newonload;
    }
    else
    {
        window.onload = scroll_init('layout');
    }
}

// Run scroll_init on/after resizing of the page
window.onresize = function()
{
	scroll_init('layout');	
}

//window.onresize = scroll_init('layout');

//document.getElementById('content_pic').onload = scroll_init('layout');

/*var add_the_handlers = function (nodes)
{
	var i;
	for(i = 0; i < nodes.length; i+=1)
	{
		nodes[i].onmouseover = function (i)
		{
			return function m_over(id)
				{
					var el_id = document.getElementByID(id);
					if (el_id.class == 'act')
						el_id.style.backgroundImage = id+"_act.gif";
					else
						el_id.style.backgroundImage = id+".gif";
				}
		}
		//nodes[i].onmouseout
	}

}*/

//add_the_handlers(document.getElementsByClassName('menu_pics'));

/*function m_over(id)
{
	//alert('background-image:url("../img/'+id+'_act.gif");')
	var el_id = document.getElementById(id);
	//alert(el_id.style.backgroundImage);
	//if (el_id.getAttribute('class') != 'act')
		//el_id.style.backgroundImage = "../img/"+id+"_act.gif";
		//el_id.style = 'background-image:url("../img/'+id+'_act.gif");';
	//else
		//el_id.style = 'background-image:url("../img/'+id+'.gif");';
}*/