/**
 * @author 2kal - inagy
 * @copyright 2010-2011
 */
var ajaxRefreshNum=0,temp='',temp2='',t,loginT,i=0,titleAddItem='',titleEditItem='',m_ver='ICogQGF1dGhvciBpbmFneQkNCiAqIEBjb3B5cmlnaHQgMjAxMC0yMDExCQ==',labels='',labels_old='';
var swfobject=swfobject?swfobject:0;
/** */
function selfUrlMaker(str){
	var xHref = String(window.location.href).replace(/\/#.*/,"");
	if(xHref[xHref.length-1]!="/") xHref += "/";
	xHref += str;
	return String(xHref);
}
var utilMH = {
	o:'',c:0,
	_each:function(obj,callback,args){
		utilMH.o = $(obj);
		utilMH.c = utilMH.o.length||0;
		for(i=0;i<utilMH.c;i++){ alert(utilMH.c+''+callback); callback.call($(utilMH.c[i]), args, $(utilMH.c[i])); }
		return utilMH.o;
	}
}

/** Flash Communication */
var flashMH = {
	id0:'f_streamView',id:'',is_open:false,
	getFlashMovie:function(movieName){
		var isIE = navigator.appName.indexOf("Microsoft") != -1;
		return (isIE) ? window[movieName]:document[movieName];
	},
	/** Szövegbeírás */
	callToActionscript:function(str){ if(this.id!=''){ flashMH.getFlashMovie(this.id).sendTextToFlash(str+" "+Math.random()); } },
	/** Bezárás */
	close:function(){ if(this.id!='' && this.is_open ){
		flashMH.getFlashMovie(this.id).closeConnect('s'); $('body').animate({dummy:1},700,function(){  }); }
		this.is_open = false;
	},
	/** Címke funkció */
	label:function(string){
		if(typeof flashMH.getFlashMovie(flashMH.id).streamLabel == 'function'){
			flashMH.getFlashMovie(flashMH.id).streamLabel(string);
		}
		else{
			$("body").animate({dummy:1},400,function(){flashMH.label(string);});
		}
	},
	/** Szünet szöveg megjelenítése */
	pause_text:function(string){
		if(typeof flashMH.getFlashMovie(flashMH.id).pause_text == 'function'){
			flashMH.getFlashMovie(flashMH.id).pause_text(string);
		}
		else{
			$("body").animate({dummy:1},400,function(){flashMH.pause_text(string);});
		}
	},
	play0:function(streamName){ return (flashMH.getFlashMovie(flashMH.id).startStream(streamName)); },
	/** Lejátszás */
	play:function(streamName){
		if(this.id!=''){
			$("#flash_player_contener").animate({dummy:1},300,function(){
				//alert(flashMH.id);
			/*/ Vizsgálata,hogy be tud-e jutni:flashMH.getFlashMovie(flashMH.id) /*/
				//var z = flashMH.play0(streamName);
				//z = flashMH.getFlashMovie(flashMH.id).startStream(streamName);
				//if(z=='undefined'||z==undefined||z==false){ alert(z); flashMH.play(streamName); }
				var z = typeof flashMH.getFlashMovie(flashMH.id).startStream == 'function';
				//console.log(streamName+"__",'info');
				if(z!=true){$("body").animate({dummy:1},400,function(){flashMH.play(streamName);});}
				else{ $("body").animate({dummy:1},400,function(){flashMH.play0(streamName);}); }
			});
		}
	},
	/** Automatikus lejátszás */
	autoPlay:function(elem){},
	/*
		if(this.id!=''){
			$('#streamView').ready(function(){
				//kell egy késleltető fvg!
				$('body').animate({dummy:1},700,function(){ $(elem).delay(100).trigger('click'); });
			});
		}
	},
	/** Flash lejátszó létrehozása */
	flashCreate_43:function(divID){
		var t = $('#'+divID);
		if(t.length>0){
			flashMH.is_open = true;
			var z = $.parseJSON($('#flash_vars').text());
			var refresh = z.a_refresh == "1" ? '?randomx='+Math.random() : '';
			this.id=(divID==undefined)?this.id0:divID.replace('d_','');
			var s = '';
			var w = 640, h = 480;
			switch(this.id){
				case "streamView":;case "streamPlay":;case "streamConf":;case "streamConfArchive":{
					s = '/player/'+this.id+'.swf'+refresh;
				};break;
				case "streamViewMini":{
					s = '/player/streamView.swf'+refresh;
					w = 210; h = 158;
				};break;
			}
			$('#'+divID).flash({ swf: s, width: w, height: h, play: false, id: flashMH.id, allowFullScreen:true, flashvars:z });
			//flashMH.play(z.a_stream);
		};
	}
};
/** Betöltő megjelenítése */
var loaderMH = {
	id : 'loaderDiv',
	obj : '',
	time : 100,
	/** Alapbeállítások */
	load:function(){
		loaderMH.obj = $('div#'+loaderMH.id);
		if((loaderMH.obj).length){
			(loaderMH.obj).delay(loaderMH.time).css("z-index",'10101');
		}
	},
	/** betöltés megkezdődött */
	loading:function(){ (loaderMH.obj).delay(loaderMH.time).show(); },
	/** Betöltés megtörtént */
	loaded:function(){ (loaderMH.obj).delay(loaderMH.time).hide(); },
	__destruct:function(){
		loaderMH.load();
		loaderMH = null;
		delete loaderMH;
	}
}
/** Óra és dátum kijelzés */
var clockMH = {
	date: '',id: '#server_time',id0:'server_time',
	firstRun:true,offset:0,repeatTime:450,time:0,
	t:'',run: false,second:-1,obj:'',z:'',z0:'',
	load:function(){
		var z = $(clockMH.id);
		if(z.length){
			var z = parseFloat($("#server_time").attr("rel"));
			clockMH.z = new Date();
			clockMH.offset = z-clockMH.z.valueOf();
			clockMH.dateCreate(clockMH.z.valueOf());
			z = null;
			
			clockMH.second = clockMH.z.getSeconds();
			clockMH.t = setInterval('clockMH.clock()',clockMH.repeatTime);
			clockMH.run = true;
			clockMH.obj = $(clockMH.id+'>'+clockMH.id+'_timeX');
			clockMH.clock();
			if(clockMH.firstRun) clockMH.firstRun = false;
		}
	},
	/*/ Dátum létrehozása /*/
	dateCreate:function(zValue){
		clockMH.z = new Date(zValue+clockMH.offset);
		clockMH.date = ' '+clockMH.z.getFullYear()+'-'+clockMH._ex(clockMH.z.getMonth()+1)+'-'+clockMH._ex(clockMH.z.getDate())+' ';
		$('#'+clockMH.id0+'_dateX').html(clockMH.date);
		//clockMH.spanCreate();
	},
	/*spanCreate:function(){
		$(clockMH.id).html('<span id="'+clockMH.id0+'_dateX">'+clockMH.date+'</span><span id="'+clockMH.id0+'_timeX"></span>');
	},*/
	/*/ Kiegészítés a szebb dátumformátumhoz /*/
	_ex:function(e){ return (e<10)?('0'+e):e; },
	/* Óra futás közben */
	clock:function(){
		if(clockMH.run){
			clockMH.z0 = new Date(); clockMH.zValue = clockMH.z0.valueOf();
			clockMH.z = new Date(clockMH.zValue+clockMH.offset);
			//if(clockMH.second != clockMH.z.getSeconds() && clockMH.second){
			if(!(clockMH.z.getSeconds()%5)||clockMH.firstRun){
				//if(clockMH.firstRun) clockMH.firstRun = false;
				if(clockMH.z.getHours()==0) clockMH.dateCreate(clockMH.zValue);
				clockMH.obj.html(clockMH._ex(clockMH.z.getHours())+':'+clockMH._ex(clockMH.z.getMinutes())+':'+clockMH._ex(clockMH.z.getSeconds()));
				clockMH.second = clockMH.z.getSeconds();
			}
		}
	},
	/*/ Óra lebontása /*/
	__destruct:function(){
		clearInterval(clockMH.t);
		clockMH = null;
		delete clockMH;
	}
}
/*
function setArchiveHeight(column,center){
	var maxHeight = 0;
    column = $(column);
    var diff = 0;
    //for(i=0,c=column.length;i<c;i++){ if(column[i].height() > maxHeight) { maxHeight = column[i].height(); } }
	column.each(function() { if($(this).height() > maxHeight) { maxHeight = $(this).height(); } });
	var margin = 0;
	column.each(function() {
		if($(this).height() < maxHeight) {
			margin = ((maxHeight-$(this).height())/2);
			$(this).find(center).css({"margin-bottom":+margin,"margin-top":+margin});
			$(this).height(maxHeight);
		}
	});
	column = null;
	//Set the height
	//column.height(maxHeight);//.css({'line-height':maxHeight});
	//alert(column.length + " - "+maxHeight);
}*/

var mainMH = {
	timer:0,lang:'hu',
	onDelegate:function(){
		$('body').delegate('a.flash_play','click',function(e){
			e.preventDefault();
			var rel = $(this).attr('rel');
			flashMH.play(rel);
		});
		$('body').delegate('.flash_controll_contener select','change',function(e){
			/*/ var rel = $(this).val(); /*/
			var z = $('#flash_neve');
			var str = '';
			str = $(this).val();
			/*/console.log(str+"-",'info'); /*/
			if(z.length){ z.html(str); }
			flashMH.play(str);
			/*/alert(str);/*/
		});
		$('body').delegate('select[name=nap], select[name=terem]','change',function(e){
			var n = $('select[name=nap]').val(), t = $('select[name=terem]').val();
			$('div.flash_controll_contener').removeClass("display_itable").addClass("display_none")
			$('div#s'+n+'_'+t).removeClass("display_none").addClass("display_itable");
			$('div#s'+n+'_'+t+" select").trigger('change');
			/*$('div.flash_controll_contener').removeClass("display_itable").hide(1,function(){
				$('div#s'+n+'_'+t).removeClass("display_none").addClass("display_itable");
			});*/
		});
	},
	onReady:function(){
		mainMH.onDelegate();
		var l1 = String(window.location.href).split("/");
		if(typeof l1 == Array && l1[3]!=undefined){
			mainMH.lang = String(l1[3]);
		}
		l1 = null;
		/*jQuery.ajax({
			cache:false,
			error:function(){ alert('Uknow Error / Ismeretlen hiba'); }
		});*/
		/*/ Tipsy css /*/
		var flashN = 0;
		var z = '';
		/*/z = $('*[class*=tipsy]');
		if(z.length){ z.css('opacity',0.1); }
		/*/
		
		/*/ Óra betöltése /*/
		$('#jsError').hide();
		/** Kettő, vagy több, mehet egybe */
		z = $("div#d_streamView,div#d_streamPlay,div#d_streamViewMini");
		if(z.length){
			/* ARCHIVE */
			flashMH.flashCreate_43(z[0].id);
			$(document).scrollTop(z.scrollTop());
			flashN++;
			if($("div#d_streamViewMini").length){
				$("div#d_streamViewMini").css({width:'auto',height:'auto'});
			}
		}
		/** Ugyanolyan sormagasságúak legyenek */
		/*
		z = $(".eqH");
		if(z.length){ setArchiveHeight('.eqH>div','img:first'); }
		*/
		
		z = $('#archive_menu').find('.tema_link');
		if(z.length){
			z.click(function(e){
				e.preventDefault();
				var id = $(this).attr('id');
				var txt = $(this).text();
				$('.tema_flag').hide();
				$('.'+id).show();
				$('#tema_view').text(txt);
				id = null;
				txt = null;
			});
		}
		z = $('form:first').find('input[type=text]:first');
		if(z.length&&flashN==0){
			z.trigger('focus');
		}
		z = $(".confirm");
		if(z.length){
			for(i=0,j=z.length;i<j;i++){
				$(z[i]).click(function(e){ return confirm($(this).attr('rel')); });
			}
			/*z.click(function(e){
				//e.preventDefault();
				return confirm($(this).attr('rel'));
			});*/
		}
		
		z = $("#tabs");
		if(z.length){
			z.tabs();
			$(".tabs-bottom .ui-tabs-nav, .tabs-bottom .ui-tabs-nav > *" ).removeClass( "ui-corner-all ui-corner-top" ).addClass( "ui-corner-bottom");
		}
		z = setTimeout('clockMH.load()',800);
		
		var z = $('.e_tipsy');
		if(z.length){ for(i=0,j=z.length;i<j;i++){ $(z[i]).tipsy({gravity: 'e',offset:3}); } }
		z = $('.se_tipsy');
		if(z.length){ for(i=0,j=z.length;i<j;i++){ $(z[i]).tipsy({gravity: 'se',offset:3}); } }
		z = $('.sw_tipsy');
		if(z.length){ for(i=0,j=z.length;i<j;i++){ $(z[i]).tipsy({gravity: 'sw',offset:3}); } }
		z = $('.w_tipsy');
		if(z.length){ for(i=0,j=z.length;i<j;i++){ $(z[i]).tipsy({gravity: 'w',offset:3}); } }
		z = $('.n_tipsy');
		if(z.length){ for(i=0,j=z.length;i<j;i++){ $(z[i]).tipsy({gravity: 'n',offset:3, html:true}); } }

		z = $('#kozvetitesek_lista');
		if(z.length){
			var r = z;
			var gorget = r.find('li').height();
		    r.vTicker({
				speed: 1000,
				pause: 3000,
				showItems: 5,
				animation: 'none',
				mousePause: true,
				height: 320,
				direction: 'up',
				top: 0
		    });
		    r.mousewheel(function(e,delta){
		    	e.preventDefault();
		    	var d = gorget;
		    	if(delta>0){
		    		d *= -1;
		    	}
		    	r.scrollTop(r.scrollTop()+d);
		    	/*/r.animate({scrollTop:(r.scrollTop()+d)},300);/*/
		    });
		    r.mouseleave(function(){
	    		r.scrollTop(Math.floor(r.scrollTop()/gorget)*gorget);
		    });
		};
		
		mainMH.calendar_control("1");
		mainMH.calendar_control("2");
		
		z = null;
	},
	/** Naptár objektum */
	calendar_control:function(id){
		var z = $("div.main_calendar_"+id);
		if(z.length){
			$(z.find('a.month_page')).unbind("click").button('destroy');
			z.find('a.next_month').button({icons:{primary:'ui-icon-carat-1-e'},text:false});
			z.find('a.prev_month').button({icons:{primary:'ui-icon-carat-1-w'},text:false});
			$(z.find('a.month_page')).click(function(e){
				e.preventDefault();
				z.load($(this).attr("href"),function(){
					/*/z.find('a.month_page').button('refresh');/*/
					mainMH.calendar_control(id);
					z=null;
				});
			});
		}
	},
	__destruct:function(){
		loaderMH.__destruct();
		clockMH.__destruct();
	}
}

$(document).ready(mainMH.onReady);
$(window).unload(mainMH.__destruct);
