
function defaultCont(msg) {
			setTimeout("draw_start('europe')",1) ;
}

// Velocity code for finding geoposition an setting background image accordingly:

// if (navigator.geolocation) {
//     navigator.geolocation.getCurrentPosition(checkCont, defaultCont,{maximumAge:60000,timeout:5000});
// } else {
// 	setTimeout("draw_start('europe')",1);
// }

// function checkCont(position) {
// lat=position.coords.latitude;
// lon=position.coords.longitude;
//        if (lon <39.869301 && lat < 81.008797 && lat> 27.636311 && lon > -31.266001) {
//  		draw_start('europe');		
//        } else if (lat < -6.069450 && lat> -53.058720  && lon < 175.292496 &&  lon > 105.37703) {
//        	draw_start('australia');	
//        } else if (lon <37.567120 && lat < 63.525379 && lat> -46.900452 && lon > -25.358740) {
//        	draw_start('africa');
//        } else if (lat < 82.500450 && lat > -12.561110 && lon <180 &&  lon > 19.638100) {
//        	draw_start('asia');
//        } else if (lat > -52.233040 && lat > 5.499550 && lon < 83.162102 && lon > -167.27641  ) {
//        	draw_start('america');
//        }  else if ( lat > -26.332470 && lat > -59.450451 && lon <13.390290 && lon > -109.474930) {
//        	draw_start('america');
//        } else {
//  		draw_start('europe');	
//        }
//}

// Amplex modification, don't ask for location, just deliver one by random:
var mylocs = new Array();
mylocs[0]='africa';
mylocs[1]='america';
mylocs[2]='asia';
mylocs[3]='australia';
mylocs[4]='europe';

var mycount = mylocs.length;
var myloc = mylocs[Math.round(Math.random()*(mycount-1))];

//setTimeout("draw_start(myloc),1");
// Amplex modification end

function dumpProps(obj, parent) {
   // Go through all the properties of the passed-in object 
   for (var i in obj) {
      // if a parent (2nd parameter) was passed in, then use that to 
      // build the message. Message includes i (the object's property name) 
      // then the object's property value on a new line 
      if (parent) { var msg = parent + "." + i + "\n" + obj[i]; } else { var msg = i + "\n" + obj[i]; }
      // Display the message. If the user clicks "OK", then continue. If they 
      // click "CANCEL" then quit this level of recursion 
      if (!confirm(msg)) { return; }
      // If this property (i) is an object, then recursively process the object 
      if (typeof obj[i] == "object") { 
         if (parent) { dumpProps(obj[i], parent + "." + i); } else { dumpProps(obj[i], i); }
      }
   }
}
function set_on(comp) {
	if (comp=="energy") {
				$("#energy_button").attr("src",'/wp-content/themes/amplex/images/icons/greenwise_over.png');
				$("#greenwise").addClass('hover');
				set_item="energy";
			
	}
	if (comp=="ebook") {
		
				$("#ebook_button").attr("src",'/wp-content/themes/amplex/images/icons/startgrid_over.png');
				$("#startgrid").addClass('hover');
				set_item="ebook";
	}
	if (comp=="monitor") {
		
				$("#monitor_button").attr("src",'/wp-content/themes/amplex/images/icons/metermind_over.png');
				$("#metermind").addClass('hover');
				set_item="monitor";
		
	}
	if (comp=="bridge") {
				$("#bridge_button").attr("src",'/wp-content/themes/amplex/images/icons/opencity_over.png');
				$("#opencity").addClass('hover');
				set_item="bridge";
	}
	if (comp=="") {
			$("#energy_button").attr("src",'/wp-content/themes/amplex/images/icons/greenwise.png');
			$("#greenwise").removeClass('hover');
			$("#monitor_button").attr("src",'/wp-content/themes/amplex/images/icons/metermind.png');
			$("#metermind").removeClass('hover');
			$("#bridge_button").attr("src",'/wp-content/themes/amplex/images/icons/opencity.png');
			$("#opencity").removeClass('hover');
			$("#ebook_button").attr("src",'/wp-content/themes/amplex/images/icons/startgrid.png');
			$("#startgrid").removeClass('hover');
	}
}

