/**
Copyright © 2008 Computer Sciences Corporation Denmark (CSC).
All rights reserved. You may not use, copy, modify or transfer this
program or any copy, modification or portion, in whole or in part,
without the explicit written permission of CSC Denmark
**/

/*SEARCH FUNCTION*/

(function ($) {

    $.fn.jsonSuggest = function (settings) {
        var defaults = {
            url: '',
            starttext: '',
            data: [],
            minCharacters: 1,
            maxResults: undefined,
            wildCard: '',
            caseSensitive: false,
            notCharacter: '!',
            timeout: 20000,
            maxHeight: 410,
            highlightMatches: true,
            onSelect: undefined,
            width: undefined
        },			
        settings = $.extend(defaults, settings);
        var fireevent = true;
        return this.each(function () {
            /**
            * Escape some text so that it can be used inside a regular expression
            * without implying regular expression rules iself. 
            */
            function regexEscape(txt, omit) {
                var specials = ['/', '.', '*', '+', '?', '|',
								'(', ')', '[', ']', '{', '}', '\\'];

                if (omit) {
                    for (var i = 0; i < specials.length; i++) {
                        if (specials[i] === omit) { specials.splice(i, 1); }
                    }
                }

                var escapePatt = new RegExp('(\\' + specials.join('|\\') + ')', 'g');
                return txt.replace(escapePatt, '\\$1');
            }

            this.InitSearchSelected = function (value, lineguid) {
                obj[0].value = value;
                $.ajax({
                    url: settings.url + 'SearchByLineGID/' + value + ',' + lineguid,
                    type: "GET",
                    contentType: "application/json",
                    processData: false,
                    async: false,
                    dataType: "jsonp",
                    success: function (result) {
                        if (result != null && result.length != 0) {
                            if (typeof settings.onSelect === 'function')
                                settings.onSelect(result);
                        }
                        else
                            $(results).html('<li class="search-menu-item ajaxSearching"><a class="search-corner-all">Ingen resultater fundet</a></li>').show().css('height', 'auto');
                    },
                    error: function (xhr, message, ex)
                    { alert("Ajax Error: " + message); }
                });
            }

            this.searchclicked = function () {

                if (visible) {
                    currentSelection = $('li:first', results).get(0);
                    $(currentSelection).trigger('click');
                }
                else {
                    runSuggestint.apply(this, [true]);
                }
                return false;
            };

            var visible = false;

            var obj = $(this),
				wildCardPatt = new RegExp(regexEscape(settings.wildCard || ''), 'g'),
				results = $('<ul />'),
				currentSelection, pageX, pageY;

            /**
            * When an item has been selected then update the input box,
            * hide the results again and if set, call the onSelect function.
            */
            function selectResultItem(item) {
                obj.val(item.text);
                $(results).html('').hide();
                visible = false;
                if (fireevent && typeof settings.onSelect === 'function') {
                    settings.onSelect(item);
                }
                fireevent = true;
            }

            /**
            * Used to get rid of the hover class on all result item elements in the
            * current set of results and add it only to the given element. We also
            * need to set the current selection to the given element here.
            */
            function setHoverClass(el) {
                $('li a', results).removeClass('search-state-hover');
                if (el) {
                    $('a', el).addClass('search-state-hover');
                }

                currentSelection = el;
            }

            /**
            * Build the results HTML based on an array of objects that matched
            * the search criteria, highlight the matches if that feature is turned 
            * on in the settings.
            */
            function buildResults(resultObjects, filterTxt) {
                filterTxt = '(' + filterTxt + ')';

                var bOddRow = true, i, iFound = 0,
					filterPatt = settings.caseSensitive ? new RegExp(filterTxt, 'g') : new RegExp(filterTxt, 'ig');

                $(results).html('').hide();
                visible = false;

                for (i = 0; i < resultObjects.length; i += 1) {
                    var item = $('<li />'),
						text = resultObjects[i].text;

                    if (settings.highlightMatches === true) {
                        text = text.replace(filterPatt, '<strong>$1</strong>');
                    }

                    $(item).append('<a class="search-corner-all">' + text + '</a>');

                    if (typeof resultObjects[i].image === 'string') {
                        $('>a', item).prepend('<img src="' + resultObjects[i].image + '" />');
                    }

                    if (typeof resultObjects[i].extra === 'string') {
                        $('>a', item).append('<small> ' + resultObjects[i].extra + '</small>');
                    }

                    $(item).addClass('search-menu-item').
						addClass((bOddRow) ? 'odd' : 'even').
						attr('role', 'menuitem').
						click((function (n) {
						    return function () {
						        selectResultItem(resultObjects[n]);
						    };
						})(i)).
						mouseover((function (el) {
						    return function () {
						        setHoverClass(el);
						    };
						})(item));

                    $(results).append(item);

                    bOddRow = !bOddRow;

                    iFound += 1;
                    if (typeof settings.maxResults === 'number' && iFound >= settings.maxResults) {
                        break;
                    }
                }

                if ($('li', results).length > 0) {
                    currentSelection = undefined;
                    $(results).show().css('height', 'auto');
                    visible = true;
                    if ($(results).height() > settings.maxHeight) {
                        $(results).css({ 'overflow': 'auto', 'height': settings.maxHeight + 'px' });
                    }
                }
            }

            function runSuggestint(showmessage) {
                var search = function (searchData) {
                    var resultObjects = [],
						filterTxt = (!settings.wildCard) ? regexEscape(this.value) : regexEscape(this.value, settings.wildCard).replace(wildCardPatt, '.*'),
						bMatch = true,
						filterPatt, i;

                    if (settings.notCharacter && filterTxt.indexOf(settings.notCharacter) === 0) {
                        filterTxt = filterTxt.substr(settings.notCharacter.length, filterTxt.length);
                        if (filterTxt.length > 0) { bMatch = false; }
                    }
                    filterTxt = filterTxt || '.*';
                    filterTxt = settings.wildCard ? '^' + filterTxt : filterTxt;
                    filterPatt = settings.caseSensitive ? new RegExp(filterTxt) : new RegExp(filterTxt, 'i');

                    // Look for the required match against each single search data item. When the not
                    // character is used we are looking for a false match. 
                    for (i = 0; i < searchData.length; i += 1) {
                        if (filterPatt.test(searchData[i].text) === bMatch) {
                            resultObjects.push(searchData[i]);
                        }
                    }

                    buildResults(resultObjects, filterTxt);
                };

                if (this.value.length < settings.minCharacters) {
                    $(results).html('').hide();
                    visible = false;
                    return false;
                }

                if (settings.data && settings.data.length) {
                    search.apply(this, [settings.data]);
                }
                else if (settings.url && typeof settings.url === 'string') {
                    var text = this.value;
                    $(results).html('<li class="search-menu-item ajaxSearching"><a class="search-corner-all">Søger...</a></li>').
						show().css('height', 'auto');

                    $.ajax({
                        url: settings.url + 'Search/' + text,
                        type: "GET",
                        contentType: "application/json",
                        processData: false,
                        timeout: defaults.timeout,
                        dataType: "jsonp",
                        success: function (result) {
                            if (result != null && result.length != 0)
                                buildResults(result, text);
                            else {
                                $(results).html('').hide();
                                visible = false;
                                if (showmessage)
                                    $(results).html('<li class="search-menu-item ajaxSearching"><a class="search-corner-all">Ingen resultater fundet</a></li>').show().css('height', 'auto');
                            }
                        },
                        error: function (xhr, message, ex) {
                            if (message == "timeout")
                                $(results).html('<li class="search-menu-item ajaxSearching"><a class="search-corner-all">Timeout. Prøv igen.</a></li>').show().css('height', 'auto');
                            else
                                $(results).html('<li class="search-menu-item ajaxSearching"><a class="search-corner-all">Fejl. Prøv igen.</a></li>').show().css('height', 'auto');
                        }
                    });

                }
            }

            /**
            * Prepare the search data based on the settings for this plugin,
            * run a match against each item in the possible results and display any 
            * results on the page allowing selection by the user.
            */
            function runSuggest(e) {
                runSuggestint.apply(this, [false]);
            }


            /**
            * To call specific actions based on the keys pressed in the input
            * box. Special keys are up, down and return. All other keys
            * act as normal.
            */
            function keyListener(e) {
                switch (e.keyCode) {
                    case 13: // return key                        
                        if (typeof currentSelection === 'undefined') {
                            currentSelection = $('li:first', results).get(0);
                        }
                        $(currentSelection).trigger('click');
                        return false;
                    case 39:
                        if (!(typeof currentSelection === 'undefined')) {
                            fireevent = false;
                            $(currentSelection).trigger('click');
                            runSuggest.apply(this, [e]);
                        }
                    case 40: // down key
                        if (typeof currentSelection === 'undefined') {
                            currentSelection = $('li:first', results).get(0);
                        }
                        else {
                            currentSelection = $(currentSelection).next().get(0);
                        }

                        setHoverClass(currentSelection);
                        if (currentSelection) {
                            $(results).scrollTop(currentSelection.offsetTop);
                        }

                        return false;
                    case 38: // up key
                        if (typeof currentSelection === 'undefined') {
                            currentSelection = $('li:last', results).get(0);
                        }
                        else {
                            currentSelection = $(currentSelection).prev().get(0);
                        }

                        setHoverClass(currentSelection);
                        if (currentSelection) {
                            $(results).scrollTop(currentSelection.offsetTop);
                        }

                        return false;
                    default:
                        runSuggest.apply(this, [e]);
                }
            }

            // Prepare the input box to show suggest results by adding in the events
            // that will initiate the search and placing the element on the page
            // that will show the results.
            $(results).addClass('jsonSuggest search-autocomplete search-menu search search-content search-corner-all').
				attr('role', 'listbox').
				css({
				    'top': (obj.position().top + obj.outerHeight()) + 'px',
				    'left': obj.position().left + 'px',
				    'width': settings.width || (obj.outerWidth() + 'px'),
				    'z-index': 999
				}).hide();

            obj.after(results).
				keyup(keyListener).
				keydown(function (e) {
				    if (e.keyCode === 13) {
				        if (typeof currentSelection === 'undefined') {
				            currentSelection = $('li:first', results).get(0);
				        }
				        $(currentSelection).trigger('click');
				        return false;
				    }
				    // for tab key only
				    if (e.keyCode === 9 && currentSelection) {
				        $(currentSelection).trigger('click');
				        return true;
				    }
				}).
				blur(function (e) {
				    // We need to make sure we don't hide the result set
				    // if the input blur event is called because of clicking on
				    // a result item.
				    var resPos = $(results).offset();
				    resPos.bottom = resPos.top + $(results).height();
				    resPos.right = resPos.left + $(results).width();

				    if (pageY < resPos.top || pageY > resPos.bottom || pageX < resPos.left || pageX > resPos.right) {
				        $(results).hide();
				    }
				}).
				focus(function (e) {
				    if (settings.starttext != '' && obj[0].value == settings.starttext)
				        obj[0].value = '';
				    $(results).css({
				        'top': (obj.position().top + obj.outerHeight()) + 'px',
				        'left': obj.position().left + 'px'
				    });

				    if ($('li', results).length > 0) {
				        $(results).show();
				    }
				}).
				attr('autocomplete', 'off');
            $(window).mousemove(function (e) {
                pageX = e.pageX;
                pageY = e.pageY;
            });

            // Escape the not character if present so that it doesn't act in the regular expression
            settings.notCharacter = regexEscape(settings.notCharacter || '');

            obj[0].value = settings.starttext;

            // Make sure the JSON data is a JavaScript object if given as a string.
            if (settings.data && typeof settings.data === 'string') {
                settings.data = $.parseJSON(settings.data);
            }
        });
        var htest = '1';
    };

})(jQuery);

