function function_indication(){
	if(document.getElementById('led')){
		var led = document.getElementById('led');
		toggle = (led.style.display == 'block') ? 'none' : 'block';
		led.style.display = toggle;
	}
}
function $i(id) {setTimeout(function_indication,200); return document.getElementById(id); }
function $t(name) { return document.getElementsByTagName(name); }
function $c(code) { return String.fromCharCode(code); } 
function $h(value) { return ('0'+Math.max(0,Math.min(255,Math.round(value))).toString(16)).slice(-2); }
function _i(id,text) { id.innerHTML=text; }

function getInternetExplorerVersion() {

    var rv = -1; // Return value assumes failure.

    if (navigator.appName == 'Microsoft Internet Explorer') {

        var ua = navigator.userAgent;

        var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");

        if (re.exec(ua) != null)

            rv = parseFloat(RegExp.$1);

    }

    return rv;

}

var ie6=(parseFloat(navigator.appVersion.split("MSIE")[1])==6) ? true : false;
var ie8=(getInternetExplorerVersion()==8) ? true : false;
var agent=navigator.appVersion;
var client=((navigator.appName=='Microsoft Internet Explorer')?'ie':(((navigator.appVersion).indexOf('Safari')!=-1)?'sa':((navigator.appName=='Opera')?'op':'ff')));
var iphone = (agent.indexOf('iPhone')!=-1) ? true : false;
var now=new Date();
var interpreter_code = true;
var environment_code = true;
var xml_http = null;
var data_path='/system/';
var data_link='parser';
var data_load=[];
var data_url;
var menu_current=0;
var command_name;
var article_id=null;
var running_articles=null;
var optionalContentBottomPadding = 10;
var component_id;

var menu_ttfsize = 11;
var menu_fontface = 3;
var title = 'RTLKlub';
var domain = 'http://www.rtlklub.hu';
var title_restore = title;
var data_type='init';
var css_url = '/site/layout/';
var timer_data;
var load_external_css = true;
var wait_timeout=10;
var cookie_time=1000;
var frame_per_second=Math.round(1000/40);
var screen_width;
var screen_height;
var navigation_buffer = 0;
var containerInitialHeight = 0;
var screenstage = 0;
var levelcode = "home";
var parameters = '';
var OSName="Unknown OS";
var flash_installed = 0;
var flash_version = 0;
var preloading = false;
var doubleclick_time = 60;
var compdebug = 0;
var default_page = 'main';
var prerender = 1;

function object_opacity(id, value) { id.style.opacity = value/100; if(client == 'ie'){id.style.filter = 'alpha(opacity='+value+')';}}


function reinit(){

	$i('content').innerHTML = '';
	xml_http = null;
	data_load=[];
}

function get_operating_system(){
	if (navigator.appVersion.indexOf("Win")!=-1){ OSName="Windows";}
	if (navigator.appVersion.indexOf("Mac")!=-1){ OSName="MacOS";}
	if ((OSName == "MacOS") && (navigator.appVersion.indexOf("5.0")!=-1)){ OSName="MacOSX Leopard";}
	if (navigator.appVersion.indexOf("X11")!=-1){ OSName="UNIX";}
	if (navigator.appVersion.indexOf("Linux")!=-1){ OSName="Linux";}
	if (navigator.appVersion.indexOf("AmigaOS")!=-1){ OSName="Amiga OS";}
	return OSName;
}

function code_certification(){
	switch(client){
		case 'ff': interpreter_code = true; break; 
		case 'ie': interpreter_code = true; break; 
		case 'sa': interpreter_code = true; break; 
		case 'op': interpreter_code = true; break; 

	}
	switch(get_operating_system()){
		case 'Windows': environment_code = true; break;
		case 'MacOS': environment_code = true; break;
		case 'MacOSX Leopard': environment_code = true; break;
		case 'AmigaOS': environment_code = false; break;
	}
}
function skip_preloading(){
	
	preloading = false;
}

function toggle_loader(s){
		//webaudit_hit();
		
		//var displaying = (s == true) ? 'block' : 'none';
		//$i('loader').style.display = displaying;
		//if(!s){ $i('content').style.visibility = 'visible'; }
		
}


function update_loader_status(status){
	
}

function compile_embedplayer(id, videoid){

		/* rtlmost player */		
		var div = $i(id+'_div');
		var width = div.offsetWidth;
		var height = div.offsetHeight;

	    swfobject.embedSWF("/site/applications/videoplayer.app/data/player/flv_player.swf?v=5"
	              ,div.id
	              ,width
	              ,height
	              ,"9.0.115"
	              ,"/site/applications/videoplayer.app/data/player/expressinstall.swf"
	              ,{parameters:"/getvideo/"+videoid
	              ,skin:"/site/applications/videoplayer.app/skin/skin.xml?v=6"}
	              ,{menu:false,allowfullscreen:true,allowscriptaccess:"always",wmode:"transparent",pluginspage:"http://www.macromedia.com/go/getflashplayer"}
	              ,{id:div.id,name:div.id}
	    );
		if(external_parameter){
			var id = external_parameter.split(':');
			//load_gallery(id[1]);
		}		
}


