/**
* Browser version detection
*/
var ns4 = false; // to be set later...
var ieversion = 0, opversion = 0, koversion = 0, saversion = 0, ua = navigator.userAgent.toLowerCase();

if (ua.indexOf("msie")!=-1 && ua.indexOf("opera")==-1){
temp=ua.split("msie");
ieversion=parseFloat(temp[1]);
}
else if (ua.indexOf("opera")!=-1){
temp=ua.split("opera");
temp[1] = temp[1].replace("/","");
opversion=parseFloat(temp[1]);
} 

else if (ua.indexOf("safari")!=-1 && ua.indexOf("chrome")==-1) {
	temp=ua.split("version");
	temp[1] = temp[1].replace("/","");
	saversion = parseFloat(temp[1]);
}
else if (ua.indexOf("konqueror")!=-1) {
	temp=ua.split("khtml");
	temp[1] = temp[1].replace("/","");
	koversion = parseFloat(temp[1]);
}

// String.trim emuláció
String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ''); }
String.prototype.ltrim = function() { return this.replace(/^\s+/g, ''); }
String.prototype.rtrim = function() { return this.replace(/^\s+$/g, ''); }
String.prototype.trimall = function() { return this.replace(/\s+/g, ''); }
String.prototype.unspace = function() { return this.replace(/\s+/g, ' '); }

// -- Array function emulations

// Array.concat() - Join two arrays
if( typeof Array.prototype.concat==='undefined' ) {
	Array.prototype.concat = function( a ) {
		for( var i = 0, b = this.copy(); i<a.length; i++ ) {
			b[b.length] = a[i];
		}
		return b;
	};
}

// Array.copy() - Copy an array
if( typeof Array.prototype.copy==='undefined' ) {
	Array.prototype.copy = function() {
		var a = [], i = this.length;
		while( i-- ) {
			a[i] = typeof this[i].copy!=='undefined' ? this[i].copy() : this[i];
		}
		return a;
	};
}

// Array.pop() - Remove and return the last element of an array
if( typeof Array.prototype.pop==='undefined' ) {
	Array.prototype.pop = function() {
		var b = this[this.length-1];
		this.length--;
		return b;
	};
}

// Array.push() - Add an element to the end of an array, return the new length
if( typeof Array.prototype.push==='undefined' ) {
	Array.prototype.push = function() {
		for( var i = 0, b = this.length, a = arguments, l = a.length; i<l; i++ ) {
			this[b+i] = a[i];
		}
		return this.length;
	};
}

// Array.shift() - Remove and return the first element
if( typeof Array.prototype.shift==='undefined' ) {
	Array.prototype.shift = function() {
		for( var i = 0, b = this[0], l = this.length-1; i<l; i++ ) {
			this[i] = this[i+1];
		}
		this.length--;
		return b;
	};
}

// Array.slice() - Copy and return several elements
if( typeof Array.prototype.slice==='undefined' ) {
	Array.prototype.slice = function( a, c ) {
		var i, l = this.length, r = [];
		if( !c ) { c = l; }
		if( c<0 ) { c = l + c; }
		if( a<0 ) { a = l - a; }
		if( c<a ) { i = a; a = c; c = i; }
		for( i = 0; i < c - a; i++ ) { r[i] = this[a+i]; }
		return r;
	};
}

// Array.splice() - Remove or replace several elements and return any deleted elements
if( typeof Array.prototype.splice==='undefined' ) {
	Array.prototype.splice = function( a, c ) {
		var i = 0, e = arguments, d = this.copy(), f = a, l = this.length;
		if( !c ) { c = l - a; }
		for( i; i < e.length - 2; i++ ) { this[a + i] = e[i + 2]; }
		for( a; a < l - c; a++ ) { this[a + e.length - 2] = d[a - c]; }
		this.length -= c - e.length + 2;
		return d.slice( f, f + c );
	};
}

// Array.unshift() - Add an element to the beginning of an array
if( typeof Array.prototype.unshift==='undefined' ) {
	Array.prototype.unshift = function() {
		this.reverse();
		var a = arguments, i = a.length;
		while(i--) { this.push(a[i]); }
		this.reverse();
		return this.length;
	};
}
// -- Additional functions

