var d=document
var g_arrSec= Array("about","book","look","talk","themes","projects","")
var g_navRef="blank.html"
var g_isPCie=(navigator.appName.search(/microsoft/i)>=0&&navigator.appVersion.search(/win/i)>=0&&navigator.userAgent.search(/opera/i)==-1)

function fnScreen(){
	if(screen.width<1024)
		return "800x600"
	else
		return "1024x768"
}		

function fnResize(){
	var sFile=fnScreen()
	if(fnGetCookie("jump")!="Y")
		fnSetCookie("page","")
	if(document.URL.indexOf(sFile)<0)
		window.top.location.replace(document.URL.replace(/(\d+x\d{3})/i,sFile))
}

function fnLoadPage(){
	if(!fnGetCookie("Centre")){
		fnSetCookie("Centre","");		
	}
	
	fnResize()
	var doc=d.URL.split("?")
	if(doc.length==2)
		doc=doc[1]
	else {
		var page=fnGetCookie("page")
		if(!d.scrollbox)
			doc=page
		else
			doc=""	
	}	
	if(doc)	
		if(self.scrollbox.location.href.indexOf(doc)<0)	
			self.scrollbox.location.replace(doc)
	//fnShowUserName()		
}	

function fnPageNav(pURL){
	if(window.top.navbox)
		if(window.top.navbox.location.href.indexOf(pURL)<0)
			window.top.navbox.location.replace(pURL)	
		
}

function fnPageTitle(pTitle){
	var flgResize=false
	var sFile=fnScreen()
	if(window.parent.document.URL.indexOf(sFile)<0)
		flgResize=true

	if(!fnGetCookie("Centre")){
		//fnSetCookie("jump","Y")
		//fnSetCookie("page",self.location.href)
		//window.top.location.replace("/home"+sFile+".asp")
		fnSetCookie("Centre","");
	}	

	for(var i=0;i<g_arrSec.length;i++){
		p=1+d.URL.indexOf("/"+g_arrSec[i])
		if(p>0)
			break
	}	
	if(self.name!="scrollbox"||flgResize){
		window.top.location.replace(d.URL.substr(0,p)+"ezone"+sFile+".html?"+d.URL.substr(p))
	}else{	
		self.parent.document.images["Title"].src="_section1024x768/title/"+pTitle+".gif"
		self.parent.document.title="::"+fnGetCookie("Centre")+":: "+pTitle.replace(/_/g," ")
		if(g_arrSec[i]=="themes"){
			g_navRef=d.URL.indexOf("/",p+g_arrSec[i].length+1)
			g_navRef=d.URL.substr(0,g_navRef)+"/navigation.html"
		}else if(d.URL.indexOf("book/default")>0){
			g_navRef=d.URL.indexOf("book")+4
			g_navRef=d.URL.substr(0,g_navRef)+"/key.asp"
		}else
			g_navRef=d.URL.substr(0,p)+g_navRef
		fnPageNav(g_navRef)
		
		d.writeln("<link rel=\"stylesheet\" href=\""+d.URL.substr(0,p-1)+"\/page.css\" type=\"text\/css\">");		
		fnSetCookie("page",d.URL)
	}	
}	
function _fixObjects(){
	if(!d.getElementsByTagName)return
	var o=d.getElementsByTagName("object")
	if(o.length)
		if(o[0].outerHTML)
			for(var i=0;i<o.length;i++){
				o[i].stop()
				var ps=""
				var a=o[i].getElementsByTagName("param")
				for(var j=0;j<a.length;j++)ps+=a[j].outerHTML
				var html=o[i].outerHTML.replace(/<\/object>/i,"")
				html=html+ps+"</object>"
				o[i].outerHTML=html
			}		
}
function fnShowFlashMovie(pSRC,pW,pH){
	d.writeln("<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0\" height=\""+fnCalc(pH)+"\" width=\""+fnCalc(pW)+"\">")
	d.writeln("<param name=\"movie\" value=\""+pSRC+"\">")
	d.writeln("<PARAM name=\"menu\" value=\"false\">")
	d.writeln("<PARAM name=\"quality\" value=\"high\">")
	d.writeln("<PARAM name=\"wmode\" value=\"opaque\">")
	d.writeln("<embed height=\""+fnCalc(pH)+"\" width=\""+fnCalc(pW)+"\" menu=\"false\" quality=\"high\" wmode=\"opaque\" devicefont=\"true\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" src=\""+pSRC+"\" type=\"application/x-shockwave-flash\">")
	d.writeln("</object>")
}

function fnShowQTMovie(pSRC,pW,pH){
	d.writeln("<object classid=\"clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B\" codebase=\"http://www.apple.com/qtactivex/qtplugin.cab\" height=\""+fnCalc(pH)+"\" width=\""+fnCalc(pW)+"\">")
	d.writeln("<param name=\"src\" value=\""+pSRC+"\">")
	d.writeln("<param name=\"autoplay\" value=\"true\">")
	d.writeln("<param name=\"controller\" value=\"true\">")
	d.writeln("<!--500,391-->")
	d.writeln("<embed pluginspage=\"http://www.apple.com/quicktime/download/\" src=\""+pSRC+"\" type=\"video/quicktime\" height=\""+fnCalc(pH)+"\" width=\""+fnCalc(pW)+"\" controller=\"true\" autoplay=\"true\">")
	d.writeln("</object>")
}

