

function Is() {
  var agent = navigator.userAgent.toLowerCase();
  this.major = parseInt(navigator.appVersion);
  this.minor = parseFloat(navigator.appVersion);
  this.ns = ((agent.indexOf('mozilla')!=-1) && ((agent.indexOf('spoofer')==-1) && (agent.indexOf('compatible') == -1)));
  this.ie = ((agent.indexOf("msie") != -1) && (agent.indexOf("opera") == -1));
  this.op = (agent.indexOf("opera") != -1);
}	// end browser sniffer
var is = new Is();

var bgImg, oldBgImg
//-------------------------------------------------------------------//
function getScrollXY() {
	/*
		How far has the window been scrolled?
	*/
	var scrOfX = 0, scrOfY = 0;
  	if( typeof( window.pageYOffset ) == 'number' ) {
    	//Netscape compliant
    	scrOfY = window.pageYOffset;
    	scrOfX = window.pageXOffset;
  	} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    	//DOM compliant
    	scrOfY = document.body.scrollTop;
    	scrOfX = document.body.scrollLeft;
  	} else if( document.documentElement &&
      	( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    	//IE6 standards compliant mode
    	scrOfY = document.documentElement.scrollTop;
    	scrOfX = document.documentElement.scrollLeft;
  	}
  	scrX = scrOfX;
  	scrY = scrOfY;
  	//return [ scrOfX, scrOfY ];
}
//-------------------------------------------------------------------//
function getAbsoluteLeft(oNode){		
	/*
		oNode as STRING now - don't forget!
	*/
   var oCurrentNode=document.getElementById(oNode);
   if (oCurrentNode != null) {
	  var iLeft=0;
   	  while(oCurrentNode.tagName!="BODY"){
      	iLeft+=oCurrentNode.offsetLeft;
      	oCurrentNode=oCurrentNode.offsetParent;
   	  }
   	  flash_left = iLeft
	}
}
//-------------------------------------------------------------------//
function getAbsoluteTop(oNode){		
	/*
		oNode as STRING now - don't forget!
	*/
   var oCurrentNode=document.getElementById(oNode);
   if (oCurrentNode != null) {
		var iTop=0;
   		while(oCurrentNode.tagName!="BODY"){
      		iTop+=oCurrentNode.offsetTop;
      		oCurrentNode=oCurrentNode.offsetParent;
   		}
   		flash_top = iTop
	}
}
//-------------------------------------------------------------------//
function getLeftAndTop(pageElement) {
	/*
		Calls both the position finding functions (see above)
		Page element now as String.  Should be OK with F***F** now.
	*/
	getAbsoluteLeft(pageElement)
	getAbsoluteTop(pageElement)
}
//-------------------------------------------------------------------//
function getBrowserDimensions() {
	windowHeight = document.body.clientHeight;
	windowWidth = document.body.clientWidth;
}
//-------------------------------------------------------------------//
function resizeBackground() {

	windowHeight = document.body.clientHeight;
	windowWidth = document.body.clientWidth;
	//
		
	//alert(imageFilename)
	if (is.ie) {
		currentImage = document.body.currentStyle.backgroundImage
		imageFilename = currentImage.substr(42,3)
		if ((windowWidth <= 1024) && (windowHeight <= 768)) {
			bgImg = 'url("http://www.barrycooper.org.uk/images/' + imageFilename + '.jpg")'
		} else {
			bgImg = 'url("http://www.barrycooper.org.uk/images/' + imageFilename + '-big.jpg")'
		}
	}
	
	if (is.ns) {
		currentImage = document.defaultView.getComputedStyle(document.body,"").backgroundImage
		imageFilename = currentImage.substr(41,3)
		if ((windowWidth <= 1024) && (windowHeight <= 768)) {
			bgImg = 'url("http://www.barrycooper.org.uk/images/' + imageFilename + '.jpg")'
		} else {
			bgImg = 'url("http://www.barrycooper.org.uk/images/' + imageFilename + '-big.jpg")'
		}
	
	}
	
	if (oldBgImg != bgImg) {
		document.body.style.backgroundImage = bgImg
	}
	oldBgImg = bgImg
	// url("http://www.barrycooper.org.uk/images/bg2.jpg")
}
//-------------------------------------------------------------------//
function resizeTextBox() {

	getScrollXY()
	getLeftAndTop("image")
	theImageHeight = theImage.offsetHeight
	if ((workseries != null) && (workseries)) {
		windowWidth = document.body.clientWidth;
		padding = 60
		availWid = windowWidth - (padding * 3)
		theImage.style.width = availWid / 2
		theTextBox.style.width = availWid / 2
		theTextBox.style.left = padding - 20
		topPadd = ((document.body.clientHeight - 400) / 2) - 80
		if (topPadd < 0) { topPadd = 0 }
		if (is.ns) {
			theImage.style.margin = topPadd + "px 50px 0 0"
			theTextBox.style.margin = topPadd + "px 0px 0 0"
		} else {
			theImage.style.margin = topPadd + "px 20px 0 0"
			theTextBox.style.margin = topPadd + "px 0px 0 0"
		}
		//theTextBox.style.top = (document.body.clientHeight / 2) - (theTextBox.offsetHeight / 2) - 80
		//theImage.style.top = (document.body.clientHeight / 2) - (theImage.offsetHeight / 2) - 80
	}
	else {
		theTextBox.style.width = flash_left - 80
	}
	
	theTextBox.style.height = 400
	if ((workseries != null) && (workseries)) {
		theImage.style.height = theTextBox.offsetHeight
	}
	
	
}
//-------------------------------------------------------------------//
function positionFS() {
	/*
		Position the "Full Screen" link
	*/
	

}
//-------------------------------------------------------------------//
function centreImage() {
	document.getElementById("image").style.float="none"
	document.getElementById("image").style.margin="auto"
	document.getElementById("image").style.textAlign="center"
	document.getElementById("image").style.width="100%"
	if (indexPage != null) {
		document.getElementById("image").style.position = "absolute"
		document.getElementById("image").style.top = (document.body.clientHeight / 2) - (document.getElementById("image").offsetHeight / 2) - 80
		document.getElementById("image").style.left = (document.body.clientWidth / 2) - (document.getElementById("image").offsetWidth / 2)
		if (document.getElementById("image").offsetTop < 0) { document.getElementById("image").style.top = 0 }
	}

}
//-------------------------------------------------------------------//
doBackground = function() {
	/*
		For now, we're going to assume that every page has an image.  We'll fix this so that even if
		no image is selected from the gallery admin, we'll write a 1px square blank gif in.
	*/
	resizeBackground()
	
	if (isText) {
		resizeTextBox()
	} else {
		centreImage()	
	}
	positionFS()
}
//-------------------------------------------------------------------//
window.onresize = doBackground
window.onscroll = doBackground

