
// document.getElementById('controlFrame').style.visibility = 'hidden';

function hideInfoWindow()
{
	var infoWindow = new Ext.get('moreWindow');
	stateM = false;
	hideFn(infoWindow, true);
}

function hidePhotoWindow()
{
	var infoWindow = new Ext.get('photoWindow');
	stateP = false;
	hideFn(infoWindow, true);
}

function parkWindows()
{
	
}


	var activeItem = 0;
	var activeItem2 = 'undefined';
	preloadArray = new Array();
	var fld = 'bsb-interactive-map/960/';


	var minHeight = 419;
	var topPadding = 6;
	var unHoverFn = function(){};

	preloadArray[8] = new Image; preloadArray[8].src = "+m/about_us_normal.gif";
	preloadArray[9] = new Image; preloadArray[9].src = "+m/academic_organisation_normal.gif";
	preloadArray[10] = new Image; preloadArray[10].src = "+m/school_life_normal.gif";
	preloadArray[11] = new Image; preloadArray[11].src = "+m/facilities_normal.gif";
	preloadArray[12] = new Image; preloadArray[12].src = "+m/services_normal.gif";
	preloadArray[13] = new Image; preloadArray[13].src = "+m/community_links_normal.gif";
	preloadArray[14] = new Image; preloadArray[14].src = "+m/admissions_normal.gif";
	preloadArray[15] = new Image; preloadArray[15].src = "+m/parents_normal.gif";
	// preloadArray[16] = new Image; preloadArray[16].src = "+m/additional_policies_normal.gif";
	preloadArray[16] = new Image; preloadArray[16].src = "+m/memberships_normal.gif"; 

	preloadArray[17] = new Image; preloadArray[17].src = fld+"_grass.jpg";

	for(i = 1; i<16; i++)
	{
		preloadArray[17+i] = new Image;
		preloadArray[17+i].src = fld+"/"+i+".jpg";
	}


	Ext.EventManager.onDocumentReady(doWhatYouMust);
	
	
	function bsbOnWindowResize()
	{
		try
		{	
			document.getElementById('controlBox2').onclick();
			document.getElementById('controlBox').onclick();
		}
		catch(e){
			adjustPageLayout();
		};
		
	}


