
/*
Copyright 2005-2009 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;
   var tiledir='http://tiles.skyvector.com/sky/tiles';
   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=\"http://skyvector.com/" + qs + "\" " + target + ">";
   html +="<img style=\"margin: 0px; padding: 0px; border: none; position: absolute; z-index: 1; right: 0px; bottom: 0px; \" width=\"82\" height=\"13\" border=\"0\" src=\"http://tiles.skyvector.com/sky/images/chart/logotiny.png\" />";
   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 tilename=protoid +"/"+ setid +"/" +"tile_" + 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=\""+tiledir + "/" + tilename + "\" />";
      }
   }
   html += "</a>";
   chart.innerHTML=html;
}


initMap('IFR',1009,412,3,4729,344,'_blank',44.731072777778,-94.714713333333);
