
var centreIcon = new google.maps.MarkerImage("http://chart.apis.google.com/chart?chst=d_map_pin_letter_withshadow&chld=|016ca2|000000");
var founderIcon = new google.maps.MarkerImage("http://chart.apis.google.com/chart?chst=d_map_pin_letter_withshadow&chld=|a7a7a7|000000");
var gmarkers = []; //stores the google maps marker objects
    
var centerLatlng = new google.maps.LatLng(51.52701, -0.13031);

var mapOptions = {
  zoom: 13,
  center: centerLatlng,
  mapTypeId: google.maps.MapTypeId.ROADMAP
};    

var markers = [
  { title:"The Francis Crick Institute", icon: centreIcon, lat:51.530608, lon:-0.129462, cat:"centre" },
  { title:"Wellcome Trust", icon: founderIcon, lat:51.525433, lon:-0.134861, cat:"founders" },
  { title:"Medical Research Council", icon: founderIcon, lat:51.51403, lon:-0.119863, cat:"founders" },
  { title:"Cancer Research UK", icon: founderIcon, lat:51.515788, lon:-0.11792, cat:"founders" },
  { title:"UCL", icon: founderIcon, lat:51.524304, lon:-0.13424, cat:"founders" },
  { title:"Wellcome Trust", icon: founderIcon, lat:51.525433, lon:-0.134861, cat:"onekm" },
  { title:"UCL", icon: founderIcon, lat:51.52350, lon:-0.134528, cat:"onekm" },
  { title:"Great Ormond Street", icon: founderIcon, lat:51.522122, lon:-0.119584, cat:"onekm" },
  { title:"Institute of Child Health", icon: founderIcon, lat:51.523377, lon:-0.12901, cat:"onekm" },
  { title:"Institute of Neurology", icon: founderIcon, lat:51.522295, lon:-0.12253, cat:"onekm" },
  { title:"London School of Hygiene and Tropical Medicine", icon: founderIcon, lat:51.522295, lon:-0.12253, cat:"onekm" },
  { title:"MRC Clinical Trials Unit", icon: founderIcon, lat:51.526581, lon:-0.132952, cat:"onekm" },
  { title:"National Hospital for Neurology and Neurosurgery", icon: founderIcon, lat:51.521382, lon:-0.122697, cat:"onekm" },
  { title:"UCL Hospital", icon: founderIcon, lat:51.524799, lon:-0.136878, cat:"onekm" },
  { title:"Cancer Research UK", icon: founderIcon, lat:51.515788, lon:-0.11792, cat:"twokm" },
  { title:"Medical Research Council", icon: founderIcon, lat:51.51403, lon:-0.119863, cat:"twokm" },
  { title:"Barts Hospital", icon: founderIcon, lat:51.518027, lon:-0.101604, cat:"twokm" },
  { title:"Barts and The London Medical School", icon: founderIcon, lat:51.516645, lon:-0.0609435, cat:"twokm" },
  { title:"King's College London", icon: founderIcon, lat:51.516788, lon:-0.060814, cat:"twokm" },
  { title:"Imperial College", icon: founderIcon, lat:51.504552, lon:-0.203628, cat:"fivekm" },
  { title:"Institute of Ophthalmology", icon: founderIcon, lat:51.527366, lon:-0.091181, cat:"fivekm" },
  { title:"Moorfields Eye Hospital", icon: founderIcon, lat:51.527836, lon:-0.089661, cat:"fivekm" },
  { title:"St Mary's Hospital", icon: founderIcon, lat:51.517352, lon:-0.172702, cat:"fivekm" }
];

function hideMarkers(category) {
  for (i in gmarkers) {
      if (gmarkers[i].category == category) {
        gmarkers[i].setMap(null);
      }
    }
};

function showMarkers(category, map) {
  for (i in gmarkers) {
      if (gmarkers[i].category == category) {
        gmarkers[i].setMap(map);
      }
    }
};    
  
function loadMap() {

  var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
  for(i in markers) {
    var marker = new google.maps.Marker({
      position: new google.maps.LatLng(markers[i].lat, markers[i].lon),
      icon: markers[i].icon,
      map: map,
      title:markers[i].title,
      category: markers[i].cat
    });
    gmarkers.push(marker);
  }
  
  var hider = function(cat) { hideMarkers(cat, map); };
  var shower = function(cat) { showMarkers(cat, map); };
  
  $('#mapfilter input').live('change',function() {
      if( $(this).is(':checked') ){
        shower($(this).attr("id"));
      }
      else {
        hider($(this).attr("id"));
      }
  })
  
  // initially hide all except for centre
  hider("founders");
  hider("twokm");
  hider("fivekm");
  hider("onekm");

};
  
$(document).ready(function() {
  $("#billboard").css("overflow", "hidden");
  
  $("#billboard").cycle({
    timeout: 6000
  });
  
  
$("a[href^='http://']").addClass("offSite").bind('click keypress', function(event) {
        var code=event.charCode || event.keyCode;

        if(!code || (code && code == 13)) {
          if(pageTracker){
            var fixedLink = this.href;
            fixedLink = fixedLink.replace(/https?:\/\/(.*)/,"$1");
            fixedLink = '/outgoing/' + fixedLink;
            pageTracker._trackPageview(fixedLink);
          };

        };
 });
  
  $('ol.question_list div.answer').hide();
  $('ol.question_list h4 a').addClass("question").toggle(function(){
    $(this).addClass("open");
    $(this).closest("h4").next("div.answer").slideDown();
    return false;
  }, function() {
    $(this).removeClass("open");
    $(this).closest("h4").next("div.answer").slideUp();
    return false;
  });
  
});


//Trim string
function Trim(text){
   return text.replace(/(^\s*)|(\s*$)/g, ""); 
}      
function Search() {
      var searchWord = Trim(document.getElementById('search').value);
      if(document.getElementById('search').value == 'Please enter your search keyword')
      {
        return false;
      }
  window.location = "/search.aspx?search=" + searchWord;
      }
function PreSearch(txtBox)
{
    if(txtBox.value == '')
    {
        txtBox.value = 'Search';
    }
    else if(txtBox.value == 'Search')
    {
        txtBox.value = '';
    }
}
function PreSearchAgain()
{
    if(Trim(document.getElementById('txtSearchAgain').value) == '')
    {
        document.getElementById("labelMessage").innerText = 'Please enter your search keyword';
        return false;
    }
    return true;
}





