function _getPageSize()
{
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY)
	{	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight) {
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else {
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	
	if (self.innerHeight)
	{
		if(document.documentElement.clientWidth)
		{
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { 
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) {
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	if(yScroll < windowHeight)
	{
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}
	
	if(xScroll < windowWidth)
	{	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}
	
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
	
	return arrayPageSize;
	
};

function _getPageScroll()
{
	
	var xScroll, yScroll;
	
	if (self.pageYOffset)
	{
		yScroll = self.pageYOffset;
		xScroll = self.pageXOffset;
	} else if (document.documentElement && document.documentElement.scrollTop) {
		yScroll = document.documentElement.scrollTop;
		xScroll = document.documentElement.scrollLeft;
	} else if (document.body) {
		yScroll = document.body.scrollTop;
		xScroll = document.body.scrollLeft;	
	}
	
	arrayPageScroll = new Array(xScroll,yScroll);
	
	return arrayPageScroll;
};

function callMe(url, callback, errorCallback)
{
	var oXMLHttpRequest = new XMLHttpRequest;
	oXMLHttpRequest.open("GET", url);
	oXMLHttpRequest.onreadystatechange = function()
	{
		if(oXMLHttpRequest.readyState == 4)
		{
			if(oXMLHttpRequest.status == 200)
			{				
				if(typeof(callback) === 'function')
				{
					callback(this.responseText);					
				}
			}			
			else if (oXMLHttpRequest.status == 401)
			{
				alert('401');
				document.location = "index.php";
				return;
			}
			else if (oXMLHttpRequest.status == 500)
			{
				alert('500');
				if (typeof(errorCallback) == 'function')
				{
					errorCallback(this.responseText);
				}
				else
				{
					alert('ERROR 500: ' + this.responseText);
				}
			}
		}
	}
	oXMLHttpRequest.send(null);
}


var startLat = 51.107732;
var startLng = 17.050996;

var startLat2 = 51.109868;
var startLng2 = 17.037853;

var startLat3 = 51.08262;
var startLng3 = 17.077281;

var startZoom = 12;
var startWidth = 540;
var startHeight = 300;
var key = 'ABQIAAAA9LsXsu2W-0useS9gm2ZlMBTeVwOM7fNtbMnrDZ510P7ttUpcSxRxcFCt5na4qbEyzKCg6Pf1xAUC1A';
var lg	= 'pl';
var activeMap = 'http://maps.google.com/maps?file=api&maps=2&key=' + key + '&hl=' + lg + '&async=2&callback=initialize';
var inactiveMap = 'http://maps.google.com/staticmap?center=' + startLat + ',' + startLng + '&markers=' + startLat + ',' + startLng + ',red&size=' + startWidth + 'x' + startHeight + '&zoom=' + startZoom + '&key=' + key + '&hl=' + lg;
function deg2dms(number,latlng)
{
	if(latlng!='lat' && latlng!='lng')
	{
		return;
	}
	if(number>0)
	{
		var znak=0;
	}else{
		var znak=1;
	}
	number = Math.abs(number);
	var d = Math.floor(number);
	var s = ((number - Math.floor(number))*3600);
	var m = Math.floor(s/60);
	s = (s - m*60).toFixed(2);
	if(s<10)
	{
		s='0'+s;
	}
	if(m<10)
	{
		m='0'+m;
	}
	if(latlng=='lat')
	{
		var sufix=['N','S'];
	}else{
		var sufix=['E','W'];
	}
	return '<b>' + sufix[znak] + '</b> ' + d + '&deg;' + m + '&#39;' + s + '&#34;';
}
function initialize(id)
{
	var map = new google.maps.Map2(document.getElementById('map'));
//	map.load("maps", "2",{"other_params":"sensor=true"});
	var container = document.getElementById('map');
	container.className = 'active'; 
	var latlng = new google.maps.LatLng(startLat,startLng);
	map.setCenter(latlng, startZoom);
	map.addControl(new GLargeMapControl());
	map.addControl(new GScaleControl());
	map.enableScrollWheelZoom();
	var types = map.getMapTypes();
	types[0].getName = function() {
		return text[0];
	}
	types[1].getName = function() {
		return text[1];
	}
	types[2].getName = function() {
		return text[2];
	}
	map.addControl(new GMenuMapTypeControl());
	map.addControl(new GOverviewMapControl());
	var baseIcon = new GIcon(G_DEFAULT_ICON);
	baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
	baseIcon.iconSize = new GSize(20, 34);
	baseIcon.shadowSize = new GSize(37, 34);
	baseIcon.iconAnchor = new GPoint(9, 34);
	baseIcon.infoWindowAnchor = new GPoint(9, 2);
	function createMarker(point, index, title, info, gps)
	{
		var letter = String.fromCharCode("A".charCodeAt(0) + index);
		var info = '<div class="googleMapInfo" class="text">' + info + '</div>';
		var letteredIcon = new GIcon(baseIcon);
		letteredIcon.image = "http://www.google.com/mapfiles/marker" + letter + ".png";
		markerOptions = { icon:letteredIcon, title:'kliknij by zobaczyc wiecej...' };
		var marker = new GMarker(point, markerOptions);
		var infoTabs = [
			new GInfoWindowTab(title, info),
			new GInfoWindowTab("GPS", gps)
		];				
		GEvent.addListener(marker, "click", function()
		{
			marker.openInfoWindowTabsHtml(infoTabs);
		});
		marker.openInfoWindowTabsHtml(infoTabs);
		return marker;
	}
	
	var point1 = new GLatLng(startLat,startLng);
	var mGPSlat1		= deg2dms(startLat,'lat');
	var mGPSlng1		= deg2dms(startLng,'lng');
	var mGPS1 	= '<div id="googleMapInfo1" class="googleMapInfo gps">' + mGPSlat1 + '<br />' + mGPSlng1 + '</div>';
	
	var point2 = new GLatLng(startLat2,startLng2);
	var mGPSlat2		= deg2dms(startLat2,'lat');
	var mGPSlng2		= deg2dms(startLng2,'lng');
	var mGPS2 	= '<div id="googleMapInfo2" class="googleMapInfo gps">' + mGPSlat2 + '<br />' + mGPSlng2 + '</div>';
	
	var point3 = new GLatLng(startLat3,startLng3);
	var mGPSlat3		= deg2dms(startLat3,'lat');
	var mGPSlng3		= deg2dms(startLng3,'lng');
	var mGPS3 	= '<div id="googleMapInfo3" class="googleMapInfo gps">' + mGPSlat3 + '<br />' + mGPSlng3 + '</div>';
	
	map.addOverlay(createMarker(point2, 2, text[3],'<b>BWA Wroc&#322;aw, Galeria Awangarda</b><br />50-149 Wroc&#322;aw,<br />ul.Wita Stwosza 32', mGPS2));
	map.addOverlay(createMarker(point3, 1, text[3],'<b>KRAKOWSKA180</b><br />52-015 Wroc&#322;aw,<br />al. Krakowska 180<br />( wjazd od ul. Rybnickiej )', mGPS3));
	map.addOverlay(createMarker(point1, 0, text[3],'Centrum Sztuki <b>IMPART</b><br />50-412 Wroc&#322;aw,<br />ul.Mazowiecka 17', mGPS1));
	
}
function createScript(url)
{
	var script = document.createElement("script");
	script.setAttribute('src',url);
	script.setAttribute('type', "text/javascript");
	document.documentElement.firstChild.appendChild(script);
}
function staticAPI(id)
{
	document.getElementById(id).style.backgroundImage = "url("+inactiveMap+")";
}
function activateAPI(id)
{
	createScript(activeMap);
	createScript("./js/greversegeocoder.js");
	createScript("./js/geoip.js");
	document.getElementById(id).style.height = "300px";
	document.getElementById(id).style.backgroundImage = 'none';
}

