// JavaScript Document

function ITheme()
{
	this.toc;
	this.Add = addTheme;
	this.themeDiv = "themes";
	this.themeArray = new Array();
	this.resetAllThemes = resetAllThemes;
	this.buildThemeList = buildThemeList;
	this.startTheme = startTheme;
	this.themeMapLayers = themeMapLayers;
	this.giveColor  = giveColor;
	this.restoreColor = restoreColor;
	this.openLegendGroup = openLegendGroup;
	this.activeTheme = null;
}



function buildThemeList()
{
	var div = document.getElementById(this.themeDiv);
	div.innerHTML = '';
	var html ='';
	html +='<table border="0" cellspacing="3" cellpadding="0">';
	html +='<tr>';
	html +='<td><img src="'+imagePath+'/themesTitle.gif"><td>';
	
	for (xx in this.themeArray)
	{
		html +='<td><div id="'+xx+'" class="themeButtons" onmouseover="myTheme.giveColor(this);" onmouseout="myTheme.restoreColor(this);" onClick="myTheme.startTheme(\''+xx+'\',this); return false;">';
		
	 xx =  xx.replace(/_/g, " "); 
		html += xx + "</div></td>";
		
		
	}	
	html +='</tr>';
	html +='</table>';
	
	div.innerHTML += html;
	
	//this.activeTheme = "County";	
	//var de = document.getElementById("County");
	//giveColor(de);	
}




function addTheme()
{
	var layerIds = '';
	var spacer = "|";
	for (var i=1; i <= arguments.length - 1; i++)
	{
		if (i == arguments.length - 1) { spacer = ''; }
		layerIds +=arguments[i] +spacer;
	}
	this.themeArray[arguments[0]] = layerIds;
}

function themeMapLayers(themeName)
{
	this.resetAllThemes();
	var themes = this.themeArray[themeName].split("|");
	
	for (var id =0; id <= themes.length - 1; id++)
	{
		var layerIndex= findLayerIndexById(themes[id]);
		RESPONSE.LAYER[layerIndex].visible = "true";
	}
}



function startTheme(themeName,that)
{
	myMap.falseAllRendering(null,true);
	
	if (this.activeTheme != null)
	{
	var oldTheme = document.getElementById(this.activeTheme);
	restoreColor(oldTheme,oldTheme);
	}
	this.activeTheme = that.id;
	
	this.themeMapLayers(themeName)
	
	//Load it UP!
	this.toc.clear("legendLayer");
	buildLegend();
	this.toc.drawLegend("legendLayer");
	this.toc.map.getMap();
	
	this.toc.closeAllGroups();
	this.toc.openSingleGroupByName(themeName);
	loadActiveTab("Legend");
}




function resetAllThemes()
{
	for (var layers  in  RESPONSE.LAYER)
	{
	 RESPONSE.LAYER[layers].visible = "false";
	}
}



function giveColor(that) 	
{  	
	that.style.border = "1px solid #FFFF00"; 
	that.style.background= "url('images/TableBg_Rotate.gif')";
}

function restoreColor(that) 
{ 	
	if (that.id != this.activeTheme)
	{
		that.style.border = "1px solid #000";
		that.style.background= "url('images/TableBg.gif')";
	}
}


function openLegendGroup()
{
		
	
}


