(function($) {
var cache = [];
$.preLoadImages = function() {
var args_len = arguments.length;
for (var i = args_len; i--;) {
var cacheImage = document.createElement('img');
cacheImage.src = arguments[i];
cache.push(cacheImage);
}
}
})(jQuery)
function pointInPolygon(x, y, poly) {
var i, j = poly.points.length-1;
var oddNodes = false;
if(x < poly.bounds.left || x > poly.bounds.right || y < poly.bounds.top || y > poly.bounds.bottom) {
return false;
}
for (i=0; i < poly.points.length; i++) {
if (poly.points[i].y < y && poly.points[j].y >= y || poly.points[j].y < y && poly.points[i].y >= y) {
if (poly.points[i].x+(y-poly.points[i].y)/(poly.points[j].y-poly.points[i].y)*(poly.points[j].x-poly.points[i].x) < x) {
oddNodes = !oddNodes;
}
}
j = i;
}
return oddNodes;
}
function arrToPoly(arr) {
var poly = {
bounds: { top: 1000000, right: 0, bottom: 0, left: 1000000 },
points: []
};
for(var i=0; i < arr.length; i+=2) {
poly.points.push({ x: arr[i], y: arr[i+1]});
if(arr[i] < poly.bounds.left) poly.bounds.left = arr[i];
if(arr[i] > poly.bounds.right) poly.bounds.right = arr[i];
if(arr[i+1] < poly.bounds.top) poly.bounds.top = arr[i+1];
if(arr[i+1] > poly.bounds.bottom) poly.bounds.bottom = arr[i+1];
}
return poly;
}
var maxPopupWidth = 350;
function showPopup(activePoly) {
if(activePoly.alias == "north_america") {
window.location = "/setregion.jsp?region=north_america®ionLanguage=english";
return;
}
$(".popup").remove();
$("#map .overlay").show().fadeTo(0,1.0);
var $worldMap = $(this);
var $img = $("");
$("body").append($img);
var fullWidth = $img.width();
var fullHeight = $img.height();
if(fullWidth > maxPopupWidth) {
fullHeight = fullHeight * maxPopupWidth/fullWidth;
fullWidth = maxPopupWidth;
}
$img.css({ left: $worldMap.offset().left + activePoly.bounds.left, position: "absolute", top: $worldMap.offset().top + activePoly.bounds.top, width: (activePoly.bounds.right-activePoly.bounds.left) });
if(!($.browser.msie && $.browser.version == 7)) $img.css({ opacity: 0.5 });
var x = $img.offset().left;
var y = $img.offset().top;
var xOffset = 25;
var yOffset = -25;
$img.animate({ left: x+xOffset, top: y+yOffset, width: fullWidth }, 350, 'linear', function() {
$img.animate({ left: $worldMap.offset().left + ($img.width() < maxPopupWidth ? (maxPopupWidth-$img.width())/2 : 0), top: $worldMap.offset().top + ($worldMap.height() > $img.height() ? ($worldMap.height() - $img.height())/2 : 0) }, 350, 'linear', function() {
if(!($.browser.msie && $.browser.version == 7)) $img.animate({ opacity: 1.0 }, 350);
var $contOptions = $("
")
.html($("#lang_display ." + activePoly.alias).html())
.css({ borderBottom: "2px solid gray", left: $worldMap.offset().left+maxPopupWidth+20, top: $worldMap.offset().top });
$("body").append($contOptions);
$contOptions.slideDown('medium', function() { $contOptions.css("border-bottom", 0); });
function closeMenu() {
$("#map .overlay, .popup").fadeOut("slow", function() { $(".popup").remove(); });
$(document).unbind("click", closeMenu);
}
$(document).click(closeMenu);
});
});
}
var naPoly = null;
var saPoly = null;
var emeaiPoly = null;
var oceanPoly = null;
var regions = null;
var overlay = null;
var activePoly = null;
function initPopup() {
showPopup.call(this, activePoly);
}
function updateCoords(e) {
var $this = $(this);
if(overlay.css("display") == "none") {
var point = { x: (e.pageX-$this.offset().left), y: (e.pageY-$this.offset().top) }
activePoly = undefined;
for(var i=0; i < regions.length; i++) {
var poly = regions[i];
if(pointInPolygon(point.x, point.y, poly)) {
activePoly = poly;
break;
}
}
if(activePoly) {
$this.find(".small").hide();
$this.find("." + activePoly.alias + "_over").show();
if(e.type == "click") {
showPopup.call(this, activePoly);
}
else {
$this.unbind('click', initPopup).css("cursor", "pointer").click(initPopup);
}
}
else {
$this.unbind('click', initPopup).css("cursor", "auto");
$this.find(".small").hide();
}
}
else {
$this.unbind('click', initPopup).css("cursor", "auto");
}
}
function fixOffset(arr, x, y) {
for(var i=0; i < arr.length; i+=2) {
arr[i] = arr[i] + x;
arr[i+1] = arr[i+1] + y;
}
return arr;
}
function setupPolys() {
naPoly = arrToPoly(fixOffset([0,20, 88,0, 230,0, 230,6, 214,22, 170,56, 152,98, 113,97, 111,102, 92,100, 61,67, 45,48, 0,45], 0, 0));
naPoly.name = "North America";
naPoly.alias = "north_america";
saPoly = arrToPoly(fixOffset([0,6, 6,0, 47,13, 85,33, 85,49, 52,105, 22,105, 27,57, 15,38, 15,19], 110, 95));
saPoly.name = "South America";
saPoly.alias = "south_america";
emeaiPoly = arrToPoly(fixOffset([/* start china border */440,61, 440,56, 443,56, 444,53, 439,54, 431,45, 426,45, 419,51, 419,52, 423,53, 424,55, 419,55, 413,58, 410,61, 404,61, 401,62, 397,61, 389,61, 386,58, 381,57, 380,53, 376,52, 366,57, 366,61, 357,64, 357,66, 361,71, 364,70, 366,71, 364,75, 364,77, 374,82, 383,82, 386,80, 389,80, 391,82, 388,84, 382,92/* end china border */, 368,119, 337,97, 325,141, 308,171, 269,172, 253,120, 233,120, 219,101, 219,89, 231,72, 210,25, 263,0, 397,0, 530,19, 530,29, 477,51, 474,39, 456,44, 456,47, 454,52, 445,61], 0, 0));
emeaiPoly.name = "EMEA-I";
emeaiPoly.alias = "emeai";
oceanPoly = arrToPoly(fixOffset([/* start china border */440,61, 440,56, 443,56, 444,53, 439,54, 431,45, 426,45, 419,51, 419,52, 423,53, 424,55, 419,55, 413,58, 410,61, 404,61, 401,62, 397,61, 389,61, 386,58, 381,57, 380,53, 376,52, 366,57, 366,61, 357,64, 357,66, 361,71, 364,70, 366,71, 364,75, 364,77, 374,82, 383,82, 386,80, 389,80, 391,82, 388,84, 382,92/* end china border */, 382,103, 384,111, 415,176, 495,194, 510,180, 508,149, 433,84, 460,70, 457,44, 454,44, 454,47, 443,61], 0, 0));
oceanPoly.name = "Oceania";
oceanPoly.alias = "oceania";
regions = [naPoly, saPoly, oceanPoly, emeaiPoly];
for(var i=0; i < regions.length; i++) {
$.preLoadImages("images/globalmap/" + regions[i].alias + ($.browser.msie && $.browser.version < 7 ? ".gif" : ".png"));
}
}
$(document).ready(function() {
overlay = $("#map .overlay");
setupPolys();
$("#map").hover(
function() { $("#map").mousemove(updateCoords); },
function(e) { updateCoords.call(this, e); $("#map").unbind('mousemove', updateCoords); }
)
.click(function(e) { updateCoords.call(this, e); });
$(".close").live('click', function() {
$("#map .overlay, .popup").fadeOut("slow", function() { $(".popup").remove(); });
return false;
});
$("#locations a[href=#]").click(function() {
var title = $(this).closest("[data-region]").attr("data-region");
if(title == "North America") {
showPopup.call($("#map")[0], naPoly);
}
else if(title == "South America") {
showPopup.call($("#map")[0], saPoly);
}
else if(title == "EMEA-I") {
showPopup.call($("#map")[0], emeaiPoly);
}
else if(title == "Asia Pacific") {
showPopup.call($("#map")[0], oceanPoly);
}
return false;
});
if($.browser.msie && $.browser.version < 7 && window.DD_belatedPNG) {
DD_belatedPNG.fix("#map, #map .small, #map .overlay");
}
});