var map="";
var map2="";
var marker2="";
var cid="";
var gmarkers = [];
var controls = [];
var mrkrCount = 0;
var pex = [];
pex[0] = "US map";
pex[1] = "Houston";
pex[2] = "Las Vegas";
pex[3] = "Los Angeles";
pex[4] = "Philadelphia";
pex[5] = "San Francisco";
pex[6] = "Miami";
pex[7] = "New York";
pex[8] = "Washington DC";
pex[9] = "Seattle";
pex[10] = "Phoenix";
pex[11] = "Dallas";
pex[12] = "Chicago";
pex[13] = "Atlanta";
pex[14] = "Detroit";
pex[15] = "Denver";
pex[16] = "Boston";
pex[17] = "Minneapolis";
pex[18] = "San Diego";
pex[19] = "St. Louis";
pex[20] = "Cleveland";
pex[21] = "Tampa";
var ltex = [];
ltex[0] = 41.508;
ltex[1] = 29.6224;
ltex[2] = 36.1888;
ltex[3] = 33.77686;
ltex[4] = 39.9844;
ltex[5] = 37.7577;
ltex[6] = 26.0123;
ltex[7] = 40.7857;
ltex[8] = 38.882;
ltex[9] = 47.631;
ltex[10] = 33.504;
ltex[11] = 32.8219;
ltex[12] = 41.8491;
ltex[13] = 33.747;
ltex[14] = 42.308;
ltex[15] = 39.777;
ltex[16] = 42.346;
ltex[17] = 44.984;
ltex[18] = 32.78;
ltex[19] = 38.64;
ltex[20] = 41.43;
ltex[21] = 27.89;

var lnex = [];
lnex[0] = -96.679;
lnex[1] = -95.1443;
lnex[2] = -115.16;
lnex[3] = -118.21014;
lnex[4] = -75.1513;
lnex[5] = -122.1515;
lnex[6] = -80.1452;
lnex[7] = -73.899;
lnex[8] = -77.058;
lnex[9] = -122.227;
lnex[10] = -112.154;
lnex[11] = -97.0147;
lnex[12] = -87.64343;
lnex[13] = -84.386;
lnex[14] = -83.321;
lnex[15] = -104.993;
lnex[16] = -71.048;
lnex[17] = -93.244;
lnex[18] = -117.15;
lnex[19] = -90.258;
lnex[20] = -81.72;
lnex[21] = -82.51;

var zex = [];
zex[0] = 3;
zex[1] = 9;
zex[2] = 11;
zex[3] = 9;
zex[4] = 9;
zex[5] = 9;
zex[6] = 9;
zex[7] = 11;
zex[8] = 9;
zex[9] = 10;
zex[10] = 9;
zex[11] = 9;
zex[12] = 9;
zex[13] = 9;
zex[14] = 9;
zex[15] = 9;
zex[16] = 9;
zex[17] = 9;
zex[18] = 9;
zex[19] = 9;
zex[20] = 9;
zex[21] = 9;

var wcv = [];
wcv[1]= "http://sim_fdot.smartraveler.com/hou/houcam1.jpg";
wcv[2]= "http://www.polotowers.com/webcam/image.jpg";
wcv[3]= "http://abclocal.go.com/three/kabc/webcam/web2-1.jpg";
wcv[4]= "http://abclocal.go.com/three/wpvi/webcam/cam_3.jpg";
wcv[5]= "http://static.cbslocal.com/cbs/kpix/webcams/baycam.jpg";
wcv[6]= "http://images.ibsys.com/mia/images/weather/auto/towercam_640x480.jpg";
wcv[7]= "http://63.229.55.11/ec_metros/ourcams/empirenorth.jpg";
wcv[8]= "http://209.178.198.74/ec_metros/ourcams/washingtondc.jpg";
wcv[9]= "http://images.ibsys.com/sea/images/weather/auto/queenannecam_640x480.jpg";
wcv[10]= "http://www.phoenixvis.net/images/photos-main/somt1.jpg";
wcv[11]= "http://www.wfaa.com/sharedcontent/dws/img/standing/cams/wfaahuge.jpg";
wcv[12]= "http://63.229.55.11/ec_metros/ourcams/field.jpg";
wcv[13]= "http://images.ibsys.com/atl/images/weather/auto/towercam1_640x480.jpg";
wcv[14]= "http://images.ibsys.com/det/images/weather/auto/windsorcam_640x480.jpg";
wcv[15]= "http://apcd.state.co.us/psi/chpark.jpg";
wcv[16]= "http://63.229.55.11/ec_metros/ourcams/bostonaqu2.jpg";
wcv[17]= "http://www.mwhazecam.net/images/photos-main/STPAUL.JPG";
wcv[18]= "http://archive.hpwren.ucsd.edu/I700/LaJollaCoast/Data/TODAY/CURRENT-large.jpg";
wcv[19]= "http://www.ksdk.com/webcam/camera3.jpg";
wcv[20]= "http://www.wkyc.com/images/webcams/cam1/Cam1-0.jpg";
wcv[21]= "http://media.myfoxtampabay.com/cams/cam.jpg";


