var edit_mode = "3";
var treecolor = "FFFFFFFF";
var dirty = false;
var site_nav_index = {'a':[1],'aa':[1,2],'ah':[1,3],'fh':[1,4],'c':[5],'ca':[5,6],'cb':[5,7],'cc':[5,8],'cd':[5,9],'cf':[5,9,10],'cg':[5,9,11],'ch':[5,9,12],'ce':[5,9,13],'d':[14],'ac':[14,15],'ad':[14,15,16],'ae':[14,15,17],'ag':[14,15,18],'da':[14,19],'f':[14,19,20],'dh':[14,21],'fb':[14,21,22],'db':[14,23],'fd':[14,23,24],'dc':[14,25],'ff':[14,25,26],'dd':[14,27],'ab':[14,27,28],'de':[14,29],'hd':[14,29,30],'df':[14,31],'he':[14,31,32],'dg':[14,33],'bc':[14,33,34],'e':[35],'ea':[35,36],'eb':[35,37],'gc':[35,38],'ed':[35,39],'ee':[35,40],'ef':[35,41],'bd':[35,42],'eh':[35,43],'be':[35,44],'bf':[35,45],'eg':[35,46],'bg':[35,47],'g':[48],'ga':[48,49],'gf':[48,50],'hf':[48,51],'hg':[48,52],'gg':[48,53],'gh':[48,54],'ge':[55],'h':[55,56],'hb':[55,57],'hc':[55,58],'b':[59],'ba':[59,60],'bb':[59,61],'hh':[59,62]};
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,'',''],['ah','Hi from the pupils','Hi from the pupils',3,1,'',''],['fh','Contact us','Contact us',4,1,'',''],],['c','Our School','Our School',5,1,'',''],[['ca','Our Values','Our Values',6,1,'',''],['cb','Location','Location',7,1,'',''],['cc','Catchment area','Catchment area',8,1,'',''],['cd','Our Staff','Our Staff',9,1,'',''],[['cf','Nursery to P3','Nursery to P3',10,1,'',''],['cg','P4 to P7','P4 to P7',11,1,'',''],['ch','Whole school support','Whole school support',12,1,'',''],['ce','Staff list','Staff list',13,1,'',''],]],['d','Our Classes','Our Classes',14,1,'',''],[['ac','Nursery','Our Nursery',15,1,'',''],[['ad','Green Room','Green Room',16,1,'',''],['ae','Blue Room','Blue Room',17,1,'',''],['ag','Outdoors','Outdoors',18,1,'',''],],['da','Primary 1','Welcome to Primary 1',19,1,'',''],[['f','Our Classroom','Our Primary 1 Classroom',20,1,'',''],],['dh','Primary 2/1','Welcome to Primary 2/1',21,1,'',''],[['fb','Our Classroom','Our Primary 1/2 Classroom',22,1,'',''],],['db','Primary 3/2','Welcome to Primary 3/2',23,1,'',''],[['fd','Our Classroom','Our Primary 2 Classroom',24,1,'',''],],['dc','Primary 3','Welcome to Primary 3',25,1,'',''],[['ff','Our Classroom','Our Primary 3 Classroom',26,1,'',''],],['dd','Primary 4','Welcome to Primary 4',27,1,'',''],[['ab','Our Classroom','Our Primary 4 Classroom',28,1,'',''],],['de','Primary 5','Primary 5',29,1,'',''],[['hd','Our Classroom','Our Primary 5 Classroom',30,1,'',''],],['df','Primary 6','Primary 6',31,1,'',''],[['he','Our Classroom','Our Primary 6 Classroom',32,1,'',''],],['dg','Primary 7','Primary 7',33,1,'',''],[['bc','Our Classroom','Our Primary 7 Classroom',34,1,'',''],]],['e','Pupil Zone','e',35,1,'',''],[['ea','Houses and Captains','Houses and Captains',36,1,'',''],['eb','Pupil Council','School Pupil Council',37,1,'',''],['gc','Eco Schools','gc',38,1,'',''],['ed','Buddies','Buddies',39,1,'',''],['ee','Health Group','Health Group',40,1,'',''],['ef','JRSO','Junior Road Safety Officers',41,1,'',''],['bd','Cycling Proficiency','Cycling Proficiency',42,1,'',''],['eh','After-School Clubs','After-School Clubs',43,1,'',''],['be','Assemblies','Assemblies',44,1,'',''],['bf','Playground Games','Playground Games',45,1,'',''],['eg','Junior Achievement','Junior Achievement',46,1,'',''],['bg','Enterprise Activities','Enterprise Activities',47,1,'',''],],['g','Parent Zone','Parent Zone',48,1,'',''],[['ga','Parents Forum/Council','Parents Forum/Council',49,1,'',''],['gf','Uniform','School Uniform',50,1,'',''],['hf','School Year','School Year',51,1,'',''],['hg','School Hours','School Hours',52,1,'',''],['gg','School Calendar','School Calendar',53,1,'',''],['gh','Newsletters','Recent Newsletters',54,1,'',''],],['ge','Events','Events',55,1,'',''],[['h','Christmas Activities','Christmas Activities',56,1,'',''],['hb','Scottish Day','Scottish Day',57,1,'',''],['hc','Fringe Festival','Fringe Festival',58,1,'',''],],['b','Community','Community',59,1,'',''],[['ba','Police','Police',60,1,'',''],['bb','Health','Health',61,1,'',''],['hh','Slide show for welcome page','Slide show for welcome page',62,0,'',''],]];
	_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';
			}
	}
}