function embedding_article_media(){

	var body = $i('article_body');
	var pagedivs = null;
	var embeds = new Array();
	var y = 0;
	if(body){
		for(var i=0;i<body.childNodes.length;i++){
			pagedivs = body.childNodes[i].getElementsByTagName("DIV");
			pageimg = body.childNodes[i].getElementsByTagName("IMG");
			
			for(var x=0;x<pagedivs.length;x++){
				
				if(pagedivs[x].id.indexOf('video')!=-1){
					embeds[y] = pagedivs[x];
					y++;
				}
				
			}
	
			/* embed images */
			for(var x=0;x<pageimg.length;x++){
				pageimg[x].style.margin = '10px';
				//pageimg[x].style.width = '568px';
				//pageimg[x].style.height = '426px';
				pageimg[x].style.overflow = 'auto';
			}
		}
		for(var x=0;x<embeds.length;x++){
			var player = new_div('embed_' + embeds[x].id + '_div', false, false);
			var fixplayer = new_div( 'embed_' + embeds[x].id + '_fix', false, false );
			var videoid = embeds[x].id.replace(/[^0-9]/g,'');
			player.style.width = '586px';
			player.style.height = '500px';
			player.style.magin = '0 auto';
			player.style.marginTop = '6px';
			player.style.marginBottom = '6px';
			player.style.backgroundColor = '#000';

        		fixplayer.style.position = 'relative';
	                fixplayer.style.width = '586px';
        		fixplayer.style.height = '500px';
	                fixplayer.style.magin = '0 auto';
	                fixplayer.style.marginTop = '6px';
        		fixplayer.style.marginBottom = '6px';
	                fixplayer.style.backgroundColor = '#000';

	                fixplayer.appendChild( player );
        		$i( embeds[x].id ).appendChild( fixplayer );
			compile_embedplayer('embed_' + embeds[x].id, videoid);
		}
		reorder_stageboxes();
	}
}
function swaplanding(id){
	var div = $i(id);
	var items = exclude_nodes(div.parentNode, '#text').childNodes;
	div.style.display = 'block';
	$i('button_'+id).className = 'page active';
	
	for(var i=0;i<items.length;i++){
		if(items[i].id != id){
			items[i].style.display = 'none';
			$i('button_'+items[i].id).className = "page";
		}
	}
}
function run_page(){
	if(levelcode){
		switch(levelcode){
			/* client_memory_modifiers */
 				
		}
		if((levelcode.indexOf('cikk')!=-1) || (page_id.indexOf('cikk')!=-1)){
			embedding_article_media();
		}

	}
	if(client == 'ie'){ load_component_stylesheet(css_url + 'frontend_ie.css');}
	
	preloading = true;

}

function preload_images(imagearray){
	
	if(prerender == true){
		if(imagearray.preloader_mem){ alert(imagearray.preloader_mem); }
		update_loader_status('Képek betöltése');
		//advertize_init();
		var data=document.images;
		var image=new Array(data.length);
		for(var i=0;i<data.length;i++){
			image[i]=new Image();
			image[i].src=data[i].src;
		}
		var imagecount = 0;
		var ready = 0;
		var naturalcount = 0;
		update_loader_status('Képek betöltése (' + data.length + ')');
		
		imagearray.preloader_mem = window.setInterval(
			function() {
				
				
				for(var i=0;i<data.length;i++){
					
					if(image[i].complete == true){ imagecount++; }
					if((image[i].naturalWidth) || (image[i].naturalHeight)){ naturalcount++; }
	
				}
			
				if((imagecount >= data.length) || image.length == 0){ ready = 1; }
				
				update_loader_status('Képek betöltése (' + imagecount + '/' + data.length + ' | ' + naturalcount + ') [<span onclick="skip_preloading()" style="cursor:pointer">skip preloading</span>]');
				imagecount = 0; // reset the num of complete images
				naturalcount = 0;
				if((ready == 1) || (preloading == false)){

					/* 
					 * if images loaded 
					 */
					window.clearInterval(imagearray.preloader_mem);

					run_page();
				}
			}
		, 10);
	} else {

		run_page();
	}

	
	
	
}


function refresh_page(){
	var articles = $i('articles');
	//webaudit_hit();
	if(articles == null){
		window.location.reload();
	} else {
		setTimeout("refresh_page()", 1740000);
	}
}

function advertize_init(){
	var obj = $i('banner336x280');
	if(obj){
		var advert_image = '/items/banners/banner_01.png';
		obj.innerHTML = '<img src="' + advert_image + '" alt=""/>';
	}
}

function set_cookie(name,value,time){
	var date=new Date();
	date.setTime(date.getTime()+time*24*60*60*1000);
	var cookie=name+'='+value+'; expires='+date.toGMTString()+'; path=/';
	document.cookie=cookie;
}

function get_cookie(name)
	{
	var value='';
	var all_cookies=document.cookie.split(';');
	for(var i=0;i<all_cookies.length;i++)
		{
		string=all_cookies[i];
		while(string.charAt(0)==' '){ string=string.substring(1,string.length); }
		if(string.indexOf(name)!=-1)
			{
			value=string.substring(name.length+1,string.length);
			break;
			}
		}
	return value;
	}

function reset_cookie()
	{
	var all_cookies=document.cookie.split(';');
	for(var i=0;i<all_cookies.length;i++)
		{
		string=all_cookies[i];
		while(string.charAt(0)==' '){ string=string.substring(1,string.length);}
		set_cookie(string.substr(0,string.indexOf('=')),undefined,-1);
		}
	document.location.href=window.location;
	}


function get_resolution(){
	switch(client){

		case 'sa':
			 screen_width=document.documentElement.clientWidth;
			screen_height=document.documentElement.clientHeight; break;

		case 'op':
			 screen_width=document.body.clientWidth;
			screen_height=document.body.clientHeight; break;
		  default: 
			 screen_width=document.documentElement.clientWidth;
			screen_height=document.documentElement.clientHeight;
	}
}


