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

function initMap(p_chart,setid,protoid,scale,posx,posy,target,lat,lon){
   var chart=false;
   var tilesize=256;
   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 + ">";
       html +="<img style=\"margin: 0px; padding: 0px; border: none; position: absolute; z-index: 1; right: 0px; bottom: 0px; \" width=\"56\" height=\"13\" border=\"0\" src=\"https://skyvector.com/images/chart/skyvector_tiny.gif\" />";

   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; z-index: 0; top: "+(i2*tilesize - posy)+"px; left: "+(j2*tilesize -posx)+"px;\" border=\"0\" width=\"" + tilesize + "\" height=\"" + tilesize + "\" src=\""+tileurl + "/" + tilename + "\" />";
      }
   }
   html += "</a>";
   chart.innerHTML=html;
}


initMap('skyvector',2502,301,3,260256,161964,'_blank',-39.006901,177.406998);
