/**
 *	metody obslugujące widoki 3d
 *	
 */	 	 		
var cameraAltitude = 30.0;
var cameraTilt = 70.0;	//nachylenie do powierzchni ziemi
var lookAtTilt = 70.0;	//nachylenie w momencie widoku na obiekt

function toNorth() {
	var camera = ge.getView().copyAsCamera(ge.ALTITUDE_RELATIVE_TO_GROUND);
	var cvLatLng = GMap.customViewLatLng;
	camera.setLatitude(parseFloat(cvLatLng.lng));
	camera.setLongitude(parseFloat(cvLatLng.lat));
	camera.setAltitude(cameraAltitude);
	camera.setTilt(cameraTilt);
	camera.setHeading(0);
	ge.getView().setAbstractView(camera);
}

function toSouth() {
	var camera = ge.getView().copyAsCamera(ge.ALTITUDE_RELATIVE_TO_GROUND);
	var cvLatLng = GMap.customViewLatLng;
	camera.setLatitude(parseFloat(cvLatLng.lng));
	camera.setLongitude(parseFloat(cvLatLng.lat));
	camera.setAltitude(cameraAltitude);
	camera.setTilt(cameraTilt);
	camera.setHeading(180);
	ge.getView().setAbstractView(camera);
}

function toEast() {
	var camera = ge.getView().copyAsCamera(ge.ALTITUDE_RELATIVE_TO_GROUND);
	var cvLatLng = GMap.customViewLatLng;
	camera.setLatitude(parseFloat(cvLatLng.lng));
	camera.setLongitude(parseFloat(cvLatLng.lat));
	camera.setAltitude(cameraAltitude);
	camera.setTilt(cameraTilt);
	camera.setHeading(90);
	ge.getView().setAbstractView(camera);
}

function toWest() {
	var camera = ge.getView().copyAsCamera(ge.ALTITUDE_RELATIVE_TO_GROUND);
	var cvLatLng = GMap.customViewLatLng;
	camera.setLatitude(parseFloat(cvLatLng.lng));
	camera.setLongitude(parseFloat(cvLatLng.lat));
	camera.setAltitude(cameraAltitude);
	camera.setTilt(cameraTilt);
	camera.setHeading(270);
	ge.getView().setAbstractView(camera);
}

function fromNorth() {
	var lookAt = ge.getView().copyAsLookAt(ge.ALTITUDE_RELATIVE_TO_GROUND);
	lookAt.setHeading(180);	//North
	var cvLatLng = GMap.customViewLatLng;
	lookAt.setLatitude(parseFloat(cvLatLng.lng));
	lookAt.setLongitude(parseFloat(cvLatLng.lat));			
	lookAt.setRange(GMap.lookAtRange);
	lookAt.setTilt(lookAtTilt);
	ge.getView().setAbstractView(lookAt);
}

function fromSouth() {
	var lookAt = ge.getView().copyAsLookAt(ge.ALTITUDE_RELATIVE_TO_GROUND);
	lookAt.setHeading(0);	//South
	var cvLatLng = GMap.customViewLatLng;
	lookAt.setLatitude(parseFloat(cvLatLng.lng));
	lookAt.setLongitude(parseFloat(cvLatLng.lat));			
	lookAt.setRange(GMap.lookAtRange);
	lookAt.setTilt(lookAtTilt);
	ge.getView().setAbstractView(lookAt);
}

function fromEast() {
	var lookAt = ge.getView().copyAsLookAt(ge.ALTITUDE_RELATIVE_TO_GROUND);
	lookAt.setHeading(270);	//East
	var cvLatLng = GMap.customViewLatLng;
	lookAt.setLatitude(parseFloat(cvLatLng.lng));
	lookAt.setLongitude(parseFloat(cvLatLng.lat));			
	lookAt.setRange(GMap.lookAtRange);
	lookAt.setTilt(lookAtTilt);
	ge.getView().setAbstractView(lookAt);
}