function detect_flash(){

	MSDetect = "false";
	if (navigator.plugins && navigator.plugins.length){
		x = navigator.plugins["Shockwave Flash"];
		if (x){
			flash_installed = 2;
			if (x.description){
				y = x.description;
				flash_version = y.charAt(y.indexOf('.')-1);
			}
		} else {
			flash_installed = 1;
		}
		if (navigator.plugins["Shockwave Flash 2.0"]){
			flash_installed = 2;
			flash_version = 2;
		}
	} else if (navigator.mimeTypes && navigator.mimeTypes.length){
		x = navigator.mimeTypes['application/x-shockwave-flash'];
		if (x && x.enabledPlugin){
			flash_installed = 2;
		} else {
			flash_installed = 1;
		}
	} else {
		MSDetect = "true";
	}
	return flash_version;
}

/*  c o m p o n e n t  _  b u i l d */

	function init_header_content(){
		var string='<i class="hl"></i><i class="hr"></i>';
			string+='<div id="textscroll_div" class="textscroll"></div>';

		return string;
	}



	function init_loader(){
		
		var string='<i class="b-'+client+'"></i><div id="led"></div><div id="cycles"></div><div id="anim"></div><div id="status"></div>';
		return string;
	}


	function init_footer_content(){
		var string='';
		return string;
	}

	function init_menuitems(){
		update_loader_status('Menü inicializálás');
		data_type = 'menu';
		load_data();
	}

	function init_footer(){
		update_loader_status('Lábléc tartalmi inicializálás');
		data_type = 'footer';
		load_data();
	}

	var memory_cycles = 0;
	function reorder_stageboxes(){
	
		var smartorder = (client == 'ie') ? true : true;
		var fe_box = exclude_nodes($i('content'), '#text').childNodes;
		
		var topHeightOffset = 0;
		var box_height = 0;
		var box_y = 0;
		var topOffsets = 0;
		var deepest_bottom = 0;
		var topfields = new Array();
		var bottomfields = new Array();
		var leftfields = new Array();
		var rightfields = new Array();

		if(smartorder){
			var x_collision = false;
			var y_collision = false;
			var collision = false;
			var box = null;
			var repass = false;
			var component_box;

			for(var i=0;i<fe_box.length;i++){

				//fe_box[i] = exclude_nodes(fe_box[i], '#text');
				
				if(fe_box[i].childNodes.length > 0){

					component_box = exclude_nodes(fe_box[i], '#text').childNodes;

					if(component_box.length > 1){
						
						var move_html = fe_box[i].innerHTML;
						fe_box[i].innerHTML = '<div id="'+fe_box[i].id+'_inner">' + move_html + '</div>';
						move_html = null; 
					
					}
					box = fe_box[i];
					if(box.childNodes.length > 0){
						var offset_H = box.childNodes[0].offsetHeight;
						if(normalize(box.style.height) < offset_H){
							move_bottom_neighbours(i);
						}
						//blu(box.id + ': ' + box.style.height + ' < ' + offset_H);
						box.style.height = offset_H + 'px';
					
					}
					
				}
			}

		}
    	        resize_container();

	}

	function move_bottom_neighbours(box_key){
	
		var fe_box = exclude_nodes($i('content'), '#text').childNodes;
		var box = (typeof(box_key) == 'object') ? box_key : fe_box[box_key];
		var x1 = normalize(box.style.left);
		var x2 = x1+box.childNodes[0].offsetWidth;
		var y1 = normalize(box.style.top);
		var y2 = y1 + box.childNodes[0].offsetHeight;		
		var distance = box.childNodes[0].offsetHeight-normalize(box.style.height);
//		//blu(box.offsetHeight);
		for(var i=0;i<fe_box.length;i++){

			/* a neighbour box */
			box = fe_box[i];
			
			/* only neighbour boxes, no self checking */
			if(i != box_key && box.childNodes.length > 0){
				n_x1 = normalize(box.style.left);
				n_x2 = n_x1+box.offsetWidth;
				n_y1 = normalize(box.style.top);
				n_y2 = n_y1 + box.childNodes[0].offsetHeight;		
				
				/*	
					a terjeszkedo doboz ala eso dobozok szelesithetik a 
					skalat, de ez megvaltozhatja az xc1 es xc2 egyenletet, 
					ezert a dist ertekhez kotheto a feltetel, kivalasztaskor. 

					tehat: y_coll-nal a distance erteknel nem lehet nagyobb 
					az also belogas.
				*/
				y_collision = ((y1 < n_y1) && ((y2-n_y1) < distance)) ? true : false;
				//x1 = (n_x1 < x1) ? n_x1 : x1;
				//x2 = (n_x2 >= x2) ? n_x2 : x2;
				
				xc1 = (((n_x1 <= x1) || (n_x1 > x1)) && (n_x1 <= x2)) ? true : false;
				xc2 = ((n_x2 > x1) && ((n_x2 <= x2) || (n_x2 > x2))) ? true : false;
				x_collision = (xc1 && xc2) ? true : false;

				collision = (x_collision && y_collision) ? true : false;
				if(collision){
					//blu(box.id + ' / n_y1:' + n_y1 + ' + d:' + distance ); 
					//blu(box.id);
					
					box.style.top = n_y1 + (distance) + 'px';
					//blu(n_y1 + (distance));
					//object_move_top(box, distance);
					//box.style.border = '2px solid green';
				}
			}
		}

	}

	function resize_container(){
		//blu('dev');
		var fe_box = exclude_nodes($i('content'), '#text').childNodes;
		var topfields = new Array();
		var topHeightOffset = 0;

		for(var i=0;i<fe_box.length;i++){

			if(fe_box[i].childNodes.length > 0){
				
				box_height = fe_box[i].childNodes[0].offsetHeight;
				febox_height = fe_box[i].offsetHeight;
				
				if( febox_height != box_height ) {
                    fe_box[i].childNodes[0].style.height = fe_box[i].offsetHeight + 'px';
				}
								
				box_y = (fe_box[i].style.top) ? fe_box[i].style.top : '0';

				box_width = fe_box[i].childNodes[0].offsetWidth;
				box_x = (fe_box[i].style.left) ? fe_box[i].style.left : '0';
				
				topOffsets = (eval(box_height)) + (eval(box_y.replace('px', '').replace('pt', '')));
				
				topHeightOffset = (topOffsets >= topHeightOffset) ? topOffsets : topHeightOffset;
				/* ne fedhesse le a felette allo a dobozt :) */
				fe_box[i].style.zIndex = topOffsets;
			}
		}
		var content = $i('content');
		var container = $i('container');
		var content_height = (!content.style.height) ? content.offsetHeight : normalize(content.style.height);
		//blu(content_height + ' - ' + topHeightOffset);

		content.style.height = topHeightOffset+optionalContentBottomPadding+'px';
		container.style.height = content.style.height
		//animate_div_height_public(content, content_height, (topHeightOffset+30), 20);
	}

	function drag_menu(){
		
		var data = data_load;

		var string = '';
		var color = 'FFFFFF';
		var message = '';
		var navobj = $i('navigation');
		if(navobj){
			if(data == undefined){
					
					message = 'FAILED TO LOAD NAVIGATION ITEMS. WRONG MENUDATA RECEIVED.\n NAVIGATION BUFFER SET TO EMPTY.';
					$i('navigation').innerHTML = '<div class="nav-item"><img src="/graphic/truetype/' + message + '/9/000000/ffffff/0" alt="'+message+'" /></div>';
					navigation_buffer = 0;
					
					init_footer();

			} else {

				if(data != null){
					
					update_loader_status('Menü elemek betöltése');
					$i('navigation').innerHTML = decodeURIComponent(data);
					navigation_buffer = 1;
					/* run only on init */
					init_footer();

				} else {

					message = 'Failed to load navigation items: empty menudata received. Navigation buffer set to empty';
					$i('navigation').innerHTML = '<div class="nav-item"><img src="/graphic/truetype/' + message + '/9/f4ead7/222222/5" alt="'+message+'" /></div>';
					toggle_loader(0);

				}

			}
		} else {
			blu('no navigation object found. checking footer ...');
			init_footer();
		}

	}
	
	function drag_footer(){
		
		var data = data_load;
		var string = '';
		var color = 'FFFFFF';
		var message = '';
		var footer = $i('footer');
		if(footer){
			if(data == undefined){
					message = 'FAILED TO LOAD FOOTER CONTENT. WRONG FOOTERDATA RECEIVED.';
					$i('footer').innerHTML = '<div class="nav-item"><img src="/graphic/truetype/' + message + '/9/000000/ffffff/0" alt="'+message+'" /></div>';
					preload_images(document.images);
			} else {

				if(data != null){
					
					update_loader_status('Lábléc tartalmak kitömörírése');
					$i('footer').innerHTML = decodeURIComponent(data);

					preload_images(document.images);
					
				} else {

					message = 'FAILED TO LOAD FOOTER CONTENT. EMPTY FOOTERDATA RECEIVED';
					$i('footer').innerHTML = '<div class="nav-item"><img src="/graphic/truetype/' + message + '/9/f4ead7/222222/5" alt="'+message+'" /></div>';
					toggle_loader(0);

				}

			}
		} else {
			blu('no footer object found. preloading images ...');
			preload_images(document.images);

		}
	}
	




