// drop down initialization
letters = new Array('a','b','c','d','e');
buttons = new Array('about_us_selected.jpg','products_selected.jpg','services_selected.jpg',
	'quality_selected.jpg','contact_us_selected.jpg');
var timeOn = null; yOffset = 88; timeOn2 = null; timeOn3 = null; timeOn4 = null; timeOn5 = null;
//document.onmouseover=menuOut;
window.onerror = null;

// preloads the images
function startUp () {
	preloadObjects('about_us_selected.jpg','products_selected.jpg','services_selected.jpg',
	'quality_selected.jpg','contact_us_selected.jpg');
} // startUp

// hide menus (only one)
function hideMenus() {
	changeVisibility('menu1', 'hidden');
} // hideMenus

// any menu over
function menuOver() {
	clearTimeout(timeOn);
} // menuOver

// any menu out
function menuOut() {
	timeOn = setTimeout("hideMenus()", 300);
} // menuOut


// hide menus (only one)
function hideMenus2() {
	changeVisibility('menu2', 'hidden');
} // hideMenus

// any menu over
function menuOver2() {
	clearTimeout(timeOn2);
} // menuOver

// any menu out
function menuOut2() {
	timeOn2 = setTimeout("hideMenus2()", 300);
} // menuOut


// hide menus3 
function hideMenus3() {
	changeVisibility('menu3', 'hidden');
} // hideMenus3

// any menu over
function menuOver3() {
	clearTimeout(timeOn3);
} // menuOver3

// any menu out
function menuOut3() {
	timeOn3 = setTimeout("hideMenus3()", 300);
} // menuOut3

// hide menus4
function hideMenus4() {
	changeVisibility('menu4', 'hidden');
} // hideMenus4

// any menu over
function menuOver4() {
	clearTimeout(timeOn4);
} // menuOver4

// any menu out
function menuOut4() {
	timeOn4 = setTimeout("hideMenus4()", 300);
} // menuOut4

// hide menus5 
function hideMenus5() {
	changeVisibility('menu5', 'hidden');
} // hideMenus5

// any menu over
function menuOver5() {
	clearTimeout(timeOn5);
} // menuOver5

// any menu out
function menuOut5() {
	timeOn5 = setTimeout("hideMenus5()", 300);
} // menuOut5

// shows div specified by 'no'
function showLayer(no, eventObj) {
	if (eventObj) {
		eventObj.cancelBubble=true;

		if (no != 1) { 
			menuOut();
		} else {
			changeVisibility(menuID,'visible')
			menuOver();
		}
		resetObjects();
		changeObject(letters[no-1],'images/'+buttons[no-1]);
		var menuID = "menu" + no;
		moveObject(menuID, yOffset, letters[no-1]);
		if (changeVisibility(menuID,'visible')) {
			return true;
		} else {
			return false;
		}
	} else {
		return false;
	}
} // showLayer

// hides div specified by 'no'
function hideLayer(no, eventObj) {
	if (eventObj) {
		eventObj.cancelBubble=true;
		var menuID = "menu" + no;
		if (changeVisibility(menuID,'hidden')) {
			return true;
		} else {
			return false;
		}
	} else {
		return false;
	}
} // hide layer

function getObjectReference (strObject, strDoc) {
	var intFrames, intCount, intObjId;  
	if(!strDoc) { 
		strDoc = document; 
	} 
	if((intFrames = strObject.indexOf("?")) > 0 && parent.frames.length) {
		strDoc = parent.frames[strObject.substring(intFrames+1)].document; 
		strObject = strObject.substring(0,intFrames);
	}
	if(!(intObjId = strDoc[strObject]) && strDoc.all) { 
		intObjId = strDoc.all[strObject]; 
	} 
	for (intCount = 0; !intObjId && intCount < strDoc.forms.length; intCount++) { 
		intObjId = strDoc.forms[intCount][strObject];
	}
	for(intCount = 0; !intObjId && strDoc.layers && intCount < strDoc.layers.length; intCount++) {
		intObjId = getObjectReference(strObject,strDoc.layers[intCount].document);
	}
	if(!intObjId && strDoc.getElementById) {
		intObjId = strDoc.getElementById(strObject);
	}
	return intObjId;
} // getObjectReference