function fromWest() {
	var lookAt = ge.getView().copyAsLookAt(ge.ALTITUDE_RELATIVE_TO_GROUND);
	lookAt.setHeading(90);	//West
	var cvLatLng = GMap.customViewLatLng;
	lookAt.setLatitude(parseFloat(cvLatLng.lng));
	lookAt.setLongitude(parseFloat(cvLatLng.lat));			
	lookAt.setRange(GMap.lookAtRange);
	lookAt.setTilt(lookAtTilt);
	ge.getView().setAbstractView(lookAt);
}


function set3DNavButton(that) {
	
	//reset guziczkow
	$('getn').down().hide();
	$('gets').down().hide();
	$('gete').down().hide();
	$('getw').down().hide();
	$('gefn').down().hide();
	$('gefs').down().hide();
	$('gefe').down().hide();
	$('gefw').down().hide();
	
	//efficient, simple, safe:)
	if (that)
		$(that).down().show();
}

function go3d() {
	//obsluzmy tutaj GEplugin
	if (!GMap.earthInstanceLoaded) {
		GMap.map.setMapType(G_SATELLITE_3D_MAP);
		
		GMap.checkPOIfilters();
		earthInstance = GMap.map.getEarthInstance(GMap.getEarthInstanceCallback);
	}
	else {
		GMap.map.setMapType(G_SATELLITE_3D_MAP);
		GMap.showCustomView();
	}
	
	set3DNavButton(null);
}

function SuperButton(x, y, width, height, imgPath, map)
{
	this.x = x;
	this.y = y;
	this.width = width;
	this.height = height;
	this.imgPath = imgPath;
	
	var screenXY1 = new GScreenPoint(this.x, this.y, "pixels", "pixels");
	var overlayXY1 = new GScreenPoint(this.width, this.height, "pixels", "pixels");
	var size1 = new GScreenSize(this.width, this.height, "pixels", "pixels");
	var imageUrl1 = this.imgPath;			
	
	this.screenOverlay = new GScreenOverlay(imageUrl1, screenXY1, overlayXY1, size1);
	
	return this.screenOverlay;
}

/**
 * Włączanie widoków 3D
 */	 	
function CustomViewControl() {}
CustomViewControl.prototype = new GControl();

CustomViewControl.prototype.initialize = function(map) {
	var container = document.createElement("div");

	var custmViewDiv = document.createElement("div");
	custmViewDiv.style.border = "1px black solid";
	this.setButtonStyle_(custmViewDiv);
	container.appendChild(custmViewDiv);
	custmViewDiv.appendChild(document.createTextNode("Zobacz w 3D"));
	GEvent.addDomListener(custmViewDiv, "click", function() {
		//obsluzmy tutaj GEplugin
		if (!GMap.earthInstanceLoaded) {
			GMap.map.setMapType(G_SATELLITE_3D_MAP);
			
			GMap.checkPOIfilters();

			earthInstance = GMap.map.getEarthInstance(GMap.getEarthInstanceCallback);
		}
		else {
			//console.log('!GMap.earthInstanceLoaded');
			GMap.map.setMapType(G_SATELLITE_3D_MAP);
			GMap.viewANiceCustomView();
		}
	});

	map.getContainer().appendChild(container);
	return container;
}


CustomViewControl.prototype.getDefaultPosition = function() {
	return new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(5, 11));
}

CustomViewControl.prototype.setButtonStyle_ = function(button) {
	button.style.color = "#000000";
	button.style.backgroundColor = "white";
	button.style.padding = "0px 3px";
	button.style.textAlign = "center";
	//button.style.width = "5em";
	button.style.cursor = "pointer";
	button.style.border = "1px black solid";
	button.style.borderColor = "#FFFFFF #B0B0B0 #B0B0B0 #FFFFFF";
}


/**
 * Nawigacja widoków z piętra
 */
