//////////////////////////////////////////////////////////////////////////
//							MENU PARAMETERS								//
//////////////////////////////////////////////////////////////////////////


MainPage = "home.asp"

MainArray = Array(
	/*0*/	"Flight Operations~ato/a3.asp",
	/*1*/	"Maintenance, Repair &amp; Overhaul~mro/mro.asp",
	/*2*/	"Airborne Fire Fighting Systems~asd/mfg_firefight.asp",
	/*3*/	"Airborne Fuel Systems~asd/mfg_fuel.asp",
    /*4*/    "Ground Support Equipment~asd/gse.asp",
   /*5*/	"Engineering Services~asd/engineer_service.asp",
	/*6*/   "Quality~QA/QA.asp",
	/*7*/	"Management Team~managementTeam.asp",
	/*8*/	"Employment~aujobs.asp",
	/*9*/	"Contact Us~general_inf.asp",
	/*10*/	"News Archive~news.asp",
	/*11*/	"Photo Gallery~asd/photomain.asp",
	/*12*/	"Related Links~related_links.asp",
	/*13*/	"Cargo Systems Product Support~ContactUs/Cargo_service.asp"
	);

/*0 "Flight Operations */
SubArray0 = Array("Aerial Firefighting~ato/firefighting.asp",
				  "Ferry Flights~ato/Ferryflight.asp",
				  "Crew training~ato/Crewtraining.asp"
				  );
/*1	"MRO Products &amp; Services */
SubArray1 = Array(
				   "Components~mro/components.asp",
				   "Structure~mro/structure.asp",
				  "Avionics~mro/Avionics.asp",
				  "Engines~mro/engine.asp"
				  );



/*1	"MFG product */


SubArray2 = Array("C-130/L-100 <br>RADS I~asd/asd_a2.asp",
					"P-3/L-188<br> RADS II~files/radsII.pdf",
					"C-130 MAFFS~files/maffs.pdf",
					"AFFS / MAFFS II~asd/asd_a7.asp",
					"Firehawk <br> RADS III~files/radsIII.pdf",
					"Skycrane <br>RADS II 220HT~files/Skycrane_RADSII.pdf"
					);
SubArray2_3 = Array("C-130 AFFS~files/AFFSC-130.pdf"
					  
					);


SubArray3 = Array("KC-130 3600 Gallon Tank~files/3600Gallontank.pdf",
					"C-130 1800 Gallon Tank~files/TwinFFTS.pdf"					
					);


					
SubArray4 = Array(
					"P-3/L-188 Landing Gear Dolly~asd/gse_landinggear.asp",
					"P-3 Component Racks~asd/gse_CR.asp",
					"C-130/L-382G Cargo Loading Trailer~files/CargoLoadingSystem.pdf",
					"T56 Engine Maintenance Stands~files/gse.pdf",
					"P-3/L-188 APU Adapter~asd/gse_apu.asp"
					);


SubArray6= Array(  
					 "Approvals &amp; Certifications~qa/Appro_Cert.asp",
					"Supplier Approval~qa/Supplier_Approval.asp",
					"Quality Team~qa/QaTeam.asp",
                     "Safety~qa/Safety.asp" 
					);

SubArray9 = Array("AUC Map and Visitor Guide~ContactUs/AUC_mapai.pdf");


SubArray11 = Array("Airborne Fire Fighting Systems~asd/asd_f.asp",
				  "Airborne Fuel Systems~asd/asd_b3.asp",
				  "Aero Union P-3s in Action~asd/asd_a5.asp",
				  "Ground Support Equipment~asd/asd_g.asp");


//////////////////////////////////////////////////////////////////////////
//							MENU LOGIC									//
//////////////////////////////////////////////////////////////////////////


var DELIMETER = "~";
var bcDELIMETER = " &gt; "
var CONTENTNAME = "content"
MENU_DELAY = 170;

var menu = null;
var menulocation = "";
var templocation = "";
var previousCounter = 0;
var previousMenu = null;
var previousMenu2 = null;
var curPtr = null;
var markFlag = false;
var TIMER = null;
var MENU_STACK = Array();


