$(function(){

    var bubbleTextWrapper =  $('.cyclops-says-bubble .vhcenter1');
    var bubbleText = $('.cyclops-says-bubble .vhcenter3');

    $('#slider').anythingSlider({
        buildNavigation:false,
        buildStartStop:false,
        expand:true,
        autoPlay:true,
        delay:10000,
        onSlideBegin: function(e, slider) {
            bubbleTextWrapper.fadeOut('fast', function(){
                bubbleText.html(slider.$targetPage.find('.slider-content').html());
                $(this).fadeIn('fast');
            });
        }
    });

    $('ul#portfolio').cycle({
        height:'390px',
        next:$('.portfolio-next a')
    });

    if($('.slider-wrap').size()){

        function sliderDissolving(){
            viewPortWidth = $(window).width();

            if(viewPortWidth > 1280){
                $('.slider-wrap').addClass('slider-wrap_dissolving');
            }
            else {
                $('.slider-wrap').removeClass('slider-wrap_dissolving');
            }
        }

        sliderDissolving();

        $(window).bind('resize',  sliderDissolving);
    }

    $('.collapsing-header span, .collapsing-header a').click(function(){

        if($(this).parent().hasClass('collapsing-header_active')) {
            $(this).parent().removeClass('collapsing-header_active');
            $('.collapsing-body').slideUp();
        }
        else {
            $('.collapsing-header').removeClass('collapsing-header_active');
            $('.collapsing-body').slideUp();

            $(this).parent().toggleClass('collapsing-header_active').next('.collapsing-body').slideToggle();
        }

        return false;
    });

    $('.region-selector a').click(function(event){
        $(this).parents('.region-select').toggleClass('region-select_opened');
        $(this).parents('.region-select').find('ul').toggle();

        return false;
    });
    
    $('.region-select ul a').click(function(){
        $('.region-selector a span').text($(this).text());

        $('.region-select ul a').removeClass('selected');
        $(this).addClass('selected');

        $('.contacts').hide();
        $('.contacts-' + $(this).attr('id')).show();
         
        $('.region-select').blur();

        return false;
    });

    $('.region-select').click(function(event){
        event.stopPropagation();
    });

    $('.region-select').blur(function(){
        $(this).removeClass('region-select_opened');
        $(this).find('ul').hide();
    });

    $('body').click(function() {
        $('.region-select').blur();
    });
	
	$('.fancybox').fancybox();

});