function LookFromObjectControl() {}
LookFromObjectControl.prototype = new GControl();

LookFromObjectControl.prototype.initialize = function(map) {
	var container = document.createElement("div");
	this.setContainerStyle_(container);
	
	var btnImg = document.createElement("img");
	btnImg.src = "/images/to/map/panoramio.gif";
	
	var toNorthLookDiv = document.createElement("div");
	this.setButtonStyleNorth_(toNorthLookDiv);
	container.appendChild(toNorthLookDiv);
	GEvent.addDomListener(toNorthLookDiv, "click", function() {
		
		var camera = ge.getView().copyAsCamera(ge.ALTITUDE_RELATIVE_TO_GROUND);
		var cvLatLng = GMap.customViewLatLng;
		camera.setLatitude(parseFloat(cvLatLng.lng));
		camera.setLongitude(parseFloat(cvLatLng.lat));
		camera.setAltitude(100.0);
		camera.setTilt(45.0);
		camera.setHeading(0);
		ge.getView().setAbstractView(camera);

	});
	
	var toSouthLookDiv = document.createElement("div");
	this.setButtonStyleSouth_(toSouthLookDiv);
	container.appendChild(toSouthLookDiv);
	GEvent.addDomListener(toSouthLookDiv, "click", function() {
		
		var camera = ge.getView().copyAsCamera(ge.ALTITUDE_RELATIVE_TO_GROUND);
		var cvLatLng = GMap.customViewLatLng;
		camera.setLatitude(parseFloat(cvLatLng.lng));
		camera.setLongitude(parseFloat(cvLatLng.lat));
		camera.setAltitude(100.0);
		camera.setTilt(45.0);
		camera.setHeading(180);
		ge.getView().setAbstractView(camera);

	});
	
	var toEastLookDiv = document.createElement("div");
	this.setButtonStyleEast_(toEastLookDiv);
	container.appendChild(toEastLookDiv);
	GEvent.addDomListener(toEastLookDiv, "click", function() {
		
		var camera = ge.getView().copyAsCamera(ge.ALTITUDE_RELATIVE_TO_GROUND);
		var cvLatLng = GMap.customViewLatLng;
		camera.setLatitude(parseFloat(cvLatLng.lng));
		camera.setLongitude(parseFloat(cvLatLng.lat));
		camera.setAltitude(100.0);
		camera.setTilt(45.0);
		camera.setHeading(90);
		ge.getView().setAbstractView(camera);

	});
	
	var toWestLookDiv = document.createElement("div");
	this.setButtonStyleWest_(toWestLookDiv);
	container.appendChild(toWestLookDiv);
	GEvent.addDomListener(toWestLookDiv, "click", function() {
		
		var camera = ge.getView().copyAsCamera(ge.ALTITUDE_RELATIVE_TO_GROUND);
		var cvLatLng = GMap.customViewLatLng;
		camera.setLatitude(parseFloat(cvLatLng.lng));
		camera.setLongitude(parseFloat(cvLatLng.lat));
		camera.setAltitude(100.0);
		camera.setTilt(45.0);
		camera.setHeading(270);
		ge.getView().setAbstractView(camera);

	});

	map.getContainer().appendChild(container);
	return container;
}

LookFromObjectControl.prototype.getDefaultPosition = function() {
	return new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(175, 80));
}

LookFromObjectControl.prototype.setContainerStyle_ = function(container1) {
	container1.style.width = "56px";
	container1.style.height = "56px";
	//container1.style.backgroundColor = "yellow";
	container1.style.border = "1px black solid";
	container1.style.background = 'url("/images/to/map/roza_wiatrow_bg.png") 0 0 white';
}
	
