
// this is for GA event tracking
var bdtime = new Date().getTime();

/* Document Ready Function (shortcut) */
$(function(){

    if( $.browser.msie && ( $.browser.version == '7.0' || $.browser.version == '8.0' || $.browser.version == '6.0' ) ){
        $('body').addClass('msie');
    }

    $('a[rel="lightbox"]').each(function(){
        var old_title = $('img', $(this)).attr('alt');
        var new_title = $('img', $(this)).attr('title');
        var theTitle = new_title + ' ' + old_title;
        $(this).attr('title', theTitle);
    });
    $('a[rel="lightbox"]:not(.groupimages)').colorbox({ current: "{current} | {total}" });
    $('a[rel="lightbox"].groupimages').colorbox({ current: "{current} | {total}", rel: "eventgroup" });



    /* --- Tab Navi --- */
    if( $('#vacancybox')[0] ){
        $('#vacancybox .tab:first').addClass('active');
        $('#vacancybox .tab_content:first').show();
        var tabNavigation = $('#vacancybox .tab');
        var tabContentArr = $('#vacancybox .tab_content');

        tabNavigation.click(function(){
            tabNavigation.removeClass('active');
            $(this).addClass('active');
            var myClick = $(this).index();
            var myI = 0;
            tabContentArr.each(function(){
               if( myI == myClick ){
                   tabContentArr.hide();
                   $(this).show();
               }
                myI++;
            });
        });
    }
    if( $('#portal_teasers')[0] ){
        $('#portal_teasers .tab:first').addClass('active');
        $('#portal_teasers .tab_content:first').each(function(){
            $(this).hide();
        });
        $('#portal_teasers .tab_content:first').show();
        var tabNavigationPort = $('#portal_teasers .tab');
        var tabContentArrPort = $('#portal_teasers .tab_content');
        tabNavigationPort.click(function(){
            tabNavigationPort.removeClass('active');
            $(this).addClass('active');
            var myClick2 = $(this).index();
            var myI2 = 0;
            tabContentArrPort.each(function(){
               if( myI2 == myClick2 ){
                   tabContentArrPort.hide();
                   $(this).show();
               }
                myI2++;
            });
        });
    }
    //Tabbox Navigation
    if( $('.tabbox_informations')[0] ){

        $('.tabbox_informations .tab_content').hide();

        var firsttab = true;
        $('.tabbox_informations .tab').each( function(i) {
            if ($(this).hasClass('active')) {
                $('.tabbox_informations .tab_content').eq(i).show();
                firsttab = false;
            }
        });

        if(firsttab) {
            $('.tabbox_informations .tab_content').each( function(i) {
                if ($(this).hasClass('active')) {
                    $('.tabbox_informations .tab').eq(i).addClass("active")
                    $('.tabbox_informations .tab_content').eq(i).show();
                    firsttab = false;
                }
            });
        }

        if(firsttab) {
            $('.tabbox_informations .tab:first').addClass('active');
            $('.tabbox_informations .tab_content:first').show();
        }

        var tabNavigationPort = $('.tabbox_informations .tab');
        var tabContentArrPort = $('.tabbox_informations .tab_content');
        tabNavigationPort.click(function(){
            tabNavigationPort.removeClass('active');
            $(this).addClass('active');
            var myClick2 = $(this).index();
            var myI2 = 0;
            tabContentArrPort.each(function(){
               if( myI2 == myClick2 ){
                   tabContentArrPort.hide();
                   $(this).show();
               }
                myI2++;
            });
        });
    }

    /* --- Slider (ACCORDION) Sidebar --- */
    $('#vacancy_search .request_entry .head').click( function(){
        $('#vacancy_search .request_entry').animate({'height': '30px'});
        $(this).parent().animate({'height': '160px'});
    });

    /* --- Header Dropdown Salzburg for --- */
    if( $('#interests')[0] ){
        $('#interests .selectbutton, #interests .actualselect').bind({
            click: function(){
                $('#interests .options').slideToggle();
                $('#interests .options').mouseleave(function(){
                    $('#interests .options').slideUp();
                });
            }
        });
    }
    if( $('#languages')[0] ){
        $('#languages .selectbutton, #languages .actualselect').bind({
            click: function(){
                $('#languages .options').slideToggle();
                $('#languages .options').mouseleave(function(){
                    $('#languages .options').slideUp();
                });
            }
        });
    }

    /* NAVIGATION */
    $.fn.dropDown = function(){
        var nav = $(this);
        nav.find('li').each( function(){
            if( $(this).find('ul').length > 0 ){
                $('ul', this).hide().css({ 'position': 'absolute' });
                // onMouseEnter
                $(this).mouseenter( function(){
                    $(this).addClass('sfhover');
					
					if($(this).find('ul li').length > 0) {
						$(this).find('ul').stop(true, true).fadeIn();
                    	nav.css('z-index', '451').find('ul').css('z-index', '451');
					}
                    if( $(this).hasClass('active') ){
                        $('a img', $(this)).attr( 'src', $('a img', $(this)).attr('src').replace('_active.gif', '_hover.gif') );
                    }else{
                        $('a img', $(this)).attr( 'src', $('a img', $(this)).attr('src').replace('.gif', '_hover.gif') );   
                    }
                    $('ul li', $(this)).hover(function(){
                        $(this).addClass('sfhover');
                    }, function(){
                        $(this).removeClass('sfhover');
                    });
                });
                // onMouseOut
                $(this).mouseleave( function(){
                    $(this).removeClass('sfhover');
                    $(this).find('ul').stop(true, true).fadeOut();
                    if( $(this).hasClass('active') ){
                        $('a img', $(this)).attr( 'src', $('a img', $(this)).attr('src').replace('_hover.gif', '_active.gif' ) );
                    }else{
                        $('a img', $(this)).attr( 'src', $('a img', $(this)).attr('src').replace('_hover.gif', '.gif' ) );
                    }
                });
            }
        });
    };
    $('#metanav').dropDown();
    if( $('#metanav li').hasClass('active') ){
        $('#metanav li.active a img').attr( 'src', $('#metanav li.active a img', $(this)).attr('src').replace('.gif', '_active.gif' ) );
    }

    /* --- Autocomplete --- */
    if( $('.searchterm')[0] ){
        $('#autocomplete_choices_top').hide();
        $('.searchterm').autocomplete({
            source: function( request, response ){
                $.ajax({
                    url: '/' + language + '/search/',
                    type: 'POST',
                    data: 'autocomplete=' + request.term,
                    minLength: 2,
                    success: function( msg ){
                        $('#autocomplete_choices_top').text( msg );
                    }
                })
            }
        });
    }

    /* --- CALENDAR --- */
    // iCal Calendar
    $('#startCal, #endCal').hide();
    $('input[name="datefrom"], input[name="dateto"]').datepicker({ showOn: 'button', buttonImage: '/resources/img/calendar_icon.gif', buttonImageOnly: true, dateFormat: 'dd.mm.yy'});
    var currentTime = new Date();
    if( $('#ical_event')[0] ){
        $('#ical_event input[name="date"]').val( (currentTime.getDay()+1) + '.' + (currentTime.getMonth()+1) + '.' + currentTime.getFullYear() );
        $('#startCal.calendarIcon').hide();
        $('#ical_event input[name="date"]').datepicker({
            showOn: "button",
            buttonImage: "/resources/img/calendar_icon_dta.gif",
            buttonImageOnly: true,
            defaultDate: new Date(),
            dateFormat: 'dd.mm.yy'
        });
    }

    
    // Standard Cal für die Sitebar und Header
    function updateHiddendate() {
        $('.f_line input[name=from]').val($('.f_line input[name=year]').val() + "-" + $('.f_line input[name=month]').val() + "-" + $('.f_line input[name=day]').val());
    }

    if( $('.f_line')[0] ){
        $('.f_line input').change(function () { updateHiddendate(); });

        $('#cal.calendar_icon').hide();
        $('.f_line input[name=year]').datepicker({
			showOn: "button",
			buttonImage: "/resources/img/calendar_icon_dta.gif",
			buttonImageOnly: true,
            defaultDate: new Date(),
            dateFormat: 'dd.mm.yy',
            onClose: function(dateText, inst) {
                if( dateText == currentTime.getFullYear() ){
                    dateText = $('.f_line input[name=day]').val() + '.' + $('.f_line input[name=month]').val() + '.' + $('.f_line input[name=year]').val();
                }
                var splitMyDate = dateText.split('.');
                $('.f_line input[name=day]').val( splitMyDate[0] );
                $('.f_line input[name=month]').val( splitMyDate[1] );
                $('.f_line input[name=year]').val( splitMyDate[2] );

                updateHiddendate();
            }
		});
    }


    if( $('.fs_line')[0] ){
        $('.fs_line input').change(function () { updateHiddendate(); });
		
		var minDate = "";
		var maxDate = "";
		
		if($('#calpackage.calendar_icon').attr("rel")) {
			var minDateArr = $('#calpackage.calendar_icon').attr("rel").split(".");
			minDate = new Date(minDateArr[2], minDateArr[1] - 1, minDateArr[0]);
		}
		if($('#calpackage.calendar_icon').attr("rev")) {
			var maxDateArr = $('#calpackage.calendar_icon').attr("rev").split(".");
			maxDate = new Date(maxDateArr[2], maxDateArr[1] - 1, maxDateArr[0]);
		}
		

        $('#calpackage.calendar_icon').hide();
        $('.fs_line input[name=startyear]').datepicker({
			showOn: "button",
			buttonImage: "/resources/img/calendar_icon_dta.gif",
			buttonImageOnly: true,
            defaultDate: new Date(),
            dateFormat: 'dd.mm.yy',
			minDate: minDate,
			maxDate: maxDate,
            onClose: function(dateText, inst) {
                if( dateText == currentTime.getFullYear() ){
                    dateText = $('.fs_line input[name=startday]').val() + '.' + $('.fs_line input[name=startmonth]').val() + '.' + $('.fs_line input[name=startyear]').val();
                }
                var splitMyDate = dateText.split('.');
                $('.fs_line input[name=startday]').val( splitMyDate[0] );
                $('.fs_line input[name=startmonth]').val( splitMyDate[1] );
                $('.fs_line input[name=startyear]').val( splitMyDate[2] );

                updateHiddendate();
            }
		});
    }
    

    /* --- Image Slider Content --- */
    if( $('.gallery_slider')[0] ){
        var sID = 0;
        $('.gallery_slider').each(function(){
            var $this = $(this);
            $this.addClass('galSl_'+sID);
            $this = $('.galSl_' + sID);
            sID++;

            var myImages = 0;
            var aktuallImage = $('.actual', $this).text();
            if( aktuallImage == 0 ){ aktuallImage = 1; $('.actual', $this).text('1'); }
            var theTextCaption = new Array();
            $('.image_entry', $this).each(function(){
                theTextCaption[myImages] = $('img', this).attr('alt');
                myImages++;
            });
            $('.total', $this).text(myImages);
            $('.captiontext', $this).text( theTextCaption[0] );
            // Slide Left
            $('.gallery_slide_left', $this).bind('click', function(){
                if( aktuallImage > 1 ){
                    $('.all_images', $this).animate({ 'left': '+=' + $('.image_entry img', $this).width() + 'px' });
                    aktuallImage--;
                    $('.actual', $this).text(aktuallImage);
                    $('.captiontext', $this).text( theTextCaption[aktuallImage-1] );
                }
            });
            // Slide Right
            $('.gallery_slide_right', $this).bind('click', function(){
                if( aktuallImage < myImages ){
                    $('.all_images', $this).animate({ 'left': '-=' + $('.image_entry img', $this).width() + 'px' });
                    aktuallImage++;
                    $('.actual', $this).text(aktuallImage);
                     $('.captiontext', $this).text( theTextCaption[aktuallImage-1] );
                }
            });

        });
    }

    /* Sliding Teaser */
    if( $('#sliding_container')[0] ){

        var slideContainer = $('#sliding_container');
        var slideCurrentPage = 1;
        var slidePages = $('.teaser_counter').length;

        slideToPage(1);

        /* Slide Next */
        $('#sliding_up').bind( 'click', function(){
            if( slideCurrentPage < slidePages ){
                slideToPage( ++slideCurrentPage );
            }
        });
        /* Slide Prev */
        $('#sliding_down').bind( 'click', function(){
            if( slideCurrentPage > 1 ){
                slideToPage( --slideCurrentPage );
            }
        });
        /* Slide to Page */
        $('.teaser_counter').bind('click', function(){
            slideToPage( $(this).attr('rel') );
        });
    }
    
    function slideToPage( page ){
        var index = page - 1;
        var margin_top = ( index * slideContainer.parent().height() ) * -1;

        slideCurrentPage = page;
        slideContainer.css({ 'margin-top': margin_top });

        $('.teaser_counter').removeClass('active');
        $('.teaser_counter[rel="' + page + '"]').addClass('active');
    }

    /* PAGING */
    if( $('#sliding_events_container')[0] ){

        var slideContainer = $('#sliding_events_container');
        var slideCurrentPage = 1;
        var slidePages = $('.teaser_counter').length;

        slideToPageEvent(1);

        /* Slide Next */
        $('#sliding_up').bind( 'click', function(){
            if( slideCurrentPage < slidePages ){
                slideToPageEvent( ++slideCurrentPage );
            }
        });
        /* Slide Prev */
        $('#sliding_down').bind( 'click', function(){
            if( slideCurrentPage > 1 ){
                slideToPageEvent( --slideCurrentPage );
            }
        });
        /* Slide to Page */
        $('.teaser_counter').bind('click', function(){
            slideToPageEvent( $(this).attr('rel') );
        });
    }

    function slideToPageEvent( page ){
        var index = page - 1;
        var margin_top = (( index * (slideContainer.parent().height()-2) ) * -1);

        slideCurrentPage = page;
        slideContainer.css({ 'margin-top': margin_top });

        $('.teaser_counter').removeClass('active');
        $('.teaser_counter[rel="' + page + '"]').addClass('active');
    }


var cookieList = function(cookieName) {
var cookie = $.cookies.get(cookieName);
var items = cookie ? cookie.split(';;') : new Array();
return {
    "add": function(val) {
        items.push( escape(val) );
        $.cookies.set(cookieName, items.join(';;'));
    },
    "remove": function(val, pos) {
        items.splice( pos, 1, val);
        $.cookies.set(cookieName, items);
    },
    "clear": function() {
        items = null;
        //clear the cookie.
        $.cookies.set(cookieName, null);
    },
    "items": function() {
        //Get all the items.
        return items;
    }
  }
};
    /* Watchlist...need the cookie plugin from jquery ... */
    if( $('.watchlist')[0] ){
        var siteTitle = document.title;
        var siteLink = document.URL;

        var liste = new cookieList('salzburginfoWatchlist');

        $('#watchlist-entries-count').text( liste.items().length );

        $('.watchlist a').click(function(){
            liste.add( siteTitle + '--' + siteLink );
            $('#watchlist-entries-count').text( liste.items().length );
            return false;
        });
    }

    //watchlist-entry-template = watchlist view
    if( $('#watchlist-entry-template')[0] ){
        var template = $('#watchlist-entry-template').text();
        var counterViewTpl = liste.items().length-1;

        for( var cVT = 0; cVT <= counterViewTpl; cVT++ ){
            var theSingleItem = liste.items()[cVT].split('--');
            $('#watchlist-entry-container').append( template.replace('${link}', theSingleItem[1].replace('http%3A//','http://'))
                                                            .replace('${name}',unescape(theSingleItem[0]) )
                                                            .replace('onclick="this.parentNode.remove(); watchlist.deleteEntry(\'${id}\')"', 'class="deleteLink" data-name="' + cVT + '"')
                                                  );
        }

        $('.entry_delete').click(function(){
            liste.remove( '', $(this).attr('data-name') );
            $(this).parent().slideUp();
        });

    }//end details watchlist

}); //end ready function()