function searchcallback(item) {
    //Todo change to integrate with map.
    if (item.type == "L") {
        var options = { 'queryStringLines': item.data };
        $('#' + globalMap.mapElm).mapUtility("drawMap", options);
    }    
}

/* --- get query string --- */
function getQueryString(varname) {
	var st = unescape(location.search);
	if (st.indexOf(varname) != -1){
		var tempst = st.substring(st.indexOf(varname + "=") + varname.length + 1,st.length);
		if (tempst.indexOf("&") != -1) {
			var newtemp = tempst.substring(0, tempst.indexOf("&"));
			return newtemp;
		} else {
			return tempst;
		}
	} else {
		return("");
	}
}

// this function gets the cookie, if it exists
function getCookie(name) {
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ((!start) && (name != document.cookie.substring(0, name.length))) {
		return null;
	}
	if (start == -1) return null;
	var end = document.cookie.indexOf(";", len);
	if (end == -1) end = document.cookie.length;
	return unescape(document.cookie.substring(len, end));
}

function setCookie(name, value, expires, path, domain, secure ) {
	var today = new Date();
	today.setTime(today.getTime());
	if (expires) {
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires));
	document.cookie = name+'='+escape(value) + ((expires) ? ';expires=' + expires_date.toGMTString() : '') + ((path) ? ';path=' + path : '') + ((domain) ? ';domain=' + domain : '') + ((secure) ? ';secure' : '' );
}

