function closeCategories(type)
{
    var numElements=document.getElementsByTagName('div').length;
    var eIndex, fElement;
    //Enumerate form elements and check required elements are filled in and display message if not
    for(eIndex=0; eIndex < numElements ; eIndex++)
    {
        fElement=document.getElementsByTagName('div')[eIndex];
        if(fElement.id.substring(0,3)==type)
        {
            if (document.getElementById(fElement.id).style.display != "none")
            {  
                Effect.SlideUp(fElement, { duration: 1.0 });
            }
        }
    }
}

function toggleCategory(cat)
{ //Function to open and close a cat
    closeCategories(cat.id.substring(0,3));
    Effect.SlideDown(cat, { duration: 1.0 });
}

function scrollPassInit()
{ 
    //Function to add a GET var to a link recording the scroll position
    var numElements=document.getElementsByTagName('a').length;
    var eIndex, fElement;
    //Enumerate elements and add an onclick event
    for(eIndex=0; eIndex < numElements ; eIndex++)
    {
        fElement=document.getElementsByTagName('a')[eIndex];
        if(fElement.id.substring(0,3)=="cat")
        {
            document.getElementById(fElement.id).onclick=function() {
                if(this.href.indexOf(".html")>(-1))  //We are using mod re-write and the "magic" urls have .html at the end
                {   
                    this.href=this.href+'?s='+posTop();  //Send the get var s with the top scroll position
                } else {
                    this.href=this.href+'&s='+posTop();  //Send the get var s with the top scroll position
                }
            };
        }
    }
}


function zoomIn(element)
{ //This makes the zoom in div visible, and loads the correct image
    // You need to pass the name of the element to be zoomed
    var xOffset, yOffset;
    document.getElementById(element).style.display="block"; //Do this early so we can get the offsetHeight and offsetWidth
    
    if($(element+'pic')!=null)
    { //For a pic zoom we are dealing with an image
        var temp=new Image();
        temp.src=$(element+'pic').src;  //Fixes an IE bug.  IE can't find the image width from an image directly, only if declared as an image object
        yOffset=Math.round(posTop()+((pageHeight()-temp.height)/2));
        xOffset=Math.round(posLeft()+((996-temp.width)/2));
    } else {  //Just a box of text
        yOffset=Math.round(posTop()+((pageHeight()-parseInt($(element).offsetHeight))/2));
        xOffset=Math.round(posLeft()+((pageWidth()-parseInt($(element).offsetWidth))/2));
    }
    //xOffset=Math.round(posLeft()+((pageWidth()-temp.width)/2));
    document.getElementById(element).style.top=yOffset+10+"px";
    document.getElementById(element).style.left=xOffset+"px";
    //document.getElementById("zoompic").src="./theme/indicator.gif";
    //document.getElementById("zoompic").src=thePic.replace(/_medium/,"");
} 
