function init(swfApps) {

	KapIT.HashManager.prototype._encode = function (h) {
		if(!h)
			return;
		buffer = KapIT.parseJSONString(h);
		chunks = new Array();
		encodeCtxSec(chunks, buffer['ctx'], buffer['sec']);
		encodeArt(chunks, buffer['ti']);
		return '/'+ chunks.join('/');
	}

	KapIT.HashManager.prototype._decode = function (h) {
		if(!h)
			return;
		buffer = h.split('/');
		chunks = new Array();
		for (i=buffer.length ; i-->0 ;)
			buffer[i] = decodeURIComponent(buffer[i]);
		while (5 > buffer.length)
			buffer[buffer.length] = "";
		if (! decodeCtx(chunks, buffer[1])) {
			chunks[chunks.length] = 'ctx:"null",sec:"null"';
			if (! decodeArt(chunks, buffer[1], buffer[2])) {
				chunks[chunks.length] = 'ti:"null"';
			}
		} else if (! decodeSec(chunks, buffer[1], buffer[2])) {
			chunks[chunks.length] = 'sec:"null"';
			if (! decodeArt(chunks, buffer[2], buffer[3])) {
				chunks[chunks.length] = 'ti:"null"';
			}
		} else {
			if (! decodeArt(chunks, buffer[3], buffer[4])) {
				chunks[chunks.length] = 'ti:"null"';
			}
		}
		return '{'+ chunks.join(',') +'}' ;
	}

	KapIT._propertybox = new KapIT.PropertyBox([
		{name: "ctx", value: 'null', instate: true},
		{name: "sec", value: 'null', instate: true},
		{name: "ti", value: 'null', instate: true}
		], false, false);

	KapIT._propertybox.addListener("ctx",document,onAppChange);
	KapIT._propertybox.addListener("sec",document,onAppChange);
	KapIT._propertybox.addListener("ti",document,onAppChange);

	for(var i = 0;i<swfApps.length;i++) {
		new KapIT.SWFWrapper(swfApps[i].file , swfApps[i].path , swfApps[i].divid, swfApps[i].width, swfApps[i].height, swfApps[i].vars, swfApps[i].version, swfApps[i].xpiurl);
	}
	onAppChange();
}


function onAppChange() {
	removeChildrenFrom("bc_1");
	removeChildrenFrom("separator1");
	removeChildrenFrom("separator2");
	removeChildrenFrom("bc_2");

	var el = document.getElementById("maintab");
	var sctList = null;
	var sections = null;
	if ( el.hasChildNodes() ) {
		var children = el.childNodes;
		for (var i=children.length ; i-->0 ; ) {
			children[i].className = "";
			sctList = document.getElementById( (i+1) +"0" );
			sctList.className = "";
			if ( sctList.hasChildNodes() ) {
				sections = sctList.childNodes;
				for (var j=sections.length ; j-->0 ; ) {
					sections[j].className = "";
				}
			}
		}
	}

	var objState = KapIT._propertybox.getCurrentState();
	var strCtx = objState.ctx.toString();
	var strSct = objState.sec.toString();
	var objNode = null;
	if (("null" == strCtx) || (0 == strCtx.length)){
		// pass
	} else if ("0" == strCtx) {
		writeCookie("KAPIT-application-state", "");
	} else {
		document.getElementById(strCtx).className = "selected";
		document.getElementById(strCtx +"0").className = "selected";

		/*
		objNode = document.createTextNode(" > ");
		document.getElementById("separator1").appendChild(objNode);
		changeLink("bc_1","changeLevel('"+ strCtx +"');",myBreadcrumb[strCtx]);
		if (("5" == strCtx) || ("null" == strSct) || (0 == strSct.length)) {
			// pass
		} else {
			document.getElementById(strSct).className = "sub_show";
			objNode = document.createTextNode(" > ");
			document.getElementById("separator2").appendChild(objNode);
			changeLink("bc_2","changeSubject('"+ strSct +"');",myBreadcrumb[strSct]);
		}
*/
		var monimage= document.createElement('img')
		monimage.src="images/separator.gif"
		document.getElementById("separator1").appendChild(monimage);
		changeLink("bc_1","changeLevel('"+ strCtx +"');",myBreadcrumb[strCtx]);
		if (("null" == strSct) || (0 == strSct.length)) {
			// pass
		} else {
			document.getElementById(strSct).className = "sub_show";
			monimage= document.createElement('img')
			monimage.src="images/separator.gif"
			document.getElementById("separator2").appendChild(monimage);
			changeLink("bc_2","changeSubject('"+ strSct +"');",myBreadcrumb[strSct]);
		}
	}
}

function removeChildrenFrom(elId) {
	var el = document.getElementById(elId);
	if ( el.hasChildNodes() ) {
		var children = el.childNodes;
		for (var i=children.length ; i-->0 ; ) {
			el.removeChild( children[i] );
		}
	}
}

function changeLink(a_id,action,strText) {
	el = document.getElementById(a_id);
	nEl = el.cloneNode(false);
	el.parentNode.insertBefore(nEl,el);
	el.parentNode.removeChild(el);
	nEl.appendChild(document.createTextNode(strText));
	var strAction = action;
	nEl.onclick = function(){
		return eval(strAction);
	};
}

function writeCookie(name, value) {
	var argv=writeCookie.arguments;
	var argc=writeCookie.arguments.length;
	var expires=(argc > 2) ? argv[2] : null;
	var path=(argc > 3) ? argv[3] : null;
	var domain=(argc > 4) ? argv[4] : null;
	var secure=(argc > 5) ? argv[5] : false;
	document.cookie=name+"="+escape(value)+
	((expires==null) ? "" : ("; expires="+expires.toGMTString()))+
	((path==null) ? "" : ("; path="+path))+
	((domain==null) ? "" : ("; domain="+domain))+
	((secure==true) ? "; secure" : "");
}

function changeLevel(value) {
	KapIT._propertybox.changeState("ctx",value);
	//KapIT._propertybox.changeState("sec","null");
	return false;
}
function changeSubject(value) {
	KapIT._propertybox.changeState("sec",value);
	return false;
}
