window.addEvent("load",function(){
	var base = $('base').get('text');
	var news = $('news');

	var news_request = new Request({
		method: 'post',
		url: base + '/ajax/news_improved.php',
		onRequest: function() { 
			news.set('html', '<img style="margin: 80px 100px 80px 100px" src="'+base+'/img/loader.gif" alt="" />')},
		onComplete: function(Response){
			news.set('html', Response);
			var news_tab = $$('.news_tab');
			var news_tab_content = $$('.news_tab_content');
			var AccordionObject = new Accordion(news_tab, news_tab_content, {
				onActive: function(toggler, element){
					toggler.addClass('active_tab');
					toggler.getElement('div.news_type').setStyle('color', '#ffffff');
					toggler.getElement('span.news_city').setStyle('color', '#fcb9b1');
					toggler.getElement('div.news_data').setStyle('color', '#ffffff');
				},
				onBackground: function(toggler, element){
					toggler.removeClass('active_tab');
					toggler.getElement('div.news_type').setStyle('color', '#747474');
					toggler.getElement('span.news_city').setStyle('color', '#a1a1a1');
					toggler.getElement('div.news_data').setStyle('color', '#d20019');
				}
			});
			}
	});
	
	$$('div.news_tab').each(function(el,i) {
		el.addEvent('mouseleave', function() {
			this.addEvent('mouseenter', function() {
				this.getElement('div.news_type').setStyle('color', '#ffffff');
				this.getElement('span.news_city').setStyle('color', '#fcb9b1');
				this.getElement('div.news_data').setStyle('color', '#ffffff');
			})
		})	
	})
	
	news_request.post({
		'city': $('city_id').get('text'),
		'region': $('region_id').get('text')
	})
	
	$$('span.link_event').each(function(item) {
		item.addEvent('click', function() {
			remove_active_events();
			this.addClass('active_event');
			news_request.post({
				'type': this.get('text'),
				'city': $('city_id').get('text'),
				'region': $('region_id').get('text')
			})
		})
	})
	
	function remove_active_events() {
		$$('span.link_event').each(function(item) {
			item.removeClass('active_event');
		})
	}
});

