//NNAlinkPopup.js //javascript methods for OHW in-content features //Netscape is not cool with this //document.write(''); //document.write(''); // dismissing the popup needs to be worked on var goldenRatio = 1.6180339887; var bestCandidate = 4; //just to default in case everything else fails var bestCandidateScore = -1; var visiblePopup = -1; //the event information needs to be stored globally var eventX = 0; var eventY = 0; var popupFile; //the correct popup lies between these two indices (1 through 7) var c=4; var l=0; var r=8; function resetValues() { c = 4; l = 0; r = 8; bestCandidate = 4; bestCandidateScore = -1; } // choose a popup width -- // - move the popup to the bottom of the screen, load content // - score it based on its proportions // move chosen one to the proper location, change it's bgcolor, and make it visible function popup(evt, file) { //alert('popup ' + file); eventX = evt.pageX; eventY = evt.pageY; popupFile = file; //start with the middle resizePopup(); } function resizePopup() { c = (l+r)/2; //move to the bottom of the page document.layers['NNpopupLayer' + c].moveTo(0, document.height); document.layers['NNpopupLayer' + c].onload = reportHeight; document.layers['NNpopupLayer' + c].src = popupFile; } function reportHeight() { // alert('height of ' + c + ' is ' + document.layers['NNpopupLayer' + c].document.height); var width = document.layers['NNpopupLayer' + c].document.width; var height = document.layers['NNpopupLayer' + c].document.height; var ratio = (width/height); //alert('ratio is ' + ratio); var score = Math.abs(goldenRatio - ratio); if(bestCandidateScore < 0 || score < bestCandidateScore) { //alert('setting best candidate to ' + c); bestCandidateScore = score; bestCandidate = c; } // if(l != c-1) { if(ratio > goldenRatio) { r = c; resizePopup(); } else { l = c; resizePopup(); } } else { //move the best candidate to eventX, eventY and make it visible //alert('best candidate is ' + bestCandidate); visiblePopup = bestCandidate; document.layers['NNpopupLayer' + visiblePopup].document.bgColor = "#ffffcc"; document.layers['NNpopupLayer' + visiblePopup].visibility = "visible"; positionPopup(visiblePopup); //reset stuff resetValues(); } } function positionPopup(i) { //in Netscape, if you go off the screen, you're out of luck -- you won't //get scrollbars, so you won't be able to see the whole popup //eventX, eventY document.layers['NNpopupLayer' + i].moveTo(10, eventY); } function alink(evt, links) { document.layers['NNalinkDiv'].moveTo(evt.pageX, evt.pageY); document.layers['NNalinkDiv'].document.open(); document.layers['NNalinkDiv'].bgColor = "#ffffcc"; document.write(''); document.write(''); for(key in links) { //it is possible to get the right style . . . //if not, don't include the style sheet document.write(''); } document.write(''); document.write(''); document.layers['NNalinkDiv'].visibility = "visible"; document.layers['NNalinkDiv'].document.close(); } function hidePopup(e) { if(visiblePopup != -1) { document.layers['NNpopupLayer' + visiblePopup].visibility = 'hidden'; visiblePopup = -1; } document.layers['NNalinkDiv'].visibility = 'hidden'; return document.routeEvent(e); } document.captureEvents(Event.CLICK); document.onclick = hidePopup; //for debugging/development purposes . . . function dumpObject(obj) { var dumpMessage = ''; for(key in obj) { dumpMessage += key + ' is ' + obj[key] + ' '; } alert(dumpMessage); }