﻿var count = 0;

//
//  Creates a 3D Window in the control with the specified ID using the specified world URL
//
function Create3DControl(id, worldURL, view)
{
    var control = document.getElementById(id);
    control.innerHTML = "<object z-index=\"0\" id=\"World\" classid=\"CLSID:DE833CC3-52E7-4C9A-BDC4-8EC24B422A2B\" codebase=\"http://www.tdlhosting.co.uk/vislite/VisLite.CAB\" name=World VIEWASTEXT width=\"781\" height=\"355\"><param name=\"World\" value=\"" + worldURL + "\"><embed id=\"World\" src=\"" + worldURL + "\" name=\"World\" type=\"application/vnd.superscape.vislite\" width=\"781\" height=\"353\" world=\"" + worldURL + "\"></embed></object>";
    
    Set3DViewpoint(view);
} 

//
//  Sets the view in the 3D world
//
var loaded = 0;
function Set3DViewpoint(view)
{
    var world = document.getElementById("World"); 
    
    // Check that world has loaded
    if (world.GetMarker(0)==0 && loaded == 0)
    {
        timeid = setTimeout("Set3DViewpoint(" + view + ");", 100);
        world.SetMarker (0, 1);
    }
    else
    {
        if (world.GetMarker(0)==0)
        {
            timeid = setTimeout("Set3DViewpoint(" + view + ");", 100);
            loaded = 0;
        }
        else
        {                             
            // Set viewpoint & clear timer
            world.SetViewPoint(view);
            world.SetMarker (0, 2); 
            clearTimeout(timeid);
            
            loaded = 1;
        }
    }
}

//
//  Displays the panel for the Member with the specified ID
//
function showHide(elementID)
{       
    // Hide all member panels
    var collection;
    collection = object("DetailsPanel").childNodes;
    for (i = 0; i < collection.length; i++)
    {
        var subcollection = collection[i].childNodes;
        for (j = 0; j < subcollection.length; j++)
            subcollection[j].style.display = "none";  
    }
             
    // Show selected member panel 
    var element; 
    element = object(elementID);
    element.style.display = "block";
   
    // Set world width
    ShowMemberDetailsPanel();
}

//
//  Hides the panel for the Member with the specified ID
//
function hide(elementID)
{
    // Hide an element
    var element;
    element = document.getElementById(elementID);
    if (element == null)
        element = document.getElementById("ctl00_content_" + elementID);  
    element.style.display = "none"; 
}

//
// Returns the object with the specified ID
//
function object(obj)
{
    var element;
    
    element = document.getElementById(obj);
    if (element == null)
        element = document.getElementById("ctl00_content_" + obj);
    return element;
}

//
//  Shows the member details panel
//
function ShowMemberDetailsPanel()
{   
    // Check panel is not fully shown
    if (object("DetailsPanel").style.width == "281px")
        return;
       
    // Move panel out
    object("MemberDetails").style.display = "none"; 
    object("DetailsPanel").style.display = "block";  
    var width = 781 - 281 * (1-Math.exp(-count/2.5));
    object("WorldPanel").style.width = width + "px";
    width = 281 * (1-Math.exp(-count/2.5))
    object("DetailsPanel").style.width = width + "px"; 
    timer = setTimeout("ShowMemberDetailsPanel()",25);
    count += 1;
    if (count>= 10)
    {
        object("WorldPanel").style.width = "500px";
        object("DetailsPanel").style.width = "281px";
        object("MemberDetails").style.display = "block";
        clearTimeout(timer);
        count = 0;
    }
}

//
//  Hides the member details panel
//
function HideMemberDetailsPanel()
{
    // Check panel is not fully shown
    if (object("DetailsPanel").style.width == "0px")
        return;
        
    // Move panel out
    object("MemberDetails").style.display = "none"; 
    var width = 500 + 281 * (1-Math.exp(-count/2.5));
    object("WorldPanel").style.width = width + "px"; 
    width = 281 - 281 * (1-Math.exp(-count/2.5)); 
    object("DetailsPanel").style.width = width + "px";  
    timer = setTimeout("HideMemberDetailsPanel()",25);
    count += 1;
    if (count>= 10)
    {
        object("WorldPanel").style.width = "781px";
        object("DetailsPanel").style.width = "0px";
        object("DetailsPanel").style.display = "none"; 
        clearTimeout(timer);
        count = 0;
    }
}
