window.addEvent('domready', function() {
	$(document.body).getElements('.car-hover').each(function(victim) {
		victim.addEvents({
			'mouseenter' : function() {
				this.getElements('.hidden').removeClass('hidden');
				this.getElements('.numurzime').addClass('hidden');
			},
			'mouseleave' : function() {
				this.getElements('.hidden').removeClass('hidden');
				this.getElements('.info').addClass('hidden');
			}
		});
	});
	$$('p[class=numurzime]').setStyle('opacity',0.7);
	$(document.body).getElements('ul[class=carslist] a').each(function(victim) {
		if ($chk($(document.body).getElement('a[rel=' + victim.get('name') + ']'))) {
		var obj = $(document.body).getElement('a[rel=' + victim.get('name') + ']').getParent('p');
			victim.addEvents({
				'mouseenter' : function() {
					obj.removeClass('hidden');
					if ($chk(obj.getNext('p'))) obj.getNext('p').addClass('hidden');
				},
				'mouseleave' : function() {
					obj.addClass('hidden');
					if ($chk(obj.getNext('p'))) obj.getNext('p').removeClass('hidden');
				}
			});
		}
	});
	$('users').getElements('.menu ul li a').addEvent('click',function(e) {
		e.stop();
		lietotaji(this);
	});
	$('online').getElements('a.on').addEvent('click',function(e) {
		e.stop();
		online(this);
	});
	$('zinas').getElements('a.on').addEvent('click',function(e) {
		e.stop();
		zinas(this);
	});
    articles();
});
function articles() {
    $('switch-articles').addEvent('click',function(e) {
        e.stop();
        new Request.HTML({
            url : host + 'html.php',
            onRequest : (function() {
                this.getElement('img').removeClass('invisible')
            }).bind(this),
            onSuccess : function(a,b,c) {
                $('artcls').set('html',c);
                articles();
            }
        }).post({
            'index' : this.get('rel')
        })
    })
}
function lietotaji(victim) {
	new Request.HTML({
		url : host + 'html.php',
		onRequest : function () {
			victim.getPrevious('img').removeClass('hidden');
		},
		onSuccess : function (response) {
			$('users').set('text','');
			$('users').adopt(response);
			$('users').getElements('.menu ul li a').addEvent('click',function(e) {
				e.stop();
				lietotaji(this);
			});
		}
	}).post({'index' : victim.get('rel')});
}
function online(victim) {
	new Request.HTML({
		url : host + 'html.php',
		onRequest : function () {
			victim.getPrevious('img').removeClass('hidden');
		},
		onSuccess : function (response) {
			$('online').set('text','');
			$('online').adopt(response);
			$('online').getElements('a.on').addEvent('click',function(e) {
				e.stop(); online(this);
			});
		}
	}).post({'index' : victim.get('rel')});
}
function zinas(victim) {
	new Request.HTML({
		url : host + 'html.php',
		onRequest : function () {
			victim.getPrevious('img').removeClass('hidden');
		},
		onSuccess : function (response) {
			$('zinas').set('text','');
			$('zinas').adopt(response);
			$('zinas').getElements('a.on').addEvent('click',function(e) {
				e.stop();
				zinas(this);
			});
		}
	}).post({'index' : victim.get('rel')});
}
function flash() {
	var obj = new Swiff(host + 'embed/Autobildes.lv-auto-fotografesana.swf', {
		id: 'flash',
		width: 310,
		height: 148,
		params: { wmode: 'transparent'}
	});
	$('fotogr').set('html','');
	obj.inject($('fotogr'));
}