/**
* Browser version detection
*/
var ns4 = document.layers; 
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) {
	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, ' '); }

// location.replace emuláció
if (location.replace == null) location.replace = location.assign;

// -- 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 fireListener(el, ev) {
	if (!(el = get(el))) return;
	if (el.dispatchEvent) {
		var evt = window.document.createEvent("HTMLEvents");
		evt.initEvent(ev, true, false );
		el.dispatchEvent(evt);
	} else if (el.fireEvent) {
		el.fireEvent("on" + ev);
	}
}
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 (var 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();
	}
}

// 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;
}
// Effektek

var Opacity = {
	get : function(obj) {
		
		if (obj.style.filter.alpha.opacity)
			return obj.style.filter.alpha.opacity;
		if (obj.style.opacity)
			return obj.style.opacity;
		if (obj.style.MozOpacity)
			return obj.style.MozOpacity;
		if (obj.style.KhtmlOpacity)
			return obj.style.KhtmlOpacity;
		return 0;
	},
	set : function(obj, opacity) {
	  opacity = Math.round(opacity);
	  //opacity = (opacity == 100)?99.999:opacity;
	  obj.style.filter = "Alpha(Opacity:"+opacity+")";
	  //obj.style.filter.alpha.opacity = opacity;
	  opacity = opacity/100;
	  obj.style.KhtmlOpacity = opacity;
	  obj.style.MozOpacity = opacity;
	  obj.style.opacity = opacity;
	},
	supported : (ieversion > 0 || opversion > 0 || koversion > 0 ) 
              ? ieversion >= 5.5 || opversion >= 9 || koversion >= 4 
			  : true
}

var Fade = {
	transition : function(element,val,speed,dir,runfunc) 
	{
		// Usage
		// 
		//delete element.loop;
		element.val = val;
		element.speed = (speed) ? speed : 5;
		element.d = 0;
		//element.dir = (dir) ? dir : "in";
		element.runfunc = runfunc;
		element.a = (element.a || element.a === 0) ? element.a : 0;
		
		Poller.drop(element.fLoopID);
		element.loop = null;
		
		var dir;
		
		element.loop = function() {
			//trace('loop');
			switch (dir) {
				case "in"     :	element.k = (element.val - element.a)/element.speed; break;
				case "linear" : element.k = element.speed; break;
				case "out"    : element.d += element.speed; element.k = element.d; break;
				default : element.k = (element.val - element.a)/element.speed;
			}
			if (element.a != element.val) {
				element.a += element.k;
				if (Math.abs(element.a - element.val) < 1) {
					element.a = element.val;
				}
				//element._alpha = element.a;
				//trace('loop a='+element.a);
				Opacity.set(element, element.a)
			} else {
				//trace('end loop');
				Poller.drop(element.fLoopID);
				if (typeof(element.runfunc)=='function') element.runfunc();
			}
		}
		Poller.add(element.loop,element.fLoopID);
	},
	init : function() 
	{
		var fadeElements = document.getElementsByClassName('fade');
		for (var i = 0, l = fadeElements.length; i < l; i++) {
			Opacity.set(fadeElements[i], 0);
			fadeElements[i].fLoopID = 'fadeLoop_'+i;
			
			fadeElements[i].link = fadeElements[i];
			var li = 0;
			while (fadeElements[i].link.tagName != "A" && li < 5) {
				fadeElements[i].link = fadeElements[i].link.parentNode;
			}
			fadeElements[i].link.fadeElement = fadeElements[i];
			
			var fokus = function(evt) {
				var _this = (evt.target) ? evt.target : evt.srcElement;
				fireListener(_this.fadeElement,'mouseover');
				/*//Fade.transition(_this,100,5);*/
			}
			
			var blure = function(evt) {
				var _this = (evt.target) ? evt.target : evt.srcElement;
				fireListener(_this.fadeElement,'mouseout');
				/*//Fade.transition(_this,100,5);*/
			}
			
			var hover = function(evt) {
				var _this = (evt.target) ? evt.target : evt.srcElement;
				Fade.transition(_this,100,5);
			}
			
			var normal = function(evt) {
				var _this = (evt.target) ? evt.target : evt.srcElement;
				//trace(_this.tagName);
				Fade.transition(_this,0,10,'',function(){/*trace('done')*/});
			}
			
			addListener(fadeElements[i],'mouseover',hover);
			//fadeElements[i].onfocus = function(){trace('focus')};
			addListener(fadeElements[i].link,'focus',fokus);
			addListener(fadeElements[i],'mouseout',normal);
			addListener(fadeElements[i].link,'blur',blure);
		}
	}
}

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);
	if (!url.split('?')[1])
		return false;
	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;
}
/*----------------------
* End Common functions *
-----------------------*/



// 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;
	}
}


/*
+=========+
| 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();
	activateObjects();
	Poller.init();
	Fade.init();
	//setMenuEvents();
	//SideMenu.init();
}
addLoadEvent(startLoad);