function deleteCookie(name, path, domain) {
	if (getCookie(name)) {
		document.cookie = name + '=' + ((path) ? ';path=' + path : '') + ((domain) ? ';domain=' + domain : '') + ';expires=Thu, 01-Jan-1970 00:00:01 GMT';
	}
}

/* --- finds an elements position --- */
function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}

	return [curleft,curtop];
}

/* --- swap images in main menu --- */
function swapMenuImage(e) {
	// get source element of the event
	if (!e) var e = window.event;
	target = (e.target) ? e.target : e.srcElement;
	if (!target) return;

	if (!target.orgSrc) {
		target.orgSrc = target.src;
		if (target.orgSrc.indexOf("_on.gif") > 0) return;
		if (target.orgSrc.indexOf("_off.gif") < 0) return;
		target.src = target.src.replace("_off.gif", "_on.gif");
	} else {
		target.src = target.orgSrc;
		target.orgSrc = null;
	}
}

/* --- clock --- */
function updateClock() {
	var elm, d, h, m, s, delimiter, outString;

	elm = document.getElementById("clock");

	// get hours and minutes
	d = new Date();
	h = d.getHours();
	m = d.getMinutes();
	s = d.getSeconds();

	// delimiter = "<div class=\"delimiter\">" + (s % 2 == 0 ? ":" : " ") + "</div>";

	outString = "<div class=\"left\">" + (h < 10 ? "0" + h : h) + "</div>";
	outString += "<div class=\"delimiter\">" + (s % 2 == 0 ? ":" : "&nbsp;") + "</div>";
	outString += "<div class=\"left\">" + (m < 10 ? "0" + m : m) + "</div>";

	elm.innerHTML = outString;
	elm.style.visibility = "visible";
	window.setTimeout(updateClock, 1000);

	return;
}