function doWhatYouMust()
{
	
/*	try{
		
	document.getElementById('lh1').src = '+c/remix/1.png';
	document.getElementById('lh2').src = '+c/remix/2.png';
	document.getElementById('lh3').src = '+c/remix/3.png';
	document.getElementById('lh4').src = '+c/remix/4.png';
	document.getElementById('lh6').src = '+c/remix/6.png';
	document.getElementById('lh7').src = '+c/remix/7.png';
	document.getElementById('lh8').src = '+c/remix/8.png';
	document.getElementById('lh9').src = '+c/remix/9.png';
		
	}catch(e){}
*/
	// attach map in flash
	
	swfobj = '';

/*
	swfobj = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="240" height="425">';
    swfobj+= '<param name="movie" value="bsb-interactive-map/replacement/Untitled-1.swf" />';
    swfobj+= '<param name="quality" value="high" />';
	swfobj+= '<embed src="bsb-interactive-map/replacement/Untitled-1.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="240" height="425"></embed>';
	swfobj+= '</object>';
	
	*/
	
	//document.getElementById('mapE').innerHTML = swfobj;
	
	// pin menu until next link hover (this should do the nagin' unnavig. bug)	
	
	
	Ext.util.CSS.swapStyleSheet("iePseudo", "+l/_hover-d.css" );
	
	var lowerMenu = Ext.get("lowerMenuEnclosing");
	var menuElements = lowerMenu.select('#lowerMenuEnclosing .subEnclosures');
	

	menuElements.item(0).on('click', function(){ 
		unHover(activeItem); activeItem = 0; menuElements.item(0).addClass(new Array("subEnclosuresHover", "about_us_enclHover"));
	});
	
	menuElements.item(1).on('click', function(){ 
		unHover(activeItem); activeItem = 1; menuElements.item(1).addClass(new Array("subEnclosuresHover", "academic_organisation_enclHover"));
	});

	menuElements.item(2).on('click', function(){ 
		unHover(activeItem); activeItem = 2; menuElements.item(2).addClass(new Array("subEnclosuresHover", "school_life_enclHover"));
	});
	
	menuElements.item(3).on('click', function(){ 
		unHover(activeItem); activeItem = 3; menuElements.item(3).addClass(new Array("subEnclosuresHover", "facilities_enclHover"));
	});
	
	menuElements.item(4).on('click', function(){ 
		unHover(activeItem); activeItem = 4; menuElements.item(4).addClass(new Array("subEnclosuresHover", "services_enclHover"));
	});
	
	menuElements.item(5).on('click', function(){ 
		unHover(activeItem); activeItem = 5; menuElements.item(5).addClass(new Array("subEnclosuresHover", "community_links_enclHover"));
	});
	
	menuElements.item(6).on('click', function(){ 
		unHover(activeItem); activeItem = 6; menuElements.item(6).addClass(new Array("subEnclosuresHover", "parents_enclHover"));
	});
	
	menuElements.item(7).on('click', function(){ 
		unHover(activeItem); activeItem = 7; menuElements.item(7).addClass(new Array("subEnclosuresHover", "admissions_enclHover"));
	});
	
/*	menuElements.item(8).on('click', function(){
		unHover(activeItem); activeItem = 8; menuElements.item(8).addClass(new Array("subEnclosuresHover", "additional_policies_enclHover"));
	});
	
*/

/*	menuElements.item(8).on('click', function(){
		unHover(activeItem); activeItem = 8; menuElements.item(8).addClass(new Array("subEnclosuresHover", "memberships_enclHover"));
	});
	
*/
	
	menuElements.item(8).on('click', function(){
		unHover(activeItem); activeItem = 8; menuElements.item(8).addClass(new Array("subEnclosuresHover", "inspections_enclHover"));
	});
	
	var unHover = function(itemNo)
	{
		switch(itemNo)
		{
			case 0: { menuElements.item(itemNo).removeClass("subEnclosuresHover"); menuElements.item(itemNo).removeClass("about_us_enclHover"); break; }
			case 1: { menuElements.item(itemNo).removeClass("subEnclosuresHover"); menuElements.item(itemNo).removeClass("academic_organisation_enclHover"); break; }
			case 2: { menuElements.item(itemNo).removeClass("subEnclosuresHover"); menuElements.item(itemNo).removeClass("school_life_enclHover"); break; }
			case 3: { menuElements.item(itemNo).removeClass("subEnclosuresHover"); menuElements.item(itemNo).removeClass("facilities_enclHover"); break; }
			case 4: { menuElements.item(itemNo).removeClass("subEnclosuresHover"); menuElements.item(itemNo).removeClass("services_enclHover"); break; }
			case 5: { menuElements.item(itemNo).removeClass("subEnclosuresHover"); menuElements.item(itemNo).removeClass("community_links_enclHover"); break; }
			case 6: { menuElements.item(itemNo).removeClass("subEnclosuresHover"); menuElements.item(itemNo).removeClass("parents_enclHover"); break; }
			case 7: { menuElements.item(itemNo).removeClass("subEnclosuresHover"); menuElements.item(itemNo).removeClass("admissions_enclHover"); break; }
			//case 8: { menuElements.item(itemNo).removeClass("subEnclosuresHover"); menuElements.item(itemNo).removeClass("additional_policies_enclHover"); break; }
			//case 8: { menuElements.item(itemNo).removeClass("subEnclosuresHover"); menuElements.item(itemNo).removeClass("memberships_enclHover"); break; }
			case 8: { menuElements.item(itemNo).removeClass("subEnclosuresHover"); menuElements.item(itemNo).removeClass("inspections_enclHover"); break; }
			default: {break;}
		}
	}
		
	unHoverFn = unHover;
		
	function performSearch()
	{
		Ext.Updater.defaults.indicatorText = '<div class="justPad"><h1>Please wait</h1> <p>Loading...</p> <p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p></div>';
		
		var mapEncl = Ext.get("mapEncl");
	
		var targetPage = new Ext.get('crossXfer');
		targetPage.load({
						url:'search.htm', 
						scripts: true,
						params:'iJustNeedTheContent=1&s='+document.getElementById('searchField').value,
						nocache:true,
						scope:this,
						callback: convertAllLinks
					});
		return false;
	}
	
	document.getElementById('searchFrame').onsubmit = performSearch;
	
	
	// set min-height and max-height for id=pageContent table

	var page = document.getElementById("page");
	var crossXfer = document.getElementById("crossXfer");
	var mapE2 = Ext.get("mapE");
	
	// var minHeight = 300;
	
	
	var enclosing = new Ext.Panel({
						region:'center',
						contentEl:'controlFrame',
						animCollapse:false,
						autoHeight:true,
						autoWidth:true,
						autoScroll:true,
						bodyBorder:false,
						bufferResize:false,
						collapsible:false
					})
	
	
	
	
	// Loads Map into place
	
	Ext.Updater.defaults.indicatorText = '<center><br /><strong>Loading map...</strong></center>';
	mapUrl = 'bsb-interactive-map/';
	
	var mapEncl = Ext.get("mapEncl");

	try{document.getElementById('JSMapMessage').style.display = 'none';}
	catch(e){}
	
	var mapE = new Ext.get('mapE');
	mapE.applyStyles({
					 	position:'absolute',
						width:'240px',
						overflow:'hidden',
						right:'0px'
					 });
	
	
	mapEncl.applyStyles({paddingTop: '0px'});
	
	// Load map functions
	
	qN_navs();
	animHouses();
	convertAllLinks('2112'); 

	/// try a global target
	
	// Convert links to ajax stuffing

	var loc = window.location.toString();
	if(loc.indexOf("inspection-report.htm")!=-1)
	{
		unHover(activeItem); 
		activeItem = 8; 
		menuElements.item(8).addClass(new Array("subEnclosuresHover", "inspections_enclHover"));
	}


	Ext.EventManager.onWindowResize(bsbOnWindowResize);
	// This is because we have iFrames that alter document's state.
	Ext.EventManager.onDocumentReady(function(){ adjustPageLayout(); try{chargeMapNow();}catch(e){}; }  );
	Ext.EventManager.onDocumentReady(function(){ document.getElementById('controlFrame').style.visibility = 'visible'; }  );
	
	
}


