// JavaScript Document

$(document).ready(function(){
	//# LINKEK TILTÁSA
	$("a[href=#]").click(function(event){
		event.preventDefault();
		$("a[href=#]").click(function(event){
			event.preventDefault();
		});
	});
	
	//BANNER
	var ajax_req = false;
	$(".click_banner").click(function(){
		var bannerLink = $(this).attr("href");
		if(!ajax_req){
			ajax_req = true;
			$.ajax({
	      		type: 'POST',
    	  		url: "pages/ajax.banner.php",
				data: { BANNER_LINK : bannerLink},
				success: function(data){
					ajax_req = false;
				}
    		});
		}
	});
	
	//ANYAKÖNYVI LLINK
	$(".anyakonyv").click(function(event){
		if($(this).attr("class") == "cell_link anyakonyv"){
			event.preventDefault();
			$(".pdfreader").attr("src",$(this).attr("href"));
			$("a").click(function(event){
				if($(this).attr("class") == "cell_link anyakonyv"){
					event.preventDefault();
					$(".pdfreader").attr("src",$(this).attr("href"));
				}
  		 	});
		}
   	});
	
	//FEJLÉC HOSSZ
	if($("#dates").height() > 25){
		$("#dates > *, #dates").css("font-size","10px");
	}
						   
	//FEJLÉC KERESŐ
	var isSearc = false;
	//if($.browser.msie
	$("#search").click(function(){
		if($("#header_search").val() != "Keresés..." & $("#header_search").val() != "Search..."){
			var pg = ($(this).attr("lang")=="en")?"searcher":"kereso";
			$(this).parent("form").attr("action",pg+"/"+encodeURI($("#header_search").val()));
		} else {
			return false;
		} 
	});
	$("#header_search").keyup(function(){
		var pg = ($("#search").attr("lang")=="en")?"searcher":"kereso";
		$(this).parent("form").attr("action",pg+"/"+encodeURI($(this).val()));
	});
	$("#header_search").focus(function(){
		if(($(this).val() == "Keresés..." | $(this).val() == "Search...") && !isSearc){
			$(this).val("");
			isSearc = true;
		} 
	});	
	if ($.browser.msie && $.browser.version.substr(0,1)<7) {
		$("#searcher").find("input[type=text]").remove();
	}
	//LOGO LINKÉÉ ALAKÍTÁS
	$("#logo").css("cursor","pointer");
	$("#logo").click(function(){
		if(window.location.href.toString().indexOf('magyarnevek.hu') > -1){
			window.location.href = 'http://magyarnevek.hu';
		} else {
			window.location.href = 'http://magyarnevek.com';
		}
	});
	
	//LAP TETEJÉRE
	$("#topofpage").css("cursor","pointer");
	$("#topofpage").html($("#topofpage").text());
	$("#topofpage").click(function(){
		$(document).scrollTop(0);
		return false;
	});
	
	//MÉRETEZÉS
	if($(window).width() < ($("#main").width() + $("#google").width())){
		$("#main").css("left","0");
		$("#main").css("margin-left","10px");
		$("#google").css("left","0");
		$("#google").css("margin-left","810px");
	} else {
		$("#main").css("left","50%");
		$("#google").css("left","50%");
		$("#main").css("margin-left","-400px");
		$("#google").css("margin-left","400px");
	}
	$(window).resize(function(){
		if($(window).width() < ($("#main").width() + $("#google").width())){
			$("#main").css("left","0");
			$("#main").css("margin-left","10px");
			$("#google").css("left","0");
			$("#google").css("margin-left","810px");
		} else {
			$("#main").css("left","50%");
			$("#google").css("left","50%");
			$("#main").css("margin-left","-400px");
			$("#google").css("margin-left","400px");
		}
	});
	
	//SZAVAZÁS
	$("#szavGomb").click(function(){	
		if($("input[@type=radio,@name=szavazas]:checked").length > 0 && readCookie('szavazas') != 1){
        	$('#votetable').html('<tr><td class="title">Szavazás</td></tr><tr><td><input id="szavazasH" type="hidden" value="'+$("input[@type=radio,@name=szavazas]:checked").val()+'" /></td></tr><tr><td>Pillanat...</td></tr>');
			createCookie('szavazas','1',30);
			$.ajax({
      			type: 'POST',
      			url: "pages/ajax.main_vote.php",
				data: { vote : $("#szavazasH").val()},
      			success: function(data) {
        			$('#votetable').html('<tr><td class="title">Szavazás</td></tr>'+data+'<tr><td class="close" colspan="2">&nbsp;</td></tr>');
      			}
    		});
		}
		return false;
	});
	
	//MEGOSZTÁS	
	$(".shareico, .shareopen").css("opacity","0.7");
	$(".shareico, .shareopen").mouseover(function(){
		$(this).css("opacity","1");
	});
	$(".shareico, .shareopen").mouseout(function(){
		$(this).css("opacity","0.7");
	});
	$(".shareico").hide();
	var shareopened = false;
	$(".shareopen").click(function(){
		$(this).hide();
		$(this).parent(".sharebar").find(".shareico").show();
		shareopened = false;
	});	
	$(".sharebar").mouseover(function(){
		shareopened = false;
	});
	$(".sharebar").mouseout(function(){
		shareopened = true;
		if(shareopened){
			setTimeout(function(){
				if(shareopened){
					$(".sharebar").find(".shareopen").show();
					$(".sharebar").find(".shareico").hide();
				}
			},500);
		}
	});
	$(".shareico").attr("title",function(){var lang = $(this).attr("class").split(" "); if(lang[1] == "ang"){return "Share on "+$(this).find("img").attr("alt")+"!";} else { return "Oszdd meg "+$(this).find("img").attr("alt")+"-"+(($(this).find("img").attr("alt") == 'facebook' || $(this).find("img").attr("alt") == 'Tumblr' || $(this).find("img").attr("alt") == 'StumbleUpon')?'on!':'en!');}});
	$(".shareico").click(function(){		
		var href = $(this).attr("href");
		href = href.split(((href.indexOf("twitter") > -1)?"?status=":((href.indexOf("stumbleupon") > -1 || href.indexOf("digg") > -1)?"?url=":"?u=")));
		var t = "";
		var u = "";
		if(href[1].indexOf("&amp;t=") > -1){
			href[1] = href[1].split("&amp;t=");	
			u = href[1][0];
			t = href[1][1];
		} else {
			u = href[1];
			t = document.title;
		}
		window.open(href[0]+(($(this).attr("href").indexOf("twitter") < 0)?(($(this).attr("href").indexOf("stumbleupon") < 0 && $(this).attr("href").indexOf("digg") < 0)?"?u=":"?url="):"?status=")+(($(this).attr("href").indexOf("twitter") < 0)?encodeURIComponent(u):u)+"&t="+encodeURIComponent(t)+(($(this).attr("href").indexOf("tumblr") > -1)?"&v=3":(($(this).attr("href").indexOf("stumbleupon") > -1)?"&s=4":"")),'sharer','toolbar=0,status=0,width=626,height=436,scrollbars=1,resizable=1');
		$(this).parent(".sharebar").find(".shareopen").show();
		$(this).parent(".sharebar").find(".shareico").hide();
		return false;
	});
	
	/*$(".comments").mouseover(function(){
		var myRegExp = new RegExp("<span(.*?) - ","g");
		var content = $(this).html();
		content = content.replace(myRegExp,"");
		if(content != '' && !$(this).children().is("em") && $(this).attr("tagName") == "P"){
			$(this).addClass("sharecom");
			$(this).children(".share").show();
			$(this).children(".share").css("display","block");
			$(this).mouseout(function(){
				$(this).children(".share").hide();
				$(this).removeClass("sharecom");
			});
		}
	});*/
	
	//KIVÁLASZTOTT NÉV
	var url = window.location.toString();
	if(url.indexOf('fiunevek') > -1 | url.indexOf('lanynevek') > -1 | url.indexOf('boys') > -1 | url.indexOf('girls') > -1){
		url = url.split('/');
		for(i = 0; i < url.length; i++){
			if((url[i] == 'fiunevek' | url[i] == 'lanynevek' | url[i] == 'boys' | url[i] == 'girls') & url[i+1] != null & url[i+2] != null){
				var name = url[i+2];
				break;
			}
		}
		if(url.join("/").indexOf("rovas") > -1){
		 	name = RunesChange(name);
		}
		for(i = 0; i < $(".name").length; i++){
			if($(".name:eq("+i+")").html() == decodeURI(name)){
				$(document).scrollTop($(".name:eq("+i+")").offset().top-20);
				break;
			}
		}
	}
	
	//NÉVNAP EMLÉKEZTETŐ
	if($("#here").length > 0){
		var emlTop = '';
		var herTop = $("#here").offset().top;
		$(window).scroll(function(){
			if (window.pageYOffset) {
	    		emlTop = window.pageYOffset;
			} else if (document.documentElement) {
	    		emlTop = document.documentElement.scrollTop;
			} else if (document.body.scrollTop) {
	    		emlTop = document.body.scrollTop;
	   		} else {
	    		emlTop = 0;
	    	}
			if(emlTop > herTop){
				$("#here").css("position","fixed");
				$("#here").css("top","5px");
				$("#here").css("overflow","auto");
				$("#here").css("max-height","95%");
			} else {
				$("#here").css("position","");
				$("#here").css("top",herTop+"px");
				$("#here").css("overflow","hidden");
				$("#here").css("max-height","none");
			}
		});
		
		$("#remclear").urit();
		$(".up").draggable({ 
			revert: "invalid", 
			appendTo: "body",
			helper: "clone"
		});
		$(".up").css("cursor","pointer");	
		$(".down").draggable({ 
			revert: "invalid", 
			appendTo: "body",
			helper: "clone"
		});
		$(".down").css("cursor","pointer");
		$("#here").parent(".content").height($("#here").height());
		$("#here").droppable({
			drop: function(event, ui) {	
				if($("#here").find("form").length == 0){
					$("#here").html('<form method="post" action=""><div id="content"></div>E-mail:<input type="text" name="rememail" id="rememail" class="input_text" /><input class="button" type="submit" name="remember" id="remember" value="Feliratkozás" /> <input class="button" type="button" id="remclear" value="Ürít" /></form>');
				}
				if($("#content").find("#"+$(ui.draggable).attr("id").replace("nev","eml")).length == 0){
					var putDom = $(ui.draggable).clone();
					var nevnapok = (readCookie('nevnapok') == null || readCookie('nevnapok') == 'null')?'':readCookie('nevnapok');
					nevnapok += "\|"+putDom.attr("id").replace(/nev|eml/g,"")+"\|";
					createCookie('nevnapok',nevnapok,10);
					putDom.attr("id",putDom.attr("id").replace("nev","eml"));
					putDom.addClass("down");
					putDom.removeClass("up");
					$("#content").append('<input type="hidden" name="addRem[]" value="'+putDom.attr("id").replace("eml","")+'" />');
					putDom.appendTo($("#content"));
					$("#content").append('<br />');
				}
				$(".down").draggable({ 
					revert: "invalid", 
					appendTo: "body",
					helper: "clone"
				});
				$("#remclear").urit();				
				$("#here").parent(".content").height($("#here").height());
			},
			out: function(event, ui) {
				$(ui.draggable).prev("input").remove();
				$(ui.draggable).next("br").remove();
				$(ui.draggable).remove();
				var nevnapok = (readCookie('nevnapok') == null || readCookie('nevnapok') == 'null')?'':readCookie('nevnapok');
				nevnapok = nevnapok.replace("\|"+$(ui.draggable).attr("id").replace("eml","")+"\|","");
				createCookie('nevnapok',nevnapok,10);
				$("#"+$(ui.draggable).attr("id")).remove();
				if($("#here").find(".down").length == 0){
					$("#here").html('<span id="empty">Húzza ide a kiválasztott neveket!</span>');
					$("#here").parent(".content").height($("#here").height());
				}
			}
		});
	}
	
	//HIÁNYZÓ NEVEK
	var months = new Array(); 
	months.Január = 1;
	months.Február = 2;
	months.Március = 3;
	months.Április = 4;
	months.Május = 5;
	months.Június = 6;
	months.Július = 7;
	months.Augusztus = 8;
	months.Szeptember = 9;
	months.Október = 10;
	months.November = 11;
	months.December = 12;
	$(".calendar_text").change(function(){
		for(i = 1; i <= 31; i++){
			$(".calendar_cell:eq("+i+")").html('<a href="#">'+i+'</a>');
		}
		$(".calendar_cell:gt("+$(this).val()+")").html("&nbsp;");
		$(".calendar_cell").find("a").click(function(){
			var toDate = $(".calendar_text").find("option:selected").text()+" "+((parseInt($(this).text()) < 10)?"0"+$(this).text():$(this).text())+"., ";
			if($("#innamedays").val().indexOf(toDate) == -1){
				$("#innamedays").val($("#innamedays").val()+toDate);
			}	
			toDate = '';
			var innamedayVal = $("#innamedays").val().replace(/, /g,",").split(",");
			var x;
			for(i = 0; i < innamedayVal.length - 1; i++){
				for(j = i + 1; j < innamedayVal.length; j++){
					var mi = innamedayVal[i].split(" ");
					var mj = innamedayVal[j].split(" ");
					if(months[mi[0]] > months[mj[0]]){
						x = innamedayVal[i];
						innamedayVal[i] = innamedayVal[j];
						innamedayVal[j] = x;
					}
				}
			}
			for(i = 0; i < innamedayVal.length - 1; i++){
				for(j = i + 1; j < innamedayVal.length; j++){
					var mi = innamedayVal[i].split(" ");
					var mj = innamedayVal[j].split(" ");
					if(months[mi[0]] == months[mj[0]]){
						if(mi[1] > mj[1]){
							x = innamedayVal[i];
							innamedayVal[i] = innamedayVal[j];
							innamedayVal[j] = x;
						}
					}
				}
			}
			for(i = 0; i < innamedayVal.length; i++){
				if(innamedayVal[i] != ''){
					toDate += innamedayVal[i]+", ";
				}
			}
			$("#innamedays").val(toDate);
			return false;
		});
	});
	$(".calendar_cell").find("a").click(function(){
		var toDate = $(".calendar_text").find("option:selected").text()+" "+((parseInt($(this).text()) < 10)?"0"+$(this).text():$(this).text())+"., ";
		if($("#innamedays").val().indexOf(toDate) == -1){
			$("#innamedays").val($("#innamedays").val()+", "+toDate);
		}	
		toDate = '';
		var innamedayVal = $("#innamedays").val().replace(/, /g,",").split(",");
		var x;
		for(i = 0; i < innamedayVal.length - 1; i++){
			for(j = i + 1; j < innamedayVal.length; j++){
				var mi = innamedayVal[i].split(" ");
				var mj = innamedayVal[j].split(" ");
				if(months[mi[0]] > months[mj[0]]){
					x = innamedayVal[i];
					innamedayVal[i] = innamedayVal[j];
					innamedayVal[j] = x;
				}
			}
		}
		for(i = 0; i < innamedayVal.length - 1; i++){
			for(j = i + 1; j < innamedayVal.length; j++){
				var mi = innamedayVal[i].split(" ");
				var mj = innamedayVal[j].split(" ");
				if(months[mi[0]] == months[mj[0]]){
					if(mi[1] > mj[1]){
						x = innamedayVal[i];
						innamedayVal[i] = innamedayVal[j];
						innamedayVal[j] = x;
					}
				}
			}
		}
		for(i = 0; i < innamedayVal.length; i++){
			if(innamedayVal[i] != ''){
				toDate += innamedayVal[i]+", ";
			}
		}
		$("#innamedays").val(toDate.replace(/,\s$/,""));
		return false;
	});
	
	//HIÁNYZÓ NEVEK ADMIN
	$(".accept, .denied").attr("onclick","");
	var lek = false;
	$(".accept, .denied").click(function(){
		var nameAct = $(this).attr("class").split(" ",2);
		var nameAle = (nameAct[0]!="accept") ? (nameAct[0]=="denied")?"elutasítod":"":"elfogadod";
		if(nameAle != ""){
			if(confirm("Biztos " + nameAle + " a nevet?") && !lek){
				lek = true;
				$(this).parent("p").css("opacity",".5");
				$.ajax({
      				type: 'GET',
      				url: "admin/pages/ajax.name.php?id=" + nameAct[1] + "&action=" + nameAct[0],
  		    		success: function(data) {
						var requestGU = data.split("=",2);
						if(requestGU[0] == "Yes"){
							$(".errors").html(requestGU[1]);
							var namescount = parseInt($("h1:contains(Ellenőrizetlen nevek)").html().replace(/[^0-9]/g,""))-1;
							$("h1:contains(Ellenőrizetlen nevek)").html($("h1:contains(Ellenőrizetlen nevek)").html().replace(/\d+/g,namescount));
							alert(requestGU[1]);
							$("#nev" + nameAct[1]).parent("p").remove();
							lek = false;
						} else {
							$(".errors").html(requestGU[1]);
							alert(requestGU[1]);
							$("#nev" + nameAct[1]).parent("p").css("opacity","1");
							lek = false;
						}
      				}
    			});
			}
		}
		return false;									
	});
	
	//VENDÉGKÖNVY
	$(".toggle").readReply();
	
	//-->smiley
	$(".smiley").click(function(){
		var smiley = $(this).attr("class").split(" ");
		smiley = smiley[1];
		$("#inmessage").val($("#inmessage").val()+smiley.replace(/\('|'\)/g,""));
		$("#inmessage").focus();
	});
	
	//-->válasz
	$(".replyMSG").click(function(){
		var rId = $(this).parent("td").text().split("#");
		rId = rId[1].split(",");
		rId = rId[0];
		$("#reply").val(rId);
		if(window.location.href.toString().indexOf('magyarnevek.hu') > -1){
			$("#replydiv").html('Válasz '+$(this).parent("td").text().replace(/, válasz erre/," üzenetére")+'<img src="images/admin/denied.png" alt="Mégsem" class="cancel" title="Mégsem" height="12" width="12" />');
			$(".cancel").css("cursor","pointer");
			$(".cancel").click(function(){
				$("#replydiv").html("");
				$("#reply").val("0");				
			});
		} else {
			$("#replydiv").html('Reply to '+$(this).parent("td").text().replace(/, válasz erre/," message")+'<img src="http://magyarnevek.hu/images/admin/denied.png" alt="Cancel" class="cancel" title="Mégsem" height="12" width="12" />');
			$(".cancel").css("cursor","pointer");
			$(".cancel").click(function(){
				$("#replydiv").html("");
				$("#reply").val("0");				
			});
		}
		
	});
	
	//--> max karakter
	$("#inmessage").keyup(function(){
		if(1000-$(this).val().length < 0){
			alert('Az üzenet hossza nem haladhatja meg az 1000 karaktert!');
			$(this).val($(this).val().substr(0,1000))
		}
		$("#szamlalo").val(1000-$(this).val().length);
	});
	
	//--> admin name
	$(".adminName").keyup(function(){
		if($(this).val() == '@@MKT@@'){
			$(this).val('Magyar Keresztnevek Tára');
		}
	});
	
	//--> link hozzáadás
	$(".addLink").click(function(){
		var url = prompt('Írd be a link URL-jét!','http://');
		if(url != '' & url != 'http://'){
			title = prompt('Írd be a link szövegét!','');  
			if (title!=''){
				$('#inmessage').val($('#inmessage').val()+' [url='+url+']'+title+'[/url]');
			} 
		}
	});
	
	//TOP 100
	var nevek = '';
	//$("#top100").find("input[type=checkbox]").parent("td").showGraph();
	//$("#top100").find("input[type=checkbox]").parent("td").showGraph();
	//$("#top100").find("input[type=checkbox]").showGraph();
	//$("#top100").find("input[type=checkbox]").parent("td").next("td").showGraph();
	//$("#top100").find("input[type=checkbox]").parent("td").next("td").next("td").showGraph();
	$("#top100").find("input[type=checkbox]").click(function(){
		if($("#top100").find("input:checked").length > 8){
			return false;
		} else {
			nevek = '';
			for(i = 0; i < $("#top100").find("input:checked").length; i++){
				nevek += $("#top100").find("input:checked:eq("+i+")").val();
				if(i < $("#top100").find("input:checked").length - 1){
					nevek += "-";
				}
			}
			$("#graphimg").children("img").attr("src","http://magyarnevek.hu/pages/graph.php?names=" + nevek);
		}
	});
	$(".top100").click(function(){
		if($("#top100").find("input:checked").length >= 2){
			CB_Open('href=http://magyarnevek.hu/pages/graph.php?names='+ nevek + ',,width=650,,height=490');
		} else {
			alert("Legalább két nevet ki kell jelölj az összehasonlításhoz!");
		}
	});
	
	//NEVEK CSOPORTOSÍTÁSA
	if($("#classificationdiv").length > 0){
		var csopTop = '';
		var divTop = $("#classificationdiv").offset().top;
		$(window).scroll(function(){
			if (window.pageYOffset) {
		   		csopTop = window.pageYOffset;
			} else if (document.documentElement) {
		   		csopTop = document.documentElement.scrollTop;
			} else if (document.body.scrollTop) {
		   		csopTop = document.body.scrollTop;
		  		} else {
		   		csopTop = 0;
		   	}
			if(csopTop > divTop){
				$("#classificationdiv").css("position","fixed");
				$("#classificationdiv").css("top","5px");
			} else {
				$("#classificationdiv").css("position","");
				$("#classificationdiv").css("top",divTop+"px");
			}
		});
	}
	
	//NYOMTATÁS
	$(".print").click(function(){
		window.print();
	});
	
	//MOBIL VERZIÓ
	$(".mobil").click(function(){
		window.location.href = '?m=true';
	});
	
	//GYENGÉNLÁTÓ VERZIÓ
	$(".gyengen").click(function(){
		window.location.href = 'gyengenlatoknak';
	});
	
	var out = false;
	//KÜLSŐ
	$(".css").mouseover(function(){	
		$("#cssek").fadeIn(100);
		out = false;
		/*if(getActiveStyleSheet() == 'default')
			setActiveStyleSheet('babas');
		else 
			setActiveStyleSheet('default');
		$(window).resize();*/
	});	
	$(".css").mouseout(function(){
		out = true;
		setTimeout(function(){
			if(out){
				$("#cssek").fadeOut(100);
			}
		},500);
	});
	$("#cssek").mouseover(function(){
		out = false;
	});
	$("#cssek").mouseout(function(){
		out = true;
		setTimeout(function(){
			if(out){
				$("#cssek").fadeOut(100);
			}
		},500);
	});
	$("#cssek").find("a").click(function(){
		var css = $(this).attr("class").replace("css_","");
		//alert(css);
		setActiveStyleSheet(css);
	});
	
	//HÓNAP CSERE
	$("span[class=change_month]").mouseover(function(){
		var title = $(this).attr("title");
		$(this).attr("title",$(this).html());
		$(this).html(title);
	});
	$("span[class=change_month]").mouseout(function(){
		var title = $(this).attr("title");
		$(this).attr("title",$(this).html());
		$(this).html(title);
	});
	
	
	if($("#vote_box").find(".errors").length <= 0){
		$("#vote_box").css({
			"opacity":".0"
		});
	} else {
		$("body").css("overflow","hidden");
	}
	//LOGO SZAVAZAS
	$("input[type=button][class=logo_vote]").click(function(){
		var lid = $(this).parent(".logo").attr("class").split(" ");
		lid = lid[1].replace("lid_","");
		$("#vote_box").find("input[type=hidden][name=lid]").val(lid);
		$("#vote_box").show();
		$("body").css("overflow","hidden");
		$("#vote_box").animate({
			"opacity":"1"
		},500);
	});
	
	$("#vote_box").find(".close_button").click(function(){
		$("#vote_box").animate({
			"opacity":".0"
		},500, function(){
			$("#vote_box").hide();
			$("body").css("overflow","scroll");
		});
	});
});

