var appMenuItems = Array()
var delayedImgID = Array(), delayedImgSrc = Array()
var openMenu = null, timerID = null
var mouseX = 0, mouseY = 0

/************** insert HTML *************************************************/

function insertHTML(text) {
	document.open()
	document.write(text)
	document.close()
	}

/************** window opener ***********************************************/

function popup(url,name,width,height) {
	var features = [
		['toolbar',	0],
		['directories',	0],
		['menubar',	0],
		['status',	0],
		['resizable',	1],
		['location',	0],
		['scrollbars',	0],
		['copyhistory',	0]
		]
	for (var nr = 4; nr < popup.arguments.length; nr++) {
		var param = popup.arguments[nr].split('=')
		for (var i = 0; i < features.length; i++)
			if (features[i][0] == param[0]) {
				features[i][1] = param[1]
				break
				}
		if (i == features.length)
			features[i] = param
		}
	var featureString = 'width=' + width + ',height=' + height
	for (var i = 0; i < features.length; i++)
		featureString += ',' + features[i][0] + '=' + features[i][1]
	window.open(url,name,featureString)
	}

/************** submitForm **************************************************/

function submitForm(id) {
	for (var i=1; i<submitForm.arguments.length; i++) {
		var url = document.forms[id].action
		url += url.indexOf('?') == -1 ? '?' : '&'
		url += submitForm.arguments[i] + '=1'
		document.forms[id].action = url
		}
	document.forms[id].submit()
	}

/************** menu template ***********************************************/

var menufwkTop =
  '<table cellpadding=0 cellspacing=0 border=0>' +
  '  <tr>' +
  '    <td bgcolor="#009999" rowspan=3><tpix height=1 width=1></td>' +
  '    <td bgcolor="#009999"><tpix height=1 width=1></td>' +
  '    <td bgcolor="#009999" rowspan=3><tpix height=1 width=1></td>' +
  '    <td><tpix height=1 width=1></td>' +
  '  </tr>' +
  '  <tr>' +
  '    <td>' +
  '      <table cellpadding=0 cellspacing=0 border=0>' +
  '        <tr>' +
  '          <td bgcolor="#ffffff"><tpix height=1 width=4></td>' +
  '          <td bgcolor="#ffffff"><tpix height=7 width=1></td>' +
  '          <td bgcolor="#ffffff"><tpix height=1 width=10></td>' +
  '        </tr>' +
  '        <tr>' +
  '          <td bgcolor="#ffffff"><tpix height=1 width=4></td>' +
  '          <td bgcolor="#ffffff" class="menu">'

var menufwkBot =
  '          </td>' +
  '          <td bgcolor="#ffffff"><tpix height=1 width=4></td>' +
  '        </tr>' +
  '        <tr>' +
  '          <td bgcolor="#ffffff"><tpix height=1 width=4></td>' +
  '          <td bgcolor="#ffffff"><tpix height=7 width=1></td>' +
  '          <td bgcolor="#ffffff"><tpix height=1 width=4></td>' +
  '        </tr>' +
  '      </table>' +
  '    </td>' +
  '    <td bgcolor="#333333"><tpix height=1 width=1></td>' +
  '  </tr>' +
  '  <tr>' +
  '    <td bgcolor="#009999"><tpix height=1 width=1></td>' +
  '    <td bgcolor="#333333" rowspan=2><tpix height=1 width=1></td>' +
  '  </tr>' +
  '  <tr>' +
  '    <td><tpix height=2 width=1></td>' +
  '    <td bgcolor="#333333" colspan=2><tpix height=2 width=1></td>' +
  '  </tr>' +
  '</table>'

/************** showMenu ****************************************************/

function showMenu(entries) {
	// assign default arguments: x, y, isRelative, mask
	var argv = showMenu.arguments
	var argc = argv.length
	var x = (argc > 1) ? argv[1] : 0
	var y = (argc > 2) ? argv[2] : 0
	var isRelative = (argc > 3) ? argv[3] : false
	var mask = (argc > 4) ? argv[4] : ''
	// assemble menuEntries string
	var menuEntries = ''
	for (var i = 0; entries && i < entries.length; i++) {
		var nameurl = entries[i].split('�')
		if (nameurl[0] == 'autoexec') {
			window.location = nameurl[1]
			return
			}
		if (mask.charAt(i) != '0')
			menuEntries += '<a href="' + nameurl[1] + '" onclick="showMenu(null)">' + nameurl[0] + '</a><br>'
		  else
			menuEntries += nameurl[0].fontcolor('a0a0a0') + '<br>'
		}
	// apply parameters to menuentires
	for (var i = 5; i < argc; i++) {
		var splitpos = argv[i].indexOf('=')
		if (splitpos != -1) {
			re = new RegExp(argv[i].slice(0, splitpos), 'g')
			menuEntries = menuEntries.replace(re, argv[i].slice(splitpos+1))
			}
		}
	// calculate correct position
	if (isRelative) {
		x += mouseX
		y += mouseY
		}
	  else
		x += getMargin('x')
	// add menu framework
	var menuContent = menufwkTop + menuEntries + menufwkBot
	menuContent = menuContent.replace(/tpix/g, 'img src="' + imagePath + 't.gif" alt=""')
	// display menu
	var newMenu = menuEntries
	if (entries && newMenu != openMenu) {
		setLayer('menu', menuContent)
		showLayer('menu', x, y)
		openMenu = newMenu
		}
	  else {
		hideLayer('menu')
		openMenu = null
		}
	}

