$(document).ready(function () {
  $('div#footer_icons').find('a').hover(function () {
    $('img#footer-image-text').show();
  }, function () {
    $('img#footer-image-text').hide();
  });

  if ($('#imageCont').length > 0) {
    $('#imageCont').cycle({ speed: 5000 });
  }

  $('a.chart-link').click(function () {
    window.open('http://ir.iguana2.com/kip/stock-chart', 'chart', 'resizable=yes,scrollbars=no,toolbar=no,location=no,directories=no,status=no,menubar=no,width=480,height=400,left=200,top=200,screenX=200,screenY=200');
    return false;
  });
});

$(window).load(function () {
  $('.imageLeftNoBorder').each(function () {
    var width = $(this).width();

    $(this).parent().find('div.text-float-right').css('width', (670 - width) + 'px');
  });
}); 

function ShowOnMap(id, location) {
  var mapNode = document.getElementById('map-' + id);

  if (!mapNode) {
    return;
  }

  $('#map-' + id).css('height', '270px');

  var map = new GMap2(mapNode);

  if (map) {
    map.addControl(new GLargeMapControl());
    var point = new GLatLng(location.lat, location.long); 
    var popupDisplayText = '<b><a href="' + location.link + '">' + location.tradingName + "</a></b><br />" + location.address;
    map.setCenter(point, 14);
    map.addOverlay(CreateMarker(popupDisplayText, point));
  }
}

function ShowAssetsOnMap(id, locations) {
  var mapNode = document.getElementById('map-' + id);

  if (!mapNode) {
    return;
  }

  $('#map-' + id).css('height', '270px');

  var map = new GMap2(mapNode);
  var geocoder = new GClientGeocoder();

  if (map && geocoder) {
    map.setCenter(new GLatLng(-40.946714, 173.034668), 4);
    map.addControl(new GLargeMapControl());

    for (var i = 0; i < locations.length; i++) {
      var location = locations[i];
      var point = new GLatLng(location.lat, location.long); 
      var popupDisplayText = '<b><a href="' + location.link + '">' + location.tradingName + "</a></b><br />" + location.address;
      map.addOverlay(CreateMarker(popupDisplayText, point));
    }
  }
}

function CreateMarker(popupDisplayText, point) {
  var marker = new GMarker(point, { icon: new GIcon(G_DEFAULT_ICON) });

  GEvent.addListener(marker, "click", function () {
    marker.openInfoWindowHtml(popupDisplayText);
  });

  return marker;
}
