function SDSitemap(id) {
	if (!document.getElementById || !document.getElementsByTagName)
		return false;	
	if ((id=='undefined')||(id=='')) {id='my_sitemap';}
	this.id = id;
	if (document.getElementById(this.id)!=null) {
	this.sitemap = document.getElementById(this.id);
	this.subsitemaps = this.sitemap.getElementsByTagName("div");
	this.remember = true;
	this.speed = 2;
	this.markCurrent = true;
	this.oneSmOnly = false;}
}
SDSitemap.prototype.init = function() {
	if (document.getElementById(this.id)!=null) {
	var mainInstance = this;
	for (var i = 0; i < this.subsitemaps.length; i++)
		if (this.subsitemaps[i].getElementsByTagName("span")[0] != undefined ) 
		this.subsitemaps[i].getElementsByTagName("span")[0].onclick = function() {
			mainInstance.toggleSitemap(this.parentNode);
		};
	if (this.markCurrent) {
		var links = this.sitemap.getElementsByTagName("a");
		for (var i = 0; i < links.length; i++)
			if (links[i].href == document.location.href) {
				links[i].className = "current";
				break;
			}
	}
	if (this.remember) {
		var regex = new RegExp("sdsitemap_" + encodeURIComponent(this.sitemap.id) + "=([01]+)");
		var match = regex.exec(document.cookie);
		if (match) {
			var states = match[1].split("");
			for (var i = 0; i < states.length; i++)
				this.subsitemaps[i].className = (states[i] == 0 ? "collapsed" : "");
		}
	}
}};
SDSitemap.prototype.toggleSitemap = function(subsitemap) {
	if (subsitemap.className == "collapsed")
		this.expandSitemap(subsitemap);
		//subsitemap.className = ""
	else
		//subsitemap.className= "collapsed"
		this.collapseSitemap(subsitemap);
};
SDSitemap.prototype.expandSitemap = function(subsitemap) {
	var fullHeight = subsitemap.getElementsByTagName("span")[0].offsetHeight;
	var links = subsitemap.getElementsByTagName("a");
	for (var i = 0; i < links.length; i++)
		fullHeight += links[i].offsetHeight;
	var moveBy = Math.round(this.speed * links.length);
	
	var mainInstance = this;
	var intId = setInterval(function() {
		var curHeight = subsitemap.offsetHeight;
		var newHeight = curHeight + moveBy;
		if (newHeight < fullHeight)
			subsitemap.style.height = newHeight + "px";
		else {
			clearInterval(intId);
			subsitemap.style.height = "";
			subsitemap.className = "";
			mainInstance.memorize();
		}
	}, 30);
	this.collapseOthers(subsitemap);
};
SDSitemap.prototype.collapseSitemap = function(subsitemap) {
	var minHeight = subsitemap.getElementsByTagName("span")[0].offsetHeight;
	var moveBy = Math.round(this.speed * subsitemap.getElementsByTagName("a").length);
	var mainInstance = this;
	var intId = setInterval(function() {
		var curHeight = subsitemap.offsetHeight;
		var newHeight = curHeight - moveBy;
		if (newHeight > minHeight)
			subsitemap.style.height = newHeight + "px";
		else {
			clearInterval(intId);
			subsitemap.style.height = "";
			subsitemap.className = "collapsed";
			mainInstance.memorize();
		}
	}, 30);
};
SDSitemap.prototype.collapseOthers = function(subsitemap) {
	if (this.oneSmOnly) {
		for (var i = 0; i < this.subsitemaps.length; i++)
			if (this.subsitemaps[i] != subsitemap && this.subsitemaps[i].className != "collapsed")
				this.collapseSitemap(this.subsitemaps[i]);
	}
};
SDSitemap.prototype.expandAll = function() {
	var oldOneSmOnly = this.oneSmOnly;
	this.oneSmOnly = false;
	for (var i = 0; i < this.subsitemaps.length; i++)
		if (this.subsitemaps[i].className == "collapsed")
			this.expandSitemap(this.subsitemaps[i]);
	this.oneSmOnly = oldOneSmOnly;
};
SDSitemap.prototype.collapseAll = function() {
	for (var i = 0; i < this.subsitemaps.length; i++)
		if (this.subsitemaps[i].className != "collapsed")
			this.collapseSitemap(this.subsitemaps[i]);
};
SDSitemap.prototype.memorize = function() {
	if (this.remember) {
		var states = new Array();
		for (var i = 0; i < this.subsitemaps.length; i++)
			states.push(this.subsitemaps[i].className == "collapsed" ? 0 : 1);
		var d = new Date();
		d.setTime(d.getTime() + (30 * 24 * 60 * 60 * 1000));
		document.cookie = "sdsitemap_" + encodeURIComponent(this.sitemap.id) + "=" + states.join("") + "; expires=" + d.toGMTString() + ";";
	}
};

SDSitemap.prototype.collapseSitemap = function(subsitemap) {
	var minHeight = subsitemap.getElementsByTagName("span")[0].offsetHeight;
	var moveBy = Math.round(this.speed * subsitemap.getElementsByTagName("a").length);
	var mainInstance = this;
	var intId = setInterval(function() {
		var curHeight = subsitemap.offsetHeight;
		var newHeight = curHeight - moveBy;
		if (newHeight > minHeight)
			subsitemap.style.height = newHeight + "px";
		else {
			clearInterval(intId);
			subsitemap.style.height = "";
			subsitemap.className = "collapsed";
			mainInstance.memorize();
		}
	}, 30);
};
SDSitemap.prototype.collapseOthers = function(subsitemap) {
	if (this.oneSmOnly) {
		for (var i = 0; i < this.subsitemaps.length; i++)
			if (this.subsitemaps[i] != subsitemap && this.subsitemaps[i].className != "collapsed")
				this.collapseSitemap(this.subsitemaps[i]);
	}
};

function addHandler(object, event, handler)
{
  if (typeof object.addEventListener != 'undefined')
    object.addEventListener(event, handler, false);
  else if (typeof object.attachEvent != 'undefined')
    object.attachEvent('on' + event, handler);
  else
    throw "Incompatible browser";
}


function windowonload(func) {
	addHandler (window, 'load', func);
}

var mySitemap;

windowonload(function () {mySitemap = new SDSitemap("my_sitemap");mySitemap.init();});