// Array.forEach( function ) - Apply a function to each element
Array.prototype.forEach = function( f ) {
	var i = this.length, j, l = this.length;
	for( i=0; i<l; i++ ) { if( ( j = this[i] ) ) { f( j ); } }
};

// Array.indexOf( value, begin, strict ) - Return index of the first element that matches value
Array.prototype.indexOf = function( v, b, s ) {
	for( var i = +b || 0, l = this.length; i < l; i++ ) {
		if( this[i]===v || s && this[i]==v ) { return i; }
	}
	return -1;
};

// Array.insert( index, value ) - Insert value at index, without overwriting existing keys
Array.prototype.insert = function( i, v ) {
	if( i>=0 ) {
		var a = this.slice(), b = a.splice( i );
		a[i] = v;
		return a.concat( b );
	}
};

// Array.lastIndexOf( value, begin, strict ) - Return index of the last element that matches value
Array.prototype.lastIndexOf = function( v, b, s ) {
	b = +b || 0;
	var i = this.length;
	while(i-->b) {
		if( this[i]===v || s && this[i]==v ) { return i; }
	}
	return -1;
};

// Array.random( range ) - Return a random element, optionally up to or from range
Array.prototype.random = function( r ) {
	var i = 0, l = this.length;
	if( !r ) { r = this.length; }
	else if( r > 0 ) { r = r % l; }
	else { i = r; r = l + r % l; }
	return this[ Math.floor( r * Math.random() - i ) ];
};

// Array.shuffle( deep ) - Randomly interchange elements
Array.prototype.shuffle = function( b ) {
	var i = this.length, j, t;
	while( i ) {
		j = Math.floor( ( i-- ) * Math.random() );
		t = b && typeof this[i].shuffle!=='undefined' ? this[i].shuffle() : this[i];
		this[i] = this[j];
		this[j] = t;
	}
	return this;
};

// Array.unique( strict ) - Remove duplicate values
Array.prototype.unique = function( b ) {
	var a = [], i, l = this.length;
	for( i=0; i<l; i++ ) {
		if( a.indexOf( this[i], 0, b ) < 0 ) { a.push( this[i] ); }
	}
	return a;
};

// Array.walk() - Change each value according to a callback function
Array.prototype.walk = function( f ) {
	var a = [], i = this.length;
	while(i--) { a.push( f( this[i] ) ); }
	return a.reverse();
};


/**
* document.getElementsByClassName() Emulation
*/
var setGetElementsByClassNameEmulation = function() {
	if (typeof(document.getElementsByClassName) !== 'undefined') return;

	//Document = (document.constructor) ? document.constructor : (document.documentElement) ? document.documentElement : document.all; 
	
	var getElementsByClassName = function(cn) {
		//trace(this);
		if (!cn || typeof cn != "string") 
			return false;
		var el = this.all ? this.all : this.getElementsByTagName('*');
		var elements = [];
		for (i in el) {
			if(el[i].className && (el[i].className == cn || new RegExp("(^|\\s)" + cn + "(\\s|$)").test(el[i].className)))
				elements.push(el[i]);
		}
		return elements;
	}
	
	if (document.constructor) {
		document.constructor.prototype.getElementsByClassName = getElementsByClassName;
		/*HTMLElement = document.createElement("x").constructor;*/
		/*HTMLElement.prototype.getElementsByClassName = */
	} else {
		document.getElementsByClassName = getElementsByClassName;
		//Object.prototype.getElementsByClassName = getElementsByClassName;
	}
	var allTags = document.getElementsByTagName('*');
	for (i in allTags) {
		allTags[i].getElementsByClassName = getElementsByClassName;
		//trace(allTags[i].tagName);
	}
}




