var xmlHttp = "";
var divTargetElement;
var cindex = 0;
var holdId = 0;

//called from default.aspx
function reposition(){
       var img_scrlup = document.getElementById('tmpimgup');
       var img_scrldown = document.getElementById('tmpimgdown');
       var img_width = img_scrlup.offsetWidth;
       var img_height = img_scrlup.offsetHeight;
       
    // x and y starting and ending coordinates for both up and down arrow
    //   alert(img_height);
       xs_scrlup = leftPos(img_scrlup);
       
       xe_scrlup = xs_scrlup + img_width;
       ys_scrlup = topPos(img_scrlup);
       ye_scrlup = ys_scrlup + img_height;   

      xs_scrldown = leftPos(img_scrldown);; 
      xe_scrldown = xs_scrldown + img_width; 
      ys_scrldown = topPos(img_scrldown);
      ye_scrldown = ys_scrldown + img_height;

//alert(xs_scrldown);
//alert(img_width);
//alert(ys_scrldown);
}

//called from default.aspx specifically - news, events, and announce xsl files
// will call ajax routine to populate the appropriate target element

function GetCMSContent(cid,TargetElement, anchor)
{
    divTargetElement = TargetElement;    
    xmlHttp = ExecuteCall('http://' + location.host + location.pathname + '?cid=' + cid, CallbackMethod);
}

// used in wunewshomepg.xsl, events.xsl, and announce.xsl for populating Tab section of WUdefault
function GetTabContent(typ,cid,xsl,TargetElement, anchor)
{
    divTargetElement = TargetElement;
    //alert('http://' + location.host + location.pathname + '?typ=' + typ + '&cid=' + cid + '&xsl=' + xsl);
    xmlHttp = ExecuteCall('http://' + location.host + location.pathname + '?typ=' + typ + '&cid=' +cid+ '&xsl=' + xsl, CallbackMethod);
}
//  function currently called from an xsl file which dynamically builds onmouseover functionality with CMS content
function ChangePic(imgurl,imgalt,TargetElement, anchor) 
{ 
    newpic='<img src="'+imgurl+'" alt="'+imgalt+'" title="'+imgalt+'"/>';
    document.getElementById(TargetElement).innerHTML = newpic;   
}

function GetBuilding(direction,TargetElement, anchor)
{
    var pos = '';
    try
    {
        cid = document.getElementById('ctl00_ContentBody_buildingIdForIndex').value;
        cindex = findArrayIndex(cid);
        if(direction == 'next')
        {
            if(cindex == cidlist.length-1)
            {
                pos="last";
            }
            else
            {
                cindex++;
                document.getElementById('ctl00_ContentBody_buildingIdForIndex').value = cidlist[cindex];
                if(cindex == cidlist.length-1)
                {
                    pos="last";
                }
            }
        }
        if(direction == 'prev')
        {
            if(cindex == 0)
            {
                pos = "first";
            }
            else
            {        
                cindex--;
                document.getElementById('ctl00_ContentBody_buildingIdForIndex').value = cidlist[cindex];
                if(cindex == 0)
                {
                    pos = "first";
                }
            }
        }
    }
    catch(e)
    {
        alert (e.message);
    }
    
    xmlHttp = '';
    divTargetElement = TargetElement;
    //alert(location.pathname);
   // alert('http://' + location.host + location.pathname + '?cid=' + cidlist[cindex] + '&pos=' + pos);
    xmlHttp = ExecuteCall('http://' + location.host + location.pathname + '?cid=' + cidlist[cindex] + '&pos=' + pos, CallbackMethod);
    
 
}

function findArrayIndex(buildingId)
{ 
    var index = 0;
    for ( i=0; i < cidlist.length; i++ ){
        if(cidlist[i] == buildingId)
        {
            index = i;
        }
    }
    return index;
}

function GetTourItem(direction, anchor) {
    var pos = '';
    try {
        cid = document.getElementById('ctl00_ContentBody_buildingIdForIndex').value;
        cindex = findArrayIndex(cid);
        if (direction == 'next') {
            if (cindex == cidlist.length - 1) {
                pos = "last";
            }
            else {
                cindex++;
                document.getElementById('ctl00_ContentBody_buildingIdForIndex').value = cidlist[cindex];
                if (cindex == cidlist.length - 1) {
                    pos = "last";
                }
            }
        }
        if (direction == 'prev') {
            if (cindex == 0) {
                pos = "first";
            }
            else {
                cindex--;
                document.getElementById('ctl00_ContentBody_buildingIdForIndex').value = cidlist[cindex];
                if (cindex == 0) {
                    pos = "first";
                }
            }
        }
    }
    catch (e) {
        alert(e.message);
    }

    
    if (pos=='')
    {
        window.location = 'http://' + location.host + location.pathname + '?id=' + cidlist[cindex];        
    }
    else 
    {
        window.location = 'http://' + location.host + location.pathname + '?id=' + cidlist[cindex] + '&pos=' + pos;
    }

}