var oTumbler;
var oMap;
var aCheckers = new Array();
var oCityName;
var oImageMap;
var oTempCitiesImg;
var iWhichState = 0;

function InitChecker()
{
	oTumbler		= document.getElementById('MapTumbler');
	oMap			= document.getElementById('MapLayers');
	aCheckers		= oTumbler.getElementsByTagName('a');
	oShowOffices	= aCheckers[0];
	oShowObjects	= aCheckers[1];
	
	oShowOffices.onclick = function () { EnableOffices( this ); return false; }
	oShowObjects.onclick = function () { EnableObjects( this ); return false; }
	
	InitCities();
}

function EnableOffices( oLink )
{
	oMap.className			= "LayerOffices";
	oShowOffices.className	= "CheckedMapItems";
	oShowObjects.className	= "";
	iWhichState = 1;
}

function EnableObjects( oLink )
{
	oMap.className			= "LayerObjects";
	oShowOffices.className	= "";
	oShowObjects.className	= "CheckedMapItems";
	iWhichState = 0;
}

function InitCities()
{
	if( aCoordinates )
	{
		oTempCitiesImg	= document.createElement('img');
		oTempCitiesImg.setAttribute('alt', '');
		oTempCitiesImg.setAttribute('src', '/i/_.gif');
		oTempCitiesImg.setAttribute('id', 'CitiesMapImg');
		oTumbler.parentNode.appendChild( oTempCitiesImg );

		oCityName	= document.createElement('div');
		oCityName.setAttribute('id', 'CityName');
		oCityName.style.display		= 'none';

		oImageMap	= document.createElement('map');
		oImageMap.setAttribute('name','CitiesMap');

		for( var i = 0; i < aCoordinates.length; i++)
		{
			var oTemp	= document.createElement('area');
				oTemp.setAttribute('shape', 'rect');
				oTemp.setAttribute('coords', aCoordinates[i].X + ',' + aCoordinates[i].Y + ',' + (aCoordinates[i].X + 12) + ',' + (aCoordinates[i].Y + 9));
				oTemp.setAttribute('city-title', aCoordinates[i].Name);
				if(  aCoordinates[i].Link )
					oTemp.setAttribute('href', aCoordinates[i].Link);
				if(  aCoordinates[i].Plant )
					oTemp.setAttribute('is-plant', 'true');
				oTemp.observe('mouseover', function(){ ShowCityTitle( this ); return false; } );
				oTemp.observe('mouseout', function(){ HideCityTitle( this ); return false;} );
				oImageMap.appendChild( oTemp );
		}
		
		oTumbler.parentNode.insertBefore(oImageMap, oTumbler.parentNode.firstChild );
		oTumbler.parentNode.appendChild( oCityName );

		oTempCitiesImg.setAttribute('usemap','#CitiesMap');
	}
}

function ShowCityTitle( oObject )
{
	if( iWhichState == 0 || (iWhichState == 1 && oObject.getAttribute('is-plant')))
	{
		var aCoords	= oObject.getAttribute('coords').split(',');
		var iX	= parseInt(aCoords[0]) + 20;
		var iY	= parseInt(aCoords[1]) - 14;
		oCityName.innerHTML	= oObject.getAttribute('city-title');
		oCityName.style.top		= iY + 'px';
		oCityName.style.left	= iX+ 'px';
		
		new Effect.Appear( oCityName, {duration: 0.15} );
	}
}

function HideCityTitle()
{
	new Effect.Fade( oCityName, {duration: 0.15} );
}