function init()
{
	// get and remember the menu item
	menu = document.getElementById("menu");
	previousMenu = document.getElementById("previousmenu");
	previousMenu2 = document.getElementById("breadcrumb2");

	// create main menu back button
	createItem(previousMenu,"MAIN","Aero Union Home");

	// get the windows current position
	winURL = window.location.href;
	winURL = winURL.split("#");
	if(winURL[2] != null && winURL[2] != "")
	{
		loadcontentpage(winURL[2]);

		try
		{
//			if(winURL[1] != null && winURL[1] != "")
				recreateMenu(winURL[1],winURL[2]);
		}
		catch(e)
		{
				mainMenu();
		}
	}
 	else
		createMain();

	winURL = null;
}

function recreateMenu(path,href)
{
	path = path.split("_");

	while( m_itm = path.shift() )
	{
		// remember how many levels down we are
		previousCounter--;

		str = "SubArray";
		if(menulocation == "")
			str = "MainArray";

		createItem(previousMenu,previousCounter, eval(str+menulocation)[m_itm]);

		if(menulocation == "")
			menulocation = m_itm;
		else
			menulocation += "_"+m_itm
	}

	window.location = "#"+menulocation+"#"+href;

	// create the subarray items
	newmenu = eval("SubArray"+menulocation);

	for(i=0; i< newmenu.length;i++)
		createItem(menu,i,newmenu[i]);

	newmenu = null;
	path = null;
	m_itm = null;
	str = null;

}

function createMain()
{
	window.location = "#";

	document.getElementById(CONTENTNAME).innerHTML = ""
	document.getElementById("topimage").src = "images/main8/aerounion_main8_01.gif";
	document.getElementById("content2").width = "387";
	document.getElementById("content2").style.backgroundImage = "url('images/main8/main_body.gif')";
	document.getElementById("content3").style.display = "block";
	document.getElementById("bottomimage").src = "images/main8/aerounion_main8_05.gif";

	// reload main page
	ajaxpage(MainPage,CONTENTNAME)

	mainMenu();

}

function mainMenu()
{
	clear();

	for(i=0; i< MainArray.length;i++)
	{
		createItem(menu,i,MainArray[i]);
	}
}

function sub(submenu,href,ptr)
{

	// check if no more submenus i.e. leaf
	try
	{
		str = "_";
		if(menulocation == "" || submenu < 0)
			str = "";
		eval("SubArray"+menulocation+str+submenu)

		// clear any pending submenus
		if(MENU_STACK.length > 0)
		{
			clearInterval(TIMER);
			TIMER = null

			while(MENU_STACK.length > 0)
				MENU_STACK.shift();
		}

	}
	catch (e)
	{
		;
	}

	if(String(submenu) == "MAIN")
	{
		// remove all except the top
		while(previousMenu.firstChild != previousMenu.lastChild)
			previousMenu.removeChild(previousMenu.lastChild);

		// reset breadcrumb2
		bc = previousMenu2.innerHTML;
		if( bc.indexOf(bcDELIMETER,bcDELIMETER.length) != -1)
			previousMenu2.innerHTML = bc.substring(0,bc.indexOf(bcDELIMETER,bcDELIMETER.length))

		// recreate main menu items
		createMain();

		// clear the location

		menulocation = "";
		previousCounter = 0;

		return;
	}

	// go backwards
	if(submenu < 0)
	{
		for(i=submenu; i > previousCounter; i--)
		{
			menulocation = menulocation.substring(0,menulocation.lastIndexOf("_"));
		}
	}

	templocation = menulocation;
	loadcontentpage(href,ptr);

	// check if no more submenus i.e. leaf
	try
	{
		str = "_";
		if(menulocation == "" || submenu < 0)
			str = "";
		eval("SubArray"+menulocation+str+submenu)
	}
	catch (e)
	{
		return;
	}

	clear();


	if(submenu >= 0)
	{
		// Check if we need to use MainArray for previousName
		current = menulocation;

		// use underscores to sepearte indexes
		if(submenu >= 0 && String(menulocation) != "")
			menulocation += "_";

		// remember the current subarray that will be loaded into the menu
		menulocation += String(submenu);

		window.location = "#"+menulocation+"#"+href;

		// remember how many levels down we are
		previousCounter--;

		str = "SubArray";
		if(current == "")
			str = "MainArray";

		if(href != "")
			markFlag = true;

		createItem(previousMenu,previousCounter, eval(str+current)[submenu]);
	}
	else
	{
		clearPrevious(submenu);
	}

	// create the subarray items
	newmenu = eval("SubArray"+menulocation);

	for(i=0; i< newmenu.length;i++)
		createItem(menu,i,newmenu[i]);

	newmenu = null;
}

