function getWindowHeight()
{
    var windowHeight=0;
    if (typeof(window.innerHeight)=='number') {
        windowHeight=window.innerHeight;
    } else {
        if (document.documentElement && document.documentElement.clientHeight) {
            windowHeight = document.documentElement.clientHeight;
        } else {
            if (document.body&&document.body.clientHeight) {
                windowHeight=document.body.clientHeight;
            }
        }
    }

    return windowHeight;
}

function getScrollHeight()
{
    var scrollHeight=0;
    if (typeof(window.scrollHeight)=='number') {
        scrollHeight=window.scrollHeight;
    } else {
        if (document.documentElement && document.documentElement.scrollHeight) {
            scrollHeight = document.documentElement.scrollHeight;
        } else {
            if (document.body&&document.body.scrollHeight) {
                scrollHeight=document.body.scrollHeight;
            }
        }
    }

    return scrollHeight;
}


// this set of functions powers the class="button" css rollovers
var W3CDOM = (document.createElement && document.getElementsByTagName);

function addButtonRollovers() {
	if (!W3CDOM) return;
	var divs = document.getElementsByTagName("a");
	for (var i=0; i<divs.length; i++) {
		if (divs[i].className.indexOf('button') >= 0) {
			divs[i].rollPosition = "-"+(divs[i].offsetWidth+0)+"px";
			divs[i].onmouseover = buttonRollOver;
			divs[i].onmouseout = buttonRollOut;
		}
	}
}
function buttonRollOver() {
	this.style.backgroundPosition = this.rollPosition;
}
function buttonRollOut() {
	this.style.backgroundPosition = "0 0";
}


/** 
 * function to allow us to add multiple onload events which works on all browsers
 * (including IE / Mac!)
 * From: http://liorean.web-graphics.com/scripts/themeswitch.html 
 **/

var loadEventHandler={  // The Event Handler main object
  Add:function(f){  // Function for adding onload handlers
    loadEventHandler.col[loadEventHandler.col.length]=f;  // Add event handler to collection
    if(typeof window.addEventListener!='undefined')  // If W3C compliant
      window.addEventListener('load',f,false);  // Apply event handler
    else if(!loadEventHandler.ieSet)  // Otherwise, unless already set
      if(typeof document.onreadystatechange!='undefined')  // If supported
        document.onreadystatechange=loadEventHandler.onload;  // Add In event handler handler
    loadEventHandler.ieSet=true;  // Specify that event handler already is set
    return(typeof window.addEventListener!='undefined')  // Return whether W3C compliant
  },
  onload:function(){  // Function for handling multiple onload handlers in IE
    var m=/mac/i.test(navigator.platform);  // Detect whether mac
    if(typeof document.readyState!='undefined')  // If supported
      if(m?document.readyState!='interactive':document.readyState!='complete')  // And not already finished
        return;  // Exit
    for(var i=0,f;(f=(i<loadEventHandler.col.length)?loadEventHandler.col[i]:null);i++)  // For all event handlers
      f();  // Run event handler
    return  // Exit
  },
  ieSet:false,  // Variable to say whether event handler is set or not
  col:[]  // Collection for event handlers
};

loadEventHandler.Add(addButtonRollovers);

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

// Preload Images

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

// Confirmation Dialog

function confirmSubmit()
{
var agree=confirm("Are you sure you wish to submit this form? Have you completed all relevant fields? Click 'OK' to continue or click 'Cancel' if you wish to make a change.");
if (agree)
	return true ;
else
	return false ;
}

function confirmRemove()
{
var agree=confirm("Are you sure you wish to remove this item? It will be deleted permanently.");
if (agree)
	return true ;
else
	return false ;
}

// JavaScript Document

var images = new Array(					   
					   'images/slides/reception-3.jpg',
						'images/slides/boardroom-1.jpg',
						'images/slides/interview-1.jpg',
						'images/slides/reception-1.jpg',
						'images/slides/boardroom-2.jpg',
						'images/slides/interview-2.jpg',
						'images/slides/reception-1.jpg',
						'images/slides/boardroom-2.jpg',
						'images/slides/interview-3.jpg'
					   );

var imageWidth = 395;
var imageHeight = 395;
var imageTimeout = 4000;
var nextImage = 1;

function setOpacity(el, opacity) { //  Which opacity method does this browser support?

	opacity /= 100;

	el.style.opacity = opacity;
	el.style.MozOpacity = opacity;
	el.style.filter = "alpha(opacity=" + (opacity*100) + ")";

}

function fadeImage(el, currentOpacity) {

	currentOpacity += 5;

	if (currentOpacity > 100) {
		setOpacity(el, 100);
		var prevEl = el.previousSibling ? el.previousSibling : el.parentNode.lastChild;
		prevEl.style.visibility = 'hidden';
		el.style.zIndex = 1;
		window.setTimeout(startFading, imageTimeout);
	}
	else {
		setOpacity(el, currentOpacity);
		window.setTimeout(function() { fadeImage(el, currentOpacity); }, 50);
	}
}

function startFading() {

	var el = document.getElementById('slideshow').childNodes[nextImage];

	el.style.visibility = 'visible';
	el.style.zIndex = 2;
	setOpacity(el, 0);
	fadeImage(el,0);

	nextImage = (nextImage < images.length-1) ? nextImage + 1 : 0;
}

function pageLoad() {

	var el = document.getElementById('slideshow');

	while (el.firstChild) { el.removeChild(el.firstChild); }

	el.style.width = imageWidth + 'px';
	el.style.height = imageHeight + 'px';

	for(var i=0; i<images.length; i++) {

		var t = document.createElement('IMG');
		t.setAttribute('src',images[i]);
		t.setAttribute('width',imageWidth);
		t.setAttribute('height',imageHeight);
		t.style.position = 'absolute';
		t.style.visibility = 'hidden';
		el.appendChild(t);

	}

	el.firstChild.style.visibility = 'visible';

	window.setTimeout(startFading, imageTimeout);

}

addLoadEvent(pageLoad);