function fnJumpToAnchor(pAnc,pWin){
	if(!pWin)
		pWin="scrollbox"
	obj=window.top.frames[pWin].document.getElementById(pAnc)
	window.top.frames[pWin].scrollTo(0,obj.offsetTop)
}

function fnCalc(pNum){
	if(screen.width<1024)
		return pNum*800/1024
	else
		return pNum	
}	

function _Cookie(pCookie){
	var val=""
	var cookies=" "+document.cookie+";"
	var p=cookies.indexOf(" "+pCookie)+pCookie.length+1
	if(p>pCookie.length){
		val=unescape(cookies.substring(p,cookies.indexOf(";",p)))
	}	
	return val
}
function fnSetCookie(pCookie,pVer){
	var NAME=pCookie+"="
	if(_Cookie(NAME)!=pVer){
		document.cookie=NAME+escape(pVer)+"; path=/"
		return true
	}
	return false
}	
function fnGetCookie(pCookie){
	return _Cookie(pCookie+"=")
}	

function fnButton(me,pState){
	var section=document.URL.match(/(\d+x\d{3})/i)
	section="_section"+section[0]+"/"
	document.images[me.id+"IMG"].src=section+pState+".gif"
}	

function fnCheck(pRez){
	var obj=document.forms[0].I0ID_School
	var id=obj.options[obj.selectedIndex].value
	var sGotoURL
	fnSetCookie("Centre","-")
	if(id==""){
		alert("W.E.L.C.O.M.E. T.O. E.Z.O.N.E.\n\nBefore you enter please select\nyour School/Centre from the list.")
		obj.focus()
	}else if(fnSetCookie("Centre",obj.options[obj.selectedIndex].text)){
		if(fnGetCookie("jump")=="Y")
			sGotoURL=fnGetCookie("page")
		if(!sGotoURL)	
			sGotoURL="ezone"+pRez+".html"
		fnSetCookie("jump","")
		self.location.href="track.asp?id="+id+"&p="+sGotoURL
	}else
		alert("           E.R.R.O.R.\nPlease enable your Browser to acept Cookies") 
}

function fnCheckLogin(pID,pName){
	var sGotoURL
	var sRez=fnScreen()
	fnSetCookie("Centre","-")
	if(pID==""){
		alert("W.E.L.C.O.M.E. T.O. E.Z.O.N.E.\n\nBefore you enter please select\nyour School/Centre from the list.")
	}else if(fnSetCookie("Centre",pName)){
		if(fnGetCookie("jump")=="Y")
			sGotoURL=fnGetCookie("page")
		if(!sGotoURL)	
			sGotoURL="ezone"+sRez+".html"
		fnSetCookie("jump","")
		self.location.href="../track.asp?id="+pID+"&p="+sGotoURL
	}else
		alert("           E.R.R.O.R.\nPlease enable your Browser to acept Cookies") 
}

function fnChkMail(theForm){
	if(theForm.C1Email){
		var val=theForm.C1Email.value.toLowerCase()
		if(val.indexOf("dudley.gov.uk")<2){
			alert("You must provide a [dudley.gov.uk] email address")
			fnSetFocus(theForm.C1Email)
			return false
		}
	}
	return fnChkForm(theForm)		
}	

function fnGetUser(){
	return fnGetCookie("Centre")
}	

function fnShowUserName(){
	var obj=self.parent.document.getElementById("username")
	if(obj)
		obj.innerHTML="User : <b>"+fnGetUser()+"</b> | <a href=logout.html>Logout</a>"
}

function fnShowPNG(pFileName,pW,pH,pAlt){
	var img=(pW ? ' width="'+pW+'"' : "")
	img=img+(pH ? ' height="'+pH+'"' : "")
	img=img+(pAlt ? ' alt="'+pAlt+'"' : "")
	d.writeln("<img border=0 "+img)
	if(g_isPCie){
		var p=d.URL.match(/\S*(\/)/)
		p=(p[0] ? p[0]:p)
		d.writeln(' src="'+p+'_images\/x.gif"')
		d.writeln('style="filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''+pFileName+'\', sizingMethod=\'scale\')">')
	}else
		d.writeln('src="'+pFileName+'">')
}

function fnFullScreenLink(pFile){
	var p=window.location.pathname
	p=p.substr(0,p.lastIndexOf('/'))
	d.writeln('<a href="\/_flashfullscreen.html?f='+p+'\/'+pFile+'" target="_blank">'+
	'<img src="\/_images\/make-bigger.gif" alt="click to make bigger" width="20" height="20" border="0" \/>'+
	'<\/a>')
}
window.onload=_fixObjects

