window.onload = function() {
  xgallery();
}

function xgallery() {

 if (GBrowserIsCompatible()) {

var main = document.getElementById("kartta");
var ppp = document.getElementById("images");
var div = document.createElement("div");
div.style.width = "50%";
div.style.height = window.innerHeight + "px";
div.style.float = "right";
//div.setAttribute("class", "gmap");
main.appendChild(div);
main.style.width = "50%";
var map = new GMap2(div);
var trecenter = new GLatLng(61.49747,23.778533);
//var trecenter = new GLatLng();
map.addControl(new GSmallMapControl());
map.addControl(new GMapTypeControl());
map.setCenter(trecenter, 1);
var images = ppp.getElementsByTagName("div");
var bounds = new GLatLngBounds();
var apu = new Array();
//main.style.width = "50%";
//images.style.float = "left";

var gx = new GGeoXml("http://hazor.iki.fi/2009/karjala/Karjala.kmz");

map.addOverlay(gx);
//gx.gotoDefaultViewport(map);


for(var i=0; i<images.length; i++) {
		var span = images[i].getElementsByTagName("span");
		if ( span[0] && span[1] ) {
			var lat = parseFloat( span[0].textContent );
			var lng = parseFloat( span[1].textContent );
			var koord = new GLatLng( lat, lng );
			var p = images[i].getElementsByTagName("p");
			if ( p[0] ) {
				var marker = new GMarker(koord, {title: p[0].textContent});
			map.addOverlay(marker);
			if ( apu[marker.getPoint()] == undefined) 
				apu[marker.getPoint()] = images[i].innerHTML;
			else 
				apu[marker.getPoint()] += images[i].innerHTML;
			  GEvent.addListener(marker, "click", function() {
			    this.openInfoWindowHtml( apu[this.getPoint()] );
			  });

			}


			bounds.extend(koord);
		}	
}



map.setCenter(bounds.getCenter(), map.getBoundsZoomLevel(bounds));

div.style.position = "absolute";
div.style.right = "0";


}


	return;
	var comment  = document.getElementById("main");

	p = document.createElement("p");
	a = document.createElement("a");
	p.setAttribute("id", "naytalinkki");
	p.style.clear = "both";
	a.setAttribute("href", "#");
	p.appendChild(a);
	a.textContent = "Kommentoi / Add comment";
	comment.appendChild ( p);
	a.addEventListener("click", lomake, false);






}

function lomake(e) {
	e.preventDefault();
	var apu  = document.getElementById("naytalinkki");
	apu.style.display = "none";

	var comment  = document.getElementById("main");
	var form = document.createElement("form");
	form.setAttribute("action", "http://hazor.iki.fi/cgi-bin/art_comment.cgi");
	form.setAttribute("method", "post");
	form.setAttribute("id", "kommenttilomake");
	comment.appendChild(form);
	var fieldset = document.createElement("fieldset");
	form.appendChild(fieldset);
	form = fieldset;
	var h2 = document.createElement("legend");
	h2.textContent = "Add Comment / kommentoi";
	form.appendChild(h2);

	fieldset = document.createElement("fieldset");
	var legend = document.createElement("legend");
	legend.textContent = "Spam protection / roskasuojaus";
	fieldset.appendChild(legend);
	var spam = document.createElement("input");
	spam.setAttribute("name", "spam");
	spam.setAttribute("type", "password");
	var label = document.createElement("label");
	label.textContent = "What is the surname of the author of this page? Mikä on tämän sivun tekijän sukunimi?";
	label.setAttribute("class", "tasa");
	var p = document.createElement("p");
	p.appendChild(spam);
	fieldset.appendChild(label);
	fieldset.appendChild(p);
	form.appendChild(fieldset);

	var url = document.createElement("input");
	url.setAttribute("name", "url");
	url.setAttribute("type", "hidden");
	url.setAttribute("value", document.location.href);
	form.appendChild(url);

	var teksti = document.createElement("textarea");
	teksti.setAttribute("name", "teksti");
	teksti.setAttribute("cols", "60");
	teksti.setAttribute("rows", "8");
	label = document.createElement("label");
	label.setAttribute("class", "tasa");
	label.textContent = "Comment / Kommentti";
	p = document.createElement("p");
	p.appendChild(teksti);
	form.appendChild(label);
	form.appendChild(p);


	var nimi = document.createElement("input");
	nimi.setAttribute("name", "nimi");
	label = document.createElement("label");
	label.textContent = "Your name / Nimesi";
	label.setAttribute("class", "tasa");
	p = document.createElement("p");
	p.appendChild(nimi);
	form.appendChild(label);
	form.appendChild(p);

	var submit = document.createElement("input");
	submit.setAttribute("type", "submit");
	submit.setAttribute("value", "Add comment / Lisää kommentti");
	p = document.createElement("p");
	p.appendChild(submit);
	form.appendChild(p);

}