function trackEventGotoLink (htmlElement, gaParams) {
	try {
		pageTracker._trackEvent(gaParams.category, gaParams.action, gaParams.label);
	} catch (e) {}
	gotoLink(htmlElement);
}

function gotoLink (htmlElement) {

	var destinationURL = "";
	var target = "";

	if(htmlElement.href) {
		destinationURL = htmlElement.href;
		target = htmlElement.getAttribute("target");
	}else{
		if(htmlElement.childNodes) {
			if(htmlElement.getElementsByTagName("a")) {
				destinationURL = htmlElement.getElementsByTagName("a")[0].href;
				target = htmlElement.getElementsByTagName("a")[0].getAttribute("target");
			}
		}
	}

	if(target == "_blank") {
		window.open(destinationURL);
	} else {
		location.href = destinationURL;
	}
}

function base64_encode( data ) {
    // Encodes string using MIME base64 algorithm
    //
    // version: 905.2617
    // discuss at: http://phpjs.org/functions/base64_encode
    // +   original by: Tyler Akins (http://rumkin.com)
    // +   improved by: Bayron Guevara
    // +   improved by: Thunder.m
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   bugfixed by: Pellentesque Malesuada
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // -    depends on: utf8_encode
    // *     example 1: base64_encode('Kevin van Zonneveld');
    // *     returns 1: 'S2V2aW4gdmFuIFpvbm5ldmVsZA=='
    // mozilla has this native
    // - but breaks in 2.0.0.12!
    //if (typeof this.window['atob'] == 'function') {
    //    return atob(data);
    //}

    var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
    var o1, o2, o3, h1, h2, h3, h4, bits, i = 0, ac = 0, enc="", tmp_arr = [];

    if (!data) {
        return data;
    }

    data = this.utf8_encode(data+'');

    do { // pack three octets into four hexets
        o1 = data.charCodeAt(i++);
        o2 = data.charCodeAt(i++);
        o3 = data.charCodeAt(i++);

        bits = o1<<16 | o2<<8 | o3;

        h1 = bits>>18 & 0x3f;
        h2 = bits>>12 & 0x3f;
        h3 = bits>>6 & 0x3f;
        h4 = bits & 0x3f;

        // use hexets to index into b64, and append result to encoded string
        tmp_arr[ac++] = b64.charAt(h1) + b64.charAt(h2) + b64.charAt(h3) + b64.charAt(h4);
    } while (i < data.length);

    enc = tmp_arr.join('');

    switch( data.length % 3 ){
        case 1:
            enc = enc.slice(0, -2) + '==';
        break;
        case 2:
            enc = enc.slice(0, -1) + '=';
        break;
    }

    return enc;
}