function toggle(comp) {
	if (set_item != "energy") {
		if (comp=="energy") {
			if ($("#energy_button").attr("src")=='/wp-content/themes/amplex/images/icons/greenwise.png') {
					$("#energy_button").attr("src",'/wp-content/themes/amplex/images/icons/greenwise_over.png');
					$("#greenwise").addClass('hover');
			} else {
				$("#energy_button").attr("src",'/wp-content/themes/amplex/images/icons/greenwise.png');
				$("#greenwise").removeClass('hover');
			}
		}
	}
	if (set_item != "ebook") {
		if (comp=="ebook") {
			if ($("#ebook_button").attr("src")=='/wp-content/themes/amplex/images/icons/startgrid.png') {
					$("#ebook_button").attr("src",'/wp-content/themes/amplex/images/icons/startgrid_over.png');
					$("#startgrid").addClass('hover');
			} else {
				$("#ebook_button").attr("src",'/wp-content/themes/amplex/images/icons/startgrid.png');
				$("#startgrid").removeClass('hover');
			}
		}
	}
	if (set_item != "monitor") {
		if (comp=="monitor") {
			if ($("#monitor_button").attr("src")=='/wp-content/themes/amplex/images/icons/metermind.png') {
					$("#monitor_button").attr("src",'/wp-content/themes/amplex/images/icons/metermind_over.png');
					$("#metermind").addClass('hover');
			} else {
				$("#monitor_button").attr("src",'/wp-content/themes/amplex/images/icons/metermind.png');
				$("#metermind").removeClass('hover');
			}
		}
	}
	if (set_item != "bridge") {
		if (comp=="bridge") {
			if ($("#bridge_button").attr("src")=='/wp-content/themes/amplex/images/icons/opencity.png') {
					$("#bridge_button").attr("src",'/wp-content/themes/amplex/images/icons/opencity_over.png');
					$("#opencity").addClass('hover');
			} else {
				$("#bridge_button").attr("src",'/wp-content/themes/amplex/images/icons/opencity.png');
				$("#opencity").removeClass('hover');
			}
		}
	}
	if (comp=="") {
			$("#energy_button").attr("src",'/wp-content/themes/amplex/images/icons/greenwise.png');
			$("#greenwise").removeClass('hover');
			$("#monitor_button").attr("src",'/wp-content/themes/amplex/images/icons/metermind.png');
			$("#metermind").removeClass('hover');
			$("#bridge_button").attr("src",'/wp-content/themes/amplex/images/icons/opencity.png');
			$("#opencity").removeClass('hover');
			$("#ebook_button").attr("src",'/wp-content/themes/amplex/images/icons/startgrid.png');
			$("#startgrid").removeClass('hover');
	}
}
function draw_start(cont) {
	set_item="";
	$("#energy_button").attr("src",'/wp-content/themes/amplex/images/icons/greenwise.png');
	$("#greenwise").removeClass('hover');
	$("#monitor_button").attr("src",'/wp-content/themes/amplex/images/icons/metermind.png');
	$("#metermind").removeClass('hover');
	$("#bridge_button").attr("src",'/wp-content/themes/amplex/images/icons/opencity.png');
	$("#opencity").removeClass('hover');
	$("#ebook_button").attr("src",'/wp-content/themes/amplex/images/icons/startgrid.png');
	$("#startgrid").removeClass('hover');

	jQuery("#zoom_out").fadeOut("slow");
	
	var drawingCanvas = document.getElementById('myDrawing');
	// Check the element is in the DOM and the browser supports canvas
	if (window.HTMLCanvasElement) {
		if(drawingCanvas.getContext) {
		
			// Initaliase a 2-dimensional drawing context
			context = drawingCanvas.getContext('2d');
			myImage = new Image();
			myImage.onload = function() {
				context.drawImage(myImage, 0, 0, 1130, 330);
			};
		}
	}
	xstartloc=0;
	ystartloc=0;
	x=0;
	y=0;
	xzoom=startwidth;
	yzoom=startheight; 
	jQuery("#energy_open").fadeOut("slow"); 
	jQuery("#ebook_open").fadeOut("slow");
	jQuery("#monitor_open").fadeOut("slow");
	jQuery("#bridge_open").fadeOut("slow");

	if (cont == "europe") {
		if (window.HTMLCanvasElement) {
			myImage.src = "/wp-content/themes/amplex/images/photos/europe/zoom2.jpg";
		}
		continent=cont;
		jQuery("#europe_label").fadeIn("fast");	
	} else if (cont == "africa") {
		continent=cont;
		if (window.HTMLCanvasElement) {
			myImage.src = "/wp-content/themes/amplex/images/photos/africa/zoom2.jpg";
		}
		jQuery("#africa_label").fadeIn("fast");	
	}   else if (cont == "asia") {
		continent=cont;
		if (window.HTMLCanvasElement) {
			myImage.src = "/wp-content/themes/amplex/images/photos/asia/zoom2.jpg";
		}
		jQuery("#asia_label").fadeIn("fast");	
	} else if (cont == "america") {
		continent=cont;
		if (window.HTMLCanvasElement) {
			myImage.src = "/wp-content/themes/amplex/images/photos/america/zoom2.jpg";
		}
		jQuery("#america_label").fadeIn("fast");	
	}  else if (cont == "australia") {
		continent=cont;
		if (window.HTMLCanvasElement) {
			myImage.src = "/wp-content/themes/amplex/images/photos/australia/zoom2.jpg";
		}
		jQuery("#australia_label").fadeIn("fast");	
	} else {
		continent='europe';
		if (window.HTMLCanvasElement) {
			myImage.src = "/wp-content/themes/amplex/images/photos/europe/zoom2.jpg";
		}
		jQuery("#europe_label").fadeIn("fast");	
	}
	if (window.HTMLCanvasElement) {
//		context.drawImage(myImage,0,0, 2716,793,0,0 ,1130, 330);
	}
}
	var set_item;
	var context;
	var continent;
	var drawingCanvas;
	var startwidth=2716;
	var startheight=793;
	var steps=25;
	var box;
	var myImage;
	var xendloc;
	var yendloc;
	var xstep;
	var ystep;
	var dxzoom;
	var dyzoom;
	var xstartloc=0;
	var ystartloc=0;
	var endxzoom=1130;
	var endyzoom=330;
	var  xzoom=startwidth;
	var yzoom=startheight;  
	var box;
	var open_box;