function loadcontentpage(href,ptr)
{
	// load a page
	if(href != "")
	{
		window.location = "#"+menulocation+"#"+href;

		document.getElementById(CONTENTNAME).innerHTML = ""
		document.getElementById("topimage").src = "images/templ2/aerounion_main_templ2_01.gif";
		document.getElementById("content2").width = "650";
		document.getElementById("content2").style.backgroundImage = "url('images/templ2/article_body.gif')";
		document.getElementById("content3").style.display = "none";
		document.getElementById("bottomimage").src = "images/templ2/aerounion_main_templ2_04.gif";

		// open in new window if pdf file
		fileExtension = href.substring(href.lastIndexOf(".")+1,href.length);
		fileExtension = fileExtension.split("?")[0];
		if( fileExtension != "asp" && fileExtension != "html" && fileExtension != "htm")
		{
			document.getElementById(CONTENTNAME).innerHTML = '<iframe id="pdf" name="pdf" src="'+href+'"FRAMEBORDER="0" SCROLLING="auto" ALIGN="top" height="769px" width="628px"></iframe><center><a href="javascript:newWindow(\''+href+'\')" title="View the file in a new window">View the file in a new Window</a></center>'
		}
		else
			ajaxpage(href,CONTENTNAME);

		// mark current item
//		addMark(ptr)
	}
}

function newWindow(href)
{
	win = window.open(href,"pdfwindow","toolbar=0,status=1,resizable=1,scrollbars=1")
	if(window.focus())
		win.focus();
}

function createItem(parent,index,str)
{
	if(parent == null)
		return;

	str = str.split(DELIMETER);

	text = "";
	var href_ = "";

	if(str.length >= 1)
		text = str[0];
	if(str.length >= 2)
		href_ = str[1];

	tr = document.createElement("tr");

	td = document.createElement("td");

	td.onclick = function () {sub(index,href_,this);};
	td.innerHTML = text;

	if( parent == document.getElementById("previousmenu") )
	{
		td.onmouseover = function () {this.style.color="black";}
		td.onmouseout = function () {this.style.color="white";}
	}
	else
	{
		td.onmouseover = function () {this.style.background="white";this.style.color="black";}
		td.onmouseout = function () {this.style.background="#aa0000";this.style.color="white";}
	}


	if(parent == previousMenu)
	{
		// create breadcrumb2 item
		str = bcDELIMETER;
		if(index == "MAIN")
			str = "&nbsp;&nbsp;&nbsp;&nbsp;";
		previousMenu2.innerHTML += str +"<a href='#"+href_+"' onclick='sub(\""+index+"\",\""+href_+"\""+",this)'>"+ text.replace("<br>","")+"</a>";

	}


	if(markFlag)
	{
//		addMark(td);
		markFlag = false;
	}

	tr.appendChild(td);

	MENU_STACK[MENU_STACK.length] = Array(parent,tr);


	str = null;
	text = null;
	href = null;
	tr = null;
	td = null;

	if(TIMER == null)
		TIMER = setInterval("addItem()",MENU_DELAY);
}

function addItem()
{
	try
	{
		itm = MENU_STACK.shift();
	}
	catch(e)
	{
		return;
	}


	itm[0].appendChild(itm[1]);


	if(MENU_STACK.length == 0)
	{
		clearInterval(TIMER);
		TIMER = null
	}
}

function clearPrevious(index)
{
	index = index - previousCounter;
	bc = previousMenu2.innerHTML;

	for(i=0; i < index; i++)
	{
		previousMenu.removeChild(previousMenu.lastChild)

		// remove breadcrumb2 items
		bc = bc.substring(0,bc.lastIndexOf(bcDELIMETER));
	}

	previousMenu2.innerHTML = bc;

	previousCounter = previousCounter + index;

	index = null;
}

function clear()
{
	while(menu.firstChild)
		menu.removeChild(menu.firstChild)
}

function addMark(ptr)
{
	if(ptr == null) return;

	MARK = "&larr;";

	// remove arrow
	if(curPtr != null)
	{
		str = curPtr.innerHTML;
		curPtr.innerHTML = str.substring(0,str.length-1)
	}

	// add arrow
	ptr.innerHTML += MARK;
	curPtr = ptr;
}