// Navigates bypassing default browser hrefs


function go_to(varURL, whatTarget, formVars)
{
	parkWindows();
	
	if(typeof(formVars) != 'object')
		formVars = {'iJustNeedTheContent':1 };	

	document.getElementById('teachingControl').style.display = 'none';
	try{ slideShow.cancel(); } catch(e){ };


	if(varURL.indexOf("search.htm") ==-1)
		document.getElementById('searchField').value = '';
	
	Ext.Updater.defaults.indicatorText = '<h3>Please wait</h3> <p>Loading...</p> <p>&nbsp; <br /> &nbsp; <br /> <br /> <br /> &nbsp;</p>';
	
	function callBackFn() { 
		/// document.getElementById('controlBox3').onclick(); 
		convertAllLinks('2112');
		adjustPageLayout();
	};

	if(whatTarget != 'iFrameEncloser')
	{
		whatTarget = 'crossXfer';
		callback = convertAllLinks;
		Ext.Updater.defaults.indicatorText = '<div class="justPad"><h1>Please wait</h1> <p>Loading...</p> <p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p></div>';
	}
	
	if(varURL == "" || varURL == " ")
		return false;


	condition = varURL.indexOf("home.htm") !=-1;
	condition = condition || varURL.indexOf("news.htm") !=-1;
	condition = condition || varURL.indexOf("events.htm") !=-1;
	condition = condition || varURL.indexOf("news-blast-newsletter.htm") !=-1;
	condition = condition || varURL.indexOf("job-vacancies.htm") !=-1;
	condition = condition || varURL.indexOf("photo-gallery.htm") !=-1;
	condition = condition || varURL.indexOf("links.htm") !=-1;
	condition = condition || varURL.indexOf("map.htm") !=-1;
	condition = condition || varURL.indexOf("school-memberships.php") !=-1;
	condition = condition || varURL.indexOf("pool-climbing-competition-2009.htm") !=-1;
	// condition = condition || varURL.indexOf("tech") !=-1;

	for(i=1; i<13; i++)
		try{ document.getElementById('lh'+i).className = ''; }catch(e){};

	if(condition)
	{
		unHoverFn(activeItem);
		if(varURL.indexOf("home.htm")!=-1) document.getElementById('lh1').className = 'lh1Hover';
		if(varURL.indexOf("news.htm")!=-1) document.getElementById('lh2').className = 'lh2Hover';
		if(varURL.indexOf("events.htm")!=-1) document.getElementById('lh3').className = 'lh3Hover';
		if(varURL.indexOf("news-blast-newsletter.htm")!=-1) document.getElementById('lh4').className = 'lh4Hover';
		if(varURL.indexOf("job-vacancies.htm")!=-1) document.getElementById('lh6').className = 'lh6Hover';
		if(varURL.indexOf("photo-gallery.htm")!=-1) document.getElementById('lh7').className = 'lh7Hover';
		if(varURL.indexOf("links.htm")!=-1) document.getElementById('lh8').className = 'lh8Hover';
		if(varURL.indexOf("map.htm")!=-1) document.getElementById('lh9').className = 'lh9Hover';
		if(varURL.indexOf("school-memberships.php")!=-1) document.getElementById('lh12').className = 'lh12Hover';
		// if(varURL.indexOf("pool-climbing-competition-2009.htm")!=-1) document.getElementById('lh10').className = 'lh10Hover';
		// if(varURL.indexOf("tech")!=-1) document.getElementById('lh11').className = 'lh11Hover';
		try{ activeItem2.style.background = ''; activeItem2 = 'undefined'; } catch (e){};
	}


	var targetPage = new Ext.get(whatTarget);
	targetPage.load({
					url: varURL, 
					scripts: true,
					params:formVars,
					nocache:false,
					scope:this,
					callback:callBackFn
				});
	
}

