var edit_mode = "3";
var treecolor = "FFFFFFFF";
var dirty = false;
var site_nav_index = {'a':[1],'aa':[1,2],'ab':[1,3],'ac':[1,4],'al':[1,5],'ad':[6],'ae':[6,7],'af':[6,8],'ag':[6,9],'ah':[6,10],'b':[11],'ba':[11,12],'bb':[11,13],'bc':[11,14],'be':[15],'la':[15,16],'bf':[15,16,17],'bi':[15,16,17,18],'bj':[15,16,17,19],'bg':[15,16,20],'cl':[15,16,20,21],'bh':[15,16,22],'ka':[15,16,22,23],'kb':[15,16,24],'ke':[15,16,24,25],'c':[15,16,26],'kd':[15,16,26,27],'ca':[15,16,28],'kg':[15,16,28,29],'cb':[15,16,30],'kj':[15,16,30,31],'cc':[15,16,32],'lk':[15,16,32,33],'lb':[15,34],'cd':[15,34,35],'ld':[15,34,35,36],'ce':[15,34,37],'cf':[15,34,38],'li':[15,34,38,39],'lj':[15,34,38,40],'cg':[15,34,41],'jb':[15,34,41,42],'ch':[15,34,43],'cj':[15,34,43,44],'d':[15,34,45],'da':[15,34,46],'jh':[15,34,46,47],'db':[15,34,48],'jk':[15,34,48,49],'dc':[50],'dd':[50,51],'de':[50,52],'df':[50,53],'dg':[50,54],'dh':[50,55],'e':[50,56],'ea':[50,57],'eb':[50,58],'ec':[50,59],'ed':[50,60],'ee':[50,61],'f':[50,62],'fa':[50,63],'fb':[50,64],'fc':[65],'fd':[65,66],'g':[65,67],'gb':[65,68],'gc':[65,69],'ge':[65,70],'gd':[65,71],'gf':[65,72],'gg':[65,73],'fj':[65,73,74],'fk':[65,73,75],'fl':[65,73,76],'gi':[65,73,77],'gj':[65,73,78],'gk':[65,73,79],'gl':[65,73,80],'gh':[65,81],'h':[65,82],'ha':[65,83],'hc':[65,84],'hd':[65,85],'fi':[65,86],'ff':[65,87],'fg':[65,88],'fh':[65,89],'he':[65,90],'hf':[91],'hh':[91,92],'hi':[91,93],'hl':[91,94],'ij':[91,95],'ik':[91,96],'ek':[91,97],'ei':[91,98],'ej':[91,99],'ie':[100],'i':[101],'ia':[101,102],'ib':[101,103],'ic':[101,104],'id':[101,105]};
var nav_path = site_nav_index[page];

