// JavaScript Document
function gallery (bg_divId, imageId)
{
	this.bgID = bg_divId;
	this.imgID = imageId;
	this.delay = 3000,
	this.imagearray = new Array();
	this.imageindex = 0;
	
	var timer = null;
	
	this.addimage = addimage;
	this.start = start;
	
	function addimage(imageurl)
	{
		this.imagearray.push(imageurl);
	}
	
	function start()
	{
		var _self = this;
		if(_self.imagearray.length > 1)
		{
		
		//$(_self.imgID).src = _self.imagearray[_self.imageindex];  //sets image
		
		new Effect.Opacity(_self.imgID, 
			{
				duration: 2.0, 
				from: 0.0, to: 1.0,
				beforeStart: function ()
				{
					$(_self.imgID).style.filter = 'alpha(opacity=0)';
					$(_self.imgID).style.MozOpacity = '0.0';
					$(_self.imgID).style.opacity = '0.0';
					$(_self.imgID).src = _self.imagearray[_self.imageindex];
					$(_self.imgID).style.visibility = 'visible';
				},
				afterFinish: function ()
				{
					$(_self.bgID).style.backgroundImage = 'url('+$(_self.imgID).src+')';
					_self.imageindex++;
					if(_self.imageindex >= _self.imagearray.length)
					{
						_self.imageindex = 0;
					}
					$(_self.imgID).style.visibility = 'hidden';
				}
			});
			//$(_self.imgID).src = _self.imagearray[_self.imageindex];
			//_self.imageindex++;
		timer = setTimeout(function (ms) { _self.start(); }, _self.delay );
		}
		else
		{
			$(_self.imgID).src = _self.imagearray[_self.imageindex];
		}
		
	}
	

}


// Function to remove white spaces from nodes
function removeWhitespace(node) 
{
	var loopIndex;
	
	for (loopIndex = 0; loopIndex < node.childNodes.length; 
	  loopIndex++) {
	
	  var currentNode = node.childNodes[loopIndex];
	
	  if (currentNode.nodeType == 1) {
		removeWhitespace(currentNode);
	  }
	
	  if (((/^\s+$/.test(currentNode.nodeValue))) &&   
		(currentNode.nodeType == 3)) {
		  node.removeChild(node.childNodes[loopIndex--]);
	  }
	}
}
function uncache (url){
	return url + '?uncache=' + new Date().getTime();
}
function getSize(type) {
  var myWidth = 0;
  var myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  if(type == 'height')
  {
  	return myHeight;
  }
  if(type == 'width')
  {
  	return myWidth;
  }
}

function generatebioslist(node)
{
	var col = document.createElement('div');
	col.className = 'boardcol';
	var col2 = document.createElement('div');
	col2.className = 'boardcol';
	for( var i=0; i < node.length; i++)
	{
		var a = document.createElement('div');
		a.innerHTML = node[i].name;
		if(node[i].title)
		{ 
			var title = document.createElement('div');
			title.className = 'boardofdirectors_title';
			title.innerHTML = node[i].title; 
			a.appendChild(title);
		}
		
		a.className='boardofdirectors_listOff';
		a.setAttribute('rel', i);
		
		a.onmouseover = function (e)
		{
			if (!e) var e = window.event;
			this.className='boardofdirectors_listOver';
			$('board_name').innerHTML = this.innerHTML;
			var index = parseInt(this.getAttribute('rel'));
			$('boardofdirectors_preview').style.display = 'block';
			$('previewImage').src = node[index].image;
			$('boardofdirectors_wrapper').style.backgroundImage = 'url(images/boardofdirectors_box_bg.gif)';
		}		
		if (a.captureEvents) a.captureEvents(Event.ONMOUSEOVER);
		
		a.onmouseout = function (e)
		{
			if (!e) var e = window.event;
			this.className='boardofdirectors_listOff';
			$('board_name').innerHTML = '';
			$('boardofdirectors_preview').style.display = 'none';
			$('boardofdirectors_wrapper').style.backgroundImage = 'url(none)';
		}		
		if (a.captureEvents) a.captureEvents(Event.ONMOUSEOUT);
		
		a.onclick = function (e)
		{
			if (!e) var e = window.event;
			openBioWindow('popup.php?index='+parseInt(this.getAttribute('rel')));
		}		
		if (a.captureEvents) a.captureEvents(Event.ONCLICK);
		
		
		
		col.appendChild(a);
		$('boardofdirectors_list').appendChild(col);
	}
	
}

function openBioWindow(theURL) { 
	var height = getSize('height');
	var width = getSize('width');
	var popupwidth = 415;
	//if (window.focus) {newwindow.focus()}
	//alert(Bios.focus());
  	var popup = window.open(theURL,'Bios', 'resizable=0, scrollbars=yes, height=500, width='+popupwidth+', left='+(width/2-popupwidth/2)+', top=50');
	popup.focus();
}
