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],'ad':[1,5],'ae':[1,6],'af':[1,7],'ag':[1,8],'ah':[1,9],'ai':[1,10],'aj':[1,11],'ak':[1,12],'al':[1,13],'b':[14],'ba':[14,15],'bb':[14,16],'bc':[14,17],'bd':[14,18],'be':[14,19],'bf':[14,20],'bg':[14,21],'bh':[14,22],'bi':[14,23],'bj':[14,24],'bk':[14,25],'bl':[14,26],'c':[27],'ca':[27,28],'d':[29],'db':[29,30],'e':[31],'f':[32],'g':[33],'gc':[33,34],'gg':[33,35],'h':[36],'j':[37],'k':[38],'kl':[38,39],'l':[40],'la':[40,41],'lb':[40,42],'ld':[40,43]};
var nav_path = site_nav_index[page];

function process_nav()
{
	var nav = [['a','Welcome to Gallowhill','GALLOWHILL PRIMARY SCHOOL',1,1,'',''],[['aa','School Information','School Information',2,1,'',''],['ab','Where to come','Map',3,1,'',''],['ac','School Day','School Day',4,1,'',''],['ad','School Newsletter','School Newsletter',5,1,'',''],['ae','Our school in action','Our school in action',6,1,'',''],['af','Holidays','Renfrewshire School Holidays - 2009 - 2010',7,1,'',''],['ag','Parent Council','Parent Council',8,1,'',''],['ah','Homework','Homework - a partnership with parents',9,1,'',''],['ai','What is the Pupil Council?','What is the Pupil Council?',10,1,'',''],['aj','Behaviour Policy','What We Expect of Gallowhill Pupils',11,1,'',''],['ak','School House System','House System',12,1,'',''],['al','Gallowhill Nursery','Nursery Unit',13,1,'',''],],['b','What\'s Happening?','What\'s Happening?',14,1,'',''],[['ba','A Health Promoting School','A Healthy School',15,1,'',''],['bb','Are you an Eco-warrior?','Are you up for the challenge?',16,1,'',''],['bc','Walk to School Week','Walk to School Week',17,1,'',''],['bd','An Interview with John- The Chair Man','John- The Chair Man',18,1,'',''],['be','Kickstart Vandalism?','Kickstart Vandalism?',19,1,'',''],['bf','Health Week','bf',20,1,'',''],['bg','Remember Remember','Remember Remember',21,1,'',''],['bh','Art Exhibition','Art Exhibition',22,1,'',''],['bi','Nativity Play','Nativity Play - It\'s a party!',23,1,'',''],['bj','Art Exhibition Photos','Art Exhibition Photos',24,1,'',''],['bk','Enterprise Week 2008','Enterprise Week 2008',25,1,'',''],['bl','Fund-raising Charity Events','Fund-raising Charity Events',26,1,'',''],],['c','School Clubs','Interesting and Fun Clubs at Gallowhill!',27,1,'',''],[['ca','Breakfast Club','Breakfast Club',28,1,'',''],],['d','Primary 1 - Mrs McLeod','Welcome to Primary 1',29,1,'',''],[['db','Autumn Walk','Autumn Walk',30,1,'',''],],['e','Primary 2/1 - Mrs Bell','Welcome to Primary 2/1',31,1,'',''],['f','Primary 3/2 - Miss Moffat','Welcome to Primary 3/2',32,1,'',''],['g','Primary 4/3 - Mrs Molloy','Welcome to Primary 4/3',33,1,'',''],[['gc','Puppet Show','Puppet Show',34,1,'',''],['gg','Our Topics','Our Topics',35,0,'',''],],['h','Primary5/4- Miss Grey & Mrs Reid','Welcome to P5/4',36,1,'',''],['j','Primary 6 - Mrs Morgan/Mrs Simpson','Welcome to Primary 6',37,1,'',''],['k','Primary 7 - Miss Webster','Welcome to P7',38,1,'',''],[['kl','Term 3 Events','Term 3 Events',39,1,'',''],],['l','Links for pupils and parents!','Links for pupils and parents!',40,1,'',''],[['la','\'Help with Homework\' websites','Help with Homework',41,1,'',''],['lb','Fun websites for primary children','Fun websites for primary children',42,1,'',''],['ld','Health links','Health websites',43,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';
			}
	}
}

