﻿//methods to handle floating item containers
function FloatingContent(controlID)
{
    this.controlID = controlID;
    this.containerID =  "FloatingItemContainer"+controlID;  //floating item container
    this.iframeID = "FloatingItemFrame"+controlID; //floating item frame   
}

FloatingContent.prototype.showContent = function(itemtitle, url, top, left, linkObject)
{
    this.startLoadingProgress();
    document.getElementById(this.containerID).style.display="block";   
    
    if (top==null) top=-5;
    if (left==null) left = 40;    
    
    if (linkObject!=null)    
    {
        //if link object passed, find position and position box at item pos
        top = this.findPosY(linkObject);
        left = this.findPosX(linkObject);
    }
    
    if (top!=null) document.getElementById(this.containerID).style.top=top+"px";                        
    if (left!=null) document.getElementById(this.containerID).style.left=left+"px";                        


    document.getElementById(this.iframeID).src = url;
    document.getElementById("floatingTitle"+this.controlID).innerHTML=itemtitle;
    
}


FloatingContent.prototype.startLoadingProgress = function()
{
    document.getElementById("progress"+this.controlID).style.display="inline";
    if (document.getElementById(this.iframeID).contentDocument)
    {
        //clear current document before loading next page
        var iframeDoc = document.getElementById(this.iframeID).contentDocument;
        var bodyDoc = iframeDoc.getElementById("controlContainer");               
        if (bodyDoc) bodyDoc.innerHTML="";
    }
}

FloatingContent.prototype.stopLoadingProgress = function()
{    
    document.getElementById("progress"+this.controlID).style.display="none";      
}

FloatingContent.prototype.refreshContainerSize = function()
{
    //called by document in frame container on load
    //resizes iframe to match content
    var docheight=document.getElementById(this.iframeID).contentWindow.document.body.scrollHeight;    
    if (docheight>400) docheight=400;
    document.getElementById(this.iframeID).height= docheight+10;
    this.stopLoadingProgress();
 }

FloatingContent.prototype.closeDialog = function()
{
    document.getElementById(this.containerID).style.display="none";
}

FloatingContent.prototype.findPosX =function(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

FloatingContent.prototype.findPosY =function(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}
