﻿<!--

	// Detect if the browser is IE or not.
	// If it is not IE, we assume that the browser is NS.
	var IE = document.all?true:false
	// If NS -- that is, !IE -- then set up for mouse capture
	if (!IE) document.captureEvents(Event.MOUSEMOVE)
	// Set-up to use getMouseXY function onMouseMove
	document.onmousemove = getMouseXY;
	// Temporary variables to hold mouse x-y pos.s
	var mouseX = 0
	var tempY = 0	
	// Main function to retrieve mouse x-y pos.s	
	function getMouseXY(e) {
	  if (IE) { // grab the x-y pos.s if browser is IE
		mouseX = event.clientX + document.body.scrollLeft
		mouseY = event.clientY + document.body.scrollTop
	  } else {  // grab the x-y pos.s if browser is NS
		mouseX = e.pageX
		mouseY = e.pageY
	  }  
	  // catch possible negative values in NS4
	  if (mouseX < 0){mouseX = 0}
	  if (mouseY < 0){mouseY = 0}  
	  return true
	}

	// Btn class
	function makeSubmenu (labels, pindex, level, menubg, width, height, imgs, hrefs, targets) {	
		// create buttons and submenu
		text = "";
		text = '<table cellspacing="0" cellpadding="0">';
		for (i = 0; i < labels.length; i++) {
			var index = pindex + '_' + i;
			eval ('btn' + index + ' = new Btn()');
			var btn = eval('btn' + index);
			btn.id = 'btn' + index;
			btn.label = labels[i];
			btn.index = index;
			btn.color = eval('btn' + pindex).color;
			// write submenu
			text += "<tr><td class='btnlevel" + (level + 1) + "' id='" + btn.id + "' onMouseOver='" +  btn.id + ".mOver()'  onMouseOut='" + btn.id + ".startTimer()' >";
			if ( targets[i].substr(0,1) != "_" ) {
				text += "<a href='javascript:" + targets[i] + "(\"" + hrefs[i] + "\");' >";
			} else
				text += "<a target='" + targets[i] + "' href='" + hrefs[i] + "' >";
			text += "<img src='"  + imgs[i] + "' />";
			text += "</a>";
			text += "</td></tr>";
		}
		text += "</table>";
		eval ('smenu' + pindex + ' = new Smenu()');
		smenu = eval('smenu' + pindex);
		smenu.id = 'smenu' + pindex;
		
		text = "<div class='submenu' id='smenu" + pindex  + "' onMouseOut='btn" + pindex + ".startTimer()' >" + text + "</div>";
		text = "<div class='submenu2' id='smenu" + pindex  + "b' >" + text + "</div>";
		getObject('submenus').innerHTML += text;
		
		//set width and position;
		
		style = getStyle(getObject(smenu.id));		
		btnObj = getObject('btn' + pindex);
		if (level == 0) { // drop down menu
			style.left = findPosX(btnObj);
			style.top = findPosY(btnObj) + getHeight(btnObj) + 3;
		} else { // slide out menu
			style.left = findPosX(btnObj) + getWidth(btnObj) + 8;
			style.top = findPosY(btnObj);
		}		
		style.visibility = "hidden";
		
		
	}
	function mOver () {
			// clear every sibling buttons highlight
			var i = 0;			
			while (true) {
				var targetindex = (this.index).substr(0, (this.index).length - 1) + i;
				var btn_name = 'btn' + targetindex;
				if (eval('window.' + btn_name)) {					
					// sub button found
					if (this.index != targetindex) {
						var btn = eval(btn_name);
						if (btn.isOver ) {
							btn.mOut();
						}
					}
				} else {
					break;
				}
				i++;
			}
			
			this.isOver = true;
			
			// change style			
			style =getStyle(getObject(this.id));			
			style.backgroundColor = this.color;		
			style.MozOpacity = 1; // NS
			style.filter = "alpha(opacity=100)"; // IE
			
			//show submenu
			if (eval('window.' + 'smenu' + this.index)) { // if got submenu
				smenu = eval('smenu' + this.index);
				getStyle(getObject(smenu.id)).visibility = "visible";
				smenu.visible = true;				
			}
			
			
	}
	function mOut () {
		//clearTimer
		if (this.timer != null) {
			clearInterval(this.timer);
			//getObject("test").innerHTML = 'timer cleared: ' + this.index ;
		}
		
		// set button style
		style =getStyle(getObject(this.id));
		style.backgroundColor = "";
		style.MozOpacity = 0.85; // NS
		style.filter = "alpha(opacity=85)";; // IE

		this.isOver = false;
		
		// hide submenu
		if (eval('window.smenu' + this.index)) { //menu exist
			var smenu = eval('smenu' + this.index);	
			if (smenu.visible == true) {
				smenu.visible = false;
				getStyle(getObject(smenu.id)).visibility = "hidden";
				
			}
			// hide sub-buttons' submenu 
			var i = 0;	
			while (true) {
				var btn_name = 'btn' + this.index + '_' + i;
				if (eval('window.' + btn_name)) {
					// sub button found
					var btn = eval(btn_name);
					btn.mOut();
				} else {
					break;
				}
				i++;
			}
		}
		
		
	}
	function checkOut (id) {
		
		// check if mouse curosr inside element with given id
		var x1, y1, x2, y2;		
		var obj = getObject(id);
		x1 = findPosX(obj);
		y1 = findPosY(obj);
		x2 = x1 + getWidth (obj);
		y2 = y1 + getHeight(obj);
		return (mouseX < x1 || mouseX > x2 || mouseY < y1 || mouseY > y2);
	}
	
	function checkHide () {		
		var isOut1, isOut2, isOut3;
		var isOut = true;
		// check curosor inside button?
		isOut1 = true;
		isOut1 = checkOut(this.id);		
		// check cursor inside submenu?
		isOut2 = true;
		if (eval('window.smenu' + this.index)) { //menu exist
			var smenu = eval('smenu' + this.index);	
			if (smenu.visible == true) {			
				isOut2 = checkOut(smenu.id);
			} else {
				isOut2 = true;				
			}			
			// check cursor inside sub-buttons' submenu?
			var i = 0;
			isOut3 = true;
			while (true) {
				var btn_name = 'btn' + this.index + '_' + i;
				if (eval('window.' + btn_name)) {
					// sub button found
					var btn1 = eval(btn_name);
					if (!btn1.checkHide() ) {
						isOut3 = false;
						break;
					}
				} else {
					break;
				}
				i++;
			}
		} else {
			isOut3 = true;
		}
		
		
		//getObject("test").innerHTML = 'out1:' + isOut1 + 'out2:' + isOut2 + 'out3:' + isOut3;
		
		isOut = isOut1 && isOut2 && isOut3;
		if (isOut) {	
			this.mOut();
		}			
		return isOut;
		
			
	}
	function startTimer () {			
		if (this.timer != null) {
			clearInterval(this.timer);
		}
		//getObject("test").innerHTML ="startTimer";
		//eval('setTimeout ("' + this.id + '.checkHide()" , 1)');				
		eval('this.timer = setInterval("' + this.id + '.checkHide()", 500)');		
	}
	function Btn (index, id, label) {
		//variables
		var href, target, index, id, label, timer, img;		
		this.index = index;
		this.label = label;
		this.id = id;		
		this.height =0;
		this.width = 0;
		
		//functions
		this.mOver = mOver;
		this.mOut = mOut;
		this.checkHide = checkHide;		
		this.startTimer = startTimer;
	}
	// Submenu class
	function Smenu () {
		var id, visible;
		visible = false;
		id="";
		
	}
	var images = new Array();
	var images2 = new Array();
	
	var images3 = new Array();
	function myPreloadImages(imgs, imgs2)
	{
		for (i = 0; i< imgs.length; i++) {
			j = imgs2.length;
			imgs2[i] = new Image();
			imgs2[i].src= imgs[i];			
		}
	}
	
	function addPath (arr) {
		for (i = 0; i < arr.length; i++) {
			arr[i] = parentPath + arr[i];
		}
	}
	function checkLoaded () {
		ready = true;
		for (i = 0; i< images.length; i++) {
			if (!images[i].complete) {
				ready = false;
				setTimeout(checkLoaded, 500);
				break;
			}		
		}
		if (ready == true) {
			buildMenu();
		}
	}
	function checkLoaded2 () {
		ready = true;
		for (i = 0; i< images2.length; i++) {
			if (!images2[i].complete) {
				ready = false;
				setTimeout(checkLoaded2, 500);
				break;
			}		
		}
		if (ready == true) {
			buildSubmenu();
		}
	}
	counter = 0;
	function checkLoaded3 () {
		ready3 = true;
		for (i = 0; i< images3.length; i++) {
			if (!images3[i].complete) {
				ready3 = false;
				setTimeout(checkLoaded3, 300);
				break;
			}		
		}
		if (ready3 == true) {
			//getObject("test").innerHTML ="loaded";
		}
	}
	function initMenu (menuId, p) {
		
		parentPath = p;
		//write menu divs		
		getObject(menuId).innerHTML = '<div id="mainmenu"></div><div id="submenus"></div>';
	
				
		// user settings
		// main menu buttons
		imgs0 = new Array ("images/menu/btn_home.gif", "images/menu/btn_introduction.gif", "images/menu/btn_achievement.gif", "images/menu/btn_online.gif", "images/menu/btn_activity.gif", "images/menu/btn_slideshow.gif", "images/menu/btn_class.gif", "images/menu/btn_gallery.gif", "images/menu/btn_pta.gif", "images/menu/btn_contact.gif");
		labels0 = new Array ("主　　頁", "學校簡介", "金榜題名", "校園在線", "校園活動", "校園剪影", "班級天地", "學生作品", "家長教師會", "聯絡我們");
	//	colors0 = new Array ( "#BBBBFF", "#CCCCCC", "#FFCCCC", "#FFCCAA", "#FFFF99", "#AAEEAA", "#CCDDFF", "#CCCCDD", "#DDAAFF", "#FFEEEE");
		colors0 = new Array ( "#AAAACC", "#AAAAAA", "#FF9999", "#FF9966", "#FFFF99", "#AAEEAA", "#99DDFF", "#AAAAFF", "#DDAAFF", "#FFDDDD");
		hrefs0 =  new Array("default.asp", "introduction/default.asp", "achievement/default.asp", "onlineSchool/default.asp","activity/default.asp", "slideshow/default.asp", "class/default.asp", "gallery/default.asp", "pta/default.asp",  "contact/default.asp");
		targets0 = new Array ("_self", "_self", "_self", "_self", "_self", "_self", "_self", "_self", "_self", "_self", "_self");
		
		// level 1 	sub menu buttons
		labels0_1 = new Array("校長的話", "學校概覽", "辦學宗旨", "辦學目標", "校　　訓", "校務計劃", "周年報告", "升學報告", "學校設施", "轉全日制消息");
		imgs0_1 = new Array ("images/menu/btn_introduction_principal.gif", "images/menu/btn_introduction_schfact.gif", "images/menu/btn_introduction_objective.gif", "images/menu/btn_introduction_goal.gif", "images/menu/btn_introduction_moral.gif", "images/menu/btn_introduction_plan.gif", "images/menu/btn_introduction_report.gif", "images/menu/btn_introduction_promotion.gif", "images/menu/btn_introduction_facility.gif");
		hrefs0_1 = new Array ("introduction/principal.asp", "introduction/schfact/sch_basic.htm", "introduction/objective.asp", "introduction/goal.asp", "introduction/moral.asp", "introduction/plan.asp", "introduction/report.asp", "introduction/promotion.asp", "introduction/facility.asp", "introdution/fulltime.asp");
		targets0_1 = new Array ("_self", "_blank", "_self", "_self", "_self", "_self", "_self", "_self", "_self");
	 	menubg0_1 = "images/menu/menu_introduction.gif";
		
		labels0_2 = new Array("校訊成績", "校際比賽", "學習金榜");		
		imgs0_2 = new Array ("images/menu/btn_achievement_award.gif", "images/menu/btn_achievement_contest.gif", "images/menu/btn_achievement_learnfame.gif");
		hrefs0_2 = new Array ("achievement/award/default.asp", "achievement/contest/default.asp", "achievement/learnfame/default.asp");
		targets0_2 = new Array ("_self", "_self", "_self");
		menubg0_2 = "images/menu/menu_achievement.gif";
		
		labels0_3 = new Array("家長教師會", "德育及公民教育", "古典文學欣賞", "小一家課冊");		
		imgs0_3 = new Array ("images/menu/btn_online_pta.gif", "images/menu/btn_online_moralandcivic.gif", "images/menu/btn_online_classic.gif", "images/menu/btn_online_homework.gif");
		hrefs0_3 = new Array ("onlineschool/pta/default.asp", "onlineschool/moralandcivic/default.asp",  "onlineschool/classic/default.asp", "onlineschool/p1homework/default.asp");
		targets0_3 = new Array ("openWindow3", "_self", "_self", "_self");
		menubg0_3 = "images/menu/menu_online.gif";
		
		labels0_4 = new Array("校內活動",  "課外活動");
		imgs0_4 = new Array ("images/menu/btn_activity_internal.gif", "images/menu/btn_activity_discipline.gif", "images/menu/btn_activity_extracurricular.gif");
		hrefs0_4 = new Array ("activity/internal/default.asp", "activity/extracurricular/default.asp");
		targets0_4 = new Array ("_self", "_self", "_self");
		menubg0_4 = "images/menu/menu_activity.gif";
		
		labels0_7 = new Array("中文作文", "英文作文", "常識科", "視覺藝術", "資訊科技");
		imgs0_7 = new Array ("images/menu/btn_gallery_chinese.gif", "images/menu/btn_gallery_english.gif", "images/menu/btn_gallery_gs.gif" , "images/menu/btn_gallery_art.gif", "images/menu/btn_gallery_it.gif");
		hrefs0_7 = new Array ("gallery/chinese.asp", "gallery/english.asp", "gallery/gs.asp", "gallery/art.asp", "gallery/it.asp");
		targets0_7 = new Array ("_self", "_self", "_self", "_self", "_self");
		menubg0_7 = "images/menu/menu_gallery.gif";
		
		labels0_8 =  new Array("網上漫遊", "學科軟件","中文網上閱讀", "英文網上閱讀", "普通話科閱讀", "普通話拼音擂台", "輔導組互動教材", "教學連結");
		imgs0_8 = new Array ("images/menu/btn_elearning_cybertrip.gif", "images/menu/btn_elearning_software.gif", "images/menu/btn_elearning_chinesereading.gif", "images/menu/btn_elearning_englishreading.gif", "images/menu/btn_elearning_pthreading.gif", "images/menu/btn_elearning_pthquiz.gif", "images/menu/btn_elearning_remedial.gif", "images/menu/btn_elearning_link.gif");
		hrefs0_8 = new Array ("elearning/cybertrip.asp", "elearning/software.asp", "elearning/chinesereading.asp", "elearning/englishreading.asp", "elearning/pthreading.asp", "elearning/pthquiz/pthquiz.asp", "elearning/remedial.asp", "elearning/link.asp");
		targets0_8 = new Array ("_self", "_self", "_self", "_self", "_self", "_self", "_self", "_self");
		menubg0_8 = "images/menu/menu_elearning.gif";
		
		labels0_2_0 = new Array("中文科", "英文科", "數學科", "常識科", "資訊科", "音樂科", "普通話科", "視覺藝術科", "體育科", "其他");
		imgs0_2_0 = new Array ("images/menu/btn_achievement_award_chinese.gif", "images/menu/btn_achievement_award_english.gif", "images/menu/btn_achievement_award_mathematic.gif", "images/menu/btn_achievement_award_general.gif", "images/menu/btn_achievement_award_it.gif", "images/menu/btn_achievement_award_music.gif", "images/menu/btn_achievement_award_putonghua.gif", "images/menu/btn_achievement_award_art.gif", "images/menu/btn_achievement_award_sport.gif", "images/menu/btn_achievement_award_other.gif");
		hrefs0_2_0 = new Array ("achievement/award/chinese/default.asp", "achievement/award/english/default.asp", "achievement/award/mathematic/default.asp", "achievement/award/general/default.asp", "achievement/award/it/default.asp", "achievement/award/music/default.asp", "achievement/award/putonghua/default.asp", "achievement/award/art/default.asp", "achievement/award/sport/default.asp", "achievement/award/other/default.asp");
		targets0_2_0 = new Array ("_self", "_self", "_self", "_self", "_self", "_self", "_self", "_self", "_self", "_self");
		menubg0_2_0 = "images/menu/menu_achievement_award.gif";		
		
		// add paths
		addPath (imgs0);	addPath(hrefs0);
		addPath (imgs0_1);	addPath(hrefs0_1);
		addPath (imgs0_2);	addPath(hrefs0_2);
		addPath (imgs0_3);	addPath(hrefs0_3);
		addPath (imgs0_4);	addPath(hrefs0_4);
		addPath (imgs0_7);	addPath(hrefs0_7);
		addPath (imgs0_8);	addPath(hrefs0_8);
		addPath (imgs0_2_0);	addPath(hrefs0_2_0);

		
		myPreloadImages (imgs0, images);
		
		myPreloadImages (imgs0_1, images2);	
		myPreloadImages (imgs0_2, images2);	
		myPreloadImages (imgs0_3, images2);	
		myPreloadImages (imgs0_4, images2);	
		myPreloadImages (imgs0_7, images2);	
		myPreloadImages (imgs0_8, images2);	
		myPreloadImages (imgs0_2_0, images2);	
		
		checkLoaded();
		checkLoaded2();
		
		//buildMenu();
		//buildSubmenu();
	}
	function buildMenu() {
		// build main menu
		for (i =0; i < imgs0.length; i++) {
			eval('btn0_' + i + ' = new Btn("0_' + i + '", "btn0_' + i + '", "' + labels0[i] + '") ');	
			var btn = eval('btn0_' + i);		
			btn.img = imgs0[i];
			btn.color = colors0[i];
			btn.href = hrefs0[i];
			btn.target = targets0[i];
			
		}				
		//draw level 0 buttons
		text = "";
		for (i = 0; i < imgs0.length; i ++) {
			var btn = eval('btn0_' + i);	
			text += "<div class='btnlevel0' id='" + btn.id + "' onMouseOver='btn0_" + i + ".mOver()' onMouseOut='btn0_" + i + ".startTimer()'>";
			text += "<a style='border:0px;padding:0px; margin:0px;' href='" + btn.href + "' target='" + btn.target + "' >";
			text += "<img style='border:0px;padding:0px; margin:0px;' src='" +  btn.img + "' />";
			//text += btn.label;
			//text += "<div id='wat' style='width:70; height:25; border:0px;padding:0px; margin:0px;background-image: url(" + btn.img + ");' ></div>";
			text += "</a>";
			text += "</div>";
		}
		getObject("mainmenu").innerHTML = text ;		
	}
	function buildSubmenu (){
		
		// construct level 1 buttons		
		
		makeSubmenu(labels0_1, "0_1", 0,  menubg0_1, 70, 185, imgs0_1, hrefs0_1, targets0_1);
		delete labels0_1, imgs0_1, hrefs0_1, targets0_1, menubg0_1;
		makeSubmenu(labels0_2, "0_2", 0, menubg0_2, 70, 70, imgs0_2, hrefs0_2, targets0_2);
		delete labels0_2, imgs0_2, hrefs0_2, targets0_2, menubg0_2;
		makeSubmenu(labels0_3, "0_3", 0, menubg0_3, 70, 70, imgs0_3, hrefs0_3, targets0_3);
		delete labels0_3, imgs0_3, hrefs0_3, targets0_3, menubg0_3;
		makeSubmenu(labels0_4, "0_4", 0, menubg0_4, 70, 70,imgs0_4, hrefs0_4, targets0_4 );
		delete labels0_4, imgs0_4, hrefs0_4, targets0_4, menubg0_4;
		makeSubmenu(labels0_7, "0_7", 0, menubg0_7, 70, 70,imgs0_7, hrefs0_7, targets0_7 );
		delete labels0_7, imgs0_7, hrefs0_7, targets0_7, menubg0_7;
		makeSubmenu(labels0_8, "0_8", 0, menubg0_8, 100, 130,imgs0_8, hrefs0_8, targets0_8 );
		delete labels0_8, imgs0_8, hrefs0_8, targets0_8, menubg0_8;
		// construct level 2 buttons
		
		makeSubmenu(labels0_2_0, "0_2_0", 1, menubg0_2_0, 80, 210,imgs0_2_0, hrefs0_2_0, targets0_2_0 );
		delete labels0_2_0, imgs0_2_0, hrefs0_2_0, targets0_2_0, menubg0_2_0;
			
	}	
-->
