var StepV12=0.048, Top12=22.46, Bottom12=22.25, StepH12=0.12, Left12=114.04, Right12=114.2625;
var StepV14=0.012, Top14=22.43, Bottom14=22.25, StepH14=0.03, Left14=114.04, Right14=114.27; 
var StepV15=0.006,Top15=22.42, Bottom15=22.25, StepH15=0.015,Left15=114.04, Right15=114.28; 

function map_estimated(){
   if(estimated==1){
        if (gFolder ==1){
            map.setMapType (custommapE1);
        }else{
            map.setMapType (custommapE2);
        }
        road5.hide();
        road51.hide();

   }else{
       if (gFolder ==1){
            map.setMapType (custommapD1);
        }else{
            map.setMapType (custommapD2);
        }
        road5.show();
        road51.show();
   }
}
function map_refresh(refreshMap){	// When refreshMap = true, the map will refresh even no update
    var now =  new Date();
	var s=Math.round(now.getTime()/1000);
     GDownloadUrl("Testgetxml.php?" + s, function(data, responseCode) {
      var xml = GXml.parse(data);
      var markers = xml.documentElement.getElementsByTagName("marker");
    if (gNewtime != markers[0].getAttribute("lable")){
        gFolder=markers[0].getAttribute("type");
        gNewtime=markers[0].getAttribute("lable");
        if (estimated!=1){
            if (gFolder ==1){
                map.setMapType (custommapE1);
            }else{
                map.setMapType (custommapE2);
            }
        }else{
           if (gFolder ==1){
                map.setMapType (custommapD1);
            }else{
                map.setMapType (custommapD2);
            }
        }
        writeTime();
    }else{
        //map.setZoom(map.getZoom());
		if (refreshMap)
		{
			map.setMapType(G_NORMAL_MAP);
		    setTimeout("changeback()",1)
		}
    }
    });

}
function changeback()
{
	if (estimated!=1){
            if (gFolder ==1){
                map.setMapType (custommapE1);
            }else{
                map.setMapType (custommapE2);
            }
        }else{
           if (gFolder ==1){
                map.setMapType (custommapD1);
            }else{
                map.setMapType (custommapD2);
            }
        }
        writeTime();
}
function map_fullMap(){
   map.setCenter(new GLatLng(22.335, 114.152),12);
}
function map_up(){
	var newLat;
	var newLng;
	newLat = map.getCenter().lat();
	newLng = map.getCenter().lng();
	if (map.getZoom() == 12){
		if (newLat > (Top12 - StepV12)){
			newLat = Top12;	
		} else {
			newLat = (newLat + StepV12);		
		}
	} else if (map.getZoom() == 14){
		if (newLat > (Top14 - StepV14)){
			newLat = Top14;	
		} else {
			newLat = (newLat + StepV14);		
		}
	}else if (map.getZoom() == 15){
		if (newLat > (Top15 - StepV15)){
			newLat = Top15;	
		} else {
			newLat = (newLat + StepV15);		
		}
	}
	map.panTo (new GLatLng(newLat,newLng));
}
function map_down(){
	var newLat;
	var newLng;
	newLat = map.getCenter().lat();
	newLng = map.getCenter().lng();
	if (map.getZoom() == 12){
		if (newLat < (Bottom12 + StepV12)){
			newLat = Bottom12;	
		} else {
			newLat = (newLat - StepV12);		
		}
	} else if (map.getZoom() == 14){
		if (newLat < (Bottom14 + StepV14)){
			newLat = Bottom14;	
		} else {
			newLat = (newLat - StepV14);		
		}
	}else if (map.getZoom() == 15){
		if (newLat < (Bottom15 + StepV15)){
			newLat = Bottom15;	
		} else {
			newLat = (newLat - StepV15);		
		}
	}
	map.panTo (new GLatLng(newLat,newLng));
   
}
function map_left(){
	var newLat;
	var newLng;
	newLat = map.getCenter().lat();
	newLng = map.getCenter().lng();
	if (map.getZoom() == 12){
		if (newLng < (Left12 + StepH12)){
			newLng = Left12;	
		} else {
			newLng = (newLng - StepH12);		
		}
	} else if (map.getZoom() == 14){
		if (newLng < (Left14 + StepH14)){
			newLng = Left14;	
		} else {
			newLng = (newLng - StepH14);		
		}
	}else if (map.getZoom() == 15){
		if (newLng < (Left15 + StepH15)){
			newLng = Left15;	
		} else {
			newLng = (newLng - StepH15);		
		}
	}
	map.panTo (new GLatLng(newLat,newLng));
   
}
function map_right(){
	var newLat;
	var newLng;
	newLat = map.getCenter().lat();
	newLng = map.getCenter().lng();
	if (map.getZoom() == 12){
		if (newLng > (Right12 - StepH12)){
			newLng = Right12;	
		} else {
			newLng = (newLng + StepH12);		
		}
	} else if (map.getZoom() == 14){
		if (newLng > (Right14 - StepH14)){
			newLng = Right14;	
		} else {
			newLng = (newLng + StepH14);		
		}
	}else if (map.getZoom() == 15){
		if (newLng > (Right15 - StepH15)){
			newLng = Right15;	
		} else {
			newLng = (newLng + StepH15);		
		}
	}
	map.panTo (new GLatLng(newLat,newLng));
   
}
function map_zoomIn(){
	var newLat;
	var newLng;
	newLat = map.getCenter().lat();
	newLng = map.getCenter().lng();
	if (map.getZoom() == 12){
		//to level  14
		if (newLat > Top14){
			newLat = Top14;	
		} 
		if (newLat < Bottom14){
			newLat=Bottom14;	
		}
		if (newLng > Right14){
			newLng=Right14;	
		} 
		if (newLng<Left14){
			newLng=Left14;	
		}
		map.setCenter (new GLatLng(newLat,newLng), 14);
	}else if (map.getZoom() == 14){
		//to level 15
		if (newLat > Top15){
			newLat = Top15;	
		} 
		if (newLat < Bottom15){
			newLat=Bottom15;	
		}
		if (newLng > Right15){
			newLng=Right15;	
		} 
		if (newLng < Left15){
			newLng=Left15;	
		}
		map.setCenter (new GLatLng(newLat,newLng), 15);
	} 
}
function map_zoomOut(){
	var newLat;
	var newLng;
	newLat = map.getCenter().lat();
	newLng = map.getCenter().lng();
	if (map.getZoom() == 14){
		//to level  12
		if (newLat > Top12){
			newLat = Top12;	
		} 
		if (newLat < Bottom12){
			newLat=Bottom12;	
		}
		if (newLng > Right12){
			newLng=Right12;	
		} 
		if (newLng < Left12){
			newLng = Left12;	
		}
		map.setCenter (new GLatLng(newLat,newLng), 12);
	}else if (map.getZoom() == 15){
		//to level 14
		if (newLat > Top14){
			newLat = Top14;	
		} 
		if (newLat < Bottom14){
			newLat=Bottom14;	
		}
		if (newLng > Right14){
			newLng=Right14;	
		} 
		if (newLng<Left14){
			newLng=Left14;	
		}
		map.setCenter (new GLatLng(newLat,newLng), 14);
	}  
	
}
writeTime();
var copyCollection = new GCopyrightCollection('RTIS');
var copyright = new GCopyright(1, new GLatLngBounds(new GLatLng(-90, -180), new GLatLng(90, 180)), 0, "");
copyCollection.addCopyright(copyright);