function lomake2(e) {
	e.preventDefault();
	var apu  = document.getElementById("naytalinkki");
	apu.style.display = "none";

	var comment  = document.getElementById("comment");

	var form = document.createElement("form");
	form.setAttribute("action", "http://hazor.iki.fi/cgi-bin/photo_comment.cgi");
	form.setAttribute("method", "post");
	comment.appendChild(form);
	var fieldset = document.createElement("fieldset");
	form.appendChild(fieldset);
	form = fieldset;
	var h2 = document.createElement("legend");
	h2.textContent = "Add Comment / kommentoi";
	form.appendChild(h2);

	fieldset = document.createElement("fieldset");
	var legend = document.createElement("legend");
	legend.textContent = "Spam protection / roskasuojaus";
	fieldset.appendChild(legend);
	var spam = document.createElement("input");
	spam.setAttribute("name", "spam");
	spam.setAttribute("type", "password");
	var label = document.createElement("label");
	label.textContent = "What is the surname of the author of this page? Mikä on tämän sivun tekijän sukunimi?";
	label.setAttribute("class", "tasa");
	var p = document.createElement("p");
	p.appendChild(spam);
	fieldset.appendChild(label);
	fieldset.appendChild(p);
	form.appendChild(fieldset);

	var url = document.createElement("input");
	url.setAttribute("name", "url");
	url.setAttribute("type", "hidden");
	url.setAttribute("value", document.location.href);
	form.appendChild(url);

	var teksti = document.createElement("textarea");
	teksti.setAttribute("name", "teksti");
	teksti.setAttribute("cols", "60");
	teksti.setAttribute("rows", "8");
	label = document.createElement("label");
	label.setAttribute("class", "tasa");
	label.textContent = "Comment / Kommentti";
	p = document.createElement("p");
	p.appendChild(teksti);
	form.appendChild(label);
	form.appendChild(p);


	var nimi = document.createElement("input");
	nimi.setAttribute("name", "nimi");
	label = document.createElement("label");
	label.textContent = "Your name / Nimesi";
	label.setAttribute("class", "tasa");
	p = document.createElement("p");
	p.appendChild(nimi);
	form.appendChild(label);
	form.appendChild(p);

	var submit = document.createElement("input");
	submit.setAttribute("type", "submit");
	submit.setAttribute("value", "Add comment / Lisää kommentti");
	p = document.createElement("p");
	p.appendChild(submit);
	form.appendChild(p);
}

function init() {

var kuva = document.getElementById("img");

if ( document.body.clientWidth > ( kuva.width +100+100 )  )
{

var left = document.getElementById("prev");
if ( left ) {

left.style.position = "absolute";
left.style.left = "0px";
left.style.top = "0px";
left.style.width = "200px";

}

var right = document.getElementById("next");

if ( right ) {

right.style.position = "absolute";
right.style.right = "0px";
right.style.top = "0px";
right.style.width = "200px";

}

}

	var comment  = document.getElementById("comment");

	p = document.createElement("p");
	a = document.createElement("a");
	p.setAttribute("id", "naytalinkki");
	p.style.clear = "both";
	p.style.width = "100%";
	a.setAttribute("href", "#");
	p.appendChild(a);
	a.textContent = "Kommentoi / Add comment";
	comment.appendChild ( p);
	a.addEventListener("click", lomake2, false);


}