var prov = "";

function gup( name )
{
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var tmpURL = window.location.href;
  var results = regex.exec( tmpURL );
  if( results == null )
    return "";
  else
    return results[1];
}

function shiftmap2(latc,lonc,zc)
{
    		map2.removeOverlay(marker2);											 
				map2.setCenter(new GLatLng(latc,lonc),zc);
				var point = new GLatLng(latc,lonc);
   			marker2= new GMarker(point);
        map2.addOverlay(marker2);
}

function firstMap2(lat,lon)
{

				map2 = new GMap2(document.getElementById("map2"));
        map2.addControl(new GSmallZoomControl(),new GControlPosition(G_ANCHOR_TOP_LEFT,new GSize(10,30)) );
        map2.addControl(new GMapTypeControl());

}				

function MainMarkers(shl) {
  clearMarkers();
	for (i=1; i<22; i++){
			var point = new GLatLng(ltex[i],lnex[i]);
      var marker = new GMarker(point,{title:pex[i]});
			if(i==1) {
						var handle = GEvent.addListener(marker, "click", function() {
						if (shl!=1){
      	    document.drop_list.Category.value = pex[1];
      			SelectSubCat();
						}
						else
								window.location="http://www.cammap.net/webcam.html?city=1";
        });
			}
			if(i==2) {
						var handle = GEvent.addListener(marker, "click", function() {
					if (shl!=1){
      	    document.drop_list.Category.value = pex[2];
      			SelectSubCat();
						}
						else
								window.location="http://www.cammap.net/webcam.html?city=2";

        });
			}
			if(i==3) {
						var handle = GEvent.addListener(marker, "click", function() {
					if (shl!=1){
      	    document.drop_list.Category.value = pex[3];
      			SelectSubCat();
						}
						else
								window.location="http://www.cammap.net/webcam.html?city=3";

        });
			}
			if(i==4) {
						var handle = GEvent.addListener(marker, "click", function() {
					if (shl!=1){
      	    document.drop_list.Category.value = pex[4];
      			SelectSubCat();
						}
						else
								window.location="http://www.cammap.net/webcam.html?city=4";

        });
			}
			if(i==5) {
						var handle = GEvent.addListener(marker, "click", function() {
					if (shl!=1){
      	    document.drop_list.Category.value = pex[5];
      			SelectSubCat();
						}
						else
								window.location="http://www.cammap.net/webcam.html?city=5";

        });
			}
			if(i==6) {
						var handle = GEvent.addListener(marker, "click", function() {
					if (shl!=1){
      	    document.drop_list.Category.value = pex[6];
      			SelectSubCat();
						}
						else
								window.location="http://www.cammap.net/webcam.html?city=6";

        });
			}
			if(i==7) {
						var handle = GEvent.addListener(marker, "click", function() {
					if (shl!=1){
      	    document.drop_list.Category.value = pex[7];
      			SelectSubCat();
						}
						else
								window.location="http://www.cammap.net/webcam.html?city=7";

        });
			}
			if(i==8) {
						var handle = GEvent.addListener(marker, "click", function() {
					if (shl!=1){
      	    document.drop_list.Category.value = pex[8];
      			SelectSubCat();
						}
						else
								window.location="http://www.cammap.net/webcam.html?city=8";

        });
			}
			if(i==9) {
						var handle = GEvent.addListener(marker, "click", function() {
					if (shl!=1){
      	    document.drop_list.Category.value = pex[9];
      			SelectSubCat();
						}
						else
								window.location="http://www.cammap.net/webcam.html?city=9";

        });
			}
			if(i==10) {
						var handle = GEvent.addListener(marker, "click", function() {
					if (shl!=1){
      	    document.drop_list.Category.value = pex[10];
      			SelectSubCat();
						}
						else
								window.location="http://www.cammap.net/webcam.html?city=10";

        });
			}
			if(i==11) {
						var handle = GEvent.addListener(marker, "click", function() {
					if (shl!=1){
      	    document.drop_list.Category.value = pex[11];
      			SelectSubCat();
						}
						else
								window.location="http://www.cammap.net/webcam.html?city=11";

        });
			}
			if(i==12) {
  	       var handle = GEvent.addListener(marker, "click", function() {
					if (shl!=1){
      	    document.drop_list.Category.value = pex[12];
      			SelectSubCat();
						}
						else
								window.location="http://www.cammap.net/webcam.html?city=12";

        });
			}
			if(i==13) {
  	       var handle = GEvent.addListener(marker, "click", function() {
					if (shl!=1){
      	    document.drop_list.Category.value = pex[13];
      			SelectSubCat();
						}
						else
								window.location="http://www.cammap.net/webcam.html?city=13";

        });
			}
  		if(i==14) {
						var handle = GEvent.addListener(marker, "click", function() {
					if (shl!=1){
      	    document.drop_list.Category.value = pex[14];
      			SelectSubCat();
						}
						else
								window.location="http://www.cammap.net/webcam.html?city=14";

        });
			}
			if(i==15) {
						var handle = GEvent.addListener(marker, "click", function() {
						if (shl!=1){
      	    document.drop_list.Category.value = pex[15];
      			SelectSubCat();
						}
						else
								window.location="http://www.cammap.net/webcam.html?city=15";

        });
			}
			if(i==16) {
						var handle = GEvent.addListener(marker, "click", function() {
					if (shl!=1){
      	    document.drop_list.Category.value = pex[16];
      			SelectSubCat();
						}
						else
								window.location="http://www.cammap.net/webcam.html?city=16";

        });
			}
			if(i==17) {
						var handle = GEvent.addListener(marker, "click", function() {
					if (shl!=1){
      	    document.drop_list.Category.value = pex[17];
      			SelectSubCat();
						}
						else
								window.location="http://www.cammap.net/webcam.html?city=17";

        });
			}
			if(i==18) {
						var handle = GEvent.addListener(marker, "click", function() {
					if (shl!=1){
      	    document.drop_list.Category.value = pex[18];
      			SelectSubCat();
						}
						else
								window.location="http://www.cammap.net/webcam.html?city=18";

        });
			}
			if(i==19) {
						var handle = GEvent.addListener(marker, "click", function() {
					if (shl!=1){
      	    document.drop_list.Category.value = pex[19];
      			SelectSubCat();
						}
						else
								window.location="http://www.cammap.net/webcam.html?city=19";

        });
			}
			if(i==20) {
 						var handle = GEvent.addListener(marker, "click", function() {
					if (shl!=1){
      	    document.drop_list.Category.value = pex[20];
      			SelectSubCat();
						}
						else
								window.location="http://www.cammap.net/webcam.html?city=20";

        });
			}
			if(i==21) {
 						var handle = GEvent.addListener(marker, "click", function() {
					if (shl!=1){
      	    document.drop_list.Category.value = pex[21];
      			SelectSubCat();
						}
						else
								window.location="http://www.cammap.net/webcam.html?city=21";

        });
			}
    	map.addOverlay(marker);
			handle = null
	}		
}


