﻿

//global variables=============================================================================
var IE6 = false /*@cc_on || @_jscript_version < 5.7 @*/;
var isMSIE = /*@cc_on!@*/false;

//=============================================================================================

/*===========================================================
Accordian List by John Bonfardeci - studiogio.com

Credits: Built upon the Prototype library and Script.aculo.us effects

Written:05-08-2008

Copyright 2008
===========================================================*/

var AccordianList = Class.create();

AccordianList.prototype = {
    
    //initialize anchor onmouseover events and image stack
    initialize: function(list) {

    var stack = [];
    var anchors = $(list).getElementsByTagName('a');
    
    for(var i=0; i < anchors.length; i++)
    {
        var anchorUri = anchors[i].getAttribute('href');

        if(anchorUri.split('#').length > 1)
        {
            var anchor = anchors[i];
            var targetID = anchor.getAttribute('href').split('#')[1];
            var targetElement = document.getElementById(targetID);
            //targetElement.style.display = "none";

            //for screen refresh and/or for bookmarking a page with anchor link in uri
            if(window.location.href.split('#')[1] == targetElement.getAttribute('id'))
            {targetElement.style.display = ""}
            else{targetElement.style.display = "none";}
            
            stack.push(targetElement);  
            anchor.onmousedown = function () {myAccordianList.transition(this, stack); return false;}          
        }    
    }
   
    },
        
	transition: function(anchor, stack) {

	    var activeID = anchor.getAttribute('href').split('#')[1];
	    
        var activeElement = document.getElementById(activeID);
        //var label = document.getElementById('label');    
        var uri = window.location.href.split('#')[0];
	        
        var hasParent = false;//could do so much with parentNode property but IE doesn't support
        if(activeElement.parentNode.getAttribute('title') != null && activeElement.parentNode.getAttribute('title').length != 0)
        {
            hasParent = true;
        }
               
        for(var i=0; i<stack.length;i++)
        {       
            //if not active element and active element is not a child of a div, close all other element in stack
            if(stack[i] != activeElement && hasParent == false)
            {
                stack[i].style.display = 'none';       
            }           
        }
        
        //on opening     
        if(activeElement.style.display == "none"){
            //window.location.href = anchor.getAttribute('href');
            new Effect.Appear(activeElement, {duration:1, from:0, to:1.0});//now apply effect
            //activeElement.focus();
        }
        //on closing
        else{
            activeElement.style.display = "none";
            //window.location.href = uri;
        }

	}
}




