/* updated */ var cssId = 'storypromocss'; // you could encode the css path itself to generate id.. if (!document.getElementById(cssId)) { var head = document.getElementsByTagName('head')[0]; var link = document.createElement('link'); link.id = cssId; link.rel = 'stylesheet'; link.type = 'text/css'; link.href = 'http://www.cnnewmedia.co.uk/storypromo/css/storypromo.css'; link.media = 'all'; head.appendChild(link); } var jsonValues = {"par":"6","title":"More articles...","values":[{"title":"Carlisle motorist had 'staggering' level of cocaine in his system","link":"http:\/\/www.newsandstar.co.uk\/news\/latest\/Carlisle-motorist-had-staggering-level-of-cocaine-in-his-system-35d29cb5-257b-4593-aee0-a92977c6ff1f-ds"},{"title":"Victim of potential Carlisle sex assault urged to contact police","link":"http:\/\/www.newsandstar.co.uk\/news\/latest\/Victim-of-potential-Carlisle-sex-assault-asked-to-contact-police-a1322c2e-7a8b-4817-8952-ed684c8f5b12-ds"},{"title":"Man dead after crash on main west Cumbrian road","link":"http:\/\/www.newsandstar.co.uk\/news\/Man-dead-after-crash-on-main-west-Cumbrian-road-6b8a03e5-37c5-4e7c-b0f8-a4d0364b2d41-ds"},{"title":"Urgent recalls for meat, fish and snack products sold at Home Bargains","link":"http:\/\/www.newsandstar.co.uk\/news\/Urgent-recalls-for-meat-fish-and-snack-products-sold-at-Home-Bargains-78d258e1-0a79-4862-ad9a-3902ab9edaae-ds"},{"title":"First look at new homes for landmark Carlisle site","link":"http:\/\/www.newsandstar.co.uk\/news\/First-look-at-new-homes-for-landmark-Carlisle-site-0e58f878-7f3c-45ca-aa6f-ed2aa1867127-ds"}]}; var insertAfter = jsonValues.par; var promotitlediv = document.getElementById("storypromotitle"); promotitlediv.innerHTML = jsonValues.title; var promodiv = document.getElementById("storypromo"); var promoarticleslist = document.getElementById("storypromoarticleslist"); if (jsonValues.values.length == 0) promodiv.style.display = "none"; else { for (x = 0; x < jsonValues.values.length; x++) { var listitem = document.createElement("li") var linkdiv = document.createElement("a"); linkdiv.setAttribute("href", jsonValues.values[x].link); linkdiv.setAttribute("title", jsonValues.values[x].title); linkdiv.innerHTML = jsonValues.values[x].title listitem.appendChild(linkdiv); promoarticleslist.appendChild(listitem); } if (jsonValues.values.length > 0) { promodiv.style.display = "block"; var articleElement = document.getElementsByClassName("article_story"); var paragraphtags = articleElement[0].getElementsByTagName("p") if (paragraphtags.length > insertAfter) articleElement[0].insertBefore(promodiv, paragraphtags[insertAfter]); else articleElement[0].insertBefore(promodiv, paragraphtags[paragraphtags.length]); } }