var map = new GMap2(document.getElementById("mainMap"));

var tilelayersD1 = [new GTileLayer(copyCollection, 12, 15)];
tilelayersD1[0].getTileUrl = CustomGetTileUrlD1;
function CustomGetTileUrlD1(a,b) {
	var now =  new Date();
	var s=Math.round(now.getTime()/300000);
	var f = "http://203.194.149.167/rtis/Testmap_D1.php?n=404&v=w2.21&x="+a.x+"&y="+a.y+"&zoom="+ b + "&feigo=" + s;
	return f;
}
var custommapD1 = new GMapType(tilelayersD1, new GMercatorProjection(18), "Chart", {errorMessage:"Please refresh the map"});
map.addMapType(custommapD1);

var tilelayersD2 = [new GTileLayer(copyCollection, 12, 15)];
tilelayersD2[0].getTileUrl = CustomGetTileUrlD2;
function CustomGetTileUrlD2(a,b) {
	var now =  new Date();
	var s=Math.round(now.getTime()/300000);
	var f = "http://203.194.149.167/rtis/Testmap_D2.php?n=404&v=w2.21&x="+a.x+"&y="+a.y+"&zoom="+ b + "&feigo=" + s;
	return f;
}
var custommapD2 = new GMapType(tilelayersD2, new GMercatorProjection(18), "Chart", {errorMessage:"Please refresh the map"});
map.addMapType(custommapD2);

var tilelayersE1 = [new GTileLayer(copyCollection, 12, 15)];
tilelayersE1[0].getTileUrl = CustomGetTileUrlE1;
function CustomGetTileUrlE1(a,b) {
	var now =  new Date();
	var s=Math.round(now.getTime()/300000);
	var f = "http://203.194.149.167/rtis/Testmap_E1.php?n=404&v=w2.21&x="+a.x+"&y="+a.y+"&zoom="+ b + "&feigo=" + s;
	return f;
}
var custommapE1 = new GMapType(tilelayersE1, new GMercatorProjection(18), "Chart", {errorMessage:"Please refresh the map"});
map.addMapType(custommapE1);