function new_div(id, classname, string){
	
	var div = document.createElement('div');
	if(id){ div.id = id; }
	if(classname){ div.className = classname; }
	if(string){ div.innerHTML = string; }
	return div;
	
}

function load_component_stylesheet(cssfile){
	
	if(load_external_css){

		var styles = document.getElementsByTagName("LINK");
		var css_buffer = 0;
		for(var i=0;i<styles.length;i++){
			if(styles[i].href.indexOf(cssfile) != -1){
				css_buffer = 1;
			}
		
		}
		
		if(css_buffer == 0){
			var oLink = document.createElement("link");
			oLink.href = cssfile  + '?rnd=' + now.getTime();
			oLink.rel = "stylesheet";
			oLink.type = "text/css";
			oLink.disabled = false;
			oLink.media = "Screen,Projection,TV";
			document.body.appendChild(oLink);
		}
		
	}
}

function setup_browser_compatibility(){
	switch(client){
		case 'ie': prerender = (ie6 == true) ? false : false; break;
		case 'sa': prerender = (iphone == true) ? false : true; break;
		case 'ff': prerender = 0; break;
		case 'op': prerender = false; break;		
		default: prerender = true;
	}
	
}
function grow(height){
	$i('rtlmenu_div').style.height = height + 'px';
	call_flash_function('rtlmenu_div').height = height;
}
function call_flash_function(id){

    var x = document.getElementById( id );

	if(client == 'ie'){
		var fl = x.getElementsByTagName('OBJECT')[0];
	} else {
		var fl = (x.getElementsByTagName('EMBED')[0]) ? x.getElementsByTagName('EMBED')[0] : x.getElementsByTagName('OBJECT')[0];
	}

	return fl;

}
function initialization(){
	
	reorder_stageboxes();
	setup_browser_compatibility();
	/* init codes, call external addressing from this scope */
	//webaudit_hit();
	/* define new page */
	get_resolution();

	/* inserting to document */
	//$i('container').appendChild($i('content'));
		
	var domain = '' + window.location + '';
	boot_pages();
	
}

