var bookProductPage = (((typeof document.forms[0].PageType != "undefined")&&(document.forms[0].PageType.value == "onixProduct")) && ((typeof document.forms[0].Subsection != "undefined")&&(document.forms[0].Subsection.value == "Titles"))) if(bookProductPage)//Is it a onix book page { var smallImg = smallCoverExist(); var pdf = pdfExist(); var audio = audioExist(); if(smallImg)//if small image exist { var largeImg = largeCoverExist(smallImg); if(largeImg) { var imgParent = document.getElementById('edDeskBody').getElementsByTagName('img')[0].parentNode; var oAnchor = document.createElement('a'); oAnchor.className = 'downloadCoverLink'; oAnchor.setAttribute('href',largeImg); oAnchor.setAttribute('target','_blank'); oAnchor.appendChild(document.createTextNode('Download cover image')); imgParent.appendChild(oAnchor); } } else { var oImg = document.getElementById('edDeskBody').getElementsByTagName('img')[0]; oImg.src = 'templates/layout/$file/noCover.gif'; } if(pdf) { var imgParent = document.getElementById('edDeskBody').getElementsByTagName('img')[0].parentNode; //imgParent.appendChild(document.createElement('br')); var oAnchor = document.createElement('a'); oAnchor.className = 'downloadCoverLink pdflink'; oAnchor.setAttribute('href',pdf); oAnchor.setAttribute('target','_blank'); oAnchor.appendChild(document.createTextNode('View sample pages')); imgParent.appendChild(oAnchor); } if(audio) { var imgParent = document.getElementById('edDeskBody').getElementsByTagName('img')[0].parentNode; var oAnchor = document.createElement('a'); oAnchor.className = 'downloadCoverLink pdflink'; oAnchor.setAttribute('href',audio); oAnchor.setAttribute('target','_blank'); oAnchor.appendChild(document.createTextNode('Listen to sample audio')); imgParent.appendChild(oAnchor); } } function largeCoverExist(imgPath) { var winLoc = window.location.toString(); if(winLoc.indexOf('macmillan.com.au') != -1)//Is it the test site { var largeImgPath = imgPath.replace('/mea/covers/','/mea/downloadcovers/'); } else { var largeImgPath = imgPath.replace('/mea/','/mea/downloadcovers/'); } var imgLoad = new HeaderLoader(largeImgPath); if(imgLoad.exist) { return largeImgPath; } else { return; } } function smallCoverExist() { var oImg = document.getElementById('edDeskBody').getElementsByTagName('img'); if(typeof oImg != 'undefined' && oImg.length == 1) { var imgPath = replaceURL(oImg[0].getAttribute('src')); var imgLoad = new HeaderLoader(imgPath); if(imgLoad.exist) { return imgPath; } else { return; } } } function pdfExist() { var oImg = document.getElementById('edDeskBody').getElementsByTagName('img'); if(typeof oImg != 'undefined' && oImg.length == 1) { var imgPath = replaceURL(oImg[0].getAttribute('src')); var winLoc = window.location.toString(); if(winLoc.indexOf('macmillan.com.au') != -1)//Is it the test site { var pdfPath = imgPath.replace('/mea/covers/','/mea/downloadpdfs/'); } else { var pdfPath = imgPath.replace('/mea/','/mea/downloadpdfs/'); } pdfPath = pdfPath.toLowerCase().replace('jpg','pdf'); var pdfLoad = new HeaderLoader(pdfPath); if(pdfLoad.exist) { return pdfPath; } else { return; } } } function audioExist() { var oImg = document.getElementById('edDeskBody').getElementsByTagName('img'); if(typeof oImg != 'undefined' && oImg.length == 1) { var imgPath = replaceURL(oImg[0].getAttribute('src')); var winLoc = window.location.toString(); if(winLoc.indexOf('macmillan.com.au') != -1)//Is it the test site { var audioPath = imgPath.replace('/mea/covers/','/mea/downloadaudio/'); } else { var audioPath = imgPath.replace('/mea/','/mea/downloadaudio/'); } var fileTypes = ['mp3','mp4','wmv','wma']; //Loop through file types and return the first one that exists for(var i = 0; i < fileTypes.length; i++) { //Get file extension to replace in file url if(i == 0) { var strReplace = 'jpg'; } else { var strReplace = fileTypes[i-1]; } audioPath = audioPath.toLowerCase().replace(strReplace,fileTypes[i]); var audioLoad = new HeaderLoader(audioPath); if(audioLoad.exist)//if file exist { return audioPath; } } return; } } function replaceURL(imgPath) { var winLoc = window.location.toString(); if(imgPath.indexOf('macmillan.com.au') != -1 && winLoc.indexOf('macmillan.com.au') == -1) { return imgPath.replace('http://www.macmillan.com.au/mea/covers/','http://primarydev.itechne.com/files/mea/'); } else { return imgPath; } }