$(window).load(function() {
/* kepes ajanlo */

	var ajanloLen = 4;
	
	var aktAjanlo = 1;
	var elozoAjanlo = ajanloLen;
	var zIndex = 1;

	var ajanloFut = true;
	var ajanloTimer = setTimeout(ajanloMutat, 200);

	$("#index_kepes_ajanlo ul li[id^='gomb_'] a").click(function(){
		var ez = $(this).parent("li").attr("id").substr(5,1);
		if (elozoAjanlo != ez) {
			clearTimeout(ajanloTimer);
			aktAjanlo = ez;
			ajanloFut = true;
			ajanloMutat();
		}
		this.blur();
		return false;
	});

	$("#index_kepes_ajanlo ul li#pause a").click(function(){
		if (ajanloFut) {
			clearTimeout(ajanloTimer);
			ajanloFut = false;
			$(this).parent("li").addClass("aktiv").siblings("li").removeClass("aktiv");
		}
		this.blur();
		return false;
	});

	$("#index_kepes_ajanlo ul li#play a").click(function(){
		if (!ajanloFut) {
			ajanloFut = true;
			$(this).parent("li").siblings("li#pause").removeClass("aktiv");
			ajanloMutat();
		}
		this.blur();
		return false;
	});

	function ajanloCiklus() {
		ajanloTimer = setTimeout(ajanloMutat, 5000);
	}

	function ajanloMutat() {
		$("#index_kepes_ajanlo div#elem_" + aktAjanlo).css("z-index", zIndex).fadeIn("slow", ajanloHide);
		$("#index_kepes_ajanlo ul li#gomb_" + aktAjanlo).siblings("li").removeClass("aktiv").end().addClass("aktiv");
		$("#index_kepes_ajanlo ul").css("z-index", ajanloLen + 1);
		zIndex++;
		if (zIndex > ajanloLen) {
			zIndex = 1;
		}
	}

	function ajanloHide() {
		$("#index_kepes_ajanlo div#elem_" + elozoAjanlo).hide();
		elozoAjanlo = aktAjanlo;
		if (aktAjanlo == ajanloLen) {
			aktAjanlo = 1;
		} else {
			aktAjanlo++;
		}
		if (ajanloFut) {
			ajanloCiklus();
		}
	}

/* hirek doboz */

	var $osszesen = $("#index_hirek ul li").length;
	var $elsoElem = 1;
	var $relmediaulim;

	$("#index_hirek a[href='#nogo']").click(function() {
		$this = $(this);

		var $maxElem = 6; /* valojaban 7, de ide 6 kell ??? */

		if ($this.attr("id") == 'fel') {
			if ($elsoElem > 1) {
				$elsoElem--;
			}
		} else {
			if ($elsoElem < ($osszesen - $maxElem)) {
				if ($elsoElem < $osszesen) {
					$elsoElem++;
				}
			}
		}

		$relmediaulim = ($elsoElem + $maxElem) > $osszesen ? $osszesen : $elsoElem + $maxElem;

		if ($("#index_hirek ul li#hir_" + ($elsoElem - 1))) {
			$("#index_hirek ul li#hir_" + ($elsoElem - 1)).removeClass("latszik");
		}
		if ($("#index_hirek ul li#hir_" + ($elsoElem))) {
			$("#index_hirek ul li#hir_" + ($elsoElem)).addClass("latszik");
		}
		if ($("#index_hirek ul li#hir_" + ($relmediaulim + 1))) {
			$("#index_hirek ul li#hir_" + ($relmediaulim + 1)).removeClass("latszik");
		}
		if ($("#index_hirek ul li#hir_" + ($relmediaulim))) {
			$("#index_hirek ul li#hir_" + ($relmediaulim)).addClass("latszik utolso").siblings().removeClass("utolso");
		}
		this.blur();
		return false;

	});
});

$(function() {
	$('#kereses_form').submit(function() {
		var emsg = '';
		if ($('input[name=text]').val() == '') {
			emsg += "Kérlek, add meg a keresendő kifejezést!\n";
		}
		if ($('input[name=type]:checked').length == 0) {
			emsg += "Kérlek, válaszd ki, hol szeretnél keresni!\n";
		}

		if (emsg == '') {
			if ($('input[name=text]').val() != '') {
				if ($('input[name=type]:checked').val() == 1) { // gyorskereso-gyogyszerek
					document.location.replace('/util/sitesearch/detail?where=detail&k=' + $('input[name=text]').val() + '&limits[]=11');
				} else if ($('input[name=type]:checked').val() == 2) { // gyorskereso-betegsegek
					document.location.replace('/util/sitesearch/detail?where=detail&k=' + $('input[name=text]').val() + '&limits[]=5');
				} else if ($('input[name=type]:checked').val() == 3) { // gyorskereso-korhazak
					document.location.replace('/services/korhazkereso?search_hosp=' + $('input[name=text]').val());
				} else if ($('input[name=type]:checked').val() == 4) { // gyorskereso-mediatar
					document.location.replace('/util/sitesearch/detail?where=detail&k=' + $('input[name=text]').val() + '&limits[]=18');
				} else if ($('input[name=type]:checked').val() == 5) { // gyorskereso-patikak
					document.location.replace('/services/patikak?search=1&name=' + $('input[name=text]').val());
				} else if ($('input[name=type]:checked').val() == 6) { // gyorskereso-forum
					document.location.replace('/csevego/kereses?f_keyword=' + $('input[name=text]').val());
				} else {
					alert('Kérlek, válaszd ki, hol szeretnél keresni!'); // devil ! sleepz...
				}
			} else {
				alert('Kérlek, add meg a keresendő kifejezést!'); // devil ! sleepz...
			}
		} else {
			alert(emsg);
		}

		return false;
	});
});