function utf8_encode ( argString ) {
    // Encodes an ISO-8859-1 string to UTF-8
    //
    // version: 905.1217
    // discuss at: http://phpjs.org/functions/utf8_encode
    // +   original by: Webtoolkit.info (http://www.webtoolkit.info/)
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: sowberry
    // +    tweaked by: Jack
    // +   bugfixed by: Onno Marsman
    // +   improved by: Yves Sucaet
    // +   bugfixed by: Onno Marsman
    // *     example 1: utf8_encode('Kevin van Zonneveld');
    // *     returns 1: 'Kevin van Zonneveld'
    var string = (argString+'').replace(/\r\n/g, "\n").replace(/\r/g, "\n");

    var utftext = "";
    var start, end;
    var stringl = 0;

    start = end = 0;
    stringl = string.length;
    for (var n = 0; n < stringl; n++) {
        var c1 = string.charCodeAt(n);
        var enc = null;

        if (c1 < 128) {
            end++;
        } else if((c1 > 127) && (c1 < 2048)) {
            enc = String.fromCharCode((c1 >> 6) | 192) + String.fromCharCode((c1 & 63) | 128);
        } else {
            enc = String.fromCharCode((c1 >> 12) | 224) + String.fromCharCode(((c1 >> 6) & 63) | 128) + String.fromCharCode((c1 & 63) | 128);
        }
        if (enc !== null) {
            if (end > start) {
                utftext += string.substring(start, end);
            }
            utftext += enc;
            start = end = n+1;
        }
    }

    if (end > start) {
        utftext += string.substring(start, string.length);
    }

    return utftext;
}

