﻿var pos = 504;
var cdivide = 0;
var cWidth = 1;

var chunks = new Array(0, 20, 100, 250, 400, 450, 472, 494, 500, 504);

var opening = true;

function instaglide(reqEleId)
{
    updatePos(0, reqEleId);
    opening = false;
    cdivide = 0;
}

function glide(reqEleId)
{    

    if ((cdivide == 0) && (!opening) && (reqEleId != null))
    {
        activatePage(reqEleId)
    }
    else
    {    
        var position;
        
        if (opening)
            position = -pos + chunks[cdivide];
        else
            position = -chunks[cdivide];
        
        updatePos(position, reqEleId);
        
        
        cdivide++;
        
        if (cdivide == chunks.length)
        {            
            cdivide = 0;
            if (opening)
            {
                opening = false;
            }
            else
            {
                opening = true;
            }
        }
        else
        {
            setTimeout("glide('"+reqEleId+"')", 100);
        }
    }
}
function updatePos(position, reqEleId)
{
    if (document.getElementById(reqEleId + "Page") != null)
    {             
        if ((cdivide == 0 && opening) || (cdivide == chunks.length-1 && !opening))
        {
            activatePage(reqEleId);
        }
    }

if (document.getElementById("glidePage").offsetWidth > cWidth)
    cWidth = document.getElementById("glidePage").offsetWidth;
    
    document.getElementById('glideBar').style.left = position + 'px';
    document.getElementById('glidePage').style.marginLeft = position + pos + 'px';
    document.getElementById('glidePage').style.width = cWidth - (position + pos) + 'px';
}

function activatePage(reqEleId)
{
    if ((window.location.pathname == "/members/member.aspx") && (reqEleId == "edit"))
    {
        window.location = "/admin/member.aspx?a="+getQueryVariable("a");
    }
    else 
{

                document.getElementById("searchPage").style.display = 'none';
                document.getElementById("siteMapPage").style.display = 'none';
                document.getElementById("contentPage").style.display = 'none';
                document.getElementById("contactPage").style.display = 'none';
                if (document.getElementById("editPage") != null) 
                    document.getElementById("editPage").style.display = 'none';

                document.getElementById(reqEleId + "Page").style.display = 'block';
            
            resizeGlide();
            }
}

function showHide(rid)
{
current=(document.getElementById(rid).style.display == 'block') ? 'none' : 'block';
document.getElementById(rid).style.display = current;
}

function getQueryVariable(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable) {
      return pair[1];
    }
  } 
  alert('Query Variable ' + variable + ' not found');
}
