// JavaScript Document
// 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;
  }
}