function delayedClosemenu(activate) {
	// if activate==true activate timer that closes open menu in 10ms
	// if activate==false deactivate that timer
	if (activate)
		timerID = setTimeout(showMenu,10,null)
	  else {
		if (timerID)
			clearTimeout(timerID)
		timerID = null
		}
	}

/************** delayed images **********************************************/

function insertDelayedImg(src, width, height, alt) {
	var align = insertDelayedImg.arguments.length > 4 ? insertDelayedImg.arguments[4] : null
	var nr = delayedImgID.length
	var id = 'dimg' + nr
	var imgSrc = '<img name="' + id + '" border="0" src="' + imagePath + 't.gif"'
	if (width) imgSrc += ' width="' + width + '"'
	if (height) imgSrc += ' height="' + height + '"'
	if (align) imgSrc += ' align="' + align + '"'
	imgSrc += ' alt="' + alt + '">'
	insertHTML(imgSrc)
	delayedImgID[nr] = id
	delayedImgSrc[nr] = src
	}

function showDelayedImages() {
	for (var i = 0; i < delayedImgID.length; i++)
		document.images[delayedImgID[i]].src = delayedImgSrc[i]
	}

/************** onload handler **********************************************/

function handlePageLoadEvent() {
	if (appMenuItems.length)
		showAppMenuDelayed()
	showDelayedImages()
	}

expandableContainer = {};
expandableContainer.container = null;
expandableContainer.more = null;
expandableContainer.limit = 3;

expandableContainer.initialize = function() {
	expandableContainer.container = document.getElementById("notes_container");
	if (
		expandableContainer.container && 
		expandableContainer.container.getElementsByTagName("A").length > expandableContainer.limit
	) {
		expandableContainer.container.innerHTML += " " + 
			"<a href='javascript:expandableContainer.setExpanded(true);void(0)' " +
				"id='notes_container_more' class='rusys' style='font-weight: bold;display:none'>" +
				expandableContainer.container.getAttribute("title_more") + "</a>";
		expandableContainer.more = document.getElementById("notes_container_more");
		expandableContainer.setExpanded(false);
	}
}

expandableContainer.setExpanded = function(expanded) {
	if (expanded === undefined) {
		expanded = expandableContainer.more.style.display !== "";
	}
	expandableContainer.more.style.display = expanded ? "none" : "";	
	if (!expanded) {
		var children = expandableContainer.container.childNodes;				
		var n = 0;			
		for (var i = 0; i < children.length; i++) {
			var node = children[i];			
			if (node && node !== expandableContainer.more && n >= expandableContainer.limit) {												
				node.style.display = "none";								
			} else if (node.nodeName === "A") {
				n++;					
			}
		}
	} else {
		var children = expandableContainer.container.childNodes;
		for (var i = 0; i < children.length; i++) {
			var node = children[i];
			if (node && node.style && node !== expandableContainer.more) {				
				node.style.display = "";
			}
		}
	}
}

jumsinfo = {};

jumsinfo.map = function(container) {
	this.container = container;	
	this.geocoder = new google.maps.Geocoder();	
	this.location = new google.maps.LatLng(54.896872, 23.892426);
	this.map = new google.maps.Map(this.container, {
		zoom: 14,
		mapTypeId: google.maps.MapTypeId.ROADMAP,
		zoomControl: true,
		zoomControlOptions: {style: google.maps.ZoomControlStyle.SMALL},
		panControl: true,
		mapTypeControl: true,
		mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU},
		size : {}
	});
	if (this.container.getAttribute("address")) {
		this.setPlace(this.container.getAttribute("address"));
	}
}

jumsinfo.map.initialize = function() {
	var container = document.getElementById('map');
	if (container) {
		new jumsinfo.map(container);
	}
}

jumsinfo.map.prototype.setPlace = function(address) {
	this.geocoder.geocode({address : address}, this.setPlaceComplete.bind(this));
}

jumsinfo.map.prototype.setPlaceComplete = function(results, status) {
	if (status == google.maps.GeocoderStatus.OK) {		
		this.location = new google.maps.LatLng(
			results[0].geometry.location.lat(), results[0].geometry.location.lng()
		);
	}
	this.map.setCenter(this.location);
	google.maps.event.addListener(
		new google.maps.Marker({map: this.map, position: this.location}), 
		"click", this.placeClicked.bind(this)
	);
}

jumsinfo.map.prototype.placeClicked = function() {
	window.open(
		"http://maps.google.com/?q=" + this.location.lat() + "," + this.location.lng() +"&z=14"
	);
}