var map;

function startcontentmap(){



    $('#veTypeMap').click(function() {
        map.setView({mapTypeId:Microsoft.Maps.MapTypeId.road});
    });

    $('#veTypeSatellite').click(function() {
        map.setView({mapTypeId:Microsoft.Maps.MapTypeId.aerial});
    });

    $('#veTypeThreeDee').click(function() {
        map.setView({mapTypeId:Microsoft.Maps.MapTypeId.birdseye});
    });

    $('#veNavUp').click(function() {
        var center = map.getCenter();
        var latitude = center.latitude+0.00050005000001;
        var longitude = center.longitude;
        map.setView({center: new Microsoft.Maps.Location(latitude, longitude)});
    });

    $('#veNavDown').click(function() {
        var center = map.getCenter();
        var latitude = center.latitude-0.00050005000001;
        var longitude = center.longitude;
        map.setView({center: new Microsoft.Maps.Location(latitude, longitude)});
    });

    $('#veNavRight').click(function() {
        var center = map.getCenter();
        var latitude = center.latitude;
        var longitude = center.longitude+0.00050005000001;
        map.setView({center: new Microsoft.Maps.Location(latitude, longitude)});
    });

    $('#veNavLeft').click(function() {
        var center = map.getCenter();
        var latitude = center.latitude;
        var longitude = center.longitude-0.00050005000001;
        map.setView({center: new Microsoft.Maps.Location(latitude, longitude)});
    });

    $('#veZoomIn').click(function() {
        zoomin();
    });


    $('#veZoomOut').click(function() {
        var newzoom = map.getZoom()-1;
        map.setView({zoom:newzoom});
    });

    $('#veRotateLeft').click(function() {
        if(map.getMapTypeId() != "be"){
            map.setView({mapTypeId:Microsoft.Maps.MapTypeId.birdseye});
            map.setView({zoom:18});
        }

        var heading = map.getHeading()-90;
        map.setView({heading:heading});
    });

    $('#veRotateRight').click(function() {
        if(map.getMapTypeId() != "be"){
            map.setView({mapTypeId:Microsoft.Maps.MapTypeId.birdseye});
            map.setView({zoom:18});
        }
        var heading = map.getHeading()+90;
        map.setView({heading:heading});
    });

    
    $('#showVeMap').click(function() {
        if(comap == "close"){
            $("#imc_map").css('display', 'block');
            $("#headerimage").css('display', 'none');
            $("#img_map_container").css('height', '435px');

            if(mode == "POI"){
                setcontentmap();
            }
            if(mode == "multiPOIsingle"){
                setcontentmapsingle();
            }
            if(mode == "multiPOI"){
                setcontentmapmulti();
            }

            comap = "open";
            $('.op', $(this)).css('display','none');
            $('.cl', $(this)).css('display','block');
        } else {
            $("#imc_map").css('display', 'none');
            $("#headerimage").css('display', 'block');
            $("#img_map_container").css('height', '230px');

            comap = "close";
            $('.op', $(this)).css('display','block');
            $('.cl', $(this)).css('display','none');
        }
    });
}

