
function MapBarControl(opts_boxStyle, opts_other, opts_callbacks) {
 
}

MapBarControl.prototype = new GControl();


/**
 * Creates a new button to control gzoom and appends to map div.
 * @param {DOM Node} map The div returned by map.getContainer()
 */
MapBarControl.prototype.initButton_ = function(mapDiv) {

  var buttonDiv = document.createElement('div');
  buttonDiv.innerHTML ="<img src='bar1.gif' title='click here to show the shoreline summary' alt='click here to show the shoreline summary'/>",
  buttonDiv.id = 'gbar1-control';
 buttonDiv.style.cursor='pointer';
  buttonDiv.style.zIndex=200;
  buttonDiv.style.width='24px';
    buttonDiv.style.height='24px';
  buttonDiv.style.border='none';
  buttonDiv.style.background= '#FFF';
  mapDiv.appendChild(buttonDiv);
  return buttonDiv;
};



/**
 * Is called by GMap2's addOverlay method. Creates the zoom control
 * divs and appends to the map div.
 * @param {GMap2} map The map that has had this MapBarControl added to it.
 * @return {DOM Object} Div that holds the gzoomcontrol button
 */ 
MapBarControl.prototype.initialize = function(map) {
  var G = this.globals;
  var me = this;
  var mapDiv = map.getContainer();
  //DOM:button
  var buttonDiv = this.initButton_(mapDiv);

  //DOM:map covers


  // add event listeners
  GEvent.addDomListener(buttonDiv, 'click', function(e) {
    me.buttonclick_(e);
  });


  return buttonDiv;
};

/**
 * Required by GMaps API for controls. 
 * @return {GControlPosition} Default location for control
 */
MapBarControl.prototype.getDefaultPosition = function() {
  return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(3, 120));
};

/**
 * Function called when the zoom button's click event is captured.
 */
MapBarControl.prototype.setButtonMode_ = function(mode){

}





/**
 * Function called when the zoom button's click event is captured.
 */
MapBarControl.prototype.buttonclick_ = function(){
  
//	this.intitCover_();
	this.resetView_();
	this.showbars_();
	this.setButtonMode_("zooming");
  
};



MapBarControl.prototype.resetView_ = function(){
	 jg.clear();
	  map.setCenter(new GLatLng(58.077,-96.575),3,G_NORMAL_MAP);
	  
}

   function subGPoints(a,b) {
        return new GPoint(a.x-b.x, a.y-b.y);
      }      

     

MapBarControl.prototype.showbars_ = function(){
	map.setCenter(new GLatLng(58.077,-96.575),3,G_NORMAL_MAP);
	var cnv = document.getElementById("map");
	jgnew = new jsGraphics(cnv);
	
	var varname = "parts";
	var totname = "ratiopart";

	
	
	
	var urlstr = "allhistory.php?provinces=all";
	var request = GXmlHttp.create();
	request.open('GET', urlstr , true);	// request XML from PHP with AJAX call
	request.onreadystatechange = function () {
		if (request.readyState == 4) {
		
			var xmlDoc = request.responseXML;
		//	alert(xmlDoc.
			var provinces = xmlDoc.documentElement.getElementsByTagName("province");
				var tots = new Array();
					tots[0] = 0;
					tots[1] = 0;
					tots[2] = 0;
					tots[3] = 0;
					tots[4] = 0;
			for (var a = 0; a < provinces.length; a++) {
				var ratiotot = provinces[a].getAttribute(totname);
				var centroidxy = (provinces[a].getAttribute('centroid')).split(" ");
			
				var lat = centroidxy[0];
				var lng = centroidxy[1];
				var coord = new GLatLng(lat,lng);
				
							
				 var CDivPixel = map.fromLatLngToDivPixel(map.getCenter());
				var pointDivPixel = map.fromLatLngToDivPixel(coord);
				 var fromCenter = subGPoints(pointDivPixel, CDivPixel); 
				
				//var point = map.fromLatLngToDivPixel(coord);
				var x = fromCenter.x +198;
				var y = fromCenter.y +120;
			
					
			
				for(var b=0;b<5;b++){
					var hexchange = d2h(Math.round((5-b)*50));
					var color = "#aa00"+hexchange;
					jgnew.setColor(color);
					var year = 2003+b
					var yeartext = varname+''+year;
					var voltext = 'vols'+year;
					
					var tot = provinces[a].getAttribute(yeartext);
					var vols = provinces[a].getAttribute(voltext);
					
					var height = tot*ratiotot;
					var amount = tot*1;
					var amount1 = vols*1;
					amount = amount+amount1;
				    tots[b] += amount;
					jgnew.fillRect(x+(b*9),y+(50-height),8,height);//bar
					//jgnew.fillRect(x+150,y+(b*15),10,10);//legend
					jgnew.setColor("000000");
					jgnew.setFont("arial","11px",Font.PLAIN);  
				//	jgnew.drawString(tot,x+(b*9),y+(50-height)); //#
					//jgnew.drawString(year,x+165,y+(b*15)-2);//legend 
				}
			
			
			}
			jgnew.setColor("#FFFFFF");
			jgnew.fillRect(73,33,180,70);//bar
			jgnew.setColor("#000000");
			jgnew.drawRect(73,33,180,70);//bar
		
			
			jgnew.setFont("arial","11px",Font.PLAIN);  
			
			for(var b=0;b<5;b++){
				var hexchange = d2h(Math.round((5-b)*50));
				var color = "#aa00"+hexchange;
				jgnew.setColor(color);
				var year = 2003+b
				jgnew.fillRect(76,36+(b*12),10,10);//bar
			    jgnew.drawString(year,88,35+(b*12));
				 jgnew.drawString(tots[b],120,35+(b*12));
			}
			
				jgnew.paint(); 
		
		}
		
	}
	request.send(null);	

}