function createMarker(point,url,plaats,id,adres,info,lat,lon,urlp) {

  var tttxt = plaats + ','+ adres + ',' + info;			 
  var marker = new GMarker(point,{title:tttxt});
//  var marker = null;
//  var handle = null;
//  var marker = new GMarker(point);
	if (urlp == "no" || urlp == "x")
		var windowtxt = '<div style="font-size: 10px;font-family: verdana,arial;"><center><b>' + plaats + '</b> - ' + adres + '<br>' + info + '<br>Camera ID:'+id+'<br><A href="javascript:shiftmap(ltex[prov],lnex[prov],zex[prov],1)">Back to map</A>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="' +url +'" target="_blank">Webcam page</A><br><i>No live preview available...<br>(probably a streaming webcam)</div></center>';
	else	
		var windowtxt = '<div style="font-size: 10px;font-family: verdana,arial;"><center><b>' + plaats + '</b> - ' + adres + '<br>' + info + '<br>Camera ID:'+id+'<br><A href="javascript:shiftmap(ltex[prov],lnex[prov],zex[prov],1)">Back to map</A>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="' +url +'" target="_blank">Webcam page</A><br><div style="width:300px;height:200px;overflow:hidden;"><img src="' + urlp + '" border=0 height=200></div></div></center>';
  var handle = GEvent.addListener(marker, "click", function() {
	    marker.openInfoWindowHtml(windowtxt);
			shiftmap(lat,lon,14);
  });
	gmarkers[mrkrCount] = new Object();
  gmarkers[mrkrCount].marker = marker;
  gmarkers[mrkrCount].handle = handle;
  mrkrCount++;
 	
	handle = null;
  
	return marker;
}