function set_box(boxin) {
	if (boxin == "energy") {
		box="energy";
		xendloc = 335;
		yendloc= 20;
		xstep = (xendloc-xstartloc)/steps;
		ystep =(yendloc-ystartloc)/steps;
		dxzoom=(startwidth - endxzoom)/steps;
		dyzoom=(startheight - endyzoom)/steps;
		jQuery("#ebook").fadeOut("slow");
		jQuery("#monitor").fadeOut("slow");
		jQuery("#bridge").fadeOut("slow");
		jQuery("#energy_button").attr("src","/wp-content/themes/amplex/images/icons/greenwise_over.png");
		jQuery("#ebook_button").attr("src","/wp-content/themes/amplex/images/icons/startgrid.png");
		jQuery("#monitor_button").attr("src","/wp-content/themes/amplex/images/icons/metermind.png");
		jQuery("#bridge_button").attr("src","/wp-content/themes/amplex/images/icons/opencity.png");
	} else if (boxin == "ebook") {
		box="ebook";
		xendloc = 14;
		yendloc= 200;	
		xstep = (xendloc-xstartloc)/steps;
		ystep =(yendloc-ystartloc)/steps;
		dxzoom=(startwidth - endxzoom)/steps;
		dyzoom=(startheight - endyzoom)/steps;
		jQuery("#energy").fadeOut("slow");
		jQuery("#monitor").fadeOut("slow");
		jQuery("#bridge").fadeOut("slow");	
		jQuery("#ebook_button").attr("src","/wp-content/themes/amplex/images/icons/startgrid_over.png");
		jQuery("#energy_button").attr("src","/wp-content/themes/amplex/images/icons/greenwise.png");
		jQuery("#monitor_button").attr("src","/wp-content/themes/amplex/images/icons/metermind.png");
		jQuery("#bridge_button").attr("src","/wp-content/themes/amplex/images/icons/opencity.png");
	} else if (boxin == "monitor" ) {
		box="monitor";
		xendloc = 500;
		yendloc= 140;
		xstep = (xendloc-xstartloc)/steps;
		ystep =(yendloc-ystartloc)/steps;
		dxzoom=(startwidth - endxzoom)/steps;
		dyzoom=(startheight - endyzoom)/steps;	
		jQuery("#ebook").fadeOut("slow");
		jQuery("#energy").fadeOut("slow");
		jQuery("#bridge").fadeOut("slow");
		jQuery("#monitor_button").attr("src","/wp-content/themes/amplex/images/icons/metermind_over.png");
		jQuery("#energy_button").attr("src","/wp-content/themes/amplex/images/icons/greenwise.png");
		jQuery("#ebook_button").attr("src","/wp-content/themes/amplex/images/icons/startgrid.png");
		jQuery("#bridge_button").attr("src","/wp-content/themes/amplex/images/icons/opencity.png");
	} else if (boxin=="bridge") {
		box="bridge";
		xendloc = 580;
		yendloc= 250;
		xstep = (xendloc-xstartloc)/steps;
		ystep =(yendloc-ystartloc)/steps;
		dxzoom=(startwidth - endxzoom)/steps;
		dyzoom=(startheight - endyzoom)/steps;	
		jQuery("#ebook").fadeOut("slow");
		jQuery("#monitor").fadeOut("slow");
		jQuery("#energy").fadeOut("slow");
		jQuery("#bridge_button").attr("src","/wp-content/themes/amplex/images/icons/opencity_over.png");
		jQuery("#energy_button").attr("src","/wp-content/themes/amplex/images/icons/greenwise.png");
		jQuery("#monitor_button").attr("src","/wp-content/themes/amplex/images/icons/metermind.png");
		jQuery("#ebook_button").attr("src","/wp-content/themes/amplex/images/icons/startgrid.png");
	}
	draw();
}
function draw() {
	var canvas = document.getElementById('myDrawing');
	if (window.HTMLCanvasElement) {	
		var ctx = canvas.getContext('2d');
		ctx.mozImageSmoothingEnabled = false;
	}
	x = xstartloc;
	y = ystartloc;
	if (x < xendloc && y < yendloc) {
	    x += xstep; 
	    y += ystep;		
		xzoom=xzoom-dxzoom;
		yzoom=yzoom-dyzoom;
		if (window.HTMLCanvasElement) {		
			context.drawImage(myImage,x,y, xzoom,yzoom,0,0 ,1130, 330);
		}
		xstartloc=x;
		ystartloc=y;
		setTimeout("draw()",1) ;
	} else { 
	  	 jQuery("#europe_label").fadeOut("fast");
	  	 jQuery("#australia_label").fadeOut("fast");	
	  	 jQuery("#asia_label").fadeOut("fast");
	  	 jQuery("#america_label").fadeOut("fast");	
	  	 jQuery("#africa_label").fadeOut("fast");
			jQuery("#zoom_out").fadeIn("slow");
			box_div_open="#"+box+"_open";			
			open_box=box;
			jQuery(box_div_open).fadeIn("slow");
			box_div="#"+box;
			jQuery(box_div).fadeOut("slow");
	}
} 
 (function($) {
  var cache = [];
  // Arguments are image paths relative to the current page.
  $.preLoadImages = function() {
    var args_len = arguments.length;
    for (var i = args_len; i--;) {
      var cacheImage = document.createElement('img');
      cacheImage.src = arguments[i];
      cache.push(cacheImage);
    }
  }
})(jQuery)

