var animation_speed = 250;
var b_mover;
var b_mover_to;
var b_dont_move = false;
var s_mover;
var s_mover_to;
var s_dont_move = false;

$(document).ready(function() {
	if(document.images) {
		pic = new Image(111,111); 
		pic.src = "/site_images/jatssz_h.gif";
		pic2 = new Image(37,60); 
		pic2.src = "/site_images/b_left_h.jpg";
		pic3 = new Image(38,61); 
		pic3.src = "/site_images/b_right_h.jpg";
		pic4 = new Image(24,40); 
		pic4.src = "/site_images/s_left_h.jpg";
		pic5 = new Image(24,40); 
		pic5.src = "/site_images/s_right_h.jpg";
	}
	if(document.getElementById('f_b_i_h')) {
		start_b_auto();
		start_s_auto();
	}
	$(".checks > div").click(function() {
		var id = $(this).attr('id');
		id = id.substr(2);
		if($(this).attr('class') == 'checkbox') {
			$('#' + id).val('1');
			$(this).attr('class', 'checked');
		} else {
			$('#' + id).val('0');
			$(this).attr('class', 'checkbox');
		}
	});
	if(document.getElementById('nyeremeny_egy')) {
		$('.g_image img').lightBox();
	}
	if(document.getElementById('termekek')) {
		$('.glass_image img').lightBox();
	}
});

function start_b_auto() {
	b_mover = setInterval('b_left()', 5000);
}

function b_left() {
	if(b_dont_move) {
		return;
	}
	b_dont_move = true;
	speed = animation_speed * 2;
	$('#f_b_i_h').animate({'left': '-604px'}, speed, 'swing', function() {
		var tmp;
		tmp = $("#f_b_i_h").find(":first-child");
		$("#f_b_i_h").find(":first-child").remove();
		$('#f_b_i_h').css('left', '0px');
		$('#f_b_i_h').append(tmp);
		b_dont_move = false;
	});
}
function b_right() {
	if(b_dont_move) {
		return;
	}
	b_dont_move = true;
	speed = animation_speed * 2;
	var tmp;
	tmp = $("#f_b_i_h").find(":last-child");
	$("#f_b_i_h").find(":last-child").remove();
	$('#f_b_i_h').prepend(tmp);
	$('#f_b_i_h').css('left', '-604px');
	$('#f_b_i_h').animate({'left': '0px'}, speed, 'swing', function() { b_dont_move = false; });
}

function start_s_auto() {
	s_mover = setInterval('s_left()', 5000);
}

function s_left() {
	if(s_dont_move) {
		return;
	}
	s_dont_move = true;
	speed = animation_speed * 2;
	$('#f_s_i_h').animate({'left': '-280px'}, speed, 'swing', function() {
		var tmp;
		tmp = $("#f_s_i_h").find(":first-child");
		$("#f_s_i_h").find(":first-child").remove();
		$('#f_s_i_h').css('left', '0px');
		$('#f_s_i_h').append(tmp);
		s_dont_move = false;
	});
}
function s_right() {
	if(s_dont_move) {
		return;
	}
	s_dont_move = true;
	speed = animation_speed * 2;
	var tmp;
	tmp = $("#f_s_i_h").find(":last-child");
	$("#f_s_i_h").find(":last-child").remove();
	$('#f_s_i_h').prepend(tmp);
	$('#f_s_i_h').css('left', '-280px');
	$('#f_s_i_h').animate({'left': '0px'}, speed, 'swing', function() { s_dont_move = false; });
}

/* kattintáskor ezek */
function move_b_left() {
	if(b_dont_move) {
		return;
	}
	clearInterval(b_mover);
	clearTimeout(b_mover_to);
	b_right();
	b_mover_to = setTimeout('start_b_auto()', 10000);
}
function move_b_right() {
	if(b_dont_move) {
		return;
	}
	clearInterval(b_mover);
	clearTimeout(b_mover_to);
	b_left();
	b_mover_to = setTimeout('start_b_auto()', 10000);
}

function move_s_left() {
	if(s_dont_move) {
		return;
	}
	clearInterval(s_mover);
	clearTimeout(s_mover_to);
	s_right();
	s_mover_to = setTimeout('start_s_auto()', 10000);
}
function move_s_right() {
	if(s_dont_move) {
		return;
	}
	clearInterval(s_mover);
	clearTimeout(s_mover_to);
	s_left();
	s_mover_to = setTimeout('start_s_auto()', 10000);
}


var fn_in_use = false;
function fn_over(fn) {
	if(fn.value == 'e-mail') {
		fn.value = '';
	}
}
function fn_focus(fn) {
	if(fn.value == 'e-mail' || fn.value == '') {
		fn.value = '';
		fn_in_use = true;
	}
}

function fn_out(fn) {
	if(fn.value == '' && fn_in_use == false) {
		fn.value = 'e-mail';
	}
}
function fn_blur(fn) {
	if(fn.value == '') {
		fn.value = 'e-mail';
		fn_in_use = false;
	}
}
var pw_in_use = false;
function pw_over(pw) {
	if(pw.value == 'jelszó') {
		pw.value = '';
	}
}
function pw_focus(pw) {
	if(pw.value == 'jelszó' || pw.value == '') {
		pw.value = '';
		pw_in_use = true;
	}
}

function pw_out(pw) {
	if(pw.value == '' && pw_in_use == false) {
		pw.value = 'jelszó';
	}
}
function pw_blur(pw) {
	if(pw.value == '') {
		pw.value = 'jelszó';
		pw_in_use = false;
	}
}

function urlencode(str) {
	return escape(str).replace('+', '%2B').replace('%20', '+').replace('*', '%2A').replace('/', '%2F').replace('@', '%40');
}
function is_email(str) {
	var filter = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
	if (!filter.test(str)) {
		return false;
	}
	return true;
}

function login() {
	var user = $("#l_user").attr('value');
	var pass = $("#l_pass").attr('value');
	if(is_email(user)) {
		$.ajax({
			type: "POST",
			url: "login.php",
			data: "user=" + urlencode(user) + "&pass=" + MD5(pass),
			success: function(msg){
				if(msg.indexOf('-fail-') > 0) {
					hibas();
				} else {
					window.location = window.location;
				}
			}
		});
	} else {
		hibas();
	}
}
var tmp;
var wait = 1500;
function ujra_li() {
	$('#loginbox').html(tmp);
}
function hibas() {
	$("#l_pass").attr('value', '');
	tmp = $("#loginbox").html();
	$("#loginbox").html('');
	$("#loginbox").append('<div class="hibas_fh_v_jsz">Hibás felhasználónév vagy jelszó!</div>');
	setTimeout("ujra_li()", wait);
	wait += 1000;
}

