$(document).ready(function(){
	events = $('.event');
	news = $('.news');

	first_event = events.eq(0);
	first_event.parent().css({'background': '#c01a1a'});
	first_event.children(':first').css({'color': '#ffdcdc'});
	first_event.css({'background' : 'none'});

	events.bind('mouseover', function(){
		var mainpic = $('#mainpic')
		var src = $(this).attr('pic');
		var url = $(this).attr('href');
		$('#imageSelector > li').css({'background': ''});
		$('#imageSelector .date').css({'color': '#c1c1c1'});
		$('.event').css({'background' : 'url(../img/borderx.png) center bottom repeat-x'});
		$('li.last a').css({'background' : 'none'});
		$(this).parent().css({'background': '#c01a1a'});
		$(this).children(':first').css({'color': '#ffdcdc'});
		$(this).css({'background' : 'none'});
		if (src != mainpic.attr('src')){
			mainpic.stop(true).animate({'opacity': '0'}, 200, "linear", function(){
				mainpic.load(function(){
					mainpic.animate({'opacity': '1'}, 200);
					mainpic.parent().attr('href', url);
				}).attr('src', src);
			});
		}
	});

	first_news = news.eq(0);
	first_news.parent().css({'background': '#738ca9'});
	first_news.children(':first').css({'color' : '#DCE6F2'});
	first_news.children(':last').css({'color' : '#DCE6F2'});
	first_news.css({'background' : 'none'});

	news.bind('mouseover', function(){
		$('#newsSelector > li').css({'background': ''});
		$('#newsSelector .date').css({'color': '#b2c3d8'});
		$('#newsSelector .commentsLink').css({'color': '#b2c3d8'});
		$('.news').css({'background' : 'url(../img/borderx.png) center bottom repeat-x'});
		$('li.last a').css({'background' : 'none'});
		$(this).parent().css({'background': '#738ca9'});
		$(this).children(':first').css({'color' : '#DCE6F2'});
		$(this).children(':last').css({'color' : '#DCE6F2'});
		$(this).css({'background' : 'none'});
		//C4D4E8
	});

	$('#searchForm input').focus(function() {
		if (this.value=="Поиск по сайту"){this.value="";$(this).removeClass('italic small');};
	});
	$('#searchForm input').blur(function() {
		if (this.value=="") {this.value="Поиск по сайту";$(this).addClass('italic small');};
	});
	$(document).ready(function(){
		$("a[rel='colorbox']").colorbox();
	});

	$('#twittSelector').html('<li><img src="/img/loading.gif" alt="загрузка"/></li>');
	$.ajax({
	    url: "/frontpage/get_twits/",
	    success: function(data){
		    $('#twittSelector').html(data);
	    },
	    error: function(){
		    $('#twittSelector').html('<li>Сервис временно недоступен</li>');
	    }
	  });
})
