//<SCRIPT>
// ------------------------------------------------------------------------------------------------------------------- //
// Any footer appendage (e.g. copyright message) is entered here. This is then tacked on to the text-menu.             //
// ------------------------------------------------------------------------------------------------------------------- //
var sFooterBase = "<BR>© 2006 - 2012, Stephen Bridges. All rights reserved."
// ------------------------------------------------------------------------------------------------------------------- //
// ------------------------------------------------------------------------------------------------------------------- //
// ------------------------------------------------------------------------------------------------------------------- //

function fnAddMenu(){
	var sMenu = "", sFoot = "", iTopMod, iTopBase, iLeftMode, iLeftBase, iWidthBase

// ------------------------------------------------------------------------------------------------------------------- //
// Pages are defined here.                                                                                             //
// ------------------------------------------------------------------------------------------------------------------- //

	
	// Create the menu. The syntax of this line is 
	// CreateMenu(<caption>, <top>, <left>, <option height>, <option width>)
	CreateMenu('menu',8,16,18,52)
	
	// Now create the menu options. These have the following syntax:
	// CreateOption(<option caption>, <page name / URL>, <page description>, <override option width [optional]>)
	CreateOption('home'        ,'index.html'       ,'Home &amp; Welcome'            )
	CreateOption('services'    ,'work.html'        ,'Services and Recent Activities')
	CreateOption('testimonials','testimonials.html','Testimonials'                  ,72)
	CreateOption('media'       ,'media.html'       ,'News &amp; Media clippings'    )
	CreateOption('contact'     ,'contact.html'     ,'Contact Details'               )


// ------------------------------------------------------------------------------------------------------------------- //
// ------------------------------------------------------------------------------------------------------------------- //
// ------------------------------------------------------------------------------------------------------------------- //









	function CreateMenu(sCaption, iTop, iLeft, iHeight, iWidth) {
		iTopMod = iHeight
		iTopBase = iTop
		iLeftMod = iWidth
		iWidthBase = iWidth
		iLeftBase = iLeft+1+iWidth
		
		sMenu += "<SPAN ID='spnMenuBase' "
		sMenu += "CLASS='clsMenu' "
		sMenu += "OnMouseOver='fnShowMenu(true)' "
		sMenu += "OnMouseOut='fnShowMenu(false)' "
		sMenu += "STYLE='WIDTH: "+(iWidthBase+iW)+"px; TOP: "+iTop+"px; LEFT: "+iLeft+"px;' "
		sMenu += ">" + sCaption + "</SPAN>"
	}

	function CreateOption(sCaption, sPage, sTitle, iWidthLocal) {
		iTopBase += iTopMod
		
		if(!iWidthLocal) iWidthLocal = iWidthBase
		iWidth = iWidthLocal
	
		
		sMenu += "<SPAN ID='spnMenuItem" + iMenuItems +"' "
		sMenu += "CLASS='clsMenuItemOff' "
		sMenu += "TITLE='" + sTitle +"' "
		sMenu += "OnClick='fnFireMenu(this)' "
		sMenu += "OnMouseOver='fnOverMenu(this,true)' "
		sMenu += "OnMouseOut='fnOverMenu(this,false)' "
		sMenu += "STYLE='WIDTH: "+(iWidth+iW)+"px; DISPLAY: none; TOP: "+iTopBase+"px; LEFT: "+iLeftBase+"px;' "
		sMenu += ">" + sCaption + "</SPAN>"
		
		if(sFoot!="") sFoot += " -- "
		sFoot += "<a href='" + sPage + "'>" + sCaption + "</a>"
		
		if(!iWidthLocal) iLeftBase += iLeftMod; else iLeftBase += iWidthLocal
		iMenuActions[iMenuItems] = sPage
		iMenuItems++;
	}
	

	var sMenuPlaceholder = "<!-- MENU -->"
	sBody = sBody.replace(sMenuPlaceholder,sMenu)

	var sFootPlaceholder = "<!-- FOOT -->", oPos
	sFoot = "<SPAN id='spnFooter' Class='clsFooterLink' Style='position:absolute; top:" + GetFooterTop() + "px; width:100%; text-align:center'> -- " + sFoot + " --" + sFooterBase +" <SPAN>"
	sBody = sBody.replace(sFootPlaceholder,sFoot)
	
}

window.onresize = function() {
	WidthFix()
	oFoot = getObj('spnFooter')
	oFoot.style.top = GetFooterTop()
}

function GetFooterTop() {
	oPos = getObj('spnBody')
	var iTop_CustomSize = parseInt(oPos.offsetTop) + parseInt(oPos.clientHeight) - 30
	oPos = getObj('spnPositioner1')
	var iTop_Maximized  = parseInt(oPos.offsetTop) + parseInt(oPos.clientHeight) - (isIE4 ? 35 : 35)
	return (iTop_CustomSize>iTop_Maximized ? iTop_CustomSize : iTop_Maximized)
}

//var isCSS = (document.body && document.body.style) ? true : false;
var isW3C = (document.getElementById) ? true : false;
var isIE4 = (document.all) ? true : false;
var iW = (isIE4 ? 4 : -14)
var iMenuItems = 0, iMenuActions = new Array


me = document.all
MenuExpandType = 1

var sBody
function fnPageLoaded(sCaption) {
	getObj('spnBody').innerHTML += "<SPAN class='clsFooterLink' style='visibility:hidden'>" + sFooterBase +"</SPAN>&nbsp;"
	sBody = document.body.innerHTML
	fnAddMenu()
	fnAddHeading(sCaption)

	document.body.innerHTML = sBody
	WidthFix()
	fnUpdateMenuPos()
	LoadPostImages()
}

