$(document).ready(function(){

$('#fejlec').css('background-image', 'url('+hatterurl+')');


$("#akciodoboz").hover(function(){
	$(this).animate({opacity: 0.95}, 500)}, function(){
		$(this).animate({opacity: 0.5}, 500)
		}
	)

$("#akciobezar").click(function(){
	$('#akciodoboz').animate({opacity: 0, top: -450}, 1000, function(){$(this).remove();});
setCookie('marlattam','igaz',3);
})

$("#akcioLogin").click(function(){
$("#alfd").slideToggle(500);
});

$("#akcioReg").click(function(){
var atid = $("#at_id").val();
window.location.replace("regisztracio/?akcioId="+atid);
});

var felhaszval = "Felhasználónév";
$('#akcioUsername').attr("value", felhaszval); 
$('#akcioUsername').focus(function(){
if( $(this).val() == felhaszval ) $(this).attr("value", ""); 
});
$('#akcioUsername').blur(function(){
if($(this).attr("value") == "") {$(this).attr("value", felhaszval); }
});

var jelszoval = "Jelszó";
$('#akcioJelszo').attr("value", jelszoval); 
$('#akcioJelszo').focus(function(){
if( $(this).val() == jelszoval ) $(this).attr("value", ""); 
});
$('#akcioJelszo').blur(function(){
if($(this).attr("value") == "") {$(this).attr("value", jelszoval); }
});

$("#akciologinsubmit").live("click", function(){
var nev = $("#akcioUsername").val();
var jelszo = $("#akcioJelszo").val();
var hova = $("#hovaurl").val();
 var eredeti = $("#alfd").html();


$.ajax({
			url: 'bin/login.php',
			type: "post",
			dataType: "text",
			data: ({login_nev : nev, login_jelszo: jelszo }),
			beforeSend: function() {
				$("#alfd").slideUp("fast");
				},

			success: function(data) {
				if(data=='fail'){
					$("#alfd").html(eredeti);
				$("#alfd").slideDown("fast");
					}

				else{
window.location.replace(hova);

					}
				}
			})
})


jQuery.preloadImages = function(){  for(var i = 0; i<arguments.length; i++){jQuery("<img>").attr("src", arguments[i]);}}
$.preloadImages("images/menu_1_1.jpg", "images/menu_1_2.jpg", "images/menu_2_1.jpg", 'images/menu_2_2.jpg', 'images/menu_3_1.jpg', 'images/menu_3_2.jpg', 'images/menu_4_1.jpg', 'images/menu_4_2.jpg', 'images/menu_5_1.jpg', 'images/menu_5_2.jpg', 'images/virag_1_1.jpg', 'images/virag_1_2.jpg', 'images/virag_2_1.jpg', 'images/virag_2_2.jpg', 'images/virag_3_1.jpg', 'images/virag_3_2.jpg', 'images/virag_4_1.jpg', 'images/virag_4_2.jpg', 'images/virag_5_1.jpg', 'images/virag_5_2.jpg');

	$(function(){$('#menu_1').hover(function(){this.src='images/menu_1_2.jpg';},function(){this.src='images/menu_1_1.jpg';});});
	$(function(){$('#menu_2').hover(function(){this.src='images/menu_2_2.jpg';},function(){this.src='images/menu_2_1.jpg';});});
	$(function(){$('#menu_3').hover(function(){this.src='images/menu_3_2.jpg';},function(){this.src='images/menu_3_1.jpg';});});
	$(function(){$('#menu_4').hover(function(){this.src='images/menu_4_2.jpg';},function(){this.src='images/menu_4_1.jpg';});});
	$(function(){$('#menu_5').hover(function(){this.src='images/menu_5_2.jpg';},function(){this.src='images/menu_5_1.jpg';});});

	$("#felsorolas p.felsorolas_head").click(function(){$(this).next("div.felsorolas_body").slideToggle(500);});

var ajan ="";

var kerval = "Mit keres?";
$('#kere').attr("value", kerval); 
$('#kere').focus(function(){
if( $(this).val() == kerval ) $(this).attr("value", ""); 
});
$('#kere').blur(function(){
if($(this).attr("value") == "") {$(this).attr("value", kerval); }
});

var felhaszval = "Felhasználónév";
$('#fnev').attr("value", felhaszval); 
$('#fnev').focus(function(){
if( $(this).val() == felhaszval ) $(this).attr("value", ""); 
});
$('#fnev').blur(function(){
if($(this).attr("value") == "") {$(this).attr("value", felhaszval); }
});

var jelszoval = "Jelszó";
$('#fpasword').attr("value", jelszoval); 
$('#fpasword').focus(function(){
if( $(this).val() == jelszoval ) $(this).attr("value", ""); 
});
$('#fpasword').blur(function(){
if($(this).attr("value") == "") {$(this).attr("value", jelszoval); }
});

$("#user_belogin").live("click", function(){
var nev = $("#fnev").val();
var jelszo = $("#fpasword").val();
 var eredeti = $("#login_belso").html();


$.ajax({
			url: 'bin/login.php',
			type: "post",
			dataType: "text",
			data: ({login_nev : nev, login_jelszo: jelszo }),
			beforeSend: function() {
				$("#login_belso").slideUp("fast");
				},

			success: function(data) {
				if(data=='fail'){
					$("#login_belso").html(eredeti);
					}

				else{
					$("#login_belso").html(data);
					$("#kosrbarak").removeAttr("disabled");
					}

					$("#login_belso").slideDown("fast");

			
			}
				})
})


$("#user_logout").live("click", function(){
$.ajax({
			url: 'bin/logout.php',
			type: "post",
			dataType: "text",
			data: ({logout : true}),
			beforeSend: function() {
			},
			success: function(data) {
				$("#login_belso").slideUp("fast",function() {
				$("#rendelesek").fadeOut("fast");
				$("#regtartalom").fadeOut("fast");
				
				$("#login_belso").html(data);
}
);
				$("#kosrbarak").attr("disabled","disabled");
				$("#login_belso").slideDown("fast");
					}
			})
		
})

	$("#elfelejtette").click(function(){
		jPrompt('Adja meg Felhasználónevét és a hozzá tartozó e-mail címre elküldjük a jelenlegi jelszavát.', 'felhasznalonev', 'Jelszó emlékeztető', function(r) { $.post("bin/elfelejtett.php", { nev: r }); }); });

	$("#usertorles").click(function(){
		 jConfirm('', 'Biztos hogy törölni akarja magát rendszerünkből?', function(r) {
		var ajdi = $("#ajdi_t").val();
		$.post("bin/usertorol.php", { ajdi_t: ajdi}, function(data) { window.location.href = "index.php" });
		 })
	});


$("#kosrbarak").click(function(){
	var termID = $("#termID").val();
	var termDB = $("#termDB").val();
	var mennyi = $("#ar").val()*$("#termDB").val();
	if(termDB>=1){
	$("#kosarbarakas").fadeIn("fast");
		var egyrend = {};
		egyrend['termID']=termID;
		egyrend['termDB']=termDB;

				$.ajax({
			url: 'bin/termupdate.php',
			type: "POST",
			data: ({termekID: termID, termekDB: termDB}),
			beforeSend: function() { $("#kosarbarakas").fadeIn("fast") },
			success: function(data){
				$("#kosarbarakas").fadeOut("fast", function(){
					$("#kosarbarakas").html("Termék sikeresen kosárba helyezve.");
					$("#kosarbarakas").fadeIn("fast");
					});
	
				$("#kosarbadoboz").fadeOut("fast", function(){
				$("#kosarbadoboz").html(data);
				$("#kosarbadoboz").fadeIn("fast");
					
					});
				
				$.ajax({
					url: "bin/arupdate.php?hogyan=plusz",
						type:"post",
						data:({osszeg:mennyi}),
			          dataType: 'json',
						success: function(asd){
							$("#kosarertek").fadeOut("fast", function(){
								$("#kosarertek").html(asd.kicsi);
								$("#kosarertek").fadeIn("fast");
							
							})
					}
		
		})
		
		}})

	}
	else{
	jAlert('Kérem írja be hány darabot \n kíván rendelni a termékből!', 'Rendszer Üzenet');
	}
});


$('#fejlec').flash( { src: flashurl, width: 790, height: 220, wmode: 'transparent' }, { version: 8 });


setCookie('marlattam','igaz',3);

$('#jogiOk').click(function(){
$("#akciodoboz").animate({top: "5"}, 1000);
setCookie('jogifigy','rendben',7);
})

$('#jogiNemOk').click(function(){
$("#akciodoboz").animate({top: "5"}, 1000);
window.location.href = "http://google.com/"
})

});

$(window).load(function(){
$('#akciodoboz').css("opacity","0.5");
var akciodobozmagas = $('#akciodoboz').height();
akciodobozmagas = (akciodobozmagas - 30)*-1;
$("#akciodoboz").animate({top: akciodobozmagas}, 1000);

$('#akcioElobuj').click(function(){
$("#akciodoboz").animate({top: "5"}, 1000);
setCookie('marlattam','igaz',3);
})

function g_nyit() {
var g_nyit = window.open('/galeria/','Galeria','scrollbars=no,menubar=no,resizable=yes,toolbar=no,location=no,status=no');
}

})

function setCookie(c_name,value,expiredays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}
