	
// AJAXOS LINKEK/FORMOK KEZELÉSE

	$(document).ready(function(){
		$.history.init(loadContent, { unescape: ",/?=" });
		createAjaxLinks("");
	});
	
	var origContent = "";
	function loadContent(hash) {
		if(hash != "") {
			if(origContent == "") {
				origContent = $('#ajax_content').html();
			}
			$("#ajax_loader").show();
			$("#ajax_content").animate(
				{'opacity': 0.5}, 
				150, 
				function(){
					$('#ajax_content').load(hash, function(){
						$("#ajax_loader").hide();
						$("#ajax_content").css('opacity', 1);
						createAjaxLinks("#ajax_content ");
						// login gombok
						$("#ajax_content .loginBtn").bind('click', function(e) {
							e.preventDefault();
							$("div#login").slideToggle();
							$(".login_button").toggleClass("login_open");
							window.scrollTo(0, 0);
						});
					});
				}
			);
		} else if(origContent != "") {
			$('#ajax_content').html(origContent);
		}
	}


	function createAjaxLinks(content){
		$(content+'a.ajax').click(function(){
			var url = $(this).attr('href');
			url = url.replace(/^.*#/, '');
			//alert(url);
			$.history.load(url);
			if (content.length > 0) window.scrollTo(0, 200);
			return false;
		});
		$(content+'form.ajax').submit(function(){
			myAjaxRequest($(this).attr('action'), $(this).serialize());
			return false;
		});
		$("a.lightbox").fancybox();
	}

	var req = false;

	function myAjaxRequest(file, postdatas){
		if (req) req.abort();
		
		if ( postdatas ){
			req = $.ajax({
				type: "POST",
				data: postdatas,
				url: file,
				dataType: "html",
				beforeSend: function(){
					$('#ajax_loader').show();
				},
				complete: function(){
					$('#ajax_loader').hide();
				},
				success: function(msg){
					$("#ajax_content").html(msg);
					createAjaxLinks("#ajax_content ");
					req = false;
				}
			});
		}
		else {
			req = $.ajax({
				type: "GET",
				url: file,
				dataType: "html",
				beforeSend: function(){
					$('#ajax_loader').show();
				},
				complete: function(){
					$('#ajax_loader').hide();
				},
				success: function(msg){
					$("#ajax_content").html(msg);
					createAjaxLinks("#ajax_content ");
					req = false;
				}
			});
		}
	}