var tilelayersE2 = [new GTileLayer(copyCollection, 12, 15)];
tilelayersE2[0].getTileUrl = CustomGetTileUrlE2;
function CustomGetTileUrlE2(a,b) {
	var now =  new Date();
	var s=Math.round(now.getTime()/300000);
	var f = "http://203.194.149.167/rtis/Testmap_E2.php?n=404&v=w2.21&x="+a.x+"&y="+a.y+"&zoom="+ b + "&feigo=" + s;
	return f;
}
var custommapE2 = new GMapType(tilelayersE2, new GMercatorProjection(18), "Chart", {errorMessage:"Please refresh the map"});
map.addMapType(custommapE2);

if (gFolder ==1){
	map.setCenter (new GLatLng(22.335, 114.152),12 ,custommapE1 );
}else{
	map.setCenter (new GLatLng(22.335, 114.152),12 ,custommapE2 );
}

map.disableDragging();
GEvent.addListener(map, "click", function(marker, point) {
	if (marker) {
} else {
	var newLat;
	var newLng;
	newLat = point.lat();
	newLng = point.lng();
	if (map.getZoom() == 12){
		//to level  14
		if (newLat > Top14){
			newLat = Top14;	
		} 
		if (newLat < Bottom14){
			newLat=Bottom14;	
		}
		if (newLng > Right14){
			newLng=Right14;	
		} 
		if (newLng<Left14){
			newLng=Left14;	
		}
		map.setCenter (new GLatLng(newLat,newLng), 14);
	}else if (map.getZoom() == 14){
		//to level 15
		if (newLat > Top15){
			newLat = Top15;	
		} 
		if (newLat < Bottom15){
			newLat=Bottom15;	
		}
		if (newLng > Right15){
			newLng=Right15;	
		} 
		if (newLng < Left15){
			newLng=Left15;	
		}
		map.setCenter (new GLatLng(newLat,newLng), 15);
	} 
	}
}); 

GEvent.addListener(map, "zoomend", function(oldLevel, newLevel){
	if (newLevel==12){
		myLegend.show();
		myNotes.show();
		myAward.show();
		myLegend2.hide();
		arrow11.hide();
		arrow12.hide();
		arrow13.hide();
		arrow21.hide();
		arrow22.hide();
		arrow23.hide();
	}else if (newLevel==14){ 
		myLegend.hide();
		myNotes.hide();
		myAward.hide();
		myLegend2.show();
		arrow11.show();
		arrow12.show();
		arrow13.show();
		arrow21.hide();
		arrow22.hide();
		arrow23.hide();
	}else if (newLevel==15){
		myLegend.hide();
		myNotes.hide();
		myAward.hide();
		myLegend2.show();
		arrow11.hide();
		arrow12.hide();
		arrow13.hide();
		arrow21.show();
		arrow22.show();
		arrow23.show();
	}
});
//map.addControl(new GSmallMapControl());
var baseIcon = new GIcon();
baseIcon.shadow = "";
baseIcon.iconSize = new GSize(20, 20);
function createMarker(point, index) {
	var icon = new GIcon(baseIcon);
	if (index==1){
		icon.iconAnchor = new GPoint(0, 0) ;
		icon.image = "../mapfiles/road1.png";
	} else if (index==2){
		icon.iconAnchor = new GPoint(0, 0);
		icon.image = "../mapfiles/road2.png";
	} else  if (index==7){
		icon.iconAnchor = new GPoint(0, 0);
		icon.image = "../mapfiles/road7.png";
	} else  if (index==8){
		icon.iconAnchor = new GPoint(0, 0);
		icon.image = "../mapfiles/road8.png";
	} else  if (index==5){
		icon.iconAnchor = new GPoint(19, 0);
		icon.image = "../mapfiles/road5.png";
	} else  if (index==3){
		icon.iconAnchor = new GPoint(19, 0);
		icon.image = "../mapfiles/road3.png";
	}
	var marker = new GMarker(point, icon, true);
	return marker;
}
var baseIcon14 = new GIcon();
baseIcon14.shadow = "";
baseIcon14.iconSize = new GSize(14, 14);
function createArrow14(point, index) {
	var icon = new GIcon(baseIcon14);
	if (index==11){
		icon.iconAnchor = new GPoint(0, 0);
		icon.image = "../mapfiles/arrow14_1.png";
	} else  if (index==12){
		icon.iconAnchor = new GPoint(0, 0);
		icon.image = "../mapfiles/arrow14_2.png";
	} else  if (index==13){
		icon.iconAnchor = new GPoint(0, 0);
		icon.image = "../mapfiles/arrow14_3.png";
	}
	var marker = new GMarker(point, icon, true);
	return marker;
}
var baseIcon15 = new GIcon();
baseIcon15.shadow = "";
baseIcon15.iconSize = new GSize(20, 20);
function createArrow15(point, index) {
	var icon = new GIcon(baseIcon15);
	if (index==21){
		icon.iconAnchor = new GPoint(0, 0);
		icon.image = "../mapfiles/arrow15_1.png";
	} else  if (index==22){
		icon.iconAnchor = new GPoint(0, 0);
		icon.image = "../mapfiles/arrow15_2.png";
	} else  if (index==23){
		icon.iconAnchor = new GPoint(0, 0);
		icon.image = "../mapfiles/arrow15_3.png";
	}
	var marker = new GMarker(point, icon, true);
	return marker;
}