/*******************
* Common functions *
********************/
function get(el) {
	return (typeof el == "string") ? window.document.getElementById(el) : el;
}
function getEventTarget(evt) {
	return (evt.srcElement) ? evt.srcElement : evt.target;
}
function getNextFormElement(formElement) {
	var _this = get(formElement);
	for (var i = 0, len = _this.form.elements.length-1; i < len; i++) {
		if (_this.form.elements[i]==_this) {
			return _this.form.elements[i+1];
			break;
		}
	}
	return false;
}
function getParent(_this, parentTagName) {
	var element = _this.parentNode;
	do {	
		if (element.tagName.toLowerCase() == parentTagName) return element; 	
	} while(element = element.parentNode);
	return false;
}
function collectionToArray(col) {
	a = new Array();
	for (i = 0; i < col.length; i++)
		a[a.length] = col[i];
	return a;
}
function addListener(el, ev, li) {
	if (!(el = get(el))) return;
	if (el.addEventListener) {
		el.addEventListener(ev, li, false); 
	} else if (el.attachEvent){
		el.attachEvent("on" + ev, li);
	}
}
function removeListener(el, ev, li) {
	if (!(el = get(el))) return;
	if (el.removeEventListener) {
		el.removeEventListener(ev,li,false);
	} else if (el.detachEvent) {
		el.detachEvent("on" + ev,li);
	}
}
function hasClassName(el,cn) {
	if (!(el = get(el))) return;
	var elementClassName = el.className;
	return (elementClassName.length > 0 && (elementClassName == cn ||
	 new RegExp("(^|\\s)" + cn + "(\\s|$)").test(elementClassName)));
}
function addClassName(el, cn) {
	if (!(el = get(el))) return;
	if (!hasClassName(el, cn))
	  el.className += (el.className ? ' ' : '') + cn;
	return el;
}
function removeClassName(el, cn) {
	if (!(el = get(el))) return;
	  el.className = el.className.replace(new RegExp("(^|\\s+)" + cn + "(\\s+|$)"), ' ');
	return el;
}
function addClassName_(el, cn) { // for use in hover.htc
if (!(el = get(el))) return;
	if (!hasClassName(el, cn)) {
		if (!el.oldClassName) el.oldClassName = el.className ? el.className : '';
		el.className += (el.className ? ' ' + el.oldClassName + '_' + cn + ' ' : '') + cn;
	}
	return el;
}
function removeClassName_(el, cn) { // for use in hover.htc
	if (!(el = get(el))) return;
	el.className = el.className.replace(new RegExp("(^|\\s+)"+ el.oldClassName + "_" + cn + "(\\s+|$)"), ' ');
	el.className = el.className.replace(new RegExp("(^|\\s+)" + cn + "(\\s+|$)"), ' ');
	return el;
}
function removeChildrenFromNode(node) {
	if (node === undefined || node === null) {
		return;
	}
	var len = node.childNodes.length;
	while (node.hasChildNodes()) {
		node.removeChild(node.firstChild);
	}
}
function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
	}
	return [curleft,curtop];
}

function getElementHeight(Elem) {
	
	if (ns4) {
		var elem = getObjNN4(document, Elem);
		return elem.clip.height;
	}
	var elem = get(Elem);
	
	if (elem.style.pixelHeight && typeof elem.style.pixelHeight != "undefined") { 
		xPos = elem.style.pixelHeight;
	} else {
		xPos = elem.offsetHeight;
		
	}
	//trace(xPos);
	return xPos;

}