startList = function() {

	// Assorted variables.
// Variables used in deciding top and left of elements
	flash_top = 0
	flash_left = 0

// Give the page elements and other useful values some understandable names
	theBackground = document.getElementById("background")
	theTextBox = document.getElementById("thetext")
	theActualText = document.getElementById("actualtext")
	theImage = document.getElementById("image")
	theFS = document.getElementById("fs")
	var windowHeight, windowWidth

// Do the text and image elements exist?
	isText = (theTextBox != null)
	isImage = (theImage != null)
	
// How far has the page been scrolled?
	var scrX, scrY


// Get window height and width
	getBrowserDimensions()
// Resize everything
	resizeBackground()
	if (isText) {
		resizeTextBox()
	} else {
		centreImage()
	}
	positionFS()
	

// Javascript to let the cascading menus work in IE
// Only if it's a suitable browser
	if (document.all&&document.getElementById) {
	navRoot = document.getElementById("menulist");
	for (i=0; i<navRoot.childNodes.length; i++) {
	node = navRoot.childNodes[i];
	if (node.nodeName=="LI") {
	node.onmouseover=function() {
	//alert(this.className)
	if (this.className == "orangeshade") {
		this.className+="over";
	}
	  }
	  node.onmouseout=function() {
	 // alert(this.className)
	  this.className=this.className.replace("over", "");
	   }
	   }
	  }
	 }
	 
if ((isText) && (isImage)) {
	theTextBox.style.visibility = "visible"
	theImage.style.visibility = "visible"
}
	
}
	
window.onload=startList;

function fullScreen() {
	thisPage = window.location
	thisPage = thisPage + "?fs=true"
	window.open(thisPage, "bigg", "fullscreen=yes")
}