function convertAllLinks(scales)
{
	
	
	if(scales != '2112')
	{
		bsbOnWindowResize();
		// document.getElementById('controlBox').onclick();
	}

	var linksOn = document.getElementsByTagName('a');
	for(i=0; i<linksOn.length; i++)
	{
		if(linksOn[i].href.indexOf('#') == -1 && (linksOn[i].target == '' || linksOn[i].target == '_parent') && linksOn[i].href.indexOf('javascript') == -1 && linksOn[i].href.indexOf('mailto') == -1)
		{
			if(linksOn[i].className == 'subLink')
				linksOn[i].onclick = function()
				{
					try{activeItem2.style.background = '';}catch(e){};
					activeItem2 = this;
					this.style.background = '#fff';
				}
			
			var attr = 'javascript:go_to("'+eval(linksOn[i])+'");';
			
		}
		else
			var attr = linksOn[i];

		linksOn[i].href = attr;
	}
	if(scales != '2112')
	{
		qN_navs();
		animHouses();	
	}
	adjustPageLayout();
	try{ 
		document.getElementById('controlBox').onclick();
		if(!mapE)
			var mapE = new Ext.get('mapE');
		
		if(mapE.getWidth() == 960 || mapE.getWidth() == 961)
			document.getElementById('mapFull').onclick();

	}catch(e){}
}



// animate house chart on houses.php

function animHouses()
{
	var xBlue = document.getElementById("hBlue");

	if(xBlue)
	{
		var hBlue = new Ext.Element.get("hBlue");
		var hRed = new Ext.Element.get("hRed");
		var hYellow = new Ext.Element.get("hYellow");
		var hGreen = new Ext.Element.get("hGreen");
		
		var targetBlue = hBlue.getHeight();
		var targetRed = hRed.getHeight();
		var targetYellow = hYellow.getHeight();
		var targetGreen = hGreen.getHeight();
		
		hBlue.setHeight(0);
		hRed.setHeight(0);
		hYellow.setHeight(0);
		hGreen.setHeight(0);
	
		function HZAnimate()
		{
			anim = {easing:"easeOutStrong", duration:1, scope:this }
			hBlue.setHeight(targetBlue, anim);
			hRed.setHeight(targetRed, anim);
			hYellow.setHeight(targetYellow, anim);
			hGreen.setHeight(targetGreen, anim);
		}
		
		var HZAnimate1 = new Ext.util.DelayedTask(HZAnimate, this);
		HZAnimate1.delay(100);
		
	}
}

// home.php quickNav links should stay put, defaults to the first one

function qN_navs()
{
	return "fake";
}

var virginPort = true;
var enclosing = 'undefined';

var mapE2 = 'undefined';
var page = 'undefined';
var crossXfer = 'undefined';
var viewport = 'undefined';


function adjustPageLayout()
{
	
	if(virginPort == true)
	{
		//minHeight = 300;
/*		enclosing = new Ext.Panel({
							region:'center',
							contentEl:'controlFrame',
							animCollapse:false,
							autoHeight:true,
							autoWidth:true,
							autoScroll:true,
							bodyBorder:false,
							bufferResize:false,
							collapsible:false
						})
*/		
		mapE2 = Ext.get("mapE");
		page = document.getElementById("page");
		crossXfer = document.getElementById("crossXfer");
		// viewport = new Ext.Viewport({layout:'fit', items:[enclosing]});
		virginPort = false;
	}
	
	
	// height = viewport.getBox();
	// availableHeight = height.height-317;

	//page.style.height = '';
	
	page.style.height = minHeight + 'px';
	
	if(crossXfer.offsetHeight>minHeight+topPadding)// && Ext.isIE == true)
		crossXfer.style.width = "700px"; 
	else
		crossXfer.style.width = "";

	//mapE2.setHeight(page.offsetHeight);
	mapE2.setHeight(minHeight+topPadding); 
}
	