//FusionMaps JavaScript DrillDown Class
/*
*   v1.0.2 (14Feb 2008) - Added ZoomSpeed control, scrollbar config 
*
*

*/
var notZoom=false;

if(typeof infosoftglobal == "undefined") var infosoftglobal = new Object();
if(typeof infosoftglobal.FusionMapsUtil == "undefined") infosoftglobal.FusionMapsUtil = new Object();
infosoftglobal.FusionMapsDrilldownFramework = function(l){
	this.level=0;
	this.mapPath ="../Maps/";
	//this.entities=new Array();
	this.mapListId="0";
	this.mapListIndex=0;
	this.ajax=false;
	this.presentDrillLevel=0;
	this.rootTitleDIV="";
	this.rootContainerDIV="";
	this.rootDrillWindowDIV=new Array();
	this.rootDrillWindowTitleDIV=new Array();
	this.rootDimension={top:"", left:"", width:"960", height:"440"};
	this.chartCounter=0;
	DivID = "FMJSD_DW"+this.level;
	DivContID = "FMJSD_DWC"+this.evel;
	
}

infosoftglobal.FusionMapsDrilldownFramework.prototype = {

instantiateMap : function(mapDiv){	
		this.createRootContainer(mapDiv);
		

		//Define map list
		this.defineMapList();
		this.mapListId="0";
		this.mapListId = this.loadMap(this.mapListId);

		//
		
	
	},
	onMapLoad : function(){
		this.getReferenceToMap();
	},

	
	loadMap : function(id){
		if(id!=""){
			var bar = this.getMapBar(id);	
			//This method loads the map
			//Store the index of new map
			this.mapListIndex = this.getMapIndex(id);
			var map = new FusionMaps(this.mapPath + this.mapList[this.mapListIndex].swf, "FM_"+this.mapListIndex, this.mapList[this.mapListIndex].width, this.mapList[this.mapListIndex].height, "0", "1");      
			
			
			if(this.mapList[this.mapListIndex].dataURL==""){
				map.setDataXML("<map animation='0' showLabels='0' borderAlpha='0' fillColor='FFFFFF' fillAlpha='0' usehoverColor='0' showToolTip='0' bgAlpha='0' CanvasBorderAlpha='0'  showShadow='0' showBevel='0' ></map>");
			}else{
				map.setDataURL(this.mapList[this.mapListIndex].dataURL);
			}
			
			
			map.render(bar.mapBar);
			
			//Update mapNameDiv with the new map's name
			var dv = document.getElementById(bar.titleBar);
			
			dv.innerHTML = " Map of " + this.mapList[this.mapListIndex].title +(id=="0" ? " [Please click on an entity to drill-down to that entity]" :" [Please click on an entity to show detailed data]" );
			
			return id;
		}
	},

	updateMap : function(){
		this.mapObj.setDataURL(this.mapList[this.mapListIndex].dataURL);
	},
	
	
	
	drillDown : function(arg){
		id = (typeof arg=="undefined" || arg[0]==null) ? "0" : arg[0] ;
			
			if(winState[level]["interval"]==null)
			{
        var ptrMaps = this.getMapIndex(id);	
				this.level=this.mapList[ptrMaps].level;
        //if(this.mapList[level].zoom){
					
					DivID = "FMJSD_DW"+this.level;
					DivContID = "FMJSD_DWC"+this.level;

					this.createDrilldownContainer(id,this.level);
					
					if(this.level==1){
						displayFloatingDiv('FMJSD_DW'+this.level,588,172,975,430);
					}else{
						displayFloatingDiv('FMJSD_DW'+this.level,585,182,960,455);
					}
					
					this.mapListId = this.loadMap(id);
					setWindow(575,181,960,455);
					zoomWindow();
				//}
			}
			
			
		
	},
	getEntityName : function(id){
		var str="";
		for (i=1; i<this.entities.length; i++){
			if(this.entities[i].id==id)
				str = this.entities[i].lName;
		}
		return str;
	},
	
	getReferenceToMap : function(){
		//This method is invoked when the map has loaded and rendered. So, we can safely
		//get a reference to the map object.
		this.mapObj =infosoftglobal.FusionMapsUtil.getMapObject("FM_"+this.mapListIndex);		
		//If we cannot get a reference to map object, it means	
		//Also, we can now get the map's entities and store it.	
		this.entities = this.mapObj.getEntityList();
		
	},

	getMapBar : function(id){
		var mapBar = "FMJSD_DWC"+this.level;
		var titleBar = "FMJSD_DW"+this.level+"Title";
		if(id=="0" || id==null) {
			mapBar ="FMJSD_root"; 
			titleBar ="FMJSD_rootTitle" ;
		}
	
		return { mapBar : mapBar , titleBar : titleBar };
	
	},
	
	getMapIndex : function(id){
		var mapIndex = 0;
		for(var i in this.mapList){
			if(id== this.mapList[i].mapListId){
				mapIndex = i;
				break;
			}
				
		}
		return mapIndex;
	},
	
	
		createRootContainer:function(mapDiv){
		this.containerHTML = "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\"><tr><td align=\"center\">" +
						 	"<div id=\"FMJSD_root\" style=\"overflow:hidden;text-align:center;\"></div></td></tr></table>" ;
		this.mapContainer = document.getElementById(mapDiv);
		this.mapContainer.innerHTML = this.containerHTML;
		
		
	},
	createDrilldownContainer:function(id,level){
		notZoom=this.mapList[this.getMapIndex(id)].zoom==false;
		var addHeader = '<table style="width:100%;" class="floatingHeader textBoldLight" >'+
       '<tr>'+
	   	'<td style="height:22px;cursor:move;" onDblClick="void(0);" onMouseOver="over=\'FMJSD_DW'+level+'\';" onMouseOut="over=null;" valign="middle"><div id="FMJSD_DW'+level+'Title" style="height:16px;overflow:hidden;cursor:move;" ></div></td>'+
        '<td style="width:14px;" align="left" valign="middle">'+
			'<a href="javascript:closeWindow(\'FMJSD_DW'+level+'\');void(0);" onDblClick="closeAll();">'+
			   '<img alt="Close" title="Close" src="app/FW/close.gif" border="0">'+
			 '</a>'+
		'</td></tr></table>';
		var cwRootStyle="width:"+this.rootDimension.width+"px;height:"+this.rootDimension.height+"px;overflow:hidden;background:#FFFFFF;";						
		var cwRoot="<div style=\""+cwRootStyle+"\"><table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" style=\"vertical-align:middle;\"><tr>";
		
		var rightPanel="<td align=\"center\" valign=\"middle\"><div id=\"FMJSD_DrillDetails"+level+"\" style=\"width:340px;height:430px;overflow:hidden;padding:0px;background:#ffffff;padding:2px;font-family:Verdana;font-size:10px;\">Please click on an entity to show Detailed Data</div></td>";
		
		
		var leftPanelStyle="overflow:hidden;"+((isFireFox || isNetscape )? "width:0px;height:0px;" :"width:"+(notZoom?600:955)+"px;height:430px;");
		var leftPanel="<td align=\"center\" valign=\"top\" >";
		leftPanel+="<div id=\"FMJSD_DWC"+level+"\" style=\""+leftPanelStyle+"\"></div>";

		var containerWindowHTML ="";
		containerWindowHTML= addHeader+cwRoot+leftPanel;
		containerWindowHTML +=(notZoom?rightPanel:"") ;
		containerWindowHTML += "</td></tr></table></div>";
		
		this.mapWindowContainer = document.getElementById("FMJSD_DW"+level);
		this.mapWindowContainer.innerHTML = containerWindowHTML;
		
	},
	
	
	
	
	defineMapList : function(){
		this.mapList = new MapList();
	},


	showChart : function(swf,dataURL,w,h,id,rjs){
		
		/*
		this.chartCounter++;
		var chartContainer=document.getElementById("FMJSD_drillCharts");
		chartContainer.innerHTML+="<div style='position:absolute;z-index:1000;' id='FMJSD_chartDIV"+this.chartCounter+"'>Chart "+this.chartCounter+"</div>";
		
		
		var cw=(w!="" && w!=null && typeof(w)!="undefined") ? w :"195";
		var ch=(h!="" && h!=null && typeof(h)!="undefined") ? h : "200";
		var cid = (id!="" && id!=null && typeof(id)!="undefined") ? id :"FMJSD_chart"+this.chartCounter;
		var crjs=(rjs=="0"||rjs=="" ||rjs==null||typeof(rjs)=="undefined")?"0":"1";
		var FC = new FusionCharts(swf+"?noChache="+Math.random() , cid , cw , ch , "0", crjs );
		FC.setDataURL(dataURL);
		
		FC.render("FMJSD_chartDIV"+this.chartCounter);
		*/
	},
	
	refreshCharts:function(){
		/*
		document.getElementById("FMJSD_drillCharts").innerHTML="";
		this.chartCounter=0;
		
		*/
		
	},
	
	//showDetails:function(source){
//		
//		//document.getElementById("FMJSD_DrillDetails").innerHTML=getDataFromSource(source);
//		document.getElementById("FMJSD_DrillDetails"+level).innerHTML="";
//		//alert(getDataFromSource(source));
//		document.getElementById("FMJSD_DrillDetails"+level).innerHTML=getDataFromSource(source);
//		
//		
//	}

showDetails:function(){

               document.getElementById("FMJSD_DrillDetails"+level).innerHTML="";
               document.getElementById("FMJSD_DrillDetails"+level).innerHTML=getDataFromSource(arguments);


}



}


/* Aliases for easy usage */
var FusionMapsDrilldownFramework = infosoftglobal.FusionMapsDrilldownFramework ;


