$(document).ready(function() {

	var index = 1;
	var indit;
	var tarolo = $('ul.scroll');
	var elemek = $(tarolo).children().size();
	var next = index + 1;
	var valtido = 8000;
	var animido;
	var szelesseg = 703;
	
	var t = setTimeout(function() {$('ul.submenu').slideUp('fast'); }, 1);
	var indit = setTimeout(function() { Kepvalt(next);}, valtido);
	var holdTheInterval;
	
	//function updateBanner(){
		//$("div#hirdetes11").hide('slow');		
	//	$("div#hirdetes11").load(burl+'index.php/front/getrightad');
		//$("div#hirdetes11").load(burl+'index.php/front/getrightad');
		/*$.get(burl+'index.php/front/getrightad', function(data){
		  $("div#hcache").html = data;
		  $("div#hirdetes11").html = $("div#hcache").html();
		  $("div#hcache").html = '';
		});*/

		//$("div#hirdetes11").show('slow');
	//}
	//holdTheInterval = setInterval(updateBanner, 10000);
	
	$('ul.menu li a').mouseover(function() {
		clearTimeout(t);
		var id = $(this).attr('id');
		if ($('ul.' + id).css('display') != 'block') {
			$('ul.submenu').slideUp('fast');
			$('a.active').attr('class', '');
			$('ul.' + id).slideDown('fast');
			$('a#' + id).addClass(id + '_a').addClass('active');
		}
	}).mouseout(function() {
		t = setTimeout(function() {
			$('ul.submenu').slideUp('fast');
			$('a.active').attr('class', '');
		 }, 500);
	});
		
	$('ul.submenu').mouseover(function() {
		clearTimeout(t);
	}).mouseout(function() {
		t = setTimeout(function() {
			$('ul.submenu').slideUp('fast'); 
			$('a.active').attr('class', '');
		}, 500);
	});
	
	function Kepvalt(index) {
		clearInterval(indit);
		
		var pos = (index - 1) * szelesseg;
		var maxpos = elemek * szelesseg;
		next = index;
		next++;
		
		if (next > elemek) next = 1;
		
		if (pos < maxpos) { pos = (index * -1 * szelesseg) + szelesseg; animido = 1500; } else { pos = 0;  animido = 2000;}
		
		$(tarolo).animate({ left: pos }, animido);
				
		indit = setInterval(function() { Kepvalt(next); }, valtido);
		
		$('ul.pages li a').removeClass('aktiv');
		$('ul.pages li a#f_' + index).addClass('aktiv');
		
	}
	
	$(tarolo).mouseover(function() {
		clearTimeout(indit);
	}).mouseout(function() {
		indit = setTimeout(function() { Kepvalt(next);}, 2000);
	});
	
	$('ul.pages li a').click(function() {
		id = $(this).attr('id').replace(/f_/g, '');
		clearTimeout(indit);
		Kepvalt(id);
	});

        var index2 = 0;
	var indit2;

	function Kepvalt2(index2) {
		clearInterval(indit2);
		var tarolo = $('div#scroller ul');
		var kepek = $(tarolo).children("li");
		var keptarolo = $('div#scroller ul li.current');
		$(keptarolo).removeClass('current');
		$(keptarolo).attr('class', 'hidden');
		$(kepek).eq(index2).css('display', 'none');
		index2++;
		if (index2 >= $(kepek).length) {
			index2 = 0;
		}
		$(kepek).eq(index2).fadeIn('slow');

		indit2 = setInterval(function() { Kepvalt2(index2); }, 5000);

	}

	Kepvalt2(index2);
	
});

function maillink(abcd, efgh) {
  document.write('<a href="mailto:' + abcd + '@' + efgh + '" title="Levélküldés">');
  document.write(abcd + '@' + efgh + '</a>');
}
