var tocVisible = true;
var tocContent="";

var vToc;
    var grpLoc;
    vToc = new TOC('-','',true,null);

	var grpLoc = vToc.addGroup( new GROUP('Shopping & Dining',true) );
	grpLoc.addLayer( new LAYER('AgriBusiness','Agri-Business', 'farm.png','','') );
	grpLoc.addLayer( new LAYER('Amish Stores','Amish Stores','buggy.png','','') );
	grpLoc.addLayer( new LAYER('Antique Stores','Antique Stores','antique3.png','','') );
	grpLoc.addLayer( new LAYER('Gift Shops','Gift Shops', 'present.png','','') );	
    grpLoc.addLayer( new LAYER('Outdoor Stores','Outdoor Stores', 'outdoor.png','','') );
	grpLoc.addLayer( new LAYER('Restaurants','Restaurants','restaurant.png','','') );
	
    var grpLoc = vToc.addGroup( new GROUP('Lodging',true) );
    grpLoc.addLayer( new LAYER('Bed &amp; Breakfast','Bed &amp; Breakfasts','bed.png','','') );
	grpLoc.addLayer( new LAYER('Campgrounds','Campgrounds','tent.png','','') );
	grpLoc.addLayer( new LAYER('Hotels &amp; Motels','Hotels &amp; Motels','hotel.png','','') );
	
	var grpLoc = vToc.addGroup( new GROUP('Entertainment',true) );
    grpLoc.addLayer( new LAYER('Bowling','Bowling','bowling.png','','') );
    grpLoc.addLayer( new LAYER('Casinos','Casinos','chips.png','','') );
	grpLoc.addLayer( new LAYER('Drive-In/Movie Theatres','Drive-in/Movie Theatres','drivein.png','','') );
	grpLoc.addLayer( new LAYER('Fairgrounds','Fairgrounds','ferriswheel.png','','') );
	grpLoc.addLayer( new LAYER('Fun Parks','Recreation/Adventure','funpark.png','','') );
    grpLoc.addLayer( new LAYER('Galleries/Museums','Galleries/Museums','galleries.png','','') );
    grpLoc.addLayer( new LAYER('Golf Courses','Golf Courses','golf.png','','') );
    grpLoc.addLayer( new LAYER('Miniature Golf','Miniature Golf','miniature.png','','') );
	grpLoc.addLayer( new LAYER('Raceways','Raceways','racetrack.png','','') );
	grpLoc.addLayer( new LAYER('Skiing  &amp; Snowtubing','Skiing  &amp; Snowtubing','ski.png','','') );
	grpLoc.addLayer( new LAYER('Day Spas','Day Spas','spa.png','','') );
	
    var grpLoc = vToc.addGroup( new GROUP('Outdoor Activities',true) );
    grpLoc.addLayer( new LAYER('Archery','Archery', 'archery.png','','') );
    grpLoc.addLayer( new LAYER('Boating &amp; Rafting','Boating &amp; Rafting','rafting.png','','') );
    grpLoc.addLayer( new LAYER('Fishing Locations','Fishing Access Points','fish.png','','') );
	grpLoc.addLayer( new LAYER('Forests and Parks','Forests and Parks','forestpark.png','','') );
	grpLoc.addLayer( new LAYER('Hunting Preserves','Hunting Preserves','huntingpreserve.png','','') );	
	grpLoc.addLayer( new LAYER('Hunting Locations','Hunting Access Points','hunting.png','','') );	
	grpLoc.addLayer( new LAYER('Ranches','Ranches','horseriding.png','','') );
	grpLoc.addLayer( new LAYER('Nature Centers','Nature Centers','bb.png','','') );
	grpLoc.addLayer( new LAYER('Recreational Land','Recreation Land','recland.png','','') );
	grpLoc.addLayer( new LAYER('Streams','Streams','streams.png','','') );
	grpLoc.addLayer( new LAYER('Water Bodies','Water Bodies','WaterBodies.png','','') );
	
    var grpLoc = vToc.addGroup( new GROUP('Public Structures',true) );
	grpLoc.addLayer( new LAYER('Armories','Armories','cannon.png','','') );
	grpLoc.addLayer( new LAYER('Cemeteries','Cemeteries','headstone.png','','') );
	grpLoc.addLayer( new LAYER('Fire Stations','Fire Stations','fire.png','','') );
	grpLoc.addLayer( new LAYER('Olean Airport','Olean Airport','plane.png','','') );
	grpLoc.addLayer( new LAYER('Public Libraries','Public Libraries','book.png','','') );
	grpLoc.addLayer( new LAYER('Schools','Schools','school.png','','') );
	//grpLoc.addLayer( new LAYER('Churches','Churches','church.png','','') );
	//grpLoc.addLayer( new LAYER('Hospitals','Hospitals','hospital.png','','') );

	var grpLoc = vToc.addGroup( new GROUP('Trails',true) );
    grpLoc.addLayer( new LAYER('Allegany State Park Trails','Allegany State Park','asptrails.png','','') );
    grpLoc.addLayer( new LAYER('Biking Trail (NYSDOT)','Biking (NYSDOT)','biking.png','','') );
    grpLoc.addLayer( new LAYER('Hiking Trails','Hiking','hiking.png','','') );
    //grpLoc.addLayer( new LAYER('Little Valley Horse Trails','Little Valley Horse','horsetrails.png','','') );
	grpLoc.addLayer( new LAYER('Snowmobile Trails','Snowmobile','snowtrails.png','','') );
    //grpLoc.addLayer( new LAYER('Mountain Biking Trails','Mountain Biking Trails','mountbike.png','','') );
    //grpLoc.addLayer( new LAYER('Griffis Sculpture Park Trails','Griffis Sculpture Park Trails',null,'','') );