function LoadPostImages() {
	var aImgs = document.getElementsByTagName('IMG')
	for(var i=0; i<aImgs.length; i++) {
		var postsrc = aImgs[i].getAttribute("postsrc")
		if(postsrc)		aImgs[i].src = postsrc
	}
}

function WidthFix() {
	if(!isIE4) {
		var oBody = getObj('spnBody');
		var oEdge = getObj('spnEdges');
		oBody.style.width = 600 - 18*2;
		//oBody.style.height = 0;
		oEdge.style.width = 600 - 18*2;
		oEdge.style.height = "100%"
		oEdge.style.height = oEdge.clientHeight-78;
	}
}

function getObj(sName){
	if(isW3C) return document.getElementById(sName)
	if(isIE4) return document.all[sName]
}

function fnUpdateMenuPos() {
	var i
	for(i=0;i<iMenuItems;i++) {
		getObj('spnMenuItem'+i).final_top  = getObj('spnMenuItem'+i).style.top
		getObj('spnMenuItem'+i).final_left = getObj('spnMenuItem'+i).style.left
		getObj('spnMenuItem'+i).style.top  = getObj('spnMenuBase').style.top
		getObj('spnMenuItem'+i).style.left = getObj('spnMenuBase').style.left
	}
}

function fnAddHeading(sCaption){
	var sHeading = ""
	sHeading = sHeading + "<SPAN ID='spnTopCorner' CLASS='clsBorder' onmouseover='window.status=\"test\"' STYLE='BORDER-TOP-STYLE: solid; BORDER-LEFT-STYLE: solid; WIDTH: 400px; TOP: 15px; MARGIN-LEFT: 6px; HEIGHT: 80px'></SPAN>"
	
	sHeading = sHeading + "<SPAN ID='spnHead' CLASS='clsHeading'>"
	sHeading = sHeading + sCaption
	sHeading = sHeading + "</SPAN>"

	sHeading = sHeading + "<SPAN ID='spnBridgesUKCaption' CLASS='clsBridgesUKCaption'>"
	sHeading = sHeading + "BridgesUK.com"
	sHeading = sHeading + "</SPAN>"

	sHeading = sHeading + "<SPAN ID='spnUnderHead' CLASS='clsBorder' STYLE='MARGIN-LEFT: 6px; BACKGROUND-COLOR: #88BBFF; BORDER-LEFT-STYLE: solid; BORDER-TOP-STYLE: solid; BORDER-BOTTOM-STYLE: solid; WIDTH: 300px; TOP: " + (isIE4 ? 75 : 74)+ "px; HEIGHT: 20px'></SPAN>"

	var sHeadingPlaceholder = '<!-- HEADING -->'
	sBody = sBody.replace(sHeadingPlaceholder,sHeading)
	
}


var iTimerID,iFinishTimerID
function fnShowMenu(bShow) {
	var iTimeout
	if(bShow) iTimeout = 1; else iTimeout = 500
	clearTimeout(iTimerID)
	if(isIE4)	{
		iTimerID = setTimeout("fnAnimateMenu('"+(bShow ? '2' : '-1')+"')",iTimeout)
	}else{
		iTimerID = setTimeout("fnAnimateMenu('"+(bShow ? '4' : '-2')+"')",iTimeout)	
	}
}

function fnOverMenu(sender,bOver) {
	if(bOver) {
		clearTimeout(iTimerID)
		sender.className="clsMenuItemOn"
		window.status = sender.title
	} else {
		fnShowMenu(false)
		sender.className="clsMenuItemOff"
		window.status = sender.title
	}
}

function fnAnimateMenu(iDir){
	var i, bFinished = true
	iDir = parseInt(iDir)
	for(i=0;i<iMenuItems;i++) {
		if(MenuExpandType==0){
		// Menu Expands Down
			var iMax = pxtoInt(getObj('spnMenuItem'+i).final_top)
			var iMin = pxtoInt(getObj('spnMenuBase').style.top)
			var iPos = pxtoInt(getObj('spnMenuItem'+i).style.top)
		} else {  
		// Menu Expands Left
			var iMax = pxtoInt(getObj('spnMenuItem'+i).final_left)
			var iMin = pxtoInt(getObj('spnMenuBase').style.left)
			var iPos = pxtoInt(getObj('spnMenuItem'+i).style.left)
		}
		if(iPos+iDir<=iMax && iPos+iDir>=iMin) {
			iPos+=iDir*(i+1)
			bFinished = false
		}
		if(iPos>iMax) iPos = iMax
		if(iPos<iMin) iPos = iMin
		
		if(MenuExpandType==0) getObj('spnMenuItem'+i).style.top = iPos; else
								getObj('spnMenuItem'+i).style.left = iPos
		getObj('spnMenuItem'+i).style.display = (iPos==iMin ? 'none' : '')
	}
	if(!bFinished) {
		clearTimeout(iFinishTimerID)
		iFinishTimerID = setTimeout("fnAnimateMenu('"+iDir+"')",1)
	}

}

function pxtoInt(sVal) {
	if(sVal.indexOf('px')!=-1) var iResult = parseInt(sVal.substring(0,sVal.indexOf('px')))	
	return iResult
}

function fnFireMenu(sender){
	var i
	i = parseInt(sender.id.substring(sender.id.length-1))
	window.open(iMenuActions[i],"_self")
}


