﻿var glCompMapTout = null;
var glCompPin = null;
var glArStrCache = new Array();

function compMap(mapimg,mapwidth,mapheight,lat0,lon0,faktorLat,faktorLon,div,divContentId) {
    this.div = div;
    this.mapimg = mapimg
    this.mapwidth = mapwidth;
    this.mapheight = mapheight;
    this.lat0 = lat0;
    this.lon0 = lon0;
    this.faktorLat = faktorLat;
    this.faktorLon = faktorLon;
    this.createPin = comMapCreatePin;
    this.pinMouseOver = comMapChngImg;
    this.selectedPin = null;
    this.divContentId = divContentId;
    
    function comMapCreatePin(lat,lon,companyId,title,url) {
        if (lat != 80 && lon != 90) {
            var oLat = this.lat0 - lat;
            var oLon = this.lon0 - lon;
            var x = oLat * this.faktorLat;
            var y = oLon * this.faktorLon;
            
            var pin = document.createElement("IMG");
            pin.id = "cpin"+companyId;
            pin.src = "App_Themes/" + glTheme + "/images/pin.gif";
            pin.style.position="absolute";
            pin.style.left= y+"px";
            pin.style.top = x+"px";
            pin.style.cursor="pointer";
            pin.style.width="18px";
            pin.style.height="18px";
            pin.title=title;
            pin.className=companyId+'|'+this.divContentId;
            pin.obj = this;
            
            pin.onmouseover = function() {
                glCompPin = this;
                glCompMapTout = setTimeout("comMapChngImg()",200);
            };
            pin.onmouseout = function() {
                clearTimeout(glCompMapTout);
            }   
            
            pin.onclick = function(t) { location.href=url };
            
            this.div.appendChild(pin);
        }
    }
      
}

function comMapChngImg() {
    var obj = glCompPin.obj;
    if (obj.selectedPin != null && obj.selectedPin == glCompPin) {
        return false;
    }

    new Effect.Pulsate(glCompPin, {duration: 2}); 
    
    if (obj.selectedPin  != null) {
        obj.selectedPin.src = "App_Themes/" + glTheme + "/images/pin.gif";
    }        
    
    obj.selectedPin = glCompPin;
    glCompPin.src = "App_Themes/" + glTheme + "/images/pin_over.gif";
    
    //Daten laden
    //t.className -> companyID|divContentID
    var ar = glCompPin.className.split("|");
    new Effect.Grow(document.getElementById(ar[1]), {duration: 0.3});    
    
    var str = "";
    if (glArStrCache[ar[0]] == null) {
        str = module_companies_overview.getCompanyPreview(ar[0],glLng,glTheme,glMenuId).value;
        glArStrCache[ar[0]] = str;
    } else {
        str = glArStrCache[ar[0]];
    }
    document.getElementById(ar[1]).innerHTML = str;  
      
}
