$(document).ready(function() {
var current_index = 0;

	var i = current_index;
	current_index++;
	
	var bkg = $('.backgrounds div').slice(i, i+1).first().html();
	var texth = $('.texsts div').slice(i, i+1).first().children('h2').first().children('a').first().html();
	var textp = $('.texsts div').slice(i, i+1).first().children('p').first().html();
	
	//$('.golovka').css('background-image', 'url(' + bkg + ')');
	$(".golovka").animate({
		opacity: 0
	}, "slow", function () {
		$('.golovka').css('background-image', 'url(' + bkg + ')').animate({
			opacity: 1
		}, "slow", function () {
		});   
	});

	
	$('.text-golova h2 a').html(texth);
	$('.text-golova p').first().html(textp);
	$('.text-golova .points img').attr('src', '/i/point_link_idle.png');
	$('.text-golova .points img').slice(i, i+1).first().attr('src', '/i/point_link.png');


setInterval(function(){
	var i = current_index;
	
	current_index++;
	if(current_index > 4) current_index=0;
	
	var bkg = $('.backgrounds div').slice(i, i+1).first().html();
	var texth = $('.texsts div').slice(i, i+1).first().children('h2').first().children('a').first().html();
	var textp = $('.texsts div').slice(i, i+1).first().children('p').first().html();
	
	//$('.golovka').css('background-image', 'url(' + bkg + ')');
	$(".golovka").animate({
		opacity: 0
	}, "slow", function () {
		$('.golovka').css('background-image', 'url(' + bkg + ')').animate({
			opacity: 1
		}, "slow", function () {
		});   
	});

	
	$('.text-golova h2 a').html(texth);
	$('.text-golova p').first().html(textp);
	$('.text-golova .points img').attr('src', '/i/point_link_idle.png');
	$('.text-golova .points img').slice(i, i+1).first().attr('src', '/i/point_link.png');
}, 15000);



$('.points a').click(function(){
	var i = $(this).index('.points a');
	var current_index = i;
	var bkg = $('.backgrounds div').slice(i, i+1).first().html();
	var texth = $('.texsts div').slice(i, i+1).first().children('h2').first().children('a').first().html();
	var textp = $('.texsts div').slice(i, i+1).first().children('p').first().html();
	
	//$('.golovka').css('background-image', 'url(' + bkg + ')');
	$(".golovka").animate({
		opacity: 0
	}, "slow", function () {
		$('.golovka').css('background-image', 'url(' + bkg + ')').animate({
			opacity: 1
		}, "slow", function () {
		});   
	});

	
	$('.text-golova h2 a').html(texth);
	$('.text-golova p').first().html(textp);
	$('.text-golova .points img').attr('src', '/i/point_link_idle.png');
	$('.text-golova .points img').slice(i, i+1).first().attr('src', '/i/point_link.png');

	return false;	
});


$("a.gala").fancybox({
	'transitionIn'  :   'elastic',
	'transitionOut' :   'elastic',
	'speedIn'   :   600,
	'speedOut'  :   200,
	'overlayShow'   :   false,
	'titleShow' :   false
});	
	

$('div.top_menu ul li a').mouseover(function(){
	$(this).parent('li').addClass('hovus');
	});
$('div.top_menu ul li a').mouseout(function(){
	$(this).parent('li').removeClass('hovus');
	});
	
$('div.entire ul li.move a').live("click", function(){
	$('div.entire ul li').removeClass('tec');
	$('div.entire ul li').addClass('move');
	$(this).parent('li').removeClass('move');
	$(this).parent('li').addClass('tec');
	$(this).parent('li').next('li').addClass('nobg');
	$('div.entire_modal').slideDown();
	
	var $xz = $(this).attr('href');
	ShowMenuOne($xz);
	return false
	});
	
$('div.entire ul li.tec a').live("click", function(){
	$(this).parent('li').removeClass('tec');
	$(this).parent('li').addClass('move');
	$(this).parent('li').next('li').removeClass('nobg');
	$('div.entire_modal').slideUp();
	return false
	});

	
$('.entire ul li:first').addClass('onus');
$('.entire ul li:last').addClass('fastus');

function ShowMenuOne(razdel){
	$('div.entire_modal div.tri_ur').html('');
	$('div.entire_modal div.two_ur').html('<div class="ajax-loader"><img src="/i/ajax-loader.gif"></div>');
	$('div.entire_modal div.two_ur').load(razdel+ ' #find_razdely',{subus:1});
	}
function ShowMenuTwo(razdel){
	$('div.entire_modal div.tri_ur').html('<div class="ajax-loader"><img src="/i/ajax-loader.gif"></div>');
	$('div.entire_modal div.tri_ur').load(razdel+ ' #find_razdely',{subus:1});
	//alert(razdel);
	}

	
$('div.entire_modal div.two_ur li a').live("click", function(){
	$('div.entire_modal div.two_ur li a').removeClass('teca');
	$(this).addClass('teca');
	var $xz = $(this).attr('href');
	ShowMenuTwo($xz);
	return false
	});

	
});
	
	

	
	
	
	
	
