var ElementMaxHeight = function() {
  this.initialize.apply(this, arguments);
}

ElementMaxHeight.prototype = {
  initialize: function(className) {
    this.elements = document.getElementsByClassName(className || 'maxheight');    
    this.textElement = document.createElement('span');
    this.textElement.appendChild(document.createTextNode('A'));
    this.textElement.style.display = 'block';
    this.textElement.style.position = 'absolute';
    this.textElement.style.fontSize = '1em';
    this.textElement.style.top = '-1000px';
    this.textElement.style.left = '-1000px';
    document.body.appendChild(this.textElement);
    this.textElementHeight = document.getDimensions(this.textElement).height;
    var __object = this;
    var __checkFontSize = this.checkFontSize;
    this.checkFontSizeInterval = window.setInterval(function() {return __checkFontSize.apply(__object)}, 500);

    this.expand();

    // Refresh elements height onResize event
    var __expand = this.expand;
    if (window.addEventListener) {
      window.addEventListener('resize', function(event) {return __expand.apply(__object, [( event || window.event)])}, false);
    } else if (window.attachEvent) {
      window.attachEvent('onresize', function(event) {return __expand.apply(__object, [( event || window.event)])});
    }
  },

  expand: function() {
    this.reset();
  	for (var i = 0; i < this.elements.length; i++) {  	
      this.elements[i].style.height = document.getDimensions(this.elements[i].parentNode).height + 'px';
  	}
  },

  reset: function() {
    for (var i = 0; i < this.elements.length; i++) {    
      this.elements[i].style.height = 'auto';
    }
  },

  checkFontSize: function() {
  	var height = document.getDimensions(this.textElement).height;
  	if(this.textElementHeight != height) {
  		this.textElementHeight = height;
  		this.expand();
  	}
  }  
}


if (!!document.evaluate) {
  document._getElementsByXPath = function(expression, parentElement) {
    var results = [];
    var query = document.evaluate(expression, parentElement || document,
      null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
    for (var i = 0, length = query.snapshotLength; i < length; i++)
      results.push(query.snapshotItem(i));
    return results;
  }
}

document.getElementsByClassName = function(className, parentElement) {
  if (!!document.evaluate) {
    var q = ".//*[contains(concat(' ', @class, ' '), ' " + className + " ')]";
    return document._getElementsByXPath(q, parentElement);
  } else {
    var children = (parentElement || document.body).getElementsByTagName('*');
    var elements = [], child;
    for (var i = 0, length = children.length; i < length; i++) {
      child = children[i];
      if (child.className.length != 0 &&
          (child.className == className ||
           child.className.match(new RegExp("(^|\\s)" + className + "(\\s|$)")))) {      
        elements.push(child);
      }
    }
    return elements;
  }
}

document.getDimensions = function (element) {
  var display = element.style.display;
  if (display != 'none' && display != null) { // Safari bug
    return {width: element.offsetWidth, height: element.offsetHeight};
  }

  return {width: originalWidth, height: originalHeight};
}







// image CROSS-OVER fading slideshow written by paul@pioneerwebsites.com.au
	// -------- full file names in each pages head script
function imagefaderF() {
	randomise='no'; // yes or no
	spot=document.getElementById('block_head'); // id of div
	wait=3000; // pause at full opacity in milliseconds but mainly adjust through next two
	blendfactor=2; // 1 to (100/blendbase) try 70
	blendrate=50; // 1 to 100 (milliseconds inbetween frames) try 80
// -----------------------------------------------------------------------------
blendbase=1; //
function randOrd(){return (Math.round(Math.random())-0.5);}
	aobr=blendfactor.toFixed(0); obr=(aobr/100).toFixed(2); z=0; if (randomise=='yes') {slidei.sort(randOrd)};
	for (y=0; y<slidei.length; y++) {
		extra=document.createElement('img'); 
		extra.setAttribute("src", slidei[y]); 
		extra.setAttribute("id", "fader"+y);
		if (y==0) {
			extra.style.cssText='opacity: 1.0; filter: alpha(opacity=100); position: absolute; top: 0px; left: 0px;'; 
		} else {
			extra.style.cssText='opacity: 0.0; filter: alpha(opacity=0); position: absolute; top: 0px; left: 0px;'; 
		}
		spot.appendChild(extra);
	}
	// spot.style.cssText='position: relative;';
	count=0; ao=100; o=1; aonxt=0; onxt=0; 
	setTimeout('trans();',(wait*2))
}

function trans() {// document.getElementById('debug').innerText=document.body.innerHTML;
	ao-=aobr; o-=obr; o=parseFloat(o).toFixed(2); aonxt=parseFloat(aonxt)+parseFloat(aobr); onxt=parseFloat(onxt)+parseFloat(obr); onxt=parseFloat(onxt).toFixed(2);
	document.getElementById('fader'+z).style.opacity=o; document.getElementById('fader'+z).style.filter='alpha(opacity='+ao+')';
	if (z==(slidei.length-1)) {
		znxt=0;
	} else {
		znxt=z+1;
	}
	document.getElementById('fader'+znxt).style.opacity=onxt; document.getElementById('fader'+znxt).style.filter='alpha(opacity='+aonxt+')';
	count++;
	if (count<(((100/blendbase+1)-blendfactor)*blendbase)) { // alert(z+'.  pic:'+znxt+'. ao, o: '+ao+','+o+'ao,onext: '+aonxt+','+onxt);
		setTimeout("trans();",blendrate)
	} else { // alert(z+'.  pic:'+znxt+'. ao, o: '+ao+','+o+'ao,onext: '+aonxt+','+onxt);
		setTimeout("count=0; ao=100; o=1; aonxt=0; onxt=0; z++; if (z==slidei.length) {z=0;}; trans();",wait);
	}
}
// end CROSS-OVER image fading slideshow