function preloadObjects () {
	var strDoc = document; 
	if(strDoc.images) { 
		if(!strDoc.aryPreImgs) {
			strDoc.aryPreImgs = new Array();
		}
		var intCount, intNoImgs = strDoc.aryPreImgs.length;
		var aryPreArg = preloadObjects.arguments; 
		for(intCount = 0; intCount < aryPreArg.length; intCount++) {
			if (aryPreArg[intCount].indexOf("#") != 0) { 
				strDoc.aryPreImgs[intNoImgs] = new Image; 
				strDoc.aryPreImgs[intNoImgs++].src = aryPreArg[intCount];
			}
		}
	}
} // preloadObjects

function changeObject (strObjId, strNewImg) { 
	var intObjId, intSrcId=0;
	document.arySrcObjs = new Array; 
	if ((intObjId = getObjectReference(strObjId)) != null) {
		document.arySrcObjs[intSrcId++] = intObjId; 
		if(!intObjId.orginSrc) {
			intObjId.orginSrc = intObjId.src; 
		}
		intObjId.src = strNewImg;
	}
} // changeObject

function resetObjects () {
	var intCount, intObjId, aryResetObjs = document.arySrcObjs; 
	for (intCount = 0; aryResetObjs && intCount < aryResetObjs.length && 
		(intObjId = aryResetObjs[intCount]) && intObjId.orginSrc; intCount++) {
			intObjId.src = intObjId.orginSrc;
	}
} // resetObjects

// find specifed object by DOM and return a style object
function getStyleObject(objectId) {
  if(document.getElementById && document.getElementById(objectId)) {
		return document.getElementById(objectId).style;
  } else if (document.all && document.all(objectId)) {
		return document.all(objectId).style;
  } else if (document.layers && document.layers[objectId]) {
		return document.layers[objectId];
  } else {
		return false;
  }
} // getStyleObject

// find specifed objects left offset
function getElementLeft(Elem) { 
	var elem = getObjectReference(Elem);
	xPos = elem.offsetLeft; 
	tempEl = elem.offsetParent; 
	while (tempEl != null) { 
		xPos += tempEl.offsetLeft; 
		tempEl = tempEl.offsetParent; 
	} 
	return xPos + 10;
} // getElementLeft

// move the menu to the right place
function moveObject(objectID, newYCoordinate, letter) {
  var styleObject = getStyleObject(objectID);
  if(styleObject) {
	styleObject.top = newYCoordinate;
	styleObject.left = getElementLeft(letter);
	return true;
  } else {
	return false;
  }
} // moveObject

// show/hide menu
function changeVisibility (objectID, newVisibility) {
	var styleObject = getStyleObject(objectID);
	if (styleObject) {
		styleObject.visibility = newVisibility;
		return true;
	} else {
		return false;
	}
} // changeVisibility

// initialize hacks whenever the page loads
window.onload = initializeHacks;

// setup an event handler to hide popups for generic clicks on the document
document.onclick = hideMenus;

function initializeHacks() {
    // this ugly little hack resizes a blank div to make sure you can click
    // anywhere in the window for Mac MSIE 5
  if ((navigator.appVersion.indexOf('MSIE 5') != -1) 
		&& (navigator.platform.indexOf('Mac') != -1)
		&& getStyleObject('blankDiv')) {
		window.onresize = explorerMacResizeFix;
  }
  resizeBlankDiv();
  // this next function creates a placeholder object for older browsers
  createFakeEventObj();
}

function createFakeEventObj() {
	// create a fake event object for older browsers to avoid errors in function call
	// when we need to pass the event object to functions
  if (!window.event) {
		window.event = false;
  }
} // createFakeEventObj

function resizeBlankDiv() {
	// resize blank placeholder div so IE 5 on mac will get all clicks in window
	if ((navigator.appVersion.indexOf('MSIE 5') != -1) 
		&& (navigator.platform.indexOf('Mac') != -1)
		&& getStyleObject('blankDiv')) {
			getStyleObject('blankDiv').width = document.body.clientWidth - 20;
			getStyleObject('blankDiv').height = document.body.clientHeight - 20;
  }
}
function explorerMacResizeFix () {
    location.reload(false);
}