function addstyle(selector, style){
	var s = document.styleSheets[0];
	
	if(s.insertRule){
		var lastrule = s.cssRules.length;
		s.insertRule(selector + '{' + style + '}', lastrule);
	} else if(s.addRule){
		var lastrule = s.rules.length;
		s.addRule(selector, style, lastrule);
	}
}
function execute(){
	levelcode = (external_addressing != null) ? external_addressing : default_page;
	parameter = (external_parameter) ? external_parameter.split('/') : null;

	code_certification(); 
	
	if(videoid == null){
		setTimeout("refresh_page()", 1740000);
	}

	if(interpreter_code == true && environment_code == true){
		if(window.addEventListener){
			window.addEventListener("load",initialization,false);
		} else if(window.attachEvent){
			window.attachEvent("onload",initialization);
		} else if(window.onload) {
			window.onload = initialization();
		} else {
			document.write('Sorry, unsupported runtime environment (' + get_operating_system() + ')');
		}
		
	} else {
			document.write('Renders disabled (' + client + ' / ' + get_operating_system() + ')');
	}
	
}



function boot_pages(){
	
	
	switch(levelcode){
	
		//case 'main': data_type = 'frontend'; menu_current = 0; load_data(); break;
		case 'main': build_layout_components(); break;
		case 'photogallery': build_layout_components(); break;
		case 'videogallery': build_layout_components(); break;
		case '24hour': data_type = 'frontend'; menu_current = 3; load_data(); break;
		case 'search': data_type = 'frontend'; menu_current = 4; load_data(); break;
		case 'hazank': build_layout_components(); break;
		default: build_layout_components();
	
	}
	
//	onLoginBoxPageLoad();


}

function slide_content(id){
	var force_reload = true;
	if(id){
		if(force_reload == true){
			window.open('/dock/' + id, '_self');
		} else {
			reinit();
			resetting_global_function_variables();
			levelcode = id;
			boot_pages();
		}
	} else {
		alert('Nem megfelelő hivatkozás');
	}
}


function timecall(modifier, obj){
	this.timeout_memory_flag = window.setInterval(
		function(){
			
			if($i('fe_box0')){
				window.clearInterval(this.timeout_memory_flag);
				blcom();
			}
	}, 10);
	
}
function build_layout_components(modifier, obj){
	
	var data = data_load;
	update_loader_status('Felépítés kirajzolása (' + data + ')');
	if(data == null) {update_loader_status('<span style="color:#e85123;">helytelen adat</span>');}
	
	/* compile frontend */
	//$i('content').innerHTML = '';
	var build = (obj) ? $i(obj) : $i('content');
	var topHeightOffset = 0;
	var topOffsets = 0;
	var compile_box;
	var parentOffset = $i('container').offsetHeight;
	var virtualHeight = 0;
	var memory_modifier = (modifier) ? modifier : null;
	var vbox = null;
	var load_boxshot = 1;
	var boxinfo;
	var boxcontent;
	if(build){

		/* creating virtual stage */
		if($i('virtualbox') == null){ document.body.appendChild(new_div('virtualbox'));}
		
		vbox = $i('virtualbox');
		vbox.style.position = 'relative';
		vbox.style.float = 'left';
		vbox.style.visibility = 'hidden';
		
		var limit = 0;
		var content = exclude_nodes(build, '#text').childNodes;
		for(i=0;i<content.length;i++){
			//limit = (data[i].item_limit == 0) ? 'unlimited' : data[i].item_limit;			
			/* load css first, to prevent render glitches */
			//load_component_stylesheet(css_url + 'components/' + data[i].component + '.css');	
			
			/*
			compile_box = $i('fe_box' + i);
			compile_box.style.border = '1px solid red';
			build.appendChild(new_div('boxinfo_'+i,'boxinfo opacity90',false));
			boxinfo = $i('boxinfo_'+i);
			boxcontent = exclude_nodes(compile_box.childNodes[0], '#text').childNodes[0];
			boxinfo.innerHTML  = boxcontent.className+'<br/>';
			boxinfo.innerHTML += 'width: '+compile_box.offsetWidth+'px<br/>';
			boxinfo.innerHTML += 'height: '+compile_box.offsetHeight+'px';
			boxinfo.style.zIndex = 10000000+i;
			boxinfo.style.top = compile_box.style.top;
			boxinfo.style.left = compile_box.style.left;
			*/
			//compile_box.style.top = (data[i].y != 0) ? data[i].y + 'px' : data[i].y;
			//compile_box.style.left = (data[i].x != 0) ? data[i].x + 'px' : data[i].x;

		}

		var old_height = ($i('content').style.height) ? eval($i('content').style.height.replace('px', '')) : 0;
		var new_height = optionalContentBottomPadding + (containerInitialHeight + topHeightOffset);

		/* flushing layout memory */
		
		document.body.removeChild(vbox);
		/* displaying content area */
		//content_resize(old_height, new_height);

		/* when buffer used */

		/* loading menuitems */
		run_page();
			
	} else {
		alert('Frontend rendering failed: No content area');
	}
}


function resize_stage_objects(){
	if(screenstage){ screenstage_resize(); }

	

	if($i('articles')){
		article_resize();
	}
}

function screenstage_resize(){
	get_resolution();
	var original_stage_height = $i('stage').offsetHeight;
	var extended_stage_height = ((screen_height - eval($i('footer').offsetHeight)) - eval($i('header').offsetHeight))-$i('top-box').offsetHeight;
	scale_div_height($i('stage'), original_stage_height, extended_stage_height, 20);
}

function content_resize(ori, ext){
	get_resolution();
	var original_stage_height = ori;
	var extended_stage_height = ext;
	$i('content').style.height = extended_stage_height + 'px';
}

