////
//// support code for HAI site research page
////

//
// required:
//   jquery.js (version 1.2.6+) (see jquery.com)
//


////
//// set up the initial style for the country information blocks
////
document.writeln("<style type='text/css'>");
document.writeln("div.countryinfo { display: none; }");
document.writeln("#mapscreen { display: none; }");
document.writeln("</style>");


$(document).ready(function(){

    ////
    //// functions to show/hide country information and main screen
    ////
    var showcountry = function($c) {
      if ($c == "") {
        // show main screen and hide all country info divs
        $("#mapscreen").show();
        $("div.countryinfo").hide();
      }
      else {
        // hide main screen and show ONE country info div
        $("#mapscreen").hide();
        $("#"+$c).show();
      }
    }

    ////
    //// set up "back to map" links
    ////
    //$("div.countryinfo").prepend("<p><a href='#mapscreen' class='backtomap'>(back to map)</a></p>");
    //$("a.backtomap").click( function() {
      //  showcountry("");
        //return false;
     // });

    ////
    //// set up links and map overlays
    ////
    //
    // create mouseover and click behaviors for each country
    //
    $("#mapmap area").each( function() {
      var countrycode = this.className;

      //
      // create mouseover overlay for each country
      //
      var overlay = $("<img src='/img/research/by_country/map_"+countrycode+".gif' class='mouseoverlay' id='imgover_"+countrycode+"' />");
      $("#divmap").append(overlay);

      //
      // show overlay on hover
      //
      //$(this).hover(
      //  function() { $("#imgover_"+countrycode).show(); },
      //  function() { $("#imgover_"+countrycode).hide(); }
      //);
      //
      // note: the hover function doesn't work on IE with image map areas... so need to do each individually:
      //
      $(this).mouseover(function() { $("#imgover_"+countrycode).show(); });
      $(this).mouseout(function() { $("#imgover_"+countrycode).hide(); });

      //
      // set click function
      //
      $(this).click( function() {
          $("#imgover_"+countrycode).hide();
          showcountry(countrycode);
          return false;
        });

    });

    ////
		//// show current "page"
		////
		var currentcountry = "";
		var hash = document.location.hash.slice(1);
    $("#mapmap area").each( function() {
      if (hash == this.className) {
				currentcountry = this.className;
			}
    });
    showcountry(currentcountry);
});
