window.addEvent('domready',function(){
	$$('.fade').fade('hide').removeClass('fade');
	$$('.slide').slide('hide').removeClass('slide');
	if ($('closeInfo')) {
		$('closeInfo').addEvent('click',function(){
			this.dispose();
			$('infoDiv').set('slide',{ onComplete: function(){ $('infoDiv').dispose(); }, transition: 'quint:out' });
			$('infoDiv').slide('out');
		});
	}
	if ($('closeError')) {
		$('closeError').addEvent('click',function(){
			this.dispose();
			$('errorDiv').set('slide',{ onComplete: function(){ $('errorDiv').dispose(); }, transition: 'quint:out' });
			$('errorDiv').slide('out');
		});
	}
});

function ajax(source,target,success) {
	if (typeof(source) == 'object') {
		source.set('send', {
			onSuccess: function(html) {
				if (target) { target.set('html',html); }
				if (success) { success(html); }
			},
			onFailure: function() {
				alert('Rendszerhiba | System error');
			}
		}).send();
	}
	else {
		var source = 'http://auto123.hu/ajax/index.php?function=' + source;
		//var source = 'http://localhost/auto123.hu/ajax/index.php?function=' + source;

		req = new Request({
			url: source,
			onSuccess: function(html){
				if (target) { target.set('html',html); }
				if (success) { success(html); }
			},
			onFailure: function(){
				alert('Rendszerhiba | System error');
			}
		}).send();
	}
}

function href(url) {
	window.location.href = url;
}

function openBox(title,el,func) {
	var bg, html, box;

	bg = new Element('table',{
		id: 'lightboxBg',
		cellspacing: 0,
		cellpadding: 0,
		html: '<tr><td></td></tr>',
		events: {
			click: function(){ closeBox(); }
		}
	});

	html = '<div class="head"><div class="left">' + title + '</div><div class="right">Bezár</div></div><div class="body fix"><div class="message hide"></div>';
	html += el.get('html');
	html += '</div><div class="foot"></div>';

	box = new Element('div',{
		id: 'lightbox',
		html: html
	}).fade('hide');

	bg.inject($('header'));
	box.inject($('main')).fade('in');
	$$('#lightbox .head .right').addEvent('click',function(){ closeBox(); });
	func();
}
function closeBox() {
	$('lightboxBg').set('tween',{
		onComplete: function(el){ el.dispose(); }
	}).fade('out');

	$('lightbox').set('tween',{
		onComplete: function(el){ el.dispose(); }
	}).fade('out');
}