function zoomin(){
    var newzoom = map.getZoom()+1;
    map.setView({zoom:newzoom});
}



function setcontentmap(){

    var options = {credentials:"Au_RInJRJkQ4rymySs6ip4Vv3z3FAH2VRxecbM5CUjlPzJD_fzn4Y1OWklhtj0EF", mapTypeId:Microsoft.Maps.MapTypeId.birdseye, center: new Microsoft.Maps.Location(lat, lon), zoom: 15, showDashboard: false};
    map = new Microsoft.Maps.Map(document.getElementById("veMap"),options);

    var pin = new Microsoft.Maps.Pushpin(new Microsoft.Maps.Location(lat, lon), {icon:"/resources/img/map/marker/current/1.png", height:50, width:50, anchor:new Microsoft.Maps.Point(0,50), draggable: false});
    map.entities.push(pin);

}

function setcontentmapsingle(){

    var options = {credentials:"Au_RInJRJkQ4rymySs6ip4Vv3z3FAH2VRxecbM5CUjlPzJD_fzn4Y1OWklhtj0EF", mapTypeId:Microsoft.Maps.MapTypeId.birdseye, center: new Microsoft.Maps.Location(json.latitude, json.longitude), zoom: 15, showDashboard: false};
    map = new Microsoft.Maps.Map(document.getElementById("veMap"),options);

    var pin = new Microsoft.Maps.Pushpin(new Microsoft.Maps.Location(json.latitude, json.longitude), {icon:"/resources/img/map/marker/"+json.icon+"/1.png", height:50, width:50, anchor:new Microsoft.Maps.Point(0,50), draggable: false});

    if(json.image != ""){
        pin.description = "<br /><strong>"+json.markername+"</strong><p>"+json.desc+"</p><a class='minfo' href='"+json.link+"'>"+moreinfo+"</a><p>"+json.address+"</p>";

    } else {
        pin.description = "<img src='"+json.image+"' width='240' height='180' alt='"+json.markername+"' title='"+json.markername+"' /><strong>"+json.markername+"</strong><p>"+json.desc+"</p><a class='minfo' href='"+json.link+"'>"+moreinfo+"</a><p>"+json.address+"</p>";
    }



    //Add handler for the pushpin click event.
    Microsoft.Maps.Events.addHandler(pin, 'mouseover', displayEventInfo);
    Microsoft.Maps.Events.addHandler(map, 'click', closeInfoBox);

    map.entities.push(pin);

}