function getElementWidth(Elem) {
	if (ns4) {
		var elem = getObjNN4(document, Elem);
		return elem.clip.width;
	} else {
		var elem = get(Elem);
		if (elem.style.pixelWidth) {
			xPos = elem.style.pixelWidth;
		} else {
			xPos = elem.offsetWidth;
		}
		return xPos;
	}
}
function f_clientWidth() {
	return f_filterResults (
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
}
function f_clientHeight() {
	return f_filterResults (
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
}
function f_scrollLeft() {
	return f_filterResults (
		window.pageXOffset ? window.pageXOffset : 0,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0
	);
}
function f_scrollTop() {
	return f_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}
function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}

// ActiveX Object Activation
var activateObjects = function() {
	if (ieversion) {
		ns = document.getElementsByTagName('noscript');
		for (i in ns) {
			var n = ns[i];
				if (n.className=='obj') {
				//var flashHTML = n.innerHTML.replace(/&lt;/g,'<').replace(/&gt;/g,'>').replace(/&amp;/g,'&').toString();
				var flashHTML = n.innerHTML.replace(/<\!\[endif\]-->/i,'').replace(/<\!--\[if IE\]>/i,'');
				var holder = document.createElement('span');
				holder.style.display = 'inline';
				holder.style.position = 'static';
				holder.innerHTML = flashHTML;
				n.parentNode.insertBefore(holder, n);
			}
		}
	}
}

// Flash Detection
var flashinstalled = 0;
var flashversion = 0;
var MSDetect = "false";
var detectFlash = function() {
	if (navigator.plugins && navigator.plugins.length) {
		var x = navigator.plugins["Shockwave Flash"];
		if (x) {
			flashinstalled = 2;
			if (x.description) {
				y = x.description;
				flashversion = y.charAt(y.indexOf('.')-1);
			}
		}
		else
			flashinstalled = 1;
		if (navigator.plugins["Shockwave Flash 2.0"]) {
			flashinstalled = 2;
			flashversion = 2;
		}
	}
	else if (navigator.mimeTypes && navigator.mimeTypes.length) {
		var x = navigator.mimeTypes['application/x-shockwave-flash'];
		if (x && x.enabledPlugin) flashinstalled = 2;
		else flashinstalled = 1;
	}
	else MSDetect = "true";
}
// end of Flash Detection js part

Poller_ = {

	functions:[],

	add : function(func) {
		this.functions.push(func);
	},
	
	drop : function(func) {
		var i = this.functions.indexOf(func);
		if (i!= -1) this.functions.splice(i,1);
	},
	
	start : function() {
		this.poll = window.setInterval(
			function() {
				for (var i=0; i<Poller.functions.length; i++) {
					 Poller.functions[i]();
				}
			}
		,25);
	},
	
	stop : function() {
		window.clearInterval(this.poll);
	},
	
	init : function() {
		this.start();
	}
}

Poller = {

	add : function(func,name) {
		//this.functions.push(func);
		this.functions[name] = func;
	},
	
	drop : function(name) {
		delete this.functions[name];
		//var i = this.functions.indexOf(func);
		//if (i!= -1) this.functions.splice(i,1);
	},
	
	start : function() {
		this.poll = window.setInterval(
			function() {
				for (i in Poller.functions) {
					 //if (typeof Poller.functions[i] == "function") 
					 Poller.functions[i]();
				}
			}
		,25);
	},
	
	stop : function() {
		window.clearInterval(this.poll);
	},
	
	init : function() {
		this.functions = {};
		this.start();
		
		if(document.all && !window.opera) try {
      document.execCommand("BackgroundImageCache", false, true);
    } catch(err) {}
	}
}



/*----------------------
* End Common functions *
-----------------------*/

// Mozgások
function velElastic(orig, dest, springConst, damp, elas) {
	elas += -springConst * (orig - dest);
	return elas *= damp;
}
function velFriction(orig, dest, coeff) {
	return (dest-orig)/coeff;
}

// IE screen redraw fix
function fixRedraw() {
	if (document.all) {
		var oh = get('root').offsetHeight;
		get('root').style.height = oh;
		get('root').style.height = 'auto';
		delete oh;
	}
}

var SideMenu = {
	
	open : function(element) {
		//trace(element);
		var element, v;
		element.moving = true;
		this.openLoop = function() {
			//trace(velFriction(element.origHeight,element.minHeight,8));
			v = velFriction(element.currHeight,element.origHeight,8);
			//v = velElastic(element.currHeight, element.origHeight, 0.50, 0.25, 0.75);
			element.currHeight += v;
			element.scrollTop = 0;
			if (element.currHeight+0.6 > element.origHeight) {
				element.currHeight = element.origHeight;
				element.style.height = Math.floor(element.currHeight)+"px";
				element.moving = false;
				Poller.drop(element.oLoopID);
			}
			element.style.height = Math.floor(element.currHeight)+"px";
		}
		Poller.drop(element.cLoopID);
		Poller.add(this.openLoop,element.oLoopID);
	},
	close : function(element) {
		var element, v;
		this.closeLoop = function() {
			element.moving = false;
			//v = velElastic(element.currHeight, element.minHeight, 0.25, 0.25, 0.75);
			v = velFriction(element.currHeight,element.minHeight,8);
			element.currHeight += v;
			element.scrollTop = 0;

			if (element.currHeight-0.6 < element.minHeight) {
				element.currHeight = element.minHeight;
				element.style.height = Math.floor(element.currHeight)+"px";
				Poller.drop(element.cLoopID);
			}
			element.style.height = Math.floor(element.currHeight)+"px";
		}
		Poller.drop(element.oLoopID);
		Poller.add(this.closeLoop,element.cLoopID);
	},
	
	init : function() {
		var sideMenu = get('sidemenu');
		if (!sideMenu) return;
		
		this.activeMenuID = getURLVariable("m");
		
		this.selected = (this.activeMenuID!==false) ? this.activeMenuID : 0;
		this.subMenu = sideMenu.getElementsByTagName('dl');
		
		if (!this.subMenu) return;
		
		
		
		for (var i = 0, l = this.subMenu.length; i < l; i++) {
			
			this.subMenu[i].a = this.subMenu[i].getElementsByTagName('a').item(0);
			if (!this.subMenu[i].a) return;
			this.subMenu[i].a._parent = this.subMenu[i];
			
			this.subMenu[i].origHeight = getElementHeight(this.subMenu[i]);
			this.subMenu[i].minHeight  = 10;
			this.subMenu[i].currHeight = 10;
			//this.subMenu[i].id = this.subMenu[i].uniqueID;
			this.subMenu[i].id = i;
			this.subMenu[i].oLoopID = "openLoop_"+this.subMenu[i].id;
			this.subMenu[i].cLoopID = "closeLoop_"+this.subMenu[i].id;
			
			if (this.activeMenuID !== false && i == this.activeMenuID) {
				//trace(i + " " + this.activeMenuID);
				addClassName(this.subMenu[i].a, 'active');
				this.subMenu[i].currHeight = this.subMenu[i].origHeight;
			}
			this.subMenu[i].style.height = this.subMenu[i].currHeight+'px';
			this.subMenu[i].style.overflow = 'hidden';
			this.subMenu[i].moving = false;
			
			
			this.subMenu[i].onmouseover = 
			this.subMenu[i].onmousemove = 
			this.subMenu[i].onmouseup = function(x) {
				//trace("x = "+x+" this.id = "+this.id+" \nSideMenu.activeMenuID = "+SideMenu.activeMenuID+" \nSideMenu.selected = "+SideMenu.selected+" \nSideMenu.subMenu["+SideMenu.selected+"].moving = "+SideMenu.subMenu[SideMenu.selected].moving);
				if (x!=1 && this.id >= SideMenu.selected && SideMenu.subMenu[SideMenu.selected].moving) return;

				var _this = this;
				var run = function() {
					SideMenu.selected = _this.id;
					for (var i = 0, l = SideMenu.subMenu.length; i < l; i++) {
						SideMenu.close(SideMenu.subMenu[i]);
						removeClassName(SideMenu.subMenu[i].a, 'active');
						//SideMenu.subMenu[i].a.blur();
					}
					SideMenu.open(_this);
					addClassName(_this.a, 'active');
				}
				clearTimeout(SideMenu.tmo);
				SideMenu.tmo = setTimeout(run,100);

			}

			this.subMenu[i].onmouseout = function() {
				if (SideMenu.selected != this.id) {
					clearTimeout(SideMenu.tmo);
				}
			}
			this.subMenu[i].a.onclick = function() {
				this._parent.onmouseover(1);
				return false;
			}
			this.subMenu[i].getID = function(){return this.id};
			
			/* onFocus events */
			this.subMenu[i].menuItem = sideMenu.getElementsByTagName('a');
			for (var j = 0, jl = this.subMenu[i].menuItem.length; j < jl; j++) {
				this.subMenu[i].menuItem[j].onfocus = function() {
					this.parentNode.parentNode.onmouseover(1);
				}
				this.subMenu[i].menuItem[j].onblur = function() {
					this.parentNode.parentNode.onmouseout();
					this.parentNode.parentNode.scrollTop = 0;
				}/**/
			}
			
			// IE before fix
			/*if (ieversion && !this.subMenu[i].spanbefore) {
				trace("IE before fix");
				this.subMenu[i].span = this.subMenu[i].a.getElementsByTagName('span').item(0);
				this.subMenu[i].spanbefore = document.createElement('b');
				this.subMenu[i].spanbefore.className = 'before';
				this.subMenu[i].spanbefore.innerHTML = this.subMenu[i].span.innerHTML;
				this.subMenu[i].a.insertBefore(this.subMenu[i].spanbefore,this.subMenu[i].span);
			}*/
		}
		// Open first
		
		
		if (!this.activeMenuID) {
			//trace(this.activeMenuID);
			var AciveMenu = this.subMenu[0];
			setTimeout(function(){AciveMenu.onmouseover(1)},0);
		}
		// IE screen redraw fix
		if (document.all) {
			var oh = get('root').offsetHeight;
			get('root').style.height = oh;
			get('root').style.height = 'auto';
			delete oh;
		}
	}
}

var getURLVariables = function() { // incomplete !!
	var output = {};
	var url = window.location.split('?')[1].split('&');
	for (var i = 0; i < url.length; i++) {
		// build output obj
	}
}
var getURLVariable = function(varname) {
	var url = String(window.location);
	var url = url.split('?')[1].split('&');
	for (var i = 0; i < url.length; i++) {
		if (url[i].indexOf(varname+"=")!=-1) {
			return url[i].split("=")[1];
			break;
		}
	}
	return false;
}


var setMenuEvents = function() {
	body  = document.getElementsByTagName("body").item(0);
	var menu = get('menu');
	window.menuItems = menu.getElementsByTagName('li');
	//window.menuItems = collectionToArray(menu.getElementsByTagName('dl'));
	//window.menuItems = menuItems.concat(collectionToArray(menu.getElementsByTagName('li')));
	
	//window.menuItems = menuItems;
	window.t = new Array();
	
	var smenu = get('submenuholder');
	window.subMenu = smenu.getElementsByTagName('div');
	
	for (var i=menuItems.length-1; i>0; i--) {
		if (get('sub'+(i+1))) {
			window.menuItems[i].subMenu = get('sub'+(i+1));
			window.menuItems[i].menuHeight = getElementHeight(menuItems[i].subMenu);
			
			window.menuItems[i].menuTop = -30;
			window.menuItems[i].menuBottom = menuItems[i].menuTop-menuItems[i].menuHeight-5;
			window.menuItems[i].subMenu.style.bottom = menuItems[i].menuBottom+'px';
			window.menuItems[i].subMenu.style.display = 'none';
			window.menuItems[i].i = i;
			window.menuItems[i].y = menuItems[i].menuBottom;
			window.menuItems[i].delay = 0;
			//menuItems[i].t = false;
			
			window.menuItems[i].alpha = 0;
			window.menuItems[i].alphaDown = 100;
			
			//trace(menuItems[i].menuHeight);
			window.menuItems[i].move = function(i,dir) {
				//Number:i = i;
				ths = window.menuItems[i];
				
				/*trace('this.i['+i+'] = '+window.t[i]+'... y='+window.menuItems[i].y);*/
				//if (window.delay < 0 || dir=='down') {
					
				
				if (dir=='down') {
					speed = 8;
					dest = ths.menuBottom;
					isondest = (ths.y < dest+1);

				} else {
					speed = 5;
					dest = ths.menuTop;
					isondest = (ths.y > dest-1);
					ths.subMenu.style.display = 'block';
				}
				
				if (window.active == ths) {
					
					if (window.delay < 1 || dir=='up') {
						window.moving = true;
						ths.y += (dest-ths.y)/speed;
					} else window.delay-=10;
	
						if (isondest) {
							window.moving = false;
							ths.y = dest;
							if (dir=='down') {
								clearInterval(window.t[i]);
								ths.subMenu.style.display = 'none';
							} else {
								window.delay = 99999999;
								clearInterval(window.t[i]);
								var f = function(){ths.move(i,'down')}
								window.t[i] = setInterval(f,20);
							}
						}
						ths.subMenu.style.bottom = Math.round(ths.y)+'px';/**/
						//ths.subMenu.style.opacity = 100/(ths.y/(dest/100));
						menuItem = ths.subMenu.getElementsByTagName('a');
						//var alpha = (dir=='down') ? 100 - Math.round(Math.abs(dest-ths.y) / ((ths.menuTop - ths.menuBottom)/100));
						ths.alpha += (dir=='down' && window.delay < 1) ? ((ths.alpha>0) ? (0-ths.alpha)/5 : 0) : ((ths.alpha<100) ? (100-ths.alpha)/8 : 0);
						var opacity = ths.alpha/100;
						for (var j=0; j < menuItem.length; j++) {
							menuItem[j].style.opacity = opacity;
							menuItem[j].style.filter = 'Alpha(Opacity='+ths.alpha+')';
						}
						//trace(window.delay);
						//
					
				} else {
					speed = 8;
					dest = ths.menuBottom;
					ths.y += (dest-ths.y)/speed;
					if (ths.y < dest+1) {
						ths.y = dest;
							clearInterval(window.t[i]);
							ths.subMenu.style.display = 'none';
							//window.delay = 0;
					}
					ths.subMenu.style.bottom = Math.round(ths.y)+'px';
				}
				//trace(window.moving+" "+window.delay);
			}
			//window.menuItems[i].onmouseover = function () { this.subMenu.style.bottom = this.menuTop+'px'; trace(this.menuHeight)/**/}
			window.menuItems[i].onmouseover = window.menuItems[i].onfocus = function () { 
				//this.subMenu.style.bottom = -this.menuHeight+'px'
				var i = this.i;
				window.active = this;
				window.delay = 0;
				clearInterval(window.t[i]);
				var f = function(){window.menuItems[i].move(i,'up',0)}
				window.t[i] = setInterval(f,20);
				//window.t[this.i] = setInterval(function(i){trace(i)},500,this.i);
			}
			window.menuItems[i].onmouseout = window.menuItems[i].onblur = function () { 
				//this.subMenu.style.bottom = -this.menuHeight+'px'
				var i = this.i;
				if (!window.moving) {
					window.delay = 500;
					clearInterval(window.t[i]);
					var f = function(){window.menuItems[i].move(i,'down')}
					window.t[i] = setInterval(f,20);
				}


				//window.t[this.i] = setInterval(function(i){trace(i)},500,this.i);
			}
			/*window.menuItems[i].onclick = function () {
				this.onmouseover();
				return false;
			}*/
		}
	}
	for (i=0; i<subMenu.length; i++) {
		subMenu[i].onmouseover = function() {if (!window.moving) window.delay=99999999;/**/}
		subMenu[i].onmouseout = function() {window.delay=500;}
		subMenu[i].onclick = function() {window.mnuclk=true;}
	}
	body.onclick = function() {
		if (!window.mnuclk) window.active=false;
		window.mnuclk=false;
	}
}


/*
+=========+
| Startup |
+=========+
*/
function addLoadEvent(func) {
	if (!document.getElementById | !document.getElementsByTagName) return;
		var oldonload = window.onload;
		if (typeof window.onload != 'function') {
			window.onload = func;
		} else {
			window.onload = function() {
			oldonload();
			func();
		}
	}
}
var startLoad = function() {
	//detectFlash();
	setGetElementsByClassNameEmulation();
	setMenuEvents();
	activateObjects();
	Poller.init();
	SideMenu.init();
}
addLoadEvent(startLoad);
