// Capabilities Map
$(document).ready(function(){
  //$("#large-map-wrapper").append("<p><a class=\"replace\" href=\"#\"><em></em>Close window</a></p>");
  $("#large-map-inner").append("<p><a class=\"replace\"><em></em>Close window</a></p>");
  $("#large-map-wrapper").addClass("hide");
  
  //Only do this if they have flash version 9 and above
  if (swfobject.hasFlashPlayerVersion("9.0.0")) {
    $(".subsection-capabilities-map #content #text a").click(
      function(){
        //remove the small map
        swfobject.removeSWF("map");
      
        $("#large-map-wrapper").removeClass("hide");
        $(".subsection-capabilities-map #main-content-inner").addClass("has-popup");
      
        //check swf hasn't removed the large-map div
        var lmDiv = document.getElementById("large-map");
        if (!lmDiv) {
      	  //if it has, recreate it.
      	  $("#large-map-inner .innerwrap").prepend("<div id=\"large-map\"></div>");
        }
        swfobject.embedSWF("/flash/map.swf", "large-map", "893", "519", "9.0.0", "false", {}, {menu: "true", wmode: "opaque"}, {});
      
        return false;
      }
    );
    $("#large-map-wrapper a").click(
      function(){
        //remove the large map
        swfobject.removeSWF("large-map");
      
        $("#large-map-wrapper").addClass("hide");
        $(".subsection-capabilities-map #main-content-inner").removeClass("has-popup");
      
        //check swf hasn't removed the map div
        var mDiv = document.getElementById("map");
        if (!mDiv) {
          //if it has, recreate it
      	  $("#map-wrapper").prepend("<div id=\"map\"></div>");
        }
        swfobject.embedSWF("/flash/map.swf", "map", "541", "314", "9.0.0.0", "false", {}, {menu: "true", wmode: "opaque"}, {});
        
        return false;
      }
    );
  }
});