function displayToc(){

/*
	tocContent = getLayersContent();
	for (var i=0;i<layerCount; i++){
		tocContent +=" <ul>";
		tocContent +="  <li>";
		//tocContent +="   <img src=\"images/linelastnode.gif\" border=\"0\" />\n";
		tocContent +="	 <input type=\"checkbox\" value=\"\" onclick=\"setVisibility(" + i + ");getMapWithCurrentExtent();\"";
		if(LayerVisible[i] == 1) tocContent += " CHECKED ";
		tocContent += "/>";
		//tocContent +="   <input type=\"radio\" name=\"activelyr\" value=\"\" onclick=\"setActiveLayer(" + i + ")\"";
		//if(i== ActiveLayerIndex) tocContent += " CHECKED ";
		//tocContent += "/> ";
		tocContent += LayerName[i] + "</li>\n";
		tocContent += " </ul>\n</li>\n";
	
	}
	tocContent += "</ul>\n";
*/
    tocContent = vToc.refresh();
    /*
    var f = '';
	for (var i=0, n=LayerID.length; i<n; i++){
		f += i + ' ' + LayerID[i] + ', ';
		}
	for (var i=0, n=LayerName.length; i<n; i++) {
		f += i + ' ' + LayerName[i] + ', ';
    }
    for (var i=0, n=LayerName.length; i<n; i++) {
        if(LayerVisible[i] == 1){
          f += i + ' ' + LayerVisible[i] + ', ';
        }
    }
	info("layers = "+f);
	*/
	updateContent("toc",tocContent);
	//bTOC_loaded = true;
    savedPointsUpdate();	
	return false;
}

function getLayersContent(){	
	var lyrsContent="";
	/*
	lyrsContent += "<ul id=\"\">\n";
  	lyrsContent += " <li><a href=\"#\" onclick=\"toggleVisibility();\" >";
  	if(tocVisible) lyrsContent += "<img src=\"images/folderopened.gif\" border=\"0\" alt=\"Folder Opened\" />\n";
  	else lyrsContent += "<img src=\"images/folderclosed.gif\" border=\"0\" alt=\"Folder Closed\" />\n";
	lyrsContent += " Layer Group</a></li>\n";
	*/
	return lyrsContent;
}

function toggleVisibility(){
	tocVisible = ! tocVisible;
	var lyrsContent = getLayersContent();
	if(!tocVisible) updateContent("toc", lyrsContent);
	else displayToc();
}

function setVisibility(lyrIndex, tmpVisible){
	if (tmpVisible == null) {
		if(LayerVisible[lyrIndex] == 1) LayerVisible[lyrIndex] = 0;
		else LayerVisible[lyrIndex] = 1;
	} else {
		LayerVisible[lyrIndex] = (tmpVisible == 1||tmpVisible == 'true')?1:0;
	}
}

/*
 *=getLayerIndexByLayerID
 *@
 */
function getLayerIndexByLayerID(tmpLayerID) {
	for (var s=0, tmpLen=LayerID.length;s<tmpLen;s++) {
		if (tmpLayerID == LayerID[s]) {
			return s;
		}
	}
	return null;
}
/*
 *=getPointIndex
 *@ Returns the point array index using the Layer ID and the Arc ID of the point
 */
function getPointIndex(tmpLayerID, tmpPointID) {
	//alert("getPointIndex "+aPoint_layer_id.length);
	for (var s=0, tmpX=aPoint_layer_id.length;s<tmpX;s++) {
		//alert("*layerID="+aPoint_layer_id[s]);
		if (aPoint_layer_id[s] == tmpLayerID) {
			//alert('LayerID found '+tmpLayerID);
			if (aPoint_arc_point_id[s] == tmpPointID) {
				//alert('PointID found '+tmpPointID);
				return s;
			}
		}
	}
	return null;
}
/*
 *=point get By LayerId ArcId
 *@ Returns the point array index using the Layer ID and the Arc ID of the point
 */
function point_getByLayerIdArcId(tmpLayerId, tmpArcId){
	return getPointIndex(tmpLayerId, tmpArcId);
}

function setActiveLayer(lyrIndex){
	ActiveLayerIndex = lyrIndex;
	ActiveLayer = LayerID[lyrIndex];
}

function updateContent(name, content) {
	var theObj = document.getElementById(name);
	if (theObj!=null) {	  
		theObj.innerHTML = content;	
	}
	Behaviour.apply();
	return false;
}

//alert("aim TOC");
