function initswfIR() {
	var borders = new swfir();
	borders.specify("border-width", "5");
	borders.specify("border-radius", "0");
	borders.specify("border-color", "FFFFFF");
	borders.specify("shadow-blur-x", "7");
	borders.specify("shadow-blur-y", "7");
	borders.specify("shadow-angle", "45");
	borders.swap(".framed-image img");
}

function navCaptionShow(caption) {
	var div = $('navbar-caption');
	if (div) {
		if (caption == null) {
			div.innerHTML = '';
		} else {
			div.innerHTML = caption;
		}
	}
}

function jumpMenu(url)
{
	if (url != '-1') {
		window.location=url;
	}
}

/* GMAPS */

function toggleMarkers(chk) {
	if (chk) {
		var chk_array = document.getElementsByName(chk.id+'_children[]');
		if (chk_array && chk_array.length > 0) {
			for(var i = 0; i < chk_array.length; i++) {
				chk_array[i].checked = chk.checked;
				toggleMarkers(chk_array[i]);
			}
		} else {
			var index;
			if (m_groups[chk.value]) {
				for(var i = 0; i < m_groups[chk.value].length; i++) {
					index = m_groups[chk.value][i];
					if (m_markers[index]) {
						chk.checked ? m_markers[index].show() : m_markers[index].hide();
					}
				}
			}
		}
	}
}

function subtree(node_id) {

	GDownloadUrl("/gmaps/cat/"+node_id, function(data, responseCode) {
		var xml = GXml.parse(data);
	});
}

function _parseData(data, reponseCode) {

	var xml = GXml.parse(data);
	var markers = xml.documentElement.getElementsByTagName("marker");

	for (var i = 0; i < markers.length; i++) {

		var id = markers[i].getAttribute('id');
		var parent_id = markers[i].getAttribute('parent');

		if (typeof(m_groups[parent_id]) == "undefined") {
			m_groups[parent_id] = new Array();
		}
		m_groups[parent_id].push(i);

		var name_node = markers[i].childNodes[0];
		var intro_node = markers[i].childNodes[1];
		var url_node = markers[i].childNodes[2];
		var location_node = markers[i].childNodes[3];
		var image_node = markers[i].childNodes[4];

		var latitude = location_node.childNodes[0].firstChild.nodeValue;
		var longitude = location_node.childNodes[1].firstChild.nodeValue;
		var zoom_level = location_node.getAttribute('zoom_level');

		var icon_node = location_node.childNodes[2];
		var icon = null;
		if (icon_node.firstChild) {
			icon = new GIcon(default_icon);
			icon.iconSize = new GSize(icon_node.childNodes[0].getAttribute("width"), icon_node.childNodes[0].getAttribute("height"));
			icon.shadowSize = new GSize(icon_node.childNodes[1].getAttribute("width"), icon_node.childNodes[1].getAttribute("height"));
			icon.image = icon_node.childNodes[0].firstChild.nodeValue;
			icon.shadow = icon_node.childNodes[1].firstChild.nodeValue;
		}

		var point = new GLatLng(parseFloat(latitude), parseFloat(longitude));
		var infoWindow = createInfoWindow(
							name_node.firstChild.nodeValue,
							markers[i].getAttribute('browseable'),
							url_node.firstChild.nodeValue,
							(parseInt(image_node.getAttribute('is_valid')) == 1) ? image_node.firstChild.nodeValue : null,
							intro_node.firstChild.nodeValue
		);

		var marker = createMarker(point, id, icon, infoWindow, zoom_level);
		m_markers.push(marker);
		map.addOverlay(marker);
	}

	if (markers.length > 0) {
		showCustomInfoWindow();
	}
}

function loadNode (node_id) {
	GDownloadUrl("/gmaps/xml/node/"+node_id, function(data, responseCode) {
		_parseData(data, responseCode);
	});
}

function loadSubtree (node_id) {
	GDownloadUrl("/gmaps/xml/subtree/"+node_id, function(data, responseCode) {
		_parseData(data, responseCode);
	});
}

function showCustomInfoWindow() {
	var container = $('map-infowindow');
	if (container) {
		container.style.display = '';
	}
}

function createInfoWindow(name, browseable, url, image, intro) {
	var html = '<div class="map-infowindow';

	if (intro) html += ' map-infowindow-with-intro';
	if (image) html += ' map-infowindow-with-image';
	html += '">';

	if (image) {
		html += '<img src="'+image+'" alt="" style="float: left; margin-right: 8px;"/>';
	}

	if (parseInt(browseable) == 1) {
		html += '<a href="'+url+'">'+name+'</a>';
	} else {
		html += '<p>'+name+'</p>';
	}
	if (intro) {
		html += '<div class="intro">'+intro+'</div>';
	}

	html += '</div>';
	return html;
}

function customInfoWindow (marker, html) {
	var container = $('map-infowindow');
	if (container) {
		container.innerHTML = html;
	} else {
		marker.openInfoWindowHtml(html);
	}
}

function createMarker(point, id, icon, html, zoom)
{
	if (icon && icon != null) {
		markerOptions = {icon:icon};
	} else {
		markerOptions = {icon:G_DEFAULT_ICON};
	}
	var marker = new GMarker(point, markerOptions);
	marker.id = id;

	GEvent.addListener(marker, "mouseover", function() {
		//marker.openInfoWindowHtml(html);
		customInfoWindow(marker, html);
	});

	GEvent.addListener(marker, "dblclick", function() {
		map.setCenter(point, zoom);
	});

	return marker;
}