function article_resize(){
	
	get_resolution();
	
	var top_dist = eval($i('article' + article_id).style.top.replace('px', ''));
	var banner_h = ($i('article_banner')) ? eval($i('article_banner').offsetHeight) : 0;
	var footer_h = ($i('footer') && screenstage) ? eval($i('footer').offsetHeight) : 0;
	var atitle_h = ($i('article_title')) ? eval($i('article_title').offsetHeight) : 0;
	var screen_hides = footer_h + banner_h + top_dist + atitle_h + 160;

	var original_article_height = $i('article_page' + article_id).offsetHeight;
	var extended_article_height = screen_height - screen_hides;
	
	if(client=='op'){
		var article_page = $i('article_page' + article_id);
		article_page.style.height = extended_article_height + 'px';
		article_page.style.overflow = 'auto';
		
	} else if(client=='sa'){
		
		var article_page = $i('article_page' + article_id);
		article_page.style.height = extended_article_height + 'px';	
		
	} else {
		scale_div_height($i('article_page' + article_id), original_article_height, extended_article_height, 5);
	}	
	$i('article_page' + article_id).style.visibility = 'visible';
}

function dump(arr,level) {
	var dumped_text = "";
	if(!level){ level = 0; }

	//The padding given at the beginning of the line.
	var level_padding = "";
	for(var j=0;j<level+1;j++){ level_padding += "    "; }

	if(typeof(arr) == 'object') { //Array/Hashes/Objects
	 for(var item in arr) {
	  var value = arr[item];
	 
	  if(typeof(value) == 'object') { //If it is an array,
	   dumped_text += level_padding + "'" + item + "' ...\n";
	   dumped_text += dump(value,level+1);
	  } else {
	   dumped_text += level_padding + "'" + item + "' => \"" + EncodeString(value) + "\"\n";
	  }
	 }
	} else { //Stings/Chars/Numbers etc.
	 dumped_text = ""+arr+" ("+typeof(arr)+")";
	}
	return dumped_text;
} 
function EncodeString(s) {
	var ss = new String();
	for( i = 0; i < s.length; i++) {
		var fs = s.charCodeAt(i);
		ss += '&#' + fs + ';';
	}
	return '' + ss + '';
}
function blu(string){
	if(blueprint == true){
		if(!$i('blujs')){
			if(!$i('blueprint')){ document.body.appendChild(new_div('blueprint',false,false)); }
			var blu = $i('blueprint');
			blu.style.display = 'block';
			blu.style.position = (ie6) ? 'absolute' : 'fixed';
			blu.style.top = '6px';
			blu.style.right = '6px';
			blu.style.border = '4px solid #0e2537';
			blu.style.display = 'block';
			blu.style.zIndex = 113000;
			blu.style.color = '#000000';
			blu.style.cursor = 'pointer';
			blu.style.width = '500px';
			blu.style.height = '200px';
			blu.style.overflowY = 'auto';
			blu.style.lineHeight = '12px';
			blu.style.backgroundColor = '#a8d5eb';
			object_opacity(blu, 75);
			blu.onclick = function () {
				blu.style.display = 'none';
			}
			var blu_puffer = blu.innerHTML;
		} else {
			var blu = $i('blujs');
			if($i('blueprint').style.display == 'none'){ $i('blueprint').style.display = 'block';}
		}
		var blu_puffer = blu.innerHTML;
		var output = (string) ? dump(string) : 'null / false / undefined';
		blu.innerHTML = blu_puffer + '<pre style="margin:0;padding:2px;">' + output + '</pre>';
		blu_puffer = null;
	}
}

function get_status(address) {

	var client = new XMLHttpRequest();
	client.open("HEAD", address);
	client.send();

}

function post_data(address, data) {

	var client = new XMLHttpRequest();
	client.open("POST", address);
	client.setRequestHeader("Content-Type", "text/plain;charset=UTF-8");
	client.send(data);
}