function moveMarker(from, to) {
	if (fromSection > toSection) {
		if (from <= to) {
			clearTimeout(timer);
			return true;
		}
	}

	if (toSection > fromSection) {
		if (from >= to) {
			clearTimeout(timer);
			return true;
		}
	}

	k = 0.45;
	//	k = k * k * (3 - 2 * k); // apply easing (original formula)
	k = k * k * (2 * k); // apply easing
	_x = parseInt((to - from) * k);

	if (fromSection > toSection) {
		if (_x > -1) _x = -1;
	} else {
		if (_x < 1) _x = 1;
	}

	elmBus.style.left = parseInt(elmBus.style.left) + _x + "px";
	timer = setTimeout("moveMarker(" + parseInt(elmBus.style.left) + "," + to + ")", 10);
	return;
}

function positionMarker() {
	var elm;

	elmBus = document.getElementById("bus");
	if (fromSection == 0) {
		fromPos = 0;
	} else {
		elm = document.getElementById("menuItem" + fromSection);
		fromPos = findPos(elm)[0] - offset;
	}

	// position marker at start
	elmBus.style.left = fromPos + "px";
	elmBus.style.display = "block";

	if (fromSection != toSection) {
		if (toSection == 0) {
			toPos = 0;
		} else {
			elm = document.getElementById("menuItem" + toSection);
			toPos = findPos(elm)[0] - offset;
		}
		moveMarker(fromPos, toPos);
	}
	return;
}

function submitRouteSearchForm() {
	var i, elm, nodes;
	var urlString = null;

	// find form element
	if (elm = document.getElementById("routeSearchForm")) {
		// loop thru all child nodes
		nodes = elm.getElementsByTagName("input");
		for (i = 0; i <= nodes.length - 1; i++) {
			// form element named 'url' must be first in the form
			if (nodes[i].name == "url") {
				urlString = nodes[i].value;
			} else {
			// build query string
			    if (nodes[i].type != "radio" || (nodes[i].type == "radio" && nodes[i].checked)) {
			        if (nodes[i].name == "returndate" || nodes[i].name == "returntime") {
			            if (document.getElementById("radioRoundtrip").checked) {
    		                urlString += (nodes[i].value) ? "&" + nodes[i].name + "=" + nodes[i].value : "";
			            }
			        } else if (nodes[i].name == "STimeType") {
			            urlString += (nodes[i].value) == "0" ? "&timesel=arrive" : "&timesel=depart";
			        } else if (nodes[i].name == "ZTimeType") {
			            urlString += (nodes[i].value) == "0" ? "&returntimesel=arrive" : "&returntimesel=depart";
			        } else 
			        if (nodes[i].value.indexOf("fx. Adresse") == 0) {
			            urlString += "&" + nodes[i].name + "=";
			        } else {
			            urlString += (nodes[i].value) ? "&" + nodes[i].name + "=" + nodes[i].value : "";
			        }
			        if (nodes[i].name == "requestboth" && nodes[i].value == "yes") {
			            urlString += "&showDateTimeFieldForReturnJourney=yes";
			        }
			    }
			}
		}
		window.open(urlString, "externalWindow", "width=1024,height=600,scrollbars,resizable");
	}
	return false;
}

