function mouseOverTab(tab)
{
	var prevLi = getPrevLi(tab);

	if(prevLi.id=='firstTab')
        prevLi.style.backgroundPosition = '0px 70px';
    else
	{
		var prevPrevLi = getPrevLi(prevLi);

		if(prevPrevLi.id=='activeTab')
			prevLi.style.backgroundPosition = '0px 105px';
		else
			prevLi.style.backgroundPosition = '0px 210px';
	}

    tab.style.backgroundPosition = '0px 35px';

	var nextLi = getNextLi(tab);

    if(nextLi.id=='lastTab')
        nextLi.style.backgroundPosition = '0px 35px';
	else
    {
		var nextNextLi = getNextLi(nextLi);

		if(nextNextLi.id=='activeTab')
			nextLi.style.backgroundPosition = '0px 35px';
		else
			nextLi.style.backgroundPosition = '0px 70px';
	}
}

function mouseOutTab(tab)
{
	var prevLi = getPrevLi(tab);

	if(prevLi.id=='firstTab')
        prevLi.style.backgroundPosition = '0px 0px';
	else
    {
		var prevPrevLi = getPrevLi(prevLi);

		if(prevPrevLi.id=='activeTab')
			prevLi.style.backgroundPosition = '0px 140px';
		else
			prevLi.style.backgroundPosition = '0px 0px';
	}

    if(tab.id!='activeTab')
        tab.style.backgroundPosition = '0px 0px';

	var nextLi = getNextLi(tab);

	if(nextLi.id=='lastTab')
        nextLi.style.backgroundPosition = '0px 175px';
    else
	{
		var nextNextLi = getNextLi(nextLi);

		if(nextNextLi.id=='activeTab')
			nextLi.style.backgroundPosition = '0px 175px';
		else
			nextLi.style.backgroundPosition = '0px 0px';
	}
}

function getNextLi(tab)
{
	var nextLi = tab;

	if(nextLi.id!='lastTab')
	{
		do
		{
			nextLi = nextLi.nextSibling;
		}
		while(nextLi.tagName != 'LI' && nextLi.id != 'lastTab');
	}

	return nextLi;
}

function getPrevLi(tab)
{
	var prevLi = tab;

	if(prevLi.id!='firstTab')
	{
		do
		{
			prevLi = prevLi.previousSibling;
		}
		while(prevLi.tagName != 'LI' && prevLi.id != 'firstTab');
	}

	return prevLi;
}

var activePanel;
var clickedPanel = document.getElementById('newToilets');
var panelInterval;

function clickPanel(element)
{
	pauseMapTour();
	if(typeof(aroundMap) == 'object')
        aroundMap.closeInfoWindow();

	if(clickedPanel == element)
        location.href = element.href;
    else
    {
        clickedPanel = element;
	    panelInterval = window.setInterval('movePanel()', 10);

	    document.getElementById(activePanel.id + 'Box').style.display = 'none';
	    document.getElementById(activePanel.id + 'Box').style.visibility = 'hidden';

	    document.getElementById(clickedPanel.id + 'Box').style.display = 'block';
	    document.getElementById(clickedPanel.id + 'Box').style.visibility = 'visible';
    }

	return false;
}

function movePanel()
{
	activePanel.style.width = (parseInt(activePanel.style.width.substr(0, activePanel.style.width.length-2)) - 2) + 'px';
	clickedPanel.style.width = (parseInt(clickedPanel.style.width.substr(0, clickedPanel.style.width.length-2)) + 2) + 'px';

	if(parseInt(activePanel.style.width.substr(0, activePanel.style.width.length-2)) <= 16)
	{
		activePanel.style.width = '16px';
		window.clearInterval(panelInterval);
		activePanel = clickedPanel;
	}
}

if(document.getElementById('newToilets'))
{
	activePanel = document.getElementById('newToilets');
}

if(document.getElementById('topToiletsBox'))
{
	document.getElementById('topToiletsBox').style.display = 'none';
	document.getElementById('topToiletsBox').style.visibility = 'hidden';
}

if(document.getElementById('badToiletsBox'))
{
	document.getElementById('badToiletsBox').style.display = 'none';
	document.getElementById('badToiletsBox').style.visibility = 'hidden';
}

var toiletBoxInterval;
var toiletBoxEndMargin = 0;
var toiletsBox;

function clickToiletUp()
{
	toiletsBox = document.getElementById(activePanel.id + 'Box');
	var marginTop = toiletsBox.style.marginTop;

	if(marginTop)
		marginTop = parseInt(marginTop.substr(0, marginTop.length-2));
	else
		marginTop = 0;

	if(marginTop%toiletsBox.getElementsByTagName('div')[0].offsetHeight == 0 && marginTop < 0)
	{
		toiletBoxEndMargin = marginTop + toiletsBox.getElementsByTagName('div')[0].offsetHeight;
		window.clearInterval(toiletBoxInterval);

		pauseMapTour();
		aroundMap.closeInfoWindow();

		toiletBoxInterval = window.setInterval('moveToiletBoxUp()', 10);
	}

	return false;
}

function moveToiletBoxUp()
{
	var marginTop = toiletsBox.style.marginTop;
	marginTop = parseInt(marginTop.substr(0, marginTop.length-2));

	toiletsBox.style.marginTop = (marginTop + 2) + 'px';

	if(toiletBoxEndMargin <= marginTop + 2)
	{
		toiletsBox.style.marginTop = toiletBoxEndMargin + 'px';
		window.clearInterval(toiletBoxInterval);
	}
}

function clickToiletDown()
{
	toiletsBox = document.getElementById(activePanel.id + 'Box');
	var marginTop = toiletsBox.style.marginTop;

	if(marginTop)
		marginTop = parseInt(marginTop.substr(0, marginTop.length-2));
	else
		marginTop = 0;

	if(marginTop%toiletsBox.getElementsByTagName('div')[0].offsetHeight == 0 && toiletsBox.offsetHeight + marginTop > document.getElementById('toiletsBox').offsetHeight)
	{
		getListToilets(toiletsBox);
		toiletBoxEndMargin = marginTop - toiletsBox.getElementsByTagName('div')[0].offsetHeight;
		window.clearInterval(toiletBoxInterval);

		pauseMapTour();
		aroundMap.closeInfoWindow();

		toiletBoxInterval = window.setInterval('moveToiletBoxDown()', 10);
	}

	return false;
}

function moveToiletBoxDown()
{
	var marginTop = toiletsBox.style.marginTop;
	marginTop = marginTop.substr(0, marginTop.length-2);

	toiletsBox.style.marginTop = marginTop - 2 + 'px';

	if(toiletBoxEndMargin >= marginTop - 2)
	{
		toiletsBox.style.marginTop = toiletBoxEndMargin + 'px';
		window.clearInterval(toiletBoxInterval);
	}
}