var road1=(createMarker(new GLatLng(22.338708,114.181595), 1));
var road2=(createMarker(new GLatLng(22.36,114.212), 2));
//var road3=(createMarker(new GLatLng(22.330,114.145632), 3));
var road3=(createMarker(new GLatLng(22.3286516493,114.1463422631), 3));	// After add CCTV
var road31=(createMarker(new GLatLng(22.378,114.0636), 3));
var road5=(createMarker(new GLatLng(22.362500,114.118000), 5));
var road51=(createMarker(new GLatLng(22.3237,114.199), 5));
var road7=(createMarker(new GLatLng(22.3148,114.241247), 7));
var road8=(createMarker(new GLatLng(22.342000,114.054600), 8));
map.addOverlay (road1);
map.addOverlay (road2);
map.addOverlay (road3);
map.addOverlay (road31);
map.addOverlay (road5);
map.addOverlay (road51);
map.addOverlay (road7);
map.addOverlay (road8);
road5.hide();
road51.hide();

var arrow11=(createArrow14(new GLatLng(22.3056,114.1592), 11));
var arrow12=(createArrow14(new GLatLng(22.3046,114.1807), 12));
var arrow13=(createArrow14(new GLatLng(22.3023,114.2345), 13));
var arrow21=(createArrow15(new GLatLng(22.305,114.1591), 21)); 
var arrow22=(createArrow15(new GLatLng(22.3036,114.18042), 22));
var arrow23=(createArrow15(new GLatLng(22.3018,114.234123), 23));
map.addOverlay (arrow11); 
map.addOverlay (arrow12);  
map.addOverlay (arrow13); 
map.addOverlay (arrow21);  
map.addOverlay (arrow22); 
map.addOverlay (arrow23); 
arrow11.hide();
arrow12.hide(); 
arrow13.hide(); 
arrow21.hide(); 
arrow22.hide(); 
arrow23.hide();

function Legend() {}
Legend.prototype = new GControl();
Legend.prototype.initialize = function(map) {
	var container = document.createElement("div");
	var strNotes ;
	strNotes = '<table width="180" border="0" cellspacing="0" cellpadding="0">';
	strNotes = strNotes + '<tr><td colspan="2"><span class="style11">Legend: </span></td></tr>';
	strNotes = strNotes +'<tr><td><span class="style11"><img src=\'./mapfiles/cctv.gif\'></span></td><td><span class="style11">Snapshot of traffic condition</span></td></tr>';
	strNotes = strNotes +'<tr><td><span class="style11"><img src=\'./mapfiles/jtis_loc2.gif\'></span></td><td><span class="style11">Journey time indicator</span></td></tr>';
	strNotes = strNotes + '<tr><td colspan="2"><span class="style11"><br></span></td></tr>';
	strNotes = strNotes + '<tr><td colspan="2"><span class="style11">Notes: </span></td></tr>';
	strNotes = strNotes +'</table>';
	container.innerHTML = strNotes ;
	map.getContainer().appendChild(container);
	this.container =container;
	return container;
}
Legend.prototype.getDefaultPosition = function() {
	return new GControlPosition(G_ANCHOR_BOTTOM_LEFT, new GSize(5, 75));
}
Legend.prototype.hide = function() {
	this.container.style.display='none';
}
Legend.prototype.show = function() {
	this.container.style.display='';
}
var myLegend = new Legend();
map.addControl(myLegend); 

