$(document).ready(function(){

	$.address.crawlable(true).init(function(event)
	{
		$('a[rel="history"]').address();
	}).change(function(event)
	{
		if(event.parameters.page != undefined)
		{
			//console.log("Lapot toltenek be..."+event.parameters.page);
			$.ajax({
				url:'do.php?'+event.queryString,
				beforeSend:function()
				{
					//console.log('Betoltes...');
					$("div#loading").text("Betöltés...").show();
				},
				success:function(data)
				{
					//console.log('Kesz...');
					$("div#loading").hide();
					$("div#content").html(data);
				},
				error:function(a, b, c)
				{
					/*console.log(a);
					console.log(b);
					console.log(c);*/
				}
			});
		}
	});



	//$.preloadCssImages();

	//setTimeout("checkmessages()",5000);

	$('div#topbanner').cycle({fx:'fade',timeout:15000,speed:200});
	$('div#bottombanner01').cycle({fx:'fade',timeout:15000,speed:200});
	$('div#bottombanner02').cycle({fx:'fade',timeout:15000,speed:200});
	$('div#bottombanner03').cycle({fx:'fade',timeout:15000,speed:200});
	$('div#bottombanner04').cycle({fx:'fade',timeout:15000,speed:200});

	for(var i = 0; i < 10; i++)
	{
		$("#anim").fadeOut().fadeIn();
	}

	var count = 0;
	$(".overlay").live('click',function(){
		var url = $(this).attr("href");
		if(count == 0)
		{
			$.fn.colorbox({href: url, open:true});
		}
		count+1;
		return false;
	});
	
	//naptár
	var datumok = [];
	fetchDataFromPhp();
	function fetchDataFromPhp()
	{
		$.getJSON('events.php',function(data){
			$(data).each(function(key, val){
				datumok.push(key, val);
			});
		});
	}
});
function fconfirm(string)
{
	var answer = confirm(string)
	if(answer)
	{
		alert("Ok!")
		return false;
	}
}
function getpage(page)
{
	var hash = page.replace(/^.*#/,'');
	$.address.value(hash);
	$.ajax({
		type:'GET',
		url:hash,
		cache:false,
		dataType:'text',
		beforeSend:function()
		{
			$("div#loading").text("Betöltés...").show();
		},
		success:function(data)
		{
			$("div#loading").fadeOut();
			$('div#content').html(data);
		}
	});
}
function checkmessages()
{
	$.get("index.php?action=checkmessage",function(obj){
		if(obj.error == 0 && obj.nummessage > 0)
		{
			if(confirm("Jött "+ obj.nummessage +" új privát üzeneted! Elolvasod most?"))
			{
				$.get('do.php?page=user&subpage=pm&location=1',function(data){
					$('#content').html(data);
				});
			}
			
		}
	},'json');
}