function process_nav()
{
	var nav = [['a','Welcome','a',1,1,'',''],[['aa','Hello from the Head Teacher','Hello from the Head Teacher',2,1,'',''],['ab','Contact us','Contact us',3,1,'',''],['ac','Hello from the Pupils','Hello from the Pupils',4,1,'',''],['al','Breaking News','Breaking News',5,1,'',''],],['ad','Our School','Our School',6,1,'',''],[['ae','Aims & Values','Aims & Values',7,1,'',''],['af','Location','Location',8,1,'',''],['ag','History','History',9,1,'',''],['ah','Catchment Area','Catchment Area',10,1,'',''],],['b','Our Staff','Our Staff',11,1,'',''],[['ba','Nursery','Nursery',12,1,'',''],['bb','Lower','Lower',13,1,'',''],['bc','Upper','Upper',14,1,'',''],],['be','Our Classes','Our Classes',15,1,'',''],[['la','Lower','Welcome to our Lower group of classes!',16,1,'',''],[['bf','Nursery','Nursery',17,1,'',''],[['bi','Our Nursery Classroom','Our Nursery Classroom',18,1,'',''],['bj','Learning Log','Nursery Learning Log',19,1,'',''],],['bg','P1a','Primary 1a',20,1,'',''],[['cl','Learning log','P1a Learning log',21,1,'',''],],['bh','P1b','Primary 1b',22,1,'',''],[['ka','Learning log','P1b Learning log',23,1,'',''],],['kb','P1c','Primary 1c',24,1,'',''],[['ke','Learning Log - P1c','Learning Log',25,1,'',''],],['c','P2a','Primary 2a',26,1,'',''],[['kd','Learning log','P2a Learning log',27,1,'',''],],['ca','P2b','Primary 2b',28,1,'',''],[['kg','Learning log','P2b Learning log',29,1,'',''],],['cb','P3a','Primary 3a',30,1,'',''],[['kj','Learning log','P3a Learning log',31,1,'',''],],['cc','P3b','Primary 3b',32,1,'',''],[['lk','Learning log','P3b Learning log',33,1,'',''],]],['lb','Upper','Welcome to our Upper group of classes!',34,1,'',''],[['cd','P4a','Primary 4a',35,1,'',''],[['ld','Learning log','P4a Learning log',36,1,'',''],],['ce','P4b','Primary 4b',37,1,'',''],['cf','P5a','Primary 5a',38,1,'',''],[['li','Unititled','Unititled',39,0,'',''],['lj','Learning log','P5a Learning log',40,1,'',''],],['cg','P5b','Primary 5b',41,1,'',''],[['jb','Learning log','P5b Learning log',42,1,'',''],],['ch','P6a','Primary 6a',43,1,'',''],[['cj','Learning log','P6a Learning log',44,1,'',''],],['d','P6b','Primary 6b',45,1,'',''],['da','P7a','Primary 7a',46,1,'',''],[['jh','Learning log','P7a Learning log',47,1,'',''],],['db','P7b','Primary 7b',48,1,'',''],[['jk','Learning Log','P7b Learning Log',49,1,'',''],]]],['dc','Pupil Zone','Pupil Zone',50,1,'',''],[['dd','Pupil Council','Pupil Council',51,1,'',''],['de','Eco Schools','Eco Schools',52,1,'',''],['df','JRSO','JRSO',53,1,'',''],['dg','Cycling Proficiency','Cycling Proficiency',54,1,'',''],['dh','Assemblies','Assemblies',55,1,'',''],['e','Houses','Houses',56,1,'',''],['ea','Playground games','Playground games',57,1,'',''],['eb','DtS','DtS',58,1,'',''],['ec','Inclusion Squad','Inclusion Squad',59,1,'',''],['ed','Celebrating Success','Celebrating Success',60,1,'',''],['ee','Extra curricular activites','Extra curricular activites',61,1,'',''],['f','Health Promotion','Health Promotion',62,1,'',''],['fa','Golden Time','Golden Time',63,1,'',''],['fb','Useful website links','Useful website links',64,1,'',''],],['fc','Parent Zone','Parent Zone',65,1,'',''],[['fd','Parent Council','Parent Council',66,1,'',''],['g','Glow','Glow',67,1,'',''],['gb','Handbook','Handbook',68,1,'',''],['gc','Behaviour Management','Behaviour Management',69,1,'',''],['ge','PE Kit','PE Kit',70,1,'',''],['gd','Uniform','Uniform',71,1,'',''],['gf','Opening Times and Holidays','Opening Times and Holidays',72,1,'',''],['gg','Homework','Homework',73,1,'',''],[['fj','P1 Homework','P1 Homework',74,1,'',''],['fk','P2 Homework','P2 Homework',75,1,'',''],['fl','P3 Homework','P3 Homework',76,1,'',''],['gi','P4 Homework','P4 Homework',77,1,'',''],['gj','P5 Homework','P5 Homework',78,1,'',''],['gk','P6 Homework','P6 Homework',79,1,'',''],['gl','P7 Homework','P7 Homework',80,1,'',''],],['gh','School Calendar','School Calendar',81,1,'',''],['h','School Lunch','School Lunch',82,1,'',''],['ha','Parent Helpers','Parent Helpers',83,1,'',''],['hc','Transition','Transition',84,1,'',''],['hd','Our cluster schools','Our cluster schools',85,1,'',''],['fi','Useful website links','Useful website links',86,1,'',''],['ff','Community Group','Community Group',87,1,'',''],['fg','Fundraising Group','Fundraising Group',88,1,'',''],['fh','School Improvement Plan','School Improvement Plan',89,1,'',''],['he','Easyfundraising Website','Easyfundraising Website',90,1,'',''],],['hf','Events','Events',91,1,'',''],[['hh','Sports Day','Sports Day',92,1,'',''],['hi','Enterprise and Money Week','Enterprise and Money Week',93,1,'',''],['hl','Sponsored Bounce','Sponsored Bounce',94,1,'',''],['ij','Scottish Schools Swimming Gala','Scottish Schools Swimming Gala',95,1,'',''],['ik','Comenius Project','Comenius Project',96,1,'',''],['ek','Comenius Visit to Greece','Comenius Visit to Greece',97,1,'',''],['ei','Comenius Visit to Germany','Comenius Visit to Germany',98,1,'',''],['ej','Comenius Partners Visit Troon','Comenius Partners Visit Troon',99,1,'',''],],['ie','Contact the Parent Council','Contact the Parent Council',100,1,'',''],['i','Community','Community',101,1,'',''],[['ia','Road crossing patrol','Road crossing patrol',102,1,'',''],['ib','Minister','Minister',103,1,'',''],['ic','Police','Police',104,1,'',''],['id','Health','Health',105,1,'',''],]];
	_process_nav(nav, 0, '');
}

