$(document).ready(function(){ buildMap(); }); var sw = document.body.clientWidth, bp = 550, $map = $('.map'); var static = "http://api.tiles.mapbox.com/v3/landplanner.map-1sdx5y5e/pin-l-park2+343055(-89.93957,13.903408)/-88.79150,13.7421,8/640x320.png"; var embed = ""; function buildMap() { if(sw>bp) { //If Large Screen if($('.map-container').length < 1) { //If map doesn't already exist buildEmbed(); } } else { if($('.static-img').length < 1) { //If static image doesn't exist buildStatic(); } } }; function buildEmbed() { //Build iframe view $('
').html(embed).prependTo($map); }; function buildStatic() { //Build static map var mapLink = $('.map-link').attr('href'), $img = $('').attr('src',static); $('').attr('href',mapLink).html($img).prependTo($map); } $(window).resize(function() { sw = document.body.clientWidth; buildMap(); });