// JavaScript Document
jQuery(document).ready(function(){
    // Highslide
    hs.graphicsDir = '/js/highslide/graphics/';
    hs.showCredits = false;
    hs.restoreTitle = 'Кликните, чтобы закрыть изображения. Кликните и тащите, чтобы переместить. Используйте клавиши курсора (стрелки) для просмотра "следующего" и "предыдущего" изображения.';
    hs.loadingText = 'Загрузка...';
   

    jQuery('input[placeholder], textarea[placeholder]').placeholder();
	
    //Слайд-шоу
    $(window).load(function() {
        $('#slider').nivoSlider({
            pauseTime: 6000,
            effect: 'fade'
        });
    });
	
    //Верхнее меню
    $('#topNav > li:not(:eq(3))').find('ul').css('left',0);
    $('#topNav > li:eq(3)').find('ul').css('right',0);
    $('#topNav li:has(ul)').mouseover(function(){
        $(this).addClass('active');
    });
    $('#topNav li').mouseout(function(){
        $(this).removeClass('active');
    });
	
    //Выравниваем колонки Событий
    var dBox1 = $('.doingBox1').height();
    var dBox2 = $('.doingBox2').height();
    if(dBox1 <= dBox2){
        $('.doingBox1').css('height', dBox2);
    }
    else{
        $('.doingBox2').css('height', dBox1);
    };
	
    //Карта района
    $('#map .placelist li a').mouseover(function(){
        var aRel = $(this).attr('rel');
        var totalPos = -246*aRel;
        $('.b-map .map').css('backgroundPosition', '0px '+totalPos+'px');
    });
    $('#map .placelist li a').mouseout(function(){
        $('.b-map .map').css('backgroundPosition', '0px 0px');
    });
	
    //Карусель на главной
    $('.listBox li:first a.photo').addClass('active');
    $('#prev').addClass('disable');
    var contentwidth = $('.listBox li').width() + 30;
    var totalcontent = $('.listBox li').size();
    var allcontentwidth = (contentwidth * totalcontent);
    $('.listBox').css('width', allcontentwidth);
    scrolling = function(napr){
        var slideid = $active.attr('rel') - 1;
        var slidedistance = slideid * 190;
        $('.listBox li a').removeClass('active');
        $active.addClass('active');
        $('.listBox').animate({
            left: -slidedistance
        }, 500);
        if(napr == 'left'){
            if($('.listBox li a.active').attr('rel') == totalcontent - 4){
                $('#next').addClass('disable');
            };
        }
        else if(napr == 'right'){
            if($('.listBox li a.active').attr('rel') == 1){
                $('#prev').addClass('disable');
            };
        }
    };
    rotationLeft = function(){
        $active = $('.listBox li a.active').parent().next().find('a.photo');
        scrolling('left');
    };
    rotationRight = function(){
        $active = $('.listBox li a.active').parent().prev().find('a.photo');
        scrolling('right');
    };
    $('#next').click(function(){
        if($('.listBox li a.active').attr('rel') == totalcontent - 4){
            return false;
        }
        else{
            $('#prev').removeClass('disable');
            rotationLeft();
        }
    });
    $('#prev').click(function(){
        if($('.listBox li a.active').attr('rel') == 1){
            return false;
        }
        else{
            $('#next').removeClass('disable');
            rotationRight();
        }
    });
    
    //Показываем погоду
    $('#weather .wrLink a').click(function(){
	$(this).parent().next().show();
	$('#wHidden .wHidden-close').click(function(){
		$('#wHidden').hide();
		return false;
	});
	return false;
    });
    
});
