/* site.js */

function popup(element) {
	  message = $(element).html();
	  var width = $(window).width();
		var height = $(window).height();
		var dheight = $(document).height();
		var obj = $('<div class="popup"><img src="/Templates/Public/Images/interactivemap/close.gif" alt="Stäng" class="close"/><div class="padding">' + message + '</div></div>').css('left', ((width / 2) - 254) + 'px').click(function(e) { var x = e.pageX - this.offsetLeft; var y = e.pageY - this.offsetTop; if (x >= 11 && x <= 18 && y >= 10 && y <= 17) { return true; } return false; });
		obj.find('A').click(function() {window.open($(this).attr('href'));});
		var container = $('<div class="popupoverlay"></div>').css('height', dheight + 'px').click(function() { $(this).fadeOut('fast', function() { $(this).remove(); }); }).append(obj)
		$('BODY').append(container);
		$('.popup .close').click(function() { $('.popupoverlay').fadeOut('fast', function() { $(this).remove(); }); })
		$('.popup').css('top', ((height / 2)  + $(window).scrollTop() - $('.popup').height()/2) + 'px');
		//$('.helplist LI').toggle(function() {$(this).siblings().children('DIV').slideUp(100);$(this).children('DIV').slideDown(100);}, function() {$(this).children('DIV').slideUp(100);});
		$('.helplist LI').click(function() {
			if($(this).children('DIV').css('display') == 'none') {
				$(this).siblings().children('DIV').slideUp(100);
				$(this).children('DIV').slideDown(100);
			}
			else {
				$(this).children('DIV').slideUp(100);
			}
        });
}

$(function() {
    $('#openpopup').click(function() { popup('#maphelp'); return true; });
    $(window).scroll(function() {
    $('.popup').each(function() { var height = $(window).height(); $(this).css('top', ((height / 2) + $(window).scrollTop() - $(this).height() / 2) + 'px'); });
    });
});
