var	setHeight = function(obj , row) {
	
			var elements = $$(obj);
			var height = 0;
			var itemHeight = 0;
	
			elements.each(function(item, index){
				height = 0;
				listItems =  item.getChildren(row);			
				listItems.each(function(listItem,listIndex){
					itemHeight= parseFloat(listItem.getStyle('height').replace('px',''));
					if (itemHeight > height){
						height = itemHeight;
					}
				});
				listItems.setStyle('height' , height+'px');
			});
	
	}
var imageReplace = function(){
		
	this.element = null;
	this.font = '';
	this.size = 20;
	this.styles = null;
	this.chars = 40;
	this.color = null;
	this.background = null;
	
	this.replace = function(){	
	
		var elements = $$(this.element);
		var tag;
		var text;
		var color;
		var background;
		var colorString;
		var backgroundString;
		var children;
		var size = this.size;
		var options = null;	
		var setLink = 0;
		var linkHref = '';
		var that = this;
		var selectedItem = null;
		
		if (elements.length < 1) {
			return false;
		}
		elements.each(function(item, index){
			
			selectedItem = item;
			text = item.getText().clean();	
			color = that.color != null ? that.color.hexToRgb(true) : item.getStyle('color').hexToRgb(true);
			background = that.background != null ? that.background.hexToRgb(true) : item.getStyle('background-color').hexToRgb(true);
							
			children = item.getChildren();
						
			if (children.length == 1) {
				if ($(children[0]).getTag() == 'a'){
					setLink = 1;
					linkHref = $(children[0]).getProperty('href');
					$(children[0]).setStyles({ display : 'block' });
				}
			}
			
			if (item.getProperty('rel')){
				options = eval('(' + item.getProperty('rel') + ')' );			
				that.size = options.size != undefined ? options.size : '' ;
				item.removeProperty('rel');
			}
			
			colorString = '&r=' + color[0] + '&g=' + color[1] + '&b=' + color[2];

			if (background == false){
				backgroundString = '&br=255&bg=255&bb=255';
			} else {
				backgroundString = '&br=' + background[0] + '&bg=' + background[1] + '&bb=' + background[2];
			}
			
			if (that.font == undefined) {
				that.font = '';
			}

			var html = '';
				html += setLink == 1 ? '<a href="' + linkHref + '">' : '' ;
				html += '<img src="images/titles/image.php?text=' + escape(text) + colorString + '&size=' + that.size + backgroundString + '&font=' + that.font.trim() + '&chars=' + that.chars + '" border="0" alt=""/>';
				html += '<div class="hidden">' + text + '</div>';
				html += setLink == 1 ? '</a>' : '' ;
			item.setHTML(html);
			
			if (that.styles != null) {
				item.setStyles(that.styles);
			}
		});
	}
}

var featureImage = function() {
	
	this.imageList = null;
	this.featureObj = null;
	this.featureLen = null;
	this.autoTime = 4000;
	this.featureCount = 0;
	this.featureLen = null;
	this.fadeSpeed = 800;
	this.zindex = 1;

	this.load = function (container){
		
	$$('#' + container + ' div').setStyles({opacity: 0});
	this.imageList = $$('#' + container + ' div');
	this.featureLen = (this.imageList).length;
	
	this.set();
		
		// imageOff hides all features. This is removed from them all when first image has faded in.
		setTimeout(function(){ $$('#' + container + ' div').removeClass('imageOff') }, this.fadeSpeed);
	}
	
	this.set = function  (){
		
		this.featurObj = this.imageList[this.featureCount];
		$(this.featurObj).setStyles({'z-index' : this.zindex  ,  opacity: 0});
		$(this.featurObj).fx = $(this.featurObj).effect('opacity', {duration: 800}).start(1);
		this.increment();
		
		// once images have rotated once, reset the z-index to 1 to prevent images overlapping anything else.
		if (this.featureCount == 0){
			this.imageList.setStyles({'z-index' : 1})
			this.zindex = 1;
		}
		this.zindex = this.zindex+1;
		
		var that = this; // 'this' is out of scope in setTimeout
		setTimeout(function(){ that.set() } , this.autoTime);
	}
	
	this.increment = function (){
		if (this.featureCount >= this.featureLen-1){
			this.featureCount = 0;
		} else {
			this.featureCount++;
		}
	}
}
	/***************************************************************************/
	