function _process_nav(nav, level, state)
{
	nav_div = document.getElementById('navblock');
	navigation = write_nav(nav, level, state);
	if (nav_div.hasChildNodes())
	{
		nav_div.removeChild(nav_div.childNodes[0]);
	}
	nav_div.appendChild(navigation);
}


function write_nav(nav, level, state)
{
	var navigation = document.createElement("ul");
	if (nav == 'undefined')
	{
		alert('Deary me, this isn\'t right!');
	}
	if (state == '' && nav_path.length >= (level + 1)) {navigation.style.display = "block";}
	navigation.className ='uln';
	for (var x = 0; x < nav.length; x++)
	{
		var item = nav[x];
		if (item && typeof(item[0]) == 'string')
		{
			if (typeof(nav[x+1]) != 'undefined' && typeof(nav[x+1][0]) != 'string' && typeof(nav[x+1][0]) != 'undefined')
			{
				var citem = write_nav_item(item, level, 'nf', state);
				if (citem != null)
				{
					x++;
					item = nav[x];
					if (nav[x - 1] != 'undefined' && nav[x-1][3] == nav_path[level] && item[4] != 0)
					{
						var child_nav = write_nav(item, level + 1, '');
						citem.appendChild(child_nav);
					}
					else
					{
						if (item[4] != 0)						{
							citem.appendChild(write_nav(item, level + 1, '_x'));
						}
					}
					navigation.appendChild(citem);
				}
			}
			else
			{
				citem = write_nav_item(item, level, 'np', state);
				if (citem != null)
				{
					navigation.appendChild(citem);
				}
			}
		}
	}
	return navigation;
}

function write_nav_item(item, level, navtype, state)
{
	var on_style = "";
	var list_on_style = "";
	var mode = 3;
	
	if (item[1] == '')
	{
		item[1] = 'Untitled';
	}
	if (item[3] == nav_path[level])	{
		on_style = " " + navtype;
		on_style += item[3] == nav_path[level] ? '_on' : '';

		list_on_style = " l" + navtype;
		list_on_style += item[3] == nav_path[level] ? '_on' : '';
	}
	else	{
		list_on_style = " l" + navtype;
		list_on_style += '_off';
	}
	if (item[4] == 0 && mode == 3)
	{
		on_style = '_hidden';
		list_on_style = '_hidden';
	}

	if (item[4] == 0 && mode == 3)
	{
		return null;
	}

	var nav_item = document.createElement("li");
	nav_item.setAttribute('id', "_" + item);
	//nav_item.setAttribute('class', "l" + navtype + list_on_style);
	nav_item.className = "l" + navtype + list_on_style;
	//if (level > 0 || navtype == 'np') {nav_item.style.display = "none";}

	div1 = document.createElement("div");
	div1.className = "nbg";

	div2 = document.createElement("div");
	//div2.setAttribute('class', navtype + on_style);
	div2.className = navtype + on_style;

// create disclosure
	if (navtype == 'nf')
	{
		d_b = document.createElement("a");
		d_b.setAttribute('name', '');
		d_b.setAttribute('onclick', 'disclose(this);');
		d_b.className="d_i";	// disclosure icon

		d_a = document.createElement("img");
		d_a.setAttribute('src', 'http://www.take2theweb.com/images/FIG.GIF');
		d_a.setAttribute('onclick', 'disclose(event);');
		d_a.onclick = disclose;
		d_a.setAttribute('height', '16');
		d_a.setAttribute('width', '16');
		d_a.className = 'nfi';
		//d_b.appendChild(d_a);
		div2.appendChild(d_a);
	}
	
//
	
	d_a = document.createElement("a");
	d_a.className = 'n_l';		// navigation link
	if (item[6] != undefined && item[6] != '')	{
		d_a.setAttribute('href', item[6]);
		d_a.setAttribute('target', '_top');
	}
	else
	{
		d_a.setAttribute('href', item[0] + '.html');
	}
	d_a.setAttribute('title', item[2]);
	d_a.setAttribute('alt', "This is a disclosure item");
	if (item[5] != '') {d_a.setAttribute('accesskey', item[5]);}
	
	d_a_txt = document.createTextNode(item[1]);
	
	d_a.appendChild(d_a_txt);
	div2.appendChild(d_a);
	div1.appendChild(div2);
	nav_item.appendChild(div1);
	return nav_item;
}

function disclose(e)
{
	if (!e) var e = window.event;
	e = e.target || e.srcElement;
	p = e.parentNode.parentNode.parentNode.lastChild;
	var state = p.style.display;
	switch(state)
	{
		case '':
		case null:
		case 'none':
			p.style.display='block';
			{
				e.className ='nfi_on';
			}
			break;
		default:
			p.style.display='none';
			{
				e.className ='nfi';
			}
	}
}

