
function displayDescription(id) {   
    //andere ausblenden 
    $('.pindescr').hide();
    $('.imgnode').show();
    //id einblenden
    $('#descr-' + id).show();
    $('#img-' + id).hide();
}


function createPin(id,name,tip,mail,url,descr,target,container, mapid) {
    var node = $('#map').appendN('div', id, 'node')
    //create box in node
    var descrnode = node.appendN('span', 'descr-' + id, 'pindescr');    
    descrnode.css({'display': 'none'});
     
    //info in several lines
    //descrnode = document.getElementById('descr-' + id)
    for (var i=0; i<descr.length-1; i++) {  
       descrnode.append(decode_utf8(descr[i]));
       descrnode.append('<br/>')
    };
    descrnode.append(decode_utf8(descr[descr.length-1]));  
    if (mail) {
        descrnode.append('<br/><a class="nodemail" href="mailto:'+mail+'">'+mail+'</a>')
    }
    if (url) {
        descrnode.append('<br/><a class="nodeurl" href="'+url+'" target="'+target+'">'+url+'</a>')
    }
    
    //create pin in node
    var imgnode = node.appendN('img', 'img-'+id, "imgnode")    
    imgnode.attr({
             src: mapid + "/" + "pin.png"             
           });
    imgnode.hover(function () {displayDescription(id);},    
                    function () {}
                );

}

function setPins(pins) {
	var params = pins['params'];
	var pathstr = this.document.location.pathname.split('/')
	var mapid = pathstr[pathstr.length-1]
	for (var i = 0; i < params.length; i++) {
		var p = params[i];
		createPin(p[0],p[1],p[1],p[7],p[2],p[5],p[6],"map", mapid);
		$('#' + p[0]).css({
			position: "absolute",
			//alert (p[3]+','+p[4])
	  		left: p[3]+'px',
	  		top: p[4]+'px'
		})
	}
	
    //alert($('#map').html())
}



function encode_utf8(rohtext)
	{
	// dient der Normalisierung des Zeilenumbruchs
	rohtext = rohtext.replace(/\r\n/g,"\n");
	var utftext = "";
	for(var n=0; n<rohtext.length; n++)
		{
		// ermitteln des Unicodes des  aktuellen Zeichens
		var c=rohtext.charCodeAt(n);
		// alle Zeichen von 0-127 => 1byte
		if (c<128)
			utftext += String.fromCharCode(c);
		// alle Zeichen von 127 bis 2047 => 2byte
		else if((c>127) && (c<2048)) {
			utftext += String.fromCharCode((c>>6)|192);
			utftext += String.fromCharCode((c&63)|128);}
		// alle Zeichen von 2048 bis 66536 => 3byte
		else {
			utftext += String.fromCharCode((c>>12)|224);
			utftext += String.fromCharCode(((c>>6)&63)|128);
			utftext += String.fromCharCode((c&63)|128);}
		}
	return utftext;
	}

function decode_utf8(utftext)
	{
	var plaintext = ""; var i=0; var c=c1=c2=0;
	// while-Schleife, weil einige Zeichen uebersprungen werden
	while(i<utftext.length)
		{
		c = utftext.charCodeAt(i);
		if (c<128) {
			plaintext += String.fromCharCode(c); i++;}
		else if((c>191) && (c<224)) {
			c2 = utftext.charCodeAt(i+1);
			plaintext += String.fromCharCode(((c&31)<<6) | (c2&63));
			i+=2;}
		else {
			c2 = utftext.charCodeAt(i+1); c3 = utftext.charCodeAt(i+2);
			plaintext += String.fromCharCode(((c&15)<<12) | ((c2&63)<<6) | (c3&63));
			i+=3;}
		}
	return plaintext;
	}
	

function Coords(x,y) {
this.x = x;
this.y = y;
}
