/* [nodename, id, name, navigationtext, href, isnavigation, childs[], templatename] */

if (typeof(decodeURIComponent) == 'undefined') {
  decodeURIComponent = function(s) {
    return unescape(s);
  }
}

function jdecode(s) {
    s = s.replace(/\+/g, "%20")
    return decodeURIComponent(s);
}

var POS_NODENAME=0;
var POS_ID=1;
var POS_NAME=2;
var POS_NAVIGATIONTEXT=3;
var POS_HREF=4;
var POS_ISNAVIGATION=5;
var POS_CHILDS=6;
var POS_TEMPLATENAME=7;
var POS_TARGET=8;
var theSitetree=[ 
	['PAGE','1312',jdecode('Home+-+The+Twin+Codicils'),jdecode(''),'/1312.html','true',[],'',''],
	['PAGE','1333',jdecode('The+Codicil+Coetus'),jdecode(''),'/1333.html','true',[],'',''],
	['PAGE','22601',jdecode('The+Translation+of+Uses'),jdecode(''),'/22601.html','true',[],'',''],
	['PAGE','30201',jdecode('Mythoplasm+ex+Somnus'),jdecode(''),'/30201.html','true',[],'',''],
	['PAGE','23201',jdecode('The+Diaries+and+Journals'),jdecode(''),'/23201.html','true',[],'',''],
	['PAGE','1407',jdecode('Contact'),jdecode(''),'/1407.html','true',[],'',''],
	['PAGE','26901',jdecode('Guestbook'),jdecode(''),'/26901.html','true',[],'','']];
var siteelementCount=7;
theSitetree.topTemplateName='Rivet';
theSitetree.paletteFamily='33405B';
theSitetree.keyvisualId='-1';
theSitetree.keyvisualName='keyv.jpg';
theSitetree.fontsetId='17272';
theSitetree.graphicsetId='12686';
theSitetree.contentColor='D3A62A';
theSitetree.contentBGColor='363B49';
var localeDef={
  language: 'en',
  country: 'GB'
};
var theTemplate={
				hasFlashNavigation: 'false',
				hasFlashLogo: 	'false',
				hasFlashCompanyname: 'false',
				hasFlashElements: 'false',
				hasCompanyname: 'false',
				name: 			'Rivet',
				paletteFamily: 	'33405B',
				keyvisualId: 	'-1',
				keyvisualName: 	'keyv.jpg',
				fontsetId: 		'17272',
				graphicsetId: 	'12686',
				contentColor: 	'D3A62A',
				contentBGColor: '363B49',
				a_color: 		'000000',
				b_color: 		'000000',
				c_color: 		'000000',
				d_color: 		'000000',
				e_color: 		'000000',
				f_color: 		'000000',
				hasCustomLogo: 	'true',
				contentFontFace:'Arial, Helvetica, sans-serif',
				contentFontSize:'12',
				useFavicon:     'false'
			  };
var webappMappings = {};
webappMappings['7002']=webappMappings['7002-446']={
webappId:    '7002',
documentId:  '26901',
internalId:  '446',
customField: 'language:en;country:GB;'
};
webappMappings['7008']=webappMappings['7008-1099']={
webappId:    '7008',
documentId:  '1407',
internalId:  '1099',
customField: 'language:en;country:GB;'
};
webappMappings['5000']=webappMappings['5000-']={
webappId:    '5000',
documentId:  '1312',
internalId:  '',
customField: '20100404-140048'
};
webappMappings['5000']=webappMappings['5000-']={
webappId:    '5000',
documentId:  '1333',
internalId:  '',
customField: '20100402-170222'
};
webappMappings['5000']=webappMappings['5000-']={
webappId:    '5000',
documentId:  '30201',
internalId:  '',
customField: '20100428-124026'
};
webappMappings['5000']=webappMappings['5000-']={
webappId:    '5000',
documentId:  '26901',
internalId:  '',
customField: '20100404-135831'
};
webappMappings['5000']=webappMappings['5000-']={
webappId:    '5000',
documentId:  '1407',
internalId:  '',
customField: '20100402-160159'
};
webappMappings['1006']=webappMappings['1006-1006']={
webappId:    '1006',
documentId:  '1312',
internalId:  '1006',
customField: '1006'
};
webappMappings['5000']=webappMappings['5000-']={
webappId:    '5000',
documentId:  '22601',
internalId:  '',
customField: '20100402-170828'
};
webappMappings['5000']=webappMappings['5000-']={
webappId:    '5000',
documentId:  '23201',
internalId:  '',
customField: '20100402-172113'
};
var canonHostname = 'coucm4all01.netbenefit.co.uk';
var accountId     = 'ANBT20IN2U98';
var companyName   = 'Biblionihilistica++%7E++%22Seekest+not+....+lest+ye+find%22';
var htmlTitle	  = 'Biblionihilistica++%7E++Seekest+not+....+lest+ye+find';
var metaKeywords  = 'Necronomicon%2C+Book+of+Eibon%2C+H+P+Lovecraft%2C+Clark+Ashton+Smith%2C+RPG+Prop%2C+Biblionihilistica%2C+Twin+Codicil%2C+Initiate+Tract%2C+Terminate+Tract%2C+LARP%2C+Ancient+Book%2C+Magic+Book%2C+Harry+Potter%3F';
var metaContents  = 'Necronomicon%2C+Book+of+Eibon%2C+now%2C+from+the+vaults+of+The+Sleepwalker+Foundation%2C+that+black+Biblionihilistica%3A+collectors+and+LARP+interest';
theSitetree.getById = function(id, ar) {
	if (typeof(ar) == 'undefined'){
		ar = this;
	}
	for (var i=0; i < ar.length; i++) {
		if (ar[i][POS_ID] == id){
			return ar[i];
		}
		if (ar[i][POS_CHILDS].length > 0) {
			var result=this.getById(id, ar[i][POS_CHILDS]);
			if (result != null){
				return result;
			}
		}
	}
	return null;
};