LookFromObjectControl.prototype.setButtonStyle_ = function(button1) {
	button1.style.color = "#000000";
	//button1.style.backgroundColor = "white";
	button1.style.padding = "0px 3px";
	button1.style.textAlign = "center";
	//button1.style.width = "5em";
	button1.style.cursor = "pointer";
	button1.style.border = "1px black solid";
	button1.style.borderColor = "#FFFFFF #B0B0B0 #B0B0B0 #FFFFFF";
}

LookFromObjectControl.prototype.setButtonStyleNorth_ = function(button) {
	button.style.top = "0px";
	button.style.left = "18px";
	button.style.cursor = "pointer";
	button.style.position = "absolute";
	//button.style.backgroundColor = "red";
	button.style.width = "18px";
	button.style.height = "18px";
	button.style.display = "block";
}

LookFromObjectControl.prototype.setButtonStyleSouth_ = function(button) {
	button.style.top = "36px";
	button.style.left = "18px";
	button.style.cursor = "pointer";
	button.style.position = "absolute";
	//button.style.backgroundColor = "red";
	button.style.width = "18px";
	button.style.height = "18px";
	button.style.display = "block";
}

LookFromObjectControl.prototype.setButtonStyleEast_ = function(button) {
	button.style.top = "18px";
	button.style.right = "0px";
	button.style.cursor = "pointer";
	button.style.position = "absolute";
	//button.style.backgroundColor = "red";
	button.style.width = "18px";
	button.style.height = "18px";
	button.style.display = "block";
}	

LookFromObjectControl.prototype.setButtonStyleWest_ = function(button) {
	button.style.top = "18px";
	button.style.left = "0px";
	button.style.cursor = "pointer";
	button.style.position = "absolute";
	//button.style.backgroundColor = "red";
	button.style.width = "18px";
	button.style.height = "18px";
	button.style.display = "block";
}	

/**
 * Widoki na obiekt
 */	 	
function LookAtObjectControl() {}
LookAtObjectControl.prototype = new GControl();

LookAtObjectControl.prototype.initialize = function(map) {
	var container = document.createElement("div");
	this.setContainerStyle_(container);
	
	var btnImg = document.createElement("img");
	btnImg.src = "/images/to/map/panoramio.gif";
	
	var fromNorthLookDiv = document.createElement("div");
	this.setButtonStyleNorth_(fromNorthLookDiv);
	container.appendChild(fromNorthLookDiv);
	//fromNorthLookDiv.appendChild(document.createTextNode("widok na północ"));
	GEvent.addDomListener(fromNorthLookDiv, "click", function() {
		
		var lookAt = ge.getView().copyAsLookAt(ge.ALTITUDE_RELATIVE_TO_GROUND);
		lookAt.setHeading(180);	//North
		var cvLatLng = GMap.customViewLatLng;
		lookAt.setLatitude(parseFloat(cvLatLng.lng));
		lookAt.setLongitude(parseFloat(cvLatLng.lat));			
		//lookAt.setRange(500.0);
		lookAt.setRange(GMap.lookAtRange);
		lookAt.setTilt(45.0);
		ge.getView().setAbstractView(lookAt);

	});
	
	
	var fromSouthLookDiv = document.createElement("div");
	this.setButtonStyleSouth_(fromSouthLookDiv);
	container.appendChild(fromSouthLookDiv);
	GEvent.addDomListener(fromSouthLookDiv, "click", function() {
		
		var lookAt = ge.getView().copyAsLookAt(ge.ALTITUDE_RELATIVE_TO_GROUND);
		lookAt.setHeading(0);	//South
		var cvLatLng = GMap.customViewLatLng;
		lookAt.setLatitude(parseFloat(cvLatLng.lng));
		lookAt.setLongitude(parseFloat(cvLatLng.lat));			
		//lookAt.setRange(500.0);
		lookAt.setRange(GMap.lookAtRange);
		lookAt.setTilt(45.0);
		ge.getView().setAbstractView(lookAt);

	});
	
	
	var fromEastLookDiv = document.createElement("div");
	this.setButtonStyleEast_(fromEastLookDiv);
	container.appendChild(fromEastLookDiv);
	GEvent.addDomListener(fromEastLookDiv, "click", function() {
		
		var lookAt = ge.getView().copyAsLookAt(ge.ALTITUDE_RELATIVE_TO_GROUND);
		lookAt.setHeading(270);	//East
		var cvLatLng = GMap.customViewLatLng;
		lookAt.setLatitude(parseFloat(cvLatLng.lng));
		lookAt.setLongitude(parseFloat(cvLatLng.lat));			
		//lookAt.setRange(500.0);
		lookAt.setRange(GMap.lookAtRange);
		lookAt.setTilt(45.0);
		ge.getView().setAbstractView(lookAt);

	});
	
	
	var fromWestLookDiv = document.createElement("div");
	this.setButtonStyleWest_(fromWestLookDiv);
	container.appendChild(fromWestLookDiv);
	GEvent.addDomListener(fromWestLookDiv, "click", function() {
		
		var lookAt = ge.getView().copyAsLookAt(ge.ALTITUDE_RELATIVE_TO_GROUND);
		lookAt.setHeading(90);	//West
		var cvLatLng = GMap.customViewLatLng;
		lookAt.setLatitude(parseFloat(cvLatLng.lng));
		lookAt.setLongitude(parseFloat(cvLatLng.lat));			
		//lookAt.setRange(500.0);
		lookAt.setRange(GMap.lookAtRange);
		lookAt.setTilt(45.0);
		ge.getView().setAbstractView(lookAt);

	});
	

	map.getContainer().appendChild(container);
	return container;
}