function setcontentmapmulti(){

    var options = {credentials:"Au_RInJRJkQ4rymySs6ip4Vv3z3FAH2VRxecbM5CUjlPzJD_fzn4Y1OWklhtj0EF", mapTypeId:Microsoft.Maps.MapTypeId.birdseye, center: new Microsoft.Maps.Location(47.800270459812, 13.043520748615), zoom: 13, showDashboard: false};
    map = new Microsoft.Maps.Map(document.getElementById("veMap"),options);




    for(j=1; j<jscount; j++){
        map.entities.push(createmultipin(json[j]));
    }

    //map.entities.push(pin);

}

if(language == 'de'){
    moreinfo = 'Mehr Informationen';
} else {
    moreinfo = 'Show details';
}

function createmultipin(json){
    var pin = new Microsoft.Maps.Pushpin(new Microsoft.Maps.Location(json.latitude, json.longitude), {icon:"/resources/img/map/marker/current/"+json.index+".png", height:50, width:50, anchor:new Microsoft.Maps.Point(0,50), draggable: false});


       pin.description = "<img src='"+json.image+"' width='240' height='180' /><strong>"+json.markername+"</strong><p>"+json.desc+"</p><a class='minfo' href='"+json.link+"'>"+moreinfo+"</a><p>"+json.address+"</p>";


    //Add handler for the pushpin click event.
    Microsoft.Maps.Events.addHandler(pin, 'mouseover', displayEventInfo);
    Microsoft.Maps.Events.addHandler(map, 'click', closeInfoBox);

    return pin;
}

function displayEventInfo(e) {
    if (e.targetType == "pushpin") {
        var pix = map.tryLocationToPixel(e.target.getLocation(), Microsoft.Maps.PixelReference.control);
        var infoboxDescription = document.getElementById('infoboxDescription');
        infoboxDescription.innerHTML = e.target.description;
        var infobox = document.getElementById('infoBox');
        infobox.style.top = (pix.y - 60) + "px";
        infobox.style.left = (pix.x + 5) + "px";
        infobox.style.visibility = "visible";
        document.getElementById('veMap').appendChild(infobox);
    }
}

function closeInfoBox() {
    var infobox = document.getElementById('infoBox');
    infobox.style.visibility = "hidden";
}