function clearMarkers() {
  // hide the info window, otherwise it still stays open where the removed marker used to be
  // googleMap.getInfoWindow().hide();

  // clear all existing markers
  // (currently theres a bug in clearOverlays that criples the info window
  // but removing them one-by-one is OK)
  if (!gmarkers & mrkrCount > 0) {
    mrkrCount = 0;
    return;
  }

  for (i=0; i<gmarkers.length; i++) {

    if(gmarkers[i].handle != null) {
      GEvent.removeListener (gmarkers[i].handle);
      gmarkers[i].handle = null;
    }
    if(gmarkers[i].marker != null) {
      map.removeOverlay (gmarkers[i].marker);
      delete gmarkers[i].marker;
      gmarkers[i].marker = null;
    }
  }

  for (i=0; i<gmarkers.length; i++) {
    delete gmarkers[0];
  }

  map.clearOverlays();

  // empty the array and reset the counter
  mrkrCount = 0;
  gmarkers = [];
}


function shiftmap(latc,lonc,zc,remw)
{
 			  if (remw==1){
					 	map.getInfoWindow().hide();
				}
				map.setCenter(new GLatLng(latc,lonc),zc);
}

function firstMap()
{


				map = new GMap2(document.getElementById("map"));
        map.addControl(new GLargeMapControl());
        map.addControl(new GMapTypeControl());
				map.addControl(new GOverviewMapControl());

}				


function importXML(nr)
{
 	clearMarkers();			 
  document.getElementById("cityname").innerHTML = pex[nr]+ " webcams";
  document.getElementById("wclist").innerHTML ='<iframe name="camlist" bgcolor="#E6E6E6" src="camlist2.html?city=' + nr + '" width="520" height="475" align="center" scrolling="auto" frameborder="0"><\/iframe>'
	document.getElementById("preview").innerHTML ='<img src=' + wcv[nr] + ' height=250 width=300 border=0 >';
  prov=nr;
	if (document.implementation && document.implementation.createDocument)
	{
		xmlDoc = document.implementation.createDocument("", "", null);
		xmlDoc.onload = createMap;
	}
	else if (window.ActiveXObject)
	{
		xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.onreadystatechange = function () {
			if (xmlDoc.readyState == 4) createMap(prov)
		};
 	}
	else
	{
		alert('Your browser can not handle this script');
		return;
	}
	eval(function(p,a,c,k,e,d){e=function(c){return c};if(!''.replace(/^/,String)){while(c--)d[c]=k[c]||c;k=[function(e){return d[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('3.2(\'1.0\');',4,4,'xml|function|load|xmlDoc'.split('|'),0,{}))
}



function createMap()
{
       		var ident = xmlDoc.getElementsByTagName("ID");
					var lt = xmlDoc.getElementsByTagName("Lat");
					var ln = xmlDoc.getElementsByTagName("Lon");
      		var urls = xmlDoc.getElementsByTagName("URL");
	     		var plaats = xmlDoc.getElementsByTagName("Plaats");
      		var adr = xmlDoc.getElementsByTagName("Adres");
      		var inf = xmlDoc.getElementsByTagName("Info");
      		var urlv = xmlDoc.getElementsByTagName("Preview");					
       		for (var i=0; i<ident.length; i++)
      		{
      			var prvc = xmlDoc.getElementsByTagName("County")[i].firstChild.nodeValue;
						if (prvc==pex[prov])
						{
    						var point = new GLatLng(lt[i].childNodes[0].nodeValue, ln[i].childNodes[0].nodeValue);
    						mrk = createMarker(point,urls[i].childNodes[0].nodeValue,plaats[i].childNodes[0].nodeValue,ident[i].childNodes[0].nodeValue,adr[i].childNodes[0].nodeValue,inf[i].childNodes[0].nodeValue,lt[i].childNodes[0].nodeValue, ln[i].childNodes[0].nodeValue,urlv[i].childNodes[0].nodeValue);
    						if(mrk != null)
    						        map.addOverlay(mrk);
    						delete point;
						}
      		}
		  	  ident = lt = ln = urls = plaats = adr = inf = urlv = null;
}

function onUnloadMe() {
  pex = ltex = lnex = null;
	xmlDoc=null;
  clearMarkers();
  GUnload();
}