var popIframeLayer = $Class({
    $init:function()
    {
		clearInterval(this._timer);
    },
    _createIframe : function()
    {
        this.container = $("<div>");
        this.elIframe = $("<iframe>");
        this.elIframe.setAttribute("scrolling", "no");
        this.elIframe.setAttribute("frameborder", "0", "0");
        this.elIframe.setAttribute("width", "100px");
        this.container.appendChild(this.elIframe);
        
        this.container.style.position = "absolute";
        this.container.style.left = "-9999px";
        this.container.style.display = "none";
        document.body.appendChild(this.container);
    },
    _removeIframe : function()
    {
        document.body.removeChild(this.container);
    },
    show : function(url)
    {
        this._createIframe();
        var iframe = this.elIframe;
        this.container.style.display = "block";
        
        if(iframe.attachEvent)
		    iframe.attachEvent('onload', $Fn(this.resizeIframe, this).bind());
		else
		    if(iframe.addEventListener)
                iframe.addEventListener('load', $Fn(this.resizeIframe, this).bind(), false);
        var subUrl = url.substring(url.indexOf('?go='));
        subUrl = subUrl.substring(4);
        subUrl += document.location.href;
        url = url.substring(0, url.indexOf('?go='));
        url += "?go=" + encodeURIComponent(subUrl);
        
        iframe.setAttribute("src", url);
    },
    hide : function(newHref)
    {
    	clearInterval(this._timer);
        SPS.layer.hide(true);
        this._removeIframe();
        if(newHref)
        {
            location.href = newHref;
        }
    },
    resizeIframe: function()
	{
    	clearInterval(this._timer);
    	var iframe = this.elIframe;
	    iframe.setAttribute("height", "1px");
	    var bHeight = iframe.contentWindow.document.body.scrollHeight;
	    var dHeight = iframe.contentWindow.document.documentElement.scrollHeight;
	    var bWidth = iframe.contentWindow.document.body.scrollWidth;
        var dWidth = iframe.contentWindow.document.documentElement.scrollWidth;
        
	    var height = Math.max(bHeight, dHeight);
	    var width = Math.max(bWidth, dWidth);
	    if(iframe.contentWindow.document.body.innerHTML.replace(/^\s*|\s*$/,"") == "")
	    {
	    	width = height = 0;
	    }
        iframe.setAttribute("height", height);
        iframe.setAttribute("width", width);
        
        this.container.style.width = width + "px";
        this.container.style.height = height + "px";

        SPS.layer.show(this.container, true);
        if(iframe.contentWindow.document.body.innerHTML.replace(/^\s*|\s*$/,"") != "")
            this._timer = setInterval($Fn(this.resetIframeHeight, this).bind(), 200);
    },
    resetIframeHeight:function()
    {
    	try{
   	    var iframe = this.elIframe;
	    iframe.setAttribute("height", "1px");
	    iframe.setAttribute("width", "1px");
	    var bHeight = iframe.contentWindow.document.body.scrollHeight;
	    var dHeight = iframe.contentWindow.document.documentElement.scrollHeight;
	    var bWidth = iframe.contentWindow.document.body.scrollWidth;
        var dWidth = iframe.contentWindow.document.documentElement.scrollWidth;
        
	    var height = Math.max(bHeight, dHeight);
	    var width = Math.max(bWidth, dWidth);
	    
        iframe.setAttribute("height", height);
        iframe.setAttribute("width", width);
        
        this.container.style.width = width + "px";
        this.container.style.height = height + "px";
		}
		catch(e){};
    }
});
window.popLayer = new popIframeLayer();