function load_data(postdata){
	timer_data=(new Date()).valueOf();
	update_loader_status('Betöltés: ' + data_type);
	switch(data_type){
		case 'frontend':
			switch(menu_current){
				case 0: data_url=data_path+data_link+'/frontend/main'; break;
				case 1: data_url=data_path+data_link+'/frontend/photogallery'; break;
				case 2: data_url=data_path+data_link+'/frontend/videogallery'; break;
				case 3: data_url=data_path+data_link+'/frontend/hour'; break;
				case 4: data_url=data_path+data_link+'/frontend/search/' + external_parameter; break;
				case 100: data_url=data_path+data_link+'/frontend/' + levelcode; break;
				default: data_url=data_path+data_link+'/frontend/main';
			}
			break;
		case 'component': data_url=data_path+data_link+'/components/' + component_id; break;
		case 'article': data_url=data_path+data_link+'/article/' + article_id; break;
		case 'command': data_url=data_path+data_link + '/command/' + command_name; break;			
		case 'menu': data_url=data_path+data_link+'/menu/dock'; break;		
		case 'footer': data_url=data_path+data_link+'/footer/dock'; break;
		case 'login': data_url=data_path+data_link+'?menu=login&username='+escape(login_username)+'&password='+escape(login_password); break;
		case 'set_topic_rank': data_url=data_path+data_link+'?menu=set_topic_rank&login='+login+'&topic='+ranking_topic+'&value='+ranking_value; break;
	}
	/* asyncron thread processing */
	var post_data = (postdata) ? postdata : null;
	var method = (post_data == null) ? 'GET' : 'POST';
	if(xml_http == null){
		if(client!='ie'){
			
			xml_http=new XMLHttpRequest();
			xml_http.onreadystatechange=xml_http_change;
			xml_http.open(method,data_url,true);
			xml_http.send(postdata);
			
		} else {
		

			xml_http=new ActiveXObject('Microsoft.XMLHTTP');





			xml_http.onreadystatechange=xml_http_change;
			xml_http.open(method,data_url,true);
			
			if(post_data == null){
				xml_http.send();
			} else {
				xml_http.send(postdata);
			}

		}
	}
}
function external_interface(cmd){
	var head = document.getElementsByTagName("HEAD")[0];
	var command_history = head.getElementsByTagName('SCRIPT');
	//for(var i=0;i<command_history.length;i++){
	//alert(command_history.length);

		head.removeChild(command_history[command_history.length-1]);
		
	//}
	var command_switch = cmd.split(':');
	var handler = '';
	update_loader_status('Betöltés, kis türelmet');
	switch(command_switch[0]){
		case 'register_a_vote': 		handler = 'display_vote_result()'; break;
        case 'vote_for_star':               handler = 'display_star_poll_result()'; break;
		case 'search_gallery_channels': 	handler = 'photogallery_search_gallery_channels()'; break;
		case 'search_galleries': 			handler = 'gallery_drag_channel_thumbnails()'; break;
		case 'search_articles': 			handler = 'search_result()'; break;
		case 'load_channel_galleries': 		handler = 'gallery_drag_channel_thumbnails()'; break;
		case 'load_channel_videogalleries': handler = 'gallery_drag_channel_thumbnails()'; break;
		case 'load_gallery':				handler = 'photogallery_drag_gallery_thumbnails()'; break;
		case 'load_videogallery':			handler = 'load_videodata()'; break;
		case 'article':						handler = 'display_article()'; break;
	}

	data_load = null;
	time = 0;
	var e = document.createElement("script");
	e.src = '/system/parser/command/' + cmd + '/2';
	e.type="text/javascript";
	document.getElementsByTagName("head")[0].appendChild(e);
	//	if (object.timeout_memory_flag) window.clearInterval(object.timeout_memory_flag);

	var frame = 0;
	e.timeout_memory_flag = window.setInterval(
		function(){
			function_indication();
			if(data_load != null){
				window.clearInterval(e.timeout_memory_flag);
				setTimeout(''+handler+'', time);
			}
	}, 10);
}


function xml_http_change(){
	
	setTimeout('function_indication()',50);
	

	if(xml_http.readyState==0){ update_loader_status('letöltés, kis türelmet');}
	if(xml_http.readyState==1){ update_loader_status('letöltés, kis türelmet');}
	if(xml_http.readyState==3){ update_loader_status('letöltés rendben, feldolgozás folyamatban');}

	update_loader_status('Tartalom feldolgozása (' + data_type.length + ' lépés)');
	
	if(xml_http.readyState==4){
		if(xml_http.status==200){
			timer_data=(new Date()).valueOf()-timer_data;
			timer_data=((timer_data-timer_data%1000)/1000)+'.'+(timer_data%1000);
			// getting the data
			try{
				data_load=PHP_Unserialize('' + xml_http.responseText + '');
			}
			catch(err){
				update_loader_status('<span style="color:#e85123;">hiba a soros művelet feldolgozásában</span> ' + data_type + ':'+xml_http.status); 
				
			}
			if(data_load != null){
				switch(data_type){
					case 'frontend':
						switch(menu_current){
							case 0: setTimeout('build_layout_components()',wait_timeout); break;
							case 1: setTimeout('build_layout_components()',wait_timeout); break;
							case 2: setTimeout('build_layout_components()',wait_timeout); break;
							case 3: setTimeout('build_layout_components()',wait_timeout); break;
							case 4: setTimeout('build_layout_components()',wait_timeout); break;
							case 100: setTimeout('build_layout_components()',wait_timeout); break;
							default:setTimeout('build_layout_components()',wait_timeout); break;
						}
						break;
					case 'menu': setTimeout('drag_menu()',wait_timeout); break;				
					case 'footer': setTimeout('drag_footer()',wait_timeout); break;
					case 'article': setTimeout('display_article()',wait_timeout); break;
					case 'command': 
						var command_switch = command_name.split(':');
						switch(command_switch[0]){
							case 'register_a_vote': 			setTimeout('display_vote_result()',wait_timeout); break;
							case 'search_gallery_channels': 	setTimeout('photogallery_search_gallery_channels()',wait_timeout); break;
							case 'search_galleries': 			setTimeout('gallery_drag_channel_thumbnails()',wait_timeout); break;
							case 'search_articles': 			setTimeout('search_result()',wait_timeout); break;
							case 'load_channel_galleries': 		setTimeout('gallery_drag_channel_thumbnails()',wait_timeout); break;
							case 'load_channel_videogalleries': setTimeout('gallery_drag_channel_thumbnails()',wait_timeout); break;

							case 'load_gallery': setTimeout('photogallery_drag_gallery_thumbnails()',wait_timeout); break;
							case 'load_videogallery': setTimeout('load_videodata()',wait_timeout+500); break;
						}
						break;				
				}
			} else {
				blu('no data parsed ' + data_type + menu_current);
			}
		}
	/* process thread limitation! */
	xml_http = null;
	}
}

function read_content(id, content_type){
	var keypressed;
	var keycode;
	this.onkeydown = function (event) {
		keycode = event.keyCode;
		if (event.keyCode == 16) {
			keypressed = 'shift';
		}
	}
	
	this.onkeyup = function (event) {
		keycode = event.keyCode;
		if (event.keyCode == 16) {
			keypressed = '';
		}
	}
	
	var target = (keypressed) ? '_blank' : '_self';
	alert(keycode);
	
	//webaudit_hit();
	if(content_type && id){
		if(content_type.indexOf('http:')!=-1){
			
			window.open(content_type, '_blank');

		} else {

			switch (content_type){
				case 'article': window.open('/cikk/' + id, target); break;
				case 'photo':	window.open('/dock/photogallery/'+channel_id+':'+id, '_self'); break;//gotoThe('photogallery', id); break;
				case 'video':	window.open('/dock/videogallery/'+channel_id+':'+id, '_self'); break;
				default: alert('hibás, vagy nem létező link. \n( read_content #' + id + ';' + title + ';' + content_type + ')');
			}

		}

	} else {
		alert(error_message(1));
	}

}