function Legend2() {}
Legend2.prototype = new GControl();
Legend2.prototype.initialize = function(map) {
	var container = document.createElement("div");
	var strNotes ;
	strNotes = '<table width="180" border="0" cellspacing="0" cellpadding="0">';
	strNotes = strNotes + '<tr><td colspan="2"><span class="style11">Legend: </span></td></tr>';
	strNotes = strNotes +'<tr><td><span class="style11"><img src=\'./mapfiles/cctv.gif\'></span></td><td><span class="style11">Snapshot of traffic condition</span></td></tr>';
	strNotes = strNotes +'<tr><td><span class="style11"><img src=\'./mapfiles/jtis_loc2.gif\'></span></td><td><span class="style11">Journey time indicator</span></td></tr>';
	strNotes = strNotes +'</table>';
	container.innerHTML = strNotes ;
	map.getContainer().appendChild(container);
	this.container =container;
	return container;
}
Legend2.prototype.getDefaultPosition = function() {
	return new GControlPosition(G_ANCHOR_BOTTOM_LEFT, new GSize(5, 5));
}
Legend2.prototype.hide = function() {
	this.container.style.display='none';
}
Legend2.prototype.show = function() {
	this.container.style.display='';
}
var myLegend2 = new Legend2();
map.addControl(myLegend2); 
myLegend2.hide();

function Notes() {}
Notes.prototype = new GControl();
Notes.prototype.initialize = function(map) {
	var container = document.createElement("div");
	var strNotes ;
	strNotes = '<table width="380" border="0" cellspacing="0" cellpadding="0">';
// Add by Henry on 23 Feb 2007
//	strNotes = strNotes + '<tr><td colspan="2"><span class="style11">Legend: </span></td></tr>';
//	strNotes = strNotes +'<tr><td><span class="style11"><img src=\'./mapfiles/cctv.gif\'></span></td><td><span class="style11">Snapshots of traffic condition</span></td></tr>';
//	strNotes = strNotes + '<tr><td colspan="2"><span class="style11"><br></span></td></tr>';
// End Added
//	strNotes = strNotes + '<tr><td colspan="2"><span class="style11">Notes: </span></td></tr>';
	strNotes = strNotes +'<tr valign="top"><td><span class="style11">1.</span></td>';
	strNotes = strNotes +'<td><span class="style11"><span class="style11">Directly deduced traffic speed is based on actual traffic movement data</span></td></tr>';
	strNotes = strNotes +'<tr><td><span class="style11"></span></td><td><span class="style11">between toll roads.</span></td></tr>';
	strNotes = strNotes +'<tr><td><span class="style11">2.</span></td><td><span class="style11">Indirectly deduced traffic speed is based on 1. and past traffic flow data.</span></td></tr>';
	strNotes = strNotes +'<tr><td><span class="style11">3.</span></td><td><span class="style11">Data on screen will be updated every 5 minutes automatically.</span></td></tr>';
	strNotes = strNotes +'<tr><td><span class="style11">4.</span></td><td><span class="style11">Data are provided by Autotoll Ltd. and Hong Kong Polytechnic University.</span></td></tr>';
	strNotes = strNotes +'<tr><td><span class="style11">5.</span></td><td><span class="style11">Best viewed at 1024x768 resolution.</span></td></tr>';
	strNotes = strNotes +'</table>';
	container.innerHTML = strNotes ;
	map.getContainer().appendChild(container);
	this.container =container;
	return container;
}
Notes.prototype.getDefaultPosition = function() {
	return new GControlPosition(G_ANCHOR_BOTTOM_LEFT, new GSize(5, 5));
}
Notes.prototype.hide = function() {
	this.container.style.display='none';
}
Notes.prototype.show = function() {
	this.container.style.display='';
}
var myNotes = new Notes();
map.addControl(myNotes);

// 1
function Controls1() {}
Controls1.prototype = new GControl();
Controls1.prototype.initialize = function(map) {
	var container = document.createElement("div");
	var strControls ;
	//strControls= '<table border="0" cellpadding="0" cellspacing="0" width="147"><tr><td align="right">';
	strControls = '';
	strControls = strControls + '<table border="0" cellpadding="0" cellspacing="0" width="147"><tr>';
	strControls = strControls + '<td rowspan="3" colspan="3"><a name="a_Image44" id="a_Image44" title="Show Indirectly Deduced Traffic Speed" style="cursor:pointer;" onClick="map_estimated();';
	strControls = strControls + 'if(estimated==1) {estimated=0;Image44.src=\'images/en_deduced_over.gif\';hidden_div();}';
	strControls = strControls + 'else{ estimated=1;Image44.src=\'images/en_estimated_over.gif\';show_div();}" onMouseOut="if(estimated==0)';
	strControls = strControls + '{Image44.src=\'images/en_bttn_deduced.gif\';}else{Image44.src=\'images/en_bttn_estimated_only.gif\';}"';
	strControls = strControls + ' onMouseOver="if(estimated==1){ MM_swapImage(\'Image44\',\'\',\'images/en_estimated_over.gif\',1) } ';
	strControls = strControls + 'else {Image44.src=\'images/en_deduced_over.gif\'; }"><img src="images/en_bttn_deduced.gif" name="Image44" border="0"></a></td>';
	strControls = strControls + '</tr></table>';
	
	//strControls = strControls + '</td></tr></table>';
	container.innerHTML = strControls ;
	map.getContainer().appendChild(container);
	return container;
}
Controls1.prototype.getDefaultPosition = function() {
	return new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(0, 0));
}
map.addControl(new Controls1());

