// JavaScript Document
var mapCmsCategoryDisplayed = new Array();
henworx.MapCms.Category={}

henworx.MapCms.Category.Click=function(catid, cat_name){
	//fetch lang settings
	_lang = henworx.MapCms.Lang;
	//remove all the markers on the map
	if(typeof(gBigOpenWindow.location)!='undefined'){
		henworx.MapCms.BigWindow.hide();	
	}
	//clear all markers from map
	gMapCms.map.clearOverlays();
	
	/*Linkrel*/
	//check if the linkrel is enabled if yest restore the linkrel marker 	
	if(typeof(objlinkrel)=="object"){					
		//objlinkrel.putMarker();	//this doesnot work due to conflict.
		 no_event=true				
		 gMapCms.putMarker(objlinkrel.linkrelLocation,no_event);
	}	
	/*Linkrel*/
	restoreSearchedPoi();
	
	//check if the same catid is already opened
	henworx.MapCms.Status(_lang.getWord("Loading..."))
	
	
	
	
	if(typeof(mapCmsCategoryDisplayed[catid]) != 'undefined'){
		//alert('previous '+catid);
		gMapCms.locations = mapCmsCategoryDisplayed[catid];
		//set center
		/*keep the marker where you are,dont change the center position*/
		//gMapCms.centerAt=gMapCms.locations[0];					
		//gMapCms.setCenter(gMapCms.centerAt);
		gMapCms.putAllMarker();
		
	}
	else{	
		//alert('first time '+catid);
		//fetch new Category Data.
		gMapCmsDb.categoryLocations=new Array();
		if(catid==0){
			//get all
			gMapCms.locations=gMapCms.allLocations
		}else{
		gMapCmsDb.getCategoryAsXML(catid,500);		
		gMapCms.locations=gMapCmsDb.categoryLocations;
		}
		
		if(gMapCms.locations.length>0){
			if(gMapCms.locations[0].id==gMapCms.locations[1].id){gMapCms.locations.pop()}
			mapCmsCategoryDisplayed[catid] = gMapCms.locations
			/*keep the marker where you are,dont change the center position*/
			//gMapCms.centerAt=gMapCmsDb.categoryLocations[0];					
			//gMapCms.setCenter(gMapCms.centerAt);
			gMapCms.putAllMarker();
		}
		else{
			
			gMapCms.locations.length=0;
		}
	}
	
	
	
	if(typeof(listViewObj)=="object"){
			listViewObj.reset();
			listViewObj.currentPage=1;
			if(gMapCms.locations.length!=0){
			listViewObj.maxPage=Math.ceil((gMapCms.locations.length)/listViewObj.postsPerPage);
			listViewObj.getData(true,'',catid);
			}else{
				listViewObj.empty();
			}
	
	}
	if(gMapCms.locations.length!=0){
		henworx.MapCms.Status(cat_name +" | "+gMapCms.locations.length +" "+_lang.getWord('Entries')+'' );
	}else{
		henworx.MapCms.Status(cat_name +" | "+_lang.getWord('No records found') );
	}
	
}

/*
Click event for Category
*/
function categoryOnClick(catid, cat_name){
	
	categoryData = new henworx.MapCms.Category.Click(catid, cat_name)
	
}