(function($){
	$.expr[':'].beginStr = function(a,i,m){
		return $(a).text().toUpperCase().match(new RegExp("^"+m[3].toUpperCase(),"g"))!=null;
	};
	$.fn.nameComplete = function(source){
		var selectedIndex = 0;		
		var pr = this;
		$('<br /><div id="nameComplete" style="position:absolute;"></div>').insertAfter(pr);
		$("#nameComplete").css({
			"width":$(pr).css("width")
		});
		for(i = 0; i < source.length; i++){
			$("#nameComplete").append('<a class="complete_'+i+'" href="#" class="nem_'+source[i].nevek_nem+'">'+source[i].nevek_nev+'</a>');	
		}
		$("#nameComplete").find("a").mousemove(function(){
			$("#nameComplete").find(".selected").removeClass("selected");
			$(this).addClass("selected");
		});
		$("#nameComplete").find("a").click(function(){
			$(pr).val($(this).html());
			$("#nameComplete").fadeOut(500);
			$(pr).css({
				"-moz-border-radius":"",
				"-webkit-border-radius":"",
				"border-radius":"",
				"border-bottom":""
			});	
			return false;
		});
		$(this).keyup(function(e){
			if(e.keyCode == 27){
				$("#nameComplete").hide();
				$(this).css({
					"-moz-border-radius":"",
					"-webkit-border-radius":"",
					"border-radius":"",
					"border-bottom":""
				});	
			} else if(e.keyCode != 13){
				var name = $(this).val();
				if(name != ""){
					if($("#nameComplete").find("a:beginStr("+name+")").length > 0){
						$("#nameComplete").show();
						$(this).css({
							"-moz-border-radius":"5px 5px 0 0",
							"-webkit-border-bottom-left-radius":"0",
							"-webkit-border-bottom-right-radius":"0",
							"border-radius":"5px 5px 0 0",
							"border-bottom":"none"	
						});	
					} else {
						$("#nameComplete").hide();
						$(this).css({
							"-moz-border-radius":"",
							"-webkit-border-radius":"",
							"border-radius":"",
							"border-bottom":""
						});	
					}
					var selectedIndex = $("#nameComplete").find("a:beginStr("+name+"):lt(40)").index($("#nameComplete").find(".selected"));
					
					$("#nameComplete").find(".selected").removeClass("selected");
					if(e.keyCode == 40){		
						if(selectedIndex++ >= $("#nameComplete").find("a:beginStr("+name+"):lt(40)").length - 1){
							selectedIndex = 0;
						}							
						$("#nameComplete").find("a:beginStr("+name+"):lt(40):eq("+selectedIndex+")").addClass("selected");
					} else if(e.keyCode == 38){	
						if(selectedIndex-- <= 0){
							selectedIndex = $("#nameComplete").find("a:beginStr("+name+"):lt(40)").length - 1;
						}	
						$("#nameComplete").find("a:beginStr("+name+"):lt(40):eq("+selectedIndex+")").addClass("selected");								
					} else {
						$("#nameComplete").find("a:beginStr("+name+"):lt(40):first").addClass("selected");							
					}
					
					$("#nameComplete").find("a:beginStr("+name+"):lt(40)").css("display","block");
					$("#nameComplete").find("a:not(:beginStr("+name+"):lt(40))").hide();
				} else {
					$("#nameComplete").hide();
					$("#nameComplete").find("a").hide();
					$(this).css({
						"-moz-border-radius":"",
						"-webkit-border-radius":"",
						"border-radius":"",
						"border-bottom":""
					});	
				}
			}
		});
		$(this).keydown(function(e){
			if(e.keyCode == 13 && $("#nameComplete").css("display") != "none"){
				$(this).val($("#nameComplete").find(".selected").text());
				$("#nameComplete").hide();
				$(this).css({
					"-moz-border-radius":"",
					"-webkit-border-radius":"",
					"border-radius":"",
					"border-bottom":""
				});	
				return false;
			}
		});
	}
   	$.fn.urit = function(){ 
		//$("#content").find("*").css("font-size","12px");
		$(this).click(function(){
			$("#here").html('<span id="empty">Húzza ide a kiválasztott neveket!</span>');
			$("#here").parent(".content").height($("#here").height());
			createCookie('nevnapok', null, 1);
		});
   	}
	$.fn.readReply = function(){
		$(this).click(function(){
       		//$(this).next(".block").toggle("slow") ;
    	    var buttonLabel=$(this).val();
			$(this).next(".block").animate({
				"height" : "toggle",
				"opacity" : "toggle"
			});
            var newLabel=(buttonLabel=="▼") ? "▲":"▼";
            $(this).val(newLabel);
        });
    }
	$.fn.showGraph = function(){      		
		$(this).mouseover(function(event){
			if($("#top100").find("input:checked").length < 1){
				
				$("#graphimg").children("img").attr("src","pages/graph.php?names=" + $(this).find("input[type=checkbox]").val());
			}
			$("#graphimg").show();	
			$("#graphimg").css("left",(15+ event.pageX - $("#main").offset().left)+"px");
			$("#graphimg").css("top",(15 + event.pageY - $("#main").offset().top)+"px");
		});
		$(this).mouseout(function(){
			$("#graphimg").hide();					
		});
	}
})(jQuery);

function RunesChange(string){
		string = decodeURI(string.toLowerCase());
		var from = new Array(
     		 /ccs/g, /ggy/g, /lly/g, /nny/g, /ssz/g, /tty/g, /zzs/g,
     		 /cs/g, /gy/g, /ly/g, /ny/g, /sz/g, /ty/g, /zs/g,
     		 /qu/g, /q/g, /w/g, /x/g, /y/g,
     		 /á/g, /é/g, /í/g, /ó/g, /ö/g, /ő/g, /ú/g, /ü/g, /ű/g
   		 );
    	var to = new Array(
     		"CC", "GG", "LL", "NN", "SS", "TT", "ZZ",
      		"C", "G", "L", "N", "S", "T", "Z",
      		"kv", "kv", "v", "kS", "i",
      		"A", "E", "I", "O", "q", "Q", "U", "w", "W"
    	);
		
		for(i = 0; i < from.length; i++){
			string = string.replace(from[i],to[i]);
		}
		
		return string;
}