// Added By Henry on 18 April 2007
// 1_1
function Controls1_1() {}
Controls1_1.prototype = new GControl();
Controls1_1.prototype.initialize = function(map) {
	var container = document.createElement("div");
	var strControls ;
	strControls = '';
	strControls = strControls + '<table border="0" cellpadding="0" cellspacing="0" width="186"><tr>';
	strControls = strControls + '<td><a title="Show Kln Approach to CHT" style="cursor:pointer;" onClick="map_showKln()" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(\'Image1_1_2\',\'\',\'images/approach_kln_over.gif\',1)"><img src="images/approach_kln.gif" name="Image1_1_2" border="0"></a></td>';
	strControls = strControls + '</tr></table>';	
	strControls = strControls + '<table border="0" cellpadding="0" cellspacing="0" width="186"><tr>';
	strControls = strControls + '<td><a title="Show HK Approach to CHT" style="cursor:pointer;" onClick="map_showHK()" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(\'Image1_1_1\',\'\',\'images/approach_hk_over.gif\',1)"><img src="images/approach_hk.gif" name="Image1_1_1" border="0"></a></td>';
	strControls = strControls + '</tr></table>';	
	container.innerHTML = strControls ;
	map.getContainer().appendChild(container);
	return container;
}
Controls1_1.prototype.getDefaultPosition = function() {
	return new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(0, 60));
}
map.addControl(new Controls1_1()); 

// 2
function Controls2() {}
Controls2.prototype = new GControl();
Controls2.prototype.initialize = function(map) {
	var container = document.createElement("div");
	var strControls ;
	//strControls= '<table border="0" cellpadding="0" cellspacing="0" width="60"><tr><td align="right">'; 
	strControls = '';
	strControls = strControls + '<table border="0"  cellpadding="0" cellspacing="0" width="60"><tr>';
	strControls = strControls + '<td rowspan="3"><a title="Go West" style="cursor:pointer;" onClick="map_left()" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(\'Image38\',\'\',\'images/bttn_left_over.gif\',1)"><img src="images/bttn_r1_c6.gif" name="Image38" border="0"></a></td>';
	strControls = strControls + '<td rowspan="3"><img name="bttn_r1_c7" src="images/bttn_r1_c7.gif" width="1" height="45" border="0" alt=""></td>';
	strControls = strControls + '<td><a title="Go North" style="cursor:pointer;" onClick="map_up()" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(\'Image39\',\'\',\'images/bttn_up_over.gif\',1)"><img src="images/bttn_r1_c8.gif" name="Image39" border="0"></a></td>';
	strControls = strControls + '<td rowspan="3"><img name="bttn_r1_c9" src="images/bttn_r1_c9.gif" width="1" height="45" border="0" alt=""></td>';
	strControls = strControls + '<td rowspan="3"><a title="Go East" style="cursor:pointer;" onClick="map_right()" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(\'Image41\',\'\',\'images/bttn_right_over.gif\',1)"><img src="images/bttn_r1_c10.gif" name="Image41" border="0"></a></td>';
	strControls = strControls + '<td><img src="images/spacer.gif" width="1" height="21" border="0" alt=""></td></tr>';
	strControls = strControls + '<tr><td><img name="bttn_r2_c8" src="images/bttn_r2_c8.gif" width="29" height="1" border="0" alt=""></td>';
	strControls = strControls + '<td><img src="images/spacer.gif" width="1" height="1" border="0" alt=""></td></tr>';
	strControls = strControls + '<tr><td><a title="Go South" style="cursor:pointer;" onClick="map_down()" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(\'Image40\',\'\',\'images/bttn_down_over.gif\',1)"><img src="images/bttn_r3_c8.gif" name="Image40"  border="0"></a></td>';
	strControls = strControls + '<td><img src="images/spacer.gif" width="1" height="23" border="0" alt=""></td></tr></table>';
	
	//strControls = strControls + '</td></tr></table>';
	container.innerHTML = strControls ;
	map.getContainer().appendChild(container);
	return container;
}
Controls2.prototype.getDefaultPosition = function() {
	return new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(0, 180));
}
map.addControl(new Controls2()); 

