// Resize map
$.fn.mapresize = function(){
  
  var $map = this.children('map');
  // var newDimensionX = this[0].style.width || this.children('img').width();
  
  // Set vars
  var originalDimensionX = 959,
      originalDimensionY = 593,
      newDimensionX = parseInt(this[0].style.width || this.children('img').width()), // Assmuing XY ratio remains, we only need to set X 
      offsetX = 1, // Offset to compensate for forced integers
      offsetY = 0;
  

  // Get the radtio of difference between the old and new images
  var diffRatio = newDimensionX / originalDimensionX;
  
  $map.children( 'area' ).each( function( i, elem ){
    var coords = $( elem ).attr( 'coords' ).split( ',' );
    var newCoords = [];
    for( var n in coords ){
      offset = n % 2 ? offsetY : offsetX ;
      newCoords[ n ] = parseInt( coords[ n ] * diffRatio ) + offset;
    }
    newCoords = newCoords.join( ',' );
    elem.coords = newCoords;
  });
  
  return this;
};



// Function to highlight siblings on mouseover
$.fn.mouseoverall = function() {
  $(this)
    .mouseover(function(e) {
      $this = $(this);
      if(!$this.data['mousedover']) {
        $this.data['mousedover'] = true;
        $this.siblings('area[title="' + $this.attr('title') + '"]').mouseover();
      }
    })
    .mouseout(function(e){
      $this = $(this);
      if($this.data['mousedover']) {
        $this.data['mousedover'] = false;
        $this.siblings('area[title="' + $this.attr('title') + '"]').mouseout();
      }
    });
  return $(this);
}