theSitetree.getParentById = function(id, ar) {
	if (typeof(ar) == 'undefined'){
		ar = this;
	}
	for (var i=0; i < ar.length; i++) {
		for (var j = 0; j < ar[i][POS_CHILDS].length; j++) {
			if (ar[i][POS_CHILDS][j][POS_ID] == id) {
				// child found
				return ar[i];
			}
			var result=this.getParentById(id, ar[i][POS_CHILDS]);
			if (result != null){
				return result;
			}
		}
	}
	return null;
};

theSitetree.getName = function(id) {
	var elem = this.getById(id);
	if (elem != null){
		return elem[POS_NAME];
	}
	return null;
};

theSitetree.getNavigationText = function(id) {
	var elem = this.getById(id);
	if (elem != null){
		return elem[POS_NAVIGATIONTEXT];
	}
	return null;
};

theSitetree.getHREF = function(id) {
	var elem = this.getById(id);
	if (elem != null){
		return elem[POS_HREF];
	}
	return null;
};

theSitetree.getIsNavigation = function(id) {
	var elem = this.getById(id);
	if (elem != null){
		return elem[POS_ISNAVIGATION];
	}
	return null;
};

theSitetree.getTemplateName = function(id, lastTemplateName, ar) {
	if (typeof(lastTemplateName) == 'undefined'){
		lastTemplateName = this.topTemplateName;
	}
	if (typeof(ar) == 'undefined'){
		ar = this;
	}
	for (var i=0; i < ar.length; i++) {
		var actTemplateName = ar[i][POS_TEMPLATENAME];
		if (actTemplateName == ''){
			actTemplateName = lastTemplateName;
		}
		if (ar[i][POS_ID] == id) {
			return actTemplateName;
		}
		if (ar[i][POS_CHILDS].length > 0) {
			var result=this.getTemplateName(id, actTemplateName, ar[i][POS_CHILDS]);
			if (result != null){
				return result;
			}
		}
	}
	return null;
};

theSitetree.getByXx = function(lookup, xx, ar) {
    if (typeof(ar) == 'undefined'){
    	ar = this;
    }
    for (var i=0; i < ar.length; i++) {
        if (ar[i][xx] == lookup){
        	return ar[i];
        }
        if (ar[i][POS_CHILDS].length > 0) {
        	var result=this.getByXx(lookup, xx, ar[i][POS_CHILDS]);
            if (result != null){
                return result;
               }
        }
    }
    return null;
};

function gotoPage(lookup) {
	if(__path_prefix__ == "/servlet/CMServeRES" && typeof (changePage) == 'function'){
		changePage(lookup);
		return;
	}
	var page = theSitetree.getHREF(lookup);
	if (!page) {
		var testFor = [ POS_NAME, POS_NAVIGATIONTEXT ];
		for (var i=0 ; i < testFor.length ; i++) {
			var p = theSitetree.getByXx(lookup, testFor[i]);
			if (p != null) {
				page = p[POS_HREF];
				break;
			}
		}
	}
	document.location.href = (new URL(__path_prefix__ + page, true, true)).toString();
};