// 3
function Controls3() {}
Controls3.prototype = new GControl();
Controls3.prototype.initialize = function(map) {
	var container = document.createElement("div");
	var strControls ;
	//strControls= '<table border="0" cellpadding="0" cellspacing="0" width="30"><tr><td align="right">'; 
	strControls = '';
	strControls = strControls + '<table border="0" cellpadding="0" cellspacing="0" width="30"><tr>';
	strControls = strControls + '<td><a title="Refresh" style="cursor:pointer;" onClick="map_refresh(true)" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(\'Image37\',\'\',\'images/bttn_refesh_over.gif\',1)"><img src="images/bttn_r1_c4.gif" name="Image37" border="0"></a></td>';
	strControls = strControls + '</tr></table>';
	strControls = strControls + '<table border="0" cellpadding="0" cellspacing="0" width="1"><tr>';
	strControls = strControls + '<td><a title="Map Overview" style="cursor:pointer;" onClick="map_fullMap()" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(\'Image36\',\'\',\'images/bttn_f_map_over.gif\',1)"><img src="images/bttn_r1_c5.gif" name="Image36" border="0"></a></td>';
	strControls = strControls + '</tr></table>';
	strControls = strControls + '<table border="0" cellpadding="0" cellspacing="0" width="1"><tr>';
	strControls = strControls + '<td><a title="Zoom In" style="cursor:pointer;" onClick="map_zoomIn()" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(\'Image42\',\'\',\'images/bttn_zoom_in_over.gif\',1)"><img src="images/bttn_r1_c11.gif" name="Image42" border="0"></a></td>';
	strControls = strControls + '</tr></table>';
	strControls = strControls + '<table border="0" cellpadding="0" cellspacing="0" width="1"><tr>';
	strControls = strControls + '<td><a title="Zoom Out" style="cursor:pointer;" onClick="map_zoomOut()" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(\'Image43\',\'\',\'images/bttn_zoom_out_over.gif\',1)"><img src="images/bttn_r1_c12.gif" name="Image43" border="0"></a></td>';
	strControls = strControls + '</tr></table>';
	//strControls = strControls + '</td></tr></table>';
	container.innerHTML = strControls ;
	map.getContainer().appendChild(container);
	return container;
}
Controls3.prototype.getDefaultPosition = function() {
	return new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(0, 225));
}
map.addControl(new Controls3());

// Add by Henry on 3 April 2007
// 4
/*function Controls4() {}
Controls4.prototype = new GControl();
Controls4.prototype.initialize = function(map) {
	var container = document.createElement("div");
	strNotes = '<table width="330" border="0" cellspacing="0" cellpadding="0">';
	strNotes = strNotes +'<tr><td><span class="style16">The cross harbour journey time indicator is under maintenance, we apologize for any inconvenience caused.</span></td></tr>';
//	strNotes = strNotes +'<tr><td><span class="style16">We apologize for any inconvenience thus caused.</span></td></tr>';
	strNotes = strNotes +'</table>';
	container.innerHTML = strNotes ;
	map.getContainer().appendChild(container);
	return container;
}
Controls4.prototype.getDefaultPosition = function() {
	return new GControlPosition(G_ANCHOR_BOTTOM_RIGHT, new GSize(0, 0));
}
map.addControl(new Controls4());*/

// Add by Henry on 2 March 2009
function Controls5() {}
Controls5.prototype = new GControl();
Controls5.prototype.initialize = function(map) {
	var container = document.createElement("div");
	strNotes = '<table width="260" border="0" cellspacing="0" cellpadding="0">';
	strNotes = strNotes +'<tr><td><img src="images/rtis_award.gif" name="Award" border="0"></td></tr>';
	strNotes = strNotes +'<tr><td><span class="style20">Best Public Service Application</span></td></tr>';
	strNotes = strNotes +'<tr><td><span class="style20">(Small Scale Project) Certificate of Merit</span></td></tr>';
	strNotes = strNotes +'<tr><td><span class="style20">最佳公共服務應用(小型項目)優異證書</span></td></tr>';
	strNotes = strNotes +'</table>';
	container.innerHTML = strNotes ;
	map.getContainer().appendChild(container);
	this.container =container;
	return container;
}
Controls5.prototype.getDefaultPosition = function() {
	return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(5, 5));
}
Controls5.prototype.hide = function() {
	this.container.style.display='none';
}
Controls5.prototype.show = function() {
	this.container.style.display='';
}
var myAward = new Controls5();
map.addControl(myAward);

