﻿
/* *****************************

expandable items

***************************** */


// ===== startup ===============

if (ei_OkBrowser()) {
var expandableItemsMap = new Array();
// add the onload event
// window.onload = ei_startExpandable();    // in 3edit.js
// hide the items
document.write ('<style>.expandableItem .content { display:none; }</style>');
}



// ===== functions ===============

function ei_startExpandable() {
ei_adjustExpandableItems()
}


function ei_adjustExpandableItems() {
// apply the magic

// get all divs in document
var x = document.getElementsByTagName("div");


// .. and look for ones with a certain class
for (var i=0; i<x.length; i++) {
if (x[i].className.indexOf("expandableItem")>-1) {
// add them to the map

ei_mapAdd(x[i]);
}
}

// check if the map has elements
if (expandableItemsMap.length>0) {

// do the links and things for each pair
for (i=0; i<expandableItemsMap.length; i++) {
ei_doToggleLink(i);
}

// get the whole parent div (this could be better)
// and attach the expand-all, collapse-all links to it.
var parent = expandableItemsMap[0]["title"].parentNode.parentNode;
parent.innerHTML = '<p class="EIMapNav"><a href="javascript:ei_expandEIMap();">expand all</a> | <a href="javascript:ei_collapseEIMap();">collapse all</a></p> ' + parent.innerHTML ;

}
}


function ei_expandEIMap() {
// expand the whole map
for (i=0; i<expandableItemsMap.length; i++) {
ei_expand(expandableItemsMap[i]["content"].id);
}
}


function ei_collapseEIMap() {
// collapse the whole map
for (i=0; i<expandableItemsMap.length; i++) {
ei_collapse(expandableItemsMap[i]["content"].id);
}
}


function ei_doToggleLink(i) {
// attach the toggle href, since it's pure javascript,
// on js-disabled-browsers this will not have any effect, but won't be attached either.

var hrefs = expandableItemsMap[i]["title"].getElementsByTagName("a");
var a = hrefs[0];
var id = ei_formatId(i);
expandableItemsMap[i]["content"].id = id;
a.href = "javascript:ei_toggle('"+id+"')";
}

function ei_formatId(i) {
return ( "_ei_" + i);
}


function ei_mapAdd(x) {
// add an expandable item x to the map

// init vars
var _title, _content, _expandableItem = new Array(2);
var foundTitle = false, foundContent = false;
var idx;

// get all spans in the element
var y = x.getElementsByTagName("span");

for (var i=0; i<y.length; i++) {

if (y[i].className.indexOf("title")>-1) { _title = y[i]; foundTitle = true;}
if (y[i].className.indexOf("content")>-1) { _content = y[i]; foundContent = true }

if (foundTitle && foundContent) {
// make these two an array and push them in
_expandableItem["title"] = _title;
_expandableItem["content"] = _content;
expandableItemsMap.push(_expandableItem);     // add the pair to the map

// _content.className = "content_off";                   // not essential, make sure the _content element is collapsed

// initialise the found/pair anew
foundTitle = foundContent = false;
_expandableItem = new Array(2);
} // end if foundtitle..
} // end for
} // end function



function ei_toggle(what)  {                                // expand/collapse an element
var b = document.getElementById (what);
var a = b.style.display;
if (a=="inline")
{ b.style.display = "none"; }
else
{ b.style.display = "inline"; }
}

function ei_checkVisible(what) {                        // check if an element is collapsed
var b = document.getElementById (what);
var a = b.style.display;
if (a=="none") return (false);
else return (true);
}



function ei_expand(id) {                                  // expand an element
var b = document.getElementById(id);
if (b) b.style.display = "inline";
}

function ei_collapse(id) {                                 // collapse an element
var b = document.getElementById(id);
if (b) b.style.display = "none";
}


function ei_OkBrowser() {
// check browser // no support for ie < 5.5, ok for safari, firefox  // this list may grow with time		// g m
// set variables
var ua = navigator.userAgent, uaName = navigator.appName, uaVer = navigator.appVersion;

var result =
!(
((uaName == "Microsoft Internet Explorer") && (ei_getIeVersion() < "5.5"))
/*
||  (ua.indexOf('Netscape6') > -1)
||  ((ua.indexOf('Macintosh')> -1))
||  ((ua.indexOf('MSIE')>-1) && (ua.indexOf('Mac')>-1))		              // ie on mac
||  ((ua.indexOf('MSIE')>-1) && (ua.indexOf('OS X')>-1))		              // ie on osx
*/
);
return (result);
}



function ei_getIeVersion() {
// fiddle with the useragent string, to find the IE version

var detect = navigator.userAgent.toLowerCase();
var lookfor = 'msie';
var place = detect.indexOf(lookfor) + 1;
if ( place > 0)  {
var version = detect.substr(place + lookfor.length,3);
return (version);
} // auto-else
return (false);
}

