
/*
Copyright 2005-2014 skyvector.com. All Rights reserved.
You may not use this script for any purpose without permission.
*/

function initMap2(p_chart,setid,protoid,scale,posx,posy,target,lat,lon,scaleset){
   var chart=false;
   var ratio = window.devicePixelRatio;
   if (!ratio) ratio = 1.0;
   var tilesize=256 / ratio;
   scale -= Math.round(2 * Math.LOG2E * Math.log(ratio));
   if (scale < 1) scale = 1;
   if (scaleset){
      var scalors = [.5, 1, 1.5, 2, 3, 4, 6, 8, 12, 16, 24, 32, 48, 64, 96, 128, 192, 256, 384, 512, 768, 1024, 1536, 2048];
   }else{
      var scalors = [.5,1,4/3,2,8/3,4,16/3,8,32/3,16,64/3,32,128/3,64,256/3,128,512/3,256,1024/3,512,2048/3,1024,4096/3,2048];
   } 
   posx = Math.round(posx/(scalors[scale]*ratio));
   posy = Math.round(posy/(scalors[scale]*ratio));

   if(p_chart){
      chart=document.getElementById(p_chart);
      if (!chart){return false};
      chart.style.position='relative';
      chart.style.border='1px solid #808080';
      chart.style.backgroundColor='#D5E6E6';
      chart.style.padding='0px';
      chart.style.overflow='hidden';
   }else{
      if (!chart){return false};
   }
   if(!(posx && posy && scale && protoid && setid)){
      return false;
   }
   var qs="?ll="+lat+","+lon+"&chart="+protoid+"&zoom="+scale;
   var vwidth=chart.clientWidth;
   var vheight=chart.clientHeight;
   if (!vwidth) vwidth=chart.style.pixelWidth;
   if (!vheight) vheight=chart.style.pixelHeight;
   if (!vwidth) vwidth=parseInt(chart.style.width);
   if (!vheight) vheight=parseInt(chart.style.height);
   if (!vwidth) vwidth=200;
   if (!vheight) vheight=200;

   var htiles=Math.ceil(vwidth/tilesize)+1;
   var vtiles=Math.ceil(vheight/tilesize)+1;
   if(isNaN(htiles) || htiles<2) htiles=2;
   if(isNaN(vtiles) || vtiles<2) vtiles=2;
   if (target){
      target=" target=\""+target+"\" ";
   }
   posx=Math.round(posx-(vwidth/2));
   posy=Math.round(posy-(vheight/2));

   var html = "<a href=\"https://skyvector.com/" + qs + "\" " + target + ">";

   var otx=Math.floor(posx/tilesize);
   var oty=Math.floor(posy/tilesize);
   for (var i=0; i < vtiles; i++){
      var i2=i+oty;
      for (var j=0; j < htiles; j++){
         var j2=j+otx;
         var servermod=(j2+i2) % 2;
         if ("https:" == document.location.protocol) {
            var tileurl = "https://t.skyvector.com/e1097d3824e";
         }else{
             var tileurl = "http://t"+servermod+".skyvector.net/e1097d3824e";
         }
         var tilename=protoid +"/"+ setid +"/" + scale + "/" + j2 + "/" + i2 + ".jpg";
         html += "<img style=\"padding: 0px; border: none; position: absolute; max-width: none; width: "+tilesize+"px; height: "+tilesize+"px; z-index: 0; top: "+(i2*tilesize - posy)+"px; left: "+(j2*tilesize -posx)+"px;\" border=\"0\" src=\""+tileurl + "/" + tilename + "\" />";
      }
   }
   html += "</a>";
   chart.innerHTML=html;
}


initMap2('sv_1791',2413,302,3,70414.79,131292.00,'',51.2,-115.533333333333,1);
