﻿// JScript File

function PopupBox(oClickedLink, oObj)
{
    this.ClickedLink = oClickedLink;
    this.Obj = oObj;
    this.MyPopup = document.getElementById(this.Obj);
    
    this.Direction = 'LeftTop';
    
    PopupBox.prototype.SetPosition = function()
    {
        
        //body heigt;
	    this.iBodyWidth = window.getBodyWidth();
	    this.iBodyHeight = window.getBodyHeight();
    	
	    //get real scrollpos
	    this.aScrollPositions = window.getScrollXY();
    	
	    this.tScrollLeft = this.aScrollPositions[0];
	    this.tScrollTop = this.aScrollPositions[1];
    	
	    this.iScrollTop = window.getScrollTop();
    	
	    //viewportheight
	    this.iViewportWidth = window.getViewportWidth();
	    this.iViewportHeight = window.getViewportHeight();
    	
    	
	    // position of link with mouseover
	    this.aPosition = window.findPos(oClickedLink);
    	
	    this.iPosX = this.aPosition[0];
	    this.iPosY = this.aPosition[1];
    	
	    //aDemension = getDemension(boxId);
    	
	    this.MyPopup.style.left = this.iPosX - 22 + 'px';
	    this.MyPopup.style.top = this.iPosY + 12 + 'px';
    	
	    this.MyPopup.style.display = 'block';
	    
	    this.MyPopupWidth = this.MyPopup.offsetWidth;
	    this.MyPopupHeight = this.MyPopup.offsetHeight;
	    
	    new window.SetObjIntervalMouseMove(this.MyPopup);
    }
    
    PopupBox.prototype.ChooseClass = function(classLeftTop, classRightTop, classRightBottom, classLeftBottom)
    {
        this.chosenClass = classLeftTop;
                
        if(this.iPosX > this.iViewportWidth / 2 && this.iPosX > this.MyPopupWidth)
	    {
		    this.chosenClass = classRightTop;
	    }
    	
	    if(this.iPosY - this.tScrollTop > this.iViewportHeight / 2 && this.iPosY - this.tScrollTop > this.MyPopupHeight)
	    {
		    if(this.iPosX > this.iViewportWidth / 2 && this.iPosX > this.MyPopupWidth)
		    {
			    this.chosenClass = classRightBottom;
		    }
		    else
		    {
			    this.chosenClass = classLeftBottom;
		    }
	    }
	    
	    if(this.chosenClass == classLeftTop)
	    {
	        this.Direction = 'LeftTop';
	    }
	    if(this.chosenClass == classRightTop)
	    {
	        this.Direction = 'RightTop';
	    }
	    if(this.chosenClass == classRightBottom)
	    {
	        this.Direction = 'RightBottom';
	    }
	    if(this.chosenClass == classLeftBottom)
	    {
	        this.Direction = 'LeftBottom';
	    }
	    return(this.chosenClass);
	    
    }
    
    PopupBox.prototype.ChangePosition = function(plusX, plusY)
    {
        switch(this.Direction)
        {
            case 'LeftTop':  
            this.MyPopup.style.left = this.iPosX  + plusX + 'px';
		    this.MyPopup.style.top = this.iPosY + plusY + 'px';
            break;
            
            case 'RightTop':  
            this.MyPopup.style.left = this.iPosX - this.MyPopupWidth + plusX + 'px';
		    this.MyPopup.style.top = this.iPosY + plusY + 'px';
            break;
            
            case 'RightBottom':  
            this.MyPopup.style.left = this.iPosX - this.MyPopupWidth + plusX + 'px';
            this.MyPopup.style.top = this.iPosY - this.MyPopupHeight + 'px';
            break;
            
            case 'LeftBottom':  
            this.MyPopup.style.left = this.iPosX  + plusX + 'px';
            this.MyPopup.style.top = this.iPosY - this.MyPopupHeight + 'px';
            break;
        }
    }
    
    
}

//infoBox.onmouseout = myMouseOut;
function SetObjIntervalMouseMove(Obj)
{
    var self = this;
    Obj.inter = null;
    
   
    Obj.onmouseover = function()
    {
        this.hoverOverBox = true;
    }
    Obj.onmouseout = function()
    {
        this.hoverOverBox = false;
    }    
     
    Obj.inter = setInterval(function() {
        self.update(Obj);
    }, 1000);
}
SetObjIntervalMouseMove.prototype.update = function(Obj)
{
   
    
    if(Obj.hoverOverBox == false)
    {
       
        clearInterval(Obj.inter);
        hideBox(Obj.id);
        Obj.hoverOverBox = null;
    }
    
    
    
    clearInterval(this.inter);
}


function displayDetailBox(ClickedLink, Obj)
{
    var DetailBox = new PopupBox(ClickedLink, Obj);
    DetailBox.SetPosition();
    var PopupClass = DetailBox.ChooseClass('DetailPopupArrowLeftTop', 'DetailPopupArrowRightTop', 'DetailPopupArrowRightBottom', 'DetailPopupArrowLeftBottom');
    
    switch(PopupClass)
    {
        case 'DetailPopupArrowLeftTop':    
        DetailBox.MyPopup.className = 'DetailPopupArrowLeftTop';
        DetailBox.ChangePosition(-20, 18);
        break;
        
        case 'DetailPopupArrowRightTop':    
        DetailBox.MyPopup.className = 'DetailPopupArrowRightTop';
        DetailBox.ChangePosition(35, 18);
        break;
        
        case 'DetailPopupArrowRightBottom': 
        DetailBox.MyPopup.className = 'DetailPopupArrowRightBottom';
        DetailBox.ChangePosition(35, 22);
        break;

        case 'DetailPopupArrowLeftBottom': 
        DetailBox.MyPopup.className = 'DetailPopupArrowLeftBottom';
        DetailBox.ChangePosition(-20, 22);
        break;
    }
}

function displayEmailBox(ClickedLink, Obj)
{
    var DetailBox = new PopupBox(ClickedLink, Obj);
    DetailBox.SetPosition();
    var PopupClass = DetailBox.ChooseClass('EmailPopupArrowLeftTop', 'EmailPopupArrowRightTop', 'EmailPopupArrowRightBottom', 'EmailPopupArrowLeftBottom');
    
    switch(PopupClass)
    {
        case 'EmailPopupArrowLeftTop':    
        DetailBox.MyPopup.className = 'EmailPopupArrowLeftTop';
        DetailBox.ChangePosition(-20, 18);
        break;
        
        case 'EmailPopupArrowRightTop':    
        DetailBox.MyPopup.className = 'EmailPopupArrowRightTop';
        DetailBox.ChangePosition(35, 18);
        break;
        
        case 'EmailPopupArrowRightBottom': 
        DetailBox.MyPopup.className = 'EmailPopupArrowRightBottom';
        DetailBox.ChangePosition(35, 18);
        break;

        case 'EmailPopupArrowLeftBottom': 
        DetailBox.MyPopup.className = 'EmailPopupArrowLeftBottom';
        DetailBox.ChangePosition(-20, 18);
        break;
    }
}