function error_message(errorcode){

	if(errorcode){

		switch(errorcode){ 
			case 1: return 'nem megfelelő hivatkozás'; break;
			case 2: return 'hibás, vagy nem létező link'; break;
			case 3: return 'ez az oldal nem elérhető'; break;
			default: return 'unknown error';
		}

	} else {

		alert('fatál error');

	}

}

function gotoThe(page, id){
	/* another page navigator */
	if(page && id){
		resetting_global_function_variables();
		switch(page){ 
			case 'main': init_home(); break;
			case 'photogallery': init_photogallery(); break;
			default: alert(error_message(2));
		}
		parameter = id;
	} else {
		alert(error_message(1));
	}
	
}

var article_multiple_instance = true;
var last_article_pos = null;
var check_aid = null;

function hide_article_space(){
	var obj = $i('articles');
	if(obj){
		obj.style.display = 'none';
		$i('articleswitch').onclick = function(){show_article_space();}
		$i('articleswitch').innerHTML = '[CIKKEK MEGJELENÍTÉSE: <strong>' + ($i('articles').childNodes.length) + ' futó cikk a háttérben.</strong>]';
	}
}
function show_article_space(){
	var obj = $i('articles');
	if(obj){
		obj.style.display = 'block';
		$i('articleswitch').onclick = function(){hide_article_space();}
		$i('articleswitch').innerHTML = '[CIKKEK ELREJTÉSE]';
	}
}

function open_link(url){

	if(url){
		//webaudit_hit();
		//window.open(url);
		blu(url);
	}
}

function pop_content(content, width,height){
/*	
	var title = content

	var w = (width) ? width : 800;
	var h = (height) ? height : 600;
	var x = ((screen.width-w)/2);
	var y = ((screen.height-y)/2);

	newwindow2=window.open('','name','height='+h+',width='+w+',left='+x+',top='+y+',dependent=1,alwaysRaised=1,location=0,resizable=0,status=0,titlebar=0,toolbar=0,directories=0,menubar=0,scrollbars=0');
	var tmp = newwindow2.document;
	tmp.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head></head><body style="margin:0">'+content+'</body></html>');
	tmp.close();
	//tmp.self.close();
*/
}

function print_article(id){
	
	var title = $i('article_title' + id);
	var paragraph = $i('paragraph' + id);

	var w = 800;
	var h = 600;
	var x = ((screen.width-w)/2);
	var y = ((screen.height-y)/2);

	newwindow2=window.open('','name','height='+w+',width='+h+',left='+x+',top='+y+'');
	var tmp = newwindow2.document;
	tmp.write('<h1>'+title.innerHTML+'</h1>'+ paragraph.innerHTML);
	tmp.close();
	newwindow2.window.print();
	//tmp.self.close();
}
/* other article functions */

function article_fontsize(id, size){
	var body = $i(id);
	var bodypages = body.getElementsByTagName('div');

	for(var i=0;i<bodypages.length;i++){
		bodypages[i].style.fontSize = size + 'px';
	}

}

function article_mail(id){
	alert('unfinished');

}


function article_videopost(id){
	alert('ez a komponens programozasra var');
}

function addListener(element, type, expression, bubbling){
	bubbling = bubbling || false;
	
	if(window.addEventListener)	{ // Standard
		element.addEventListener(type, expression, bubbling);
		return true;
	} else if(window.attachEvent) { // IE
		element.attachEvent('on' + type, expression);
		return true;
	} else return false;
}

function startup(){

}

function fade_stage(){
	var obj = (screenstage) ? 'stage' : 'content';

	if(prerender == true){ motion_fader_on_components($i(obj), 0, 100, 2);}
}

function fadeout_stage(){
	var obj = (screenstage) ? 'stage' : 'content';
	if(prerender == true){ motion_fader_on_components($i(obj), 100, 0, 2);}
}
function post_header_search(){
	var obj = document.forms['search_site'];
	var	keyword = (obj.elements[0].value.replace('Keresés ...')) ? obj.elements[0].value.replace('Keresés ...') : false;
	window.open('/dock/sitesearch/' + keyword, '_self'); 

}
function toggle_article_page(page){

	var body = exclude_nodes($i('article_body'), '#text');
	if($i('article_body')){
		for(var i=0;i<body.childNodes.length;i++){
			body.childNodes[i].style.display = (page == i) ? 'block' : 'none';
			$i('articlepage_' + i).className = (page == i) ? 'active' : 'inactive';
		}
		reorder_stageboxes();
		window.location.hash = 'article';
	} else {
		blu('mit lapozzak, semmit ?');
	}
}

function onTextFieldEnter( field_id, text ) {
    if ( $i( field_id ).value == text ) {
         $i( field_id ).value ='' ;
         $i( field_id ).style.color = "#000000"; 
    }
}

function onTextFieldLeave( field_id, text ) {
    if ( $i( field_id ).value == '' ) {
         $i( field_id ).style.color = "#888";
         $i( field_id ).value = text;
    }
}

function submitKeresesForm( form_id, field_id ) {
    var x = $i( field_id ).value;
    if ( x.substr( 0, 16 ) != 'Keresett kifejez' ) {
        $i( form_id ).submit();
    }
}