// based on http://www.alistapart.com/articles/dropdowns and http://www.htmldog.com/articles/suckerfish/dropdowns/
if ((document.all) && (document.getElementById)) {
	function MenuListElementHoverFix() {
		var _this	= this;
		
		if (typeof(Array.prototype.push) == 'undefined') {
			// IE < 5.5 does not support push/pop
			function push() {
				var j = this.length;
				for (var i = 0; i < push.arguments.length; ++i) {
					this[j] = push.arguments[i];
					j++;
				}
			}
			function pop() {
				var i = this[this.length - 1];
				this.length--;
				return i;
			}
			Array.prototype.push	= push;
			Array.prototype.pop		= pop;
		}
		
		this.className				= 'hover';	// change the class name to use here if you are not happy with it
		this.classNameSuffix		= ' ' + this.className;
		this.removeClassNameRegExp	= new RegExp("\\b ?" + this.className + "\\b");
		this.hoverElementStack		= new Array();
		
		this.onmouseover	= function() {
			if (!_this.isHover(this)) {
				if (this.getAttribute('is_hover_class_removing') != 'true') {
					this.className	+= _this.classNameSuffix;
				}
				this.setAttribute('is_hover', 'true');
			}
		}
		this.isHover	= function(element) {
			return (element.getAttribute('is_hover') == 'true');
		}
		this.checkNonHoverState	= function(element) {
			if (!_this.isHover(element)) {
				element.className	= element.className.replace(_this.removeClassNameRegExp, '');
			}
			element.removeAttribute('is_hover_class_removing');
		}
		this.checkLastNonHoverState	= function() {
			var hoverElement	= null;
			if (_this.hoverElementStack.length > 0) {
				hoverElement	= _this.hoverElementStack.pop();
			}
			for (var i = _this.hoverElementStack.length - 1; i >= 0; i--) {
				// we need to apply the "non-hover" class to the children first - else the result is mixed in the IE
				var o = _this.hoverElementStack[i];
				while (o != null) {
					o	= o.offsetParent;
					if (o == hoverElement) {
						_this.checkNonHoverState(_this.hoverElementStack[i]);
						break;
					}
				}
			}
			if (hoverElement != null) {
				_this.checkNonHoverState(hoverElement);
			}
		}
		this.onmouseout		= function() {
			// all this mess to not change the class immediately (which would cause flickering in the IE)
			this.setAttribute('is_hover', 'false');
			if (this.getAttribute('is_hover_class_removing') != 'true') {
				this.setAttribute('is_hover_class_removing', 'true');
				_this.hoverElementStack.push(this);
				window.setTimeout(_this.checkLastNonHoverState, 100);
			}
		}
		this.fixElement		= function(elementRoot) {
			for (var i=0; i < elementRoot.childNodes.length; i++) {
				var node = elementRoot.childNodes[i];
				if (node.nodeName == "LI") {
					node.onmouseover	= this.onmouseover;
					node.onmouseout		= this.onmouseout;
				}
				this.fixElement(node);
			}
		};
		this.findElement	= function(elementRoot) {
			for (var i=0; i< elementRoot.childNodes.length; i++) {
				var node = elementRoot.childNodes[i];
				if (node.nodeName == "UL") {
					//if ((node.id != '') && ((node.id.indexOf("menu") >= 0) || (node.id.indexOf("nav") >= 0))) {
						this.fixElement(node);
						continue;	// do not iterate through children of already fixed element
					//}
				}
				this.findElement(node);
			}
		};
		this.fix			= function() {
			var node = document.body;
			if (node) {
				_this.findElement(node);
			}
		}
		this.addOnLoad		= function() {
			
			
			if (window.attachEvent) {
				window.attachEvent("onload", this.fix);
			} else {
				window.onload	= this.fix;
			}
		}
	}
	(new MenuListElementHoverFix()).addOnLoad();
}