if (! window.imooch) var imooch = {}; imooch.getId = function (el) { if (! el) el = {}; if (! el.id) { el.id = "imooch_"+ parseInt(Math.random() *100000000); } return el.id; } imooch.api_placer = function (host, module, html, css, js, id, isTiny) { var head = document.getElementsByTagName('head')[0]; if (id && document.getElementById(id)) { var tmpId = id; document.getElementById(id).className += ' imooch_api'+ (isTiny ? ' imooch_api_tiny':''); } else { var tmpId = imooch.getId(); document.write('
'); } setTimeout(function (html, id) { return function () { var El = document.getElementById(id); if (El) El.innerHTML = html; } }(html, tmpId), 10); if (css && css != '') { var elStyle = document.createElement('style'); elStyle.setAttribute('type', 'text/css'); head.appendChild(elStyle); var prependId = ''; var elTrg = document.getElementById(tmpId); if (elTrg) { var elUp = elTrg; while (elUp = elUp.parentNode) { if (elUp.id) { prependId = elUp.id; break; } } if (prependId != '') prependId = '#'+ prependId +' '; } // add some specificity with two ancestral IDs, and convert relative/root URLs to absolute cssWithIDs = css.replace(/^(\* html |\*\:first\-child\+html )?div\.imooch_/mgi, '$1'+ prependId +'#'+ tmpId +' div.imooch_'); cssWithIDsAndHost = cssWithIDs.replace(/\burl\(img/gi, 'url('+ host +'/api/'+ module +'/img'); cssWithIDsAndHost = cssWithIDs.replace(/\burl\(\//gi, 'url('+ host +'/'); try { // DOM elStyle.appendChild(document.createTextNode(cssWithIDsAndHost)); } catch (e) { try { // IE elStyle.styleSheet.cssText = cssWithIDsAndHost; } catch (e) { // last-ditch attempt document.write(''); } } } if (js && js != '') { var jsId = 'imooch_' + js.substring(js.indexOf('/api/') +5, js.length -4).replace(/[^\w]/, '_'); if (! document.getElementById(jsId)) { var scrp = document.createElement('scr\ipt'); scrp.setAttribute('type', 'text/javascript'); scrp.setAttribute('src', js); head.appendChild(scrp); scrp.id = jsId; } } } imooch.api_placer( 'http://www.imooch.com', 'banner', '