User:KarimB/monaco.js

/*** DOMReady ***/ $(function { /*** For each Decepticon, check page name, attach event listener ***/  for (i=0; i<tfGameDecepticons.length; i++) {    var d = tfGameDecepticons[i];    if (wgPageName == d.targetPage) {      $("[src$=" + d.targetImage + "]").one("mouseover", {decepticon: i}, tfGameReveal);    }   } });

/*** Array of Decepticon objects. Contains information about each of the reveal images ***/ tfGameDecepticons = [ {   targetPage: "Fire_in_the_Sky", targetImage: "FireintheSky_Memorial.jpg", src: "http://images.wikia.com/transformers/images/b/bc/Wiki.png", top: -94, left: -2 }, {    targetPage: "Megatron_(G1)", targetImage: "Megatronddjoe.jpg", src: "http://images.wikia.com/transformers/images/b/bc/Wiki.png", top: -152, left: 4 }, {    targetPage: "Cybertron_(planet)", targetImage: "200px-Movie_Cybertron_surfaceconcept.jpg", src: "http://images.wikia.com/transformers/images/b/bc/Wiki.png", top: -108, left: -10 }, {    targetPage: "Unicron", targetImage: "Unicronwiki.jpg", src: "http://images.wikia.com/transformers/images/b/bc/Wiki.png", top: 0, left: 0 }, ];

/*** Called once on mouseover ***/ function tfGameReveal(e) {

/*** Get decepticon object from array ***/ var d = tfGameDecepticons[e.data.decepticon]; /*** Calculate position for decepticon ***/ var targetTop = $(this).offset.top + d.top; var targetLeft = $(this).offset.left + d.left;

/*** Create elements ***/ $("body").append('');

/*** Position/style Decepticon ***/ $("#tfGameChar") .attr("src", d.src) .css({     position: "absolute",      top: targetTop,      left: targetLeft    }); }