function processLocalEnterKey(e,o) {
    if (null == e)
        e = window.event;
    if (e.keyCode == 13) {
        document.getElementById(o).click(); 
    }
}

function init() {
	var elm, i, qs;

	// clock update function
	if (elm = document.getElementById("clock")) {
		updateClock();
	}

	// image swapping in main menu
	for (var i = 1; i <= 5; i++) {
		if (elm = document.getElementById("menuItem" + i)) {
			elm.onmouseover = swapMenuImage;
			elm.onmouseout = swapMenuImage;
		}
	}

	// populate 'date' field
	if (elm = document.getElementById("date")) {
		var jsCurrentDate = new Date();
		var jsDay = jsCurrentDate.getDate();
		var jsMonth = eval(jsCurrentDate.getMonth() +1);
		var jsYear = eval(jsCurrentDate.getFullYear() % 100);
		var jsDayOutput = ((jsDay < 10) ? "0" + jsDay : jsDay);
		var jsMonthOutput = ((jsMonth < 10) ? "0" + jsMonth : jsMonth);
		var jsYearOutput = ((jsYear < 10) ? "0" + jsYear : jsYear);
		var jsDateOutput =  (jsDayOutput + "/" + jsMonthOutput + "/" + jsYearOutput);
		elm.value = jsDateOutput;
	}

	// populate 'return date' field
	if (elm = document.getElementById("returndate")) {
	    var jsCurrentDate = new Date();
	    var jsDay = jsCurrentDate.getDate();
	    var jsMonth = eval(jsCurrentDate.getMonth() + 1);
	    var jsYear = eval(jsCurrentDate.getFullYear() % 100);
	    var jsDayOutput = ((jsDay < 10) ? "0" + jsDay : jsDay);
	    var jsMonthOutput = ((jsMonth < 10) ? "0" + jsMonth : jsMonth);
	    var jsYearOutput = ((jsYear < 10) ? "0" + jsYear : jsYear);
	    var jsDateOutput = (jsDayOutput + "/" + jsMonthOutput + "/" + jsYearOutput);
	    elm.value = jsDateOutput;
	}

	// populate 'time' field
	if (elm = document.getElementById("time")) {
		var jsCurrentTime = new Date();
		var jsHours = jsCurrentTime.getHours();
		var jsMinutes = jsCurrentTime.getMinutes();
		var jsHoursOutput = ((jsHours < 10) ? "0" + jsHours : jsHours);
		var jsMinutesOutput = ((jsMinutes < 10) ? "0" + jsMinutes : jsMinutes);
		var jsTimeOutput =  (jsHoursOutput + ":" + jsMinutesOutput);
		elm.value = jsTimeOutput;
	}

	// populate 'return time' field
	if (elm = document.getElementById("returntime")) {
	    var jsCurrentTime = new Date();
	    var jsHours = jsCurrentTime.getHours();
	    var jsMinutes = jsCurrentTime.getMinutes();
	    var jsHoursOutput = ((jsHours < 10) ? "0" + jsHours : jsHours);
	    var jsMinutesOutput = ((jsMinutes < 10) ? "0" + jsMinutes : jsMinutes);
	    var jsTimeOutput = (jsHoursOutput + ":" + jsMinutesOutput);
	    elm.value = jsTimeOutput;
	}

	// onclick for searchRouteForm submit button
	/*
	if (elm = document.getElementById("routeSearchAdvancedFormSubmit")) {
		elm.onclick = submitRouteSearchForm;
	}
	*/

	// rejseplan iframe
	if (elm = document.getElementById("rejseplan")) {
		qs = location.search;
		if (qs.indexOf("http://") > 0) {
			elm.src = qs.substring(qs.indexOf("http://"), qs.length);
		}
	}

	// hightlight active menu item
	sPath = location.href.toLowerCase();
	currentActiveTopNavItem = 0;
	maxNumberTopNavElements = 0;
	// match topNav images with location
	if (elm = document.getElementById("topNav")) {
		childElements = elm.getElementsByTagName("A");
		maxNumberTopNavElements = childElements.length;
		for (var i = 0; i < childElements.length; i++) {
			s = childElements[i].firstChild.src;
			if (s.indexOf("_off.gif") >= 0) {
				s = s.substring(s.indexOf("menu_") + 5, s.indexOf("_off.gif"));
			} else if (s.indexOf("_on.gif") >= 0) {
				s = s.substring(s.indexOf("menu_") + 5, s.indexOf("_on.gif"));
			}
			s = "/" + s.replace("_", "/") + "/";
			if (sPath.indexOf(s) >= 0) {
				childElements[i].firstChild.src = childElements[i].firstChild.src.replace("_off.gif", "_on.gif");
				currentActiveTopNavItem = i + 1;
			}
		}
	}

	if (maxNumberTopNavElements > 0) { // if 0 we're probably on a popup page
		// get settings for bus marker
		fromSection = getCookie("BusCookie");
		if (fromSection > maxNumberTopNavElements) {
			fromSection = 0;
		}
		toSection = currentActiveTopNavItem;
	}

	// display map1 or map2 depending on querystring
	if ((getQueryString("zoom") == "true") && (elm = document.getElementById("webmap2"))) {
		document.getElementById("webmap1").style.display = "none";
		elm.style.display = "block";
	} else if (elm = document.getElementById("webmap1")) {
		document.getElementById("webmap2").style.display = "none";
		elm.style.display = "block";
	}

	// handle clicks in image map on 'köreplaner' pages
	if (elm = document.getElementById("webkort_Map1")) {
		if (typeof(cityInputId) != "undefined" && cityInputId.length > 0) {
			for (i = 0; i < elm.childNodes.length; i++) {
				if (elm.childNodes[i].tagName == "AREA") {
					elm.childNodes[i].onclick = function() {
						if (x = document.getElementById(cityInputId)) x.value = this.title;
					}
				}
			}
		}
	}

	// handle clicks in image map on 'köreplaner' pages
	if (elm = document.getElementById("webkort_Map2")) {
		if (typeof(cityInputId) != "undefined" && cityInputId.length > 0) {
			for (i = 0; i < elm.childNodes.length; i++) {
				if (elm.childNodes[i].tagName == "AREA") {
					elm.childNodes[i].onclick = function() {
						if (x = document.getElementById(cityInputId)) x.value = this.title;
					}
				}
			}
		}
	}

	if (maxNumberTopNavElements > 0) { // if 0 we're probably on a popup page
		// set bus cookie
		setCookie("BusCookie", currentActiveTopNavItem, null, "/", null, null);
	}

	// animate the 'bus'
	if (elm = document.getElementById("bus")) {
		if (typeof(fromSection) != "undefined" && typeof(toSection) != "undefined") {
			if (fromSection != null && toSection != null) {
				offset = findPos(document.getElementById("topNav"))[0] - 30;
				positionMarker();
			}
		}
	}

	if (elm = document.getElementById("MitMoviaInfo")) {
	    elm.onclick = function() {
	        document.location.href = "http://www.moviatrafik.dk/Service/Personligservice/Pages/NewUser.aspx"
	    }
	}

	return;
}
function expand(obj) {
	if (elm = document.getElementById(obj)) {
		if (elm.visible != true) {
			elm.style.display = "block";
			elm.visible = true;
		} else {
			elm.style.display = "none";
			elm.visible = false;
		}
	}
}
function collapseExpand(openCloseId, changeId, idNumber) {
  var exp, lbl;
  if (exp = document.getElementById(changeId + idNumber)) {
    if (exp.visible != true && exp.visible != "true" && exp.visible != undefined) {
        exp.style.display = "block";
        exp.visible = true;
    } else {
        exp.style.display = "none";
        exp.visible = false;
    }
  }
  if (lbl = document.getElementById(openCloseId + idNumber)) {
    if (exp.visible == false || exp.visible == undefined) {
      lbl.innerHTML = "Åbn";
      lbl.title = "Åbn";
    }
    else {
      lbl.innerHTML = "Luk";
      lbl.title = "Luk";
    }
  }
}

var timer = null;
var elmBus = null;

/* attach event / add event listener */ 
if (window.attachEvent) {
	window.attachEvent("onload", init); // the IE way
} else if (window.addEventListener) {
	window.addEventListener("load", init, false); // W3C compliant browsers
}

