// ***********************************************************
// Copyright by MACRON Software Entwicklungs u. Marketing GmbH
//          Fichtestrasse 66-68, A-8020 Graz, Austria
//             Tel: +43-(0)316-931837  Fax: DW -20
//          http://www.macron.at     office@macron.at
// ***********************************************************

var buttonTimer = null
var oldBackgroundId = null;
var webRoot = null;
var userClick = false;
var mc_bg_inactive = new Image (); 
var mc_bg_active = new Image (); 
var bgPrefix = "Bg";

function setWebRoot (url)
{
    webRoot = url;
}

function setButtonTimer ()
{
    var timeSpan = 500;
    var args = setButtonTimer.arguments;
    if (args != null && args.length > 0)
    {
	timeSpan = args[0];
    }
    buttonTimer = window.setInterval ("setActiveButton ()", timeSpan);
}

function clearButtonTimer ()
{
    window.clearInterval (buttonTimer);
    buttonTimer = null;
}

function setActiveButton ()
{
    var viewFrame = eval (parseFrames ("top", "DepartmentView"));
    var adminArr = new Array ("", "showContents", "showStartPath");

    if (viewFrame)
    {
	var viewUrl = unescape (viewFrame.location.href).replace (webRoot, "");
	var cPath = getContentPath (viewUrl);
	for (var i = adminArr.length; i-- > 0; )
	{
	    if (adminArr[i] == cPath)
	    {
		cPath = "ZCMS";
		break;
	    }
	}
	var bgId = bgPrefix + cPath;
	if (userClick)
	{
	    userClick = false;
	    oldBackgroundId = bgId;
	}
	switchBgAction (bgId);
    }
}

function switchButtonBackground (id)
{
    userClick = true;
    switchBgAction (id);
}

function switchBgAction (id)
{
    if (document.getElementById && id != oldBackgroundId)
    {
	if (oldBackgroundId && oldBackgroundId != " " && document.getElementById (oldBackgroundId))
	{
	    document.getElementById (oldBackgroundId).style.backgroundImage = "url(" + mc_bg_inactive.src + ")";
	}
	if (document.getElementById (id))
	{
	    document.getElementById (id).style.backgroundImage = "url(" + mc_bg_active.src + ")";
	    oldBackgroundId = id;
	}
    }
}

function getContentPath (url)
{
    var contentPath = getUrlAttribute (url, "contentPath");
    if (contentPath.length == 0 || contentPath == "/" || contentPath.toLowerCase () == "%2f")
    {
	slashPos = url.indexOf ("index.html", 1);
	if (slashPos == -1)
	{
	    slashPos = url.indexOf ("?", 1);
	}
	if (slashPos == -1)
	{
	    slashPos = url.length;
	}
	contentPath = url.substring (1, slashPos);
    }
    return contentPath;
}
