if (!Array.indexOf) { Array.prototype.indexOf = function(obj) { for(var i=0; i < this.length; i++) { if(this[i] == obj) { return i; } } return -1; } } var iframes = new Array(); function registerIFrame(iframe) { if (iframes.indexOf(iframe) === -1) { iframes.push(iframe); var guid = generateGUID(); iframe.src = iframe.src + "#GUID=" + guid; setTimeout(function() { pollForHeight(guid, iframe, 0); }, 100); setTimeout(function() { pollForResize(iframe); }, 200); } } function pollForHeight(guid, iframe, retryCount) { if (retryCount < 10) { var getHeightImage = new Image(); getHeightImage.onload = function() { iframe.style.height = getHeightImage.height + "px"; }; getHeightImage.onerror = function() { setTimeout(function() { pollForHeight(guid, iframe, retryCount + 1); }, 200); }; getHeightImage.src = "http://mte.apple.kuluvalley.com/scripts/getIframeHeight?guid=" + guid + "&cacheKiller=" + Math.random().toString().substring(2); } else { iframe.src = iframe.src.substring(0, iframe.src.indexOf("#")) + "#SHOW_SCROLL"; } } function pollForResize(iframe) { if (location.hash.indexOf("RESIZE=") !== -1) { var height = parseInt(location.hash.substring(location.hash.indexOf("RESIZE=") + 7)); iframe.style.height = height + "px"; location.hash = "#"; } setTimeout(function() { pollForResize(iframe); }, 200); } function generateGUID() { function G4() { return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1); } return G4()+G4()+"-"+G4()+"-"+G4()+"-"+G4()+"-"+G4()+G4()+G4(); }