LookAtObjectControl.prototype.getDefaultPosition = function() {
	return new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(10, 80));
}

LookAtObjectControl.prototype.setContainerStyle_ = function(container1) {
	container1.style.width = "56px";
	container1.style.height = "56px";
	//container1.style.backgroundColor = "yellow";
	container1.style.border = "1px black solid";
	container1.style.background = 'url("/images/to/map/roza_wiatrow_bg.png") 0 0 white';
}
	
LookAtObjectControl.prototype.setButtonStyle_ = function(button1) {
	button1.style.color = "#000000";
	//button1.style.backgroundColor = "white";
	button1.style.padding = "0px 3px";
	button1.style.textAlign = "center";
	//button1.style.width = "5em";
	button1.style.cursor = "pointer";
	button1.style.border = "1px black solid";
	button1.style.borderColor = "#FFFFFF #B0B0B0 #B0B0B0 #FFFFFF";
}

LookAtObjectControl.prototype.setButtonStyleNorth_ = function(button) {
	button.style.top = "0px";
	button.style.left = "18px";
	button.style.cursor = "pointer";
	button.style.position = "absolute";
	//button.style.backgroundColor = "red";
	button.style.width = "18px";
	button.style.height = "18px";
	button.style.display = "block";
}

LookAtObjectControl.prototype.setButtonStyleSouth_ = function(button) {
	button.style.top = "36px";
	button.style.left = "18px";
	button.style.cursor = "pointer";
	button.style.position = "absolute";
	//button.style.backgroundColor = "red";
	button.style.width = "18px";
	button.style.height = "18px";
	button.style.display = "block";
}

LookAtObjectControl.prototype.setButtonStyleEast_ = function(button) {
	button.style.top = "18px";
	button.style.right = "0px";
	button.style.cursor = "pointer";
	button.style.position = "absolute";
	//button.style.backgroundColor = "red";
	button.style.width = "18px";
	button.style.height = "18px";
	button.style.display = "block";
}	

LookAtObjectControl.prototype.setButtonStyleWest_ = function(button) {
	button.style.top = "18px";
	button.style.left = "0px";
	button.style.cursor = "pointer";
	button.style.position = "absolute";
	//button.style.backgroundColor = "red";
	button.style.width = "18px";
	button.style.height = "18px";
	button.style.display = "block";
}