// Add by Henry on 4 April 2009 for takover JTISHK
// 6
/*function Controls6() {}
Controls6.prototype = new GControl();
Controls6.prototype.initialize = function(map) {
	var container = document.createElement("div");
	strNotes = '<table width="330" border="0" cellspacing="0" cellpadding="0">';
	strNotes = strNotes +'<tr><td><span class="style17">The Journey Time Indicator is undergoing enhancement works; and there may be difference in the journey time displayed between this Traffic Speed Map and the Journey Time Indicators sited on Hong Kong Island. We apologize for any inconvenience caused.</span></td></tr>';
//	strNotes = strNotes +'<tr><td><span class="style16">We apologize for any inconvenience thus caused.</span></td></tr>';
	strNotes = strNotes +'</table>';
	container.innerHTML = strNotes ;
	map.getContainer().appendChild(container);
	return container;
}
Controls6.prototype.getDefaultPosition = function() {
	return new GControlPosition(G_ANCHOR_BOTTOM_RIGHT, new GSize(0, 0));
}
map.addControl(new Controls6());
*/
//add cctv
function createCCTV(point,html) {
	var icon = new GIcon();
	icon.image = "./mapfiles/cctv.gif";
	icon.shadow = "";
	icon.iconSize = new GSize(14, 12);
	//icon.shadowSize = new GSize(22, 20);
	icon.iconAnchor = new GPoint(7, 6);
	//icon.infoWindowAnchor = new GPoint(5, 1);
	//var marker = new GMarker(point, icon);
	var marker = new GMarker(point, {title:'Snapshot of traffic condition', icon:icon});
	GEvent.addListener(marker, "click", function() {
		marker.openLittleInfoWindow(html);
	});
	return marker;
}  

var request = GXmlHttp.create();
request.open("GET", "cctv.xml", true);
request.onreadystatechange = function() {
if (request.readyState == 4) {
	var xmlDoc = request.responseXML;
	var markers = xmlDoc.documentElement.getElementsByTagName("marker");
    for (var i = 0; i < markers.length; i++) {
		var lat = parseFloat(markers[i].getAttribute("lat"));
		var lng = parseFloat(markers[i].getAttribute("lng"));
		var point = new GLatLng(lat,lng);
		var pid = markers[i].getAttribute("id");
		var html = '<iframe width=320 height=284 frameborder="0" scrolling="no" src="http://203.194.149.167/rtis/opencctv.php?flag=1&dot_id=' + pid + '&lang=en"></iframe>'
		var marker = createCCTV(point,html);
		map.addOverlay(marker);
  }
  }
}
request.send(null);  

//add JTIS gantry by henry on 22 March 2007
function createJTIS(point,html,pid,iwidth,iheight) {
	var icon = new GIcon();
	icon.image = "./mapfiles/jtis_" + pid + ".gif";
	icon.shadow = "";
	icon.iconSize = new GSize(iwidth, iheight);
	//icon.shadowSize = new GSize(22, 20);
	icon.iconAnchor = new GPoint(iwidth/2, iheight/2);
	//icon.infoWindowAnchor = new GPoint(5, 1);
//	var marker = new GMarker(point, icon);
	var marker = new GMarker(point, {title:'Journey time indicator', icon:icon});
	GEvent.addListener(marker, "click", function() {
		marker.openLittleInfoWindow(html);
	});
	return marker;
}  

var request2 = GXmlHttp.create();
request2.open("GET", "jtis.xml", true);
request2.onreadystatechange = function() {
if (request2.readyState == 4) {
	var xmlDoc = request2.responseXML;
	var markers = xmlDoc.documentElement.getElementsByTagName("marker");
    for (var i = 0; i < markers.length; i++) {
		var lat = parseFloat(markers[i].getAttribute("lat"));
		var lng = parseFloat(markers[i].getAttribute("lng"));
		var point = new GLatLng(lat,lng);
		var pid = markers[i].getAttribute("id");
		var iwidth = parseFloat(markers[i].getAttribute("iwidth"));
		var iheight = parseFloat(markers[i].getAttribute("iheight"));
		var html = '<iframe width=300 height=110 frameborder="0" scrolling="no" src="/rtis/jtis_indicator.php?loc_id=' + pid + '&lang=en"></iframe>';
		var marker = createJTIS(point,html,pid,iwidth,iheight);
		map.addOverlay(marker);
  }
  }
}
request2.send(null);  

//add approach HK abd Kln by henry on 19 April 2007
function map_showHK() {
	map.setCenter(new GLatLng(22.281420, 114.181761),14);
	map_deduced();
}

function map_showKln() {
	map.setCenter(new GLatLng(22.305301, 114.181473),14);
	map_deduced();
}

function map_deduced() {
	if (gFolder ==1){
		map.setMapType (custommapD1);
	}else{
		map.setMapType (custommapD2);
	}
	road5.show();
	road51.show();

	estimated=1;
	Image44.src='images/en_bttn_estimated_only.gif';
	show_div();
}