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() {
	
	whiteSpace = 200
	theTextBox.style.width = (document.body.clientWidth - whiteSpace) + "px"
	
		theTextBox.style.height = "400px"
	
	// Let's try this...
	theTextBox.style.left = (whiteSpace/2) - 20
	theTextBox.style.top = (document.body.clientHeight / 2) - (theTextBox.offsetHeight / 2) - 80
}
//-------------------------------------------------------------------//
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%"

}
//-------------------------------------------------------------------//
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()
		resizeTextBox()
	
	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()
if (isText) {
	theTextBox.style.visibility = "visible"
}

// 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", "");
	   }
	   }
	  }
	 }
	 
	 /*	We'll also put some code in here to check the query string.  If fs-true, then we're in full screen mode
	 	and we need to change back to windowed mode */
	qStr = window.location.search
	if (qStr == "?fs=true") {
		document.getElementById("fs").innerHTML = "<a href=\"javascript:window.close()\" style=\"color: red;\">Exit Full Screen</a>"
	}
	
}
	
window.onload=startList;

function fullScreen() {
	thisPage = window.location
	thisPage = thisPage + "?fs=true"
	window.open(thisPage, "bigg", "fullscreen=yes")
}