
(function($) {
	$.datepicker.regional['ru'] = {
		monthNames: ['Январь','Февраль','Март','Апрель','Май','Июнь',
		'Июль','Август','Сентябрь','Октябрь','Ноябрь','Декабрь'],
		monthNamesShort: ['Янв','Фев','Мар','Апр','Май','Июн',
		'Июл','Авг','Сен','Окт','Ноя','Дек'],
		dayNames: ['воскресенье','понедельник','вторник','среда','четверг','пятница','суббота'],
		dayNamesShort: ['вск','пнд','втр','срд','чтв','птн','сбт'],
		dayNamesMin: ['Вс','Пн','Вт','Ср','Чт','Пт','Сб'],
		dateFormat: 'dd.mm.yyyy', firstDay: 1,
		renderer: $.datepicker.defaultRenderer,
		prevText: '&#x3c;Пред',  prevStatus: '',
		prevJumpText: '&#x3c;&#x3c;', prevJumpStatus: '',
		nextText: 'След&#x3e;', nextStatus: '',
		nextJumpText: '&#x3e;&#x3e;', nextJumpStatus: '',
		currentText: 'Сегодня', currentStatus: '',
		todayText: 'Сегодня', todayStatus: '',
		clearText: 'Очистить', clearStatus: '',
		closeText: 'Закрыть', closeStatus: '',
		yearStatus: '', monthStatus: '',
		weekText: 'Не', weekStatus: '',
		dayStatus: 'D, M d', defaultStatus: '',
		isRTL: false
	};
	$.datepicker.setDefaults($.datepicker.regional['ru']);
})(jQuery);
$(document).ready(function(){

                    
    /************ СРЕЗАНЫЕ БОРТИКИ *****************/
    $('.asdasd').attr('id','asd');

    /**************************** CLOCK ******************************/
    var angleSec = 0;
    var angleMin = 0;
    var angleHour = 0;

    $(document).ready(function () {
        $("#sec").rotate(angleSec);
        $("#min").rotate(angleMin);
        $("#hour").rotate(angleHour);
    });

    setInterval(function () {
        var d = new Date;

        angleSec = (d.getSeconds() * 6);
        $("#sec").rotate(angleSec);

        angleMin = (d.getMinutes() * 6);
        $("#min").rotate(angleMin);

        angleHour = ((d.getHours() * 5 + d.getMinutes() / 12) * 6);
        $("#hour").rotate(angleHour);

    }, 1000);

    /*********************** CARUSEL ***********************/
	var jCar =  jQuery('#mycarousel li').length;
	
	if(jCar > 1)
	{
    jQuery('#mycarousel').jcarousel({
        wrap: 'circular',
        scroll: 1
    });
 }
    /************************* UI TABS **************************/
    if ($("#tabs").length >=1){	
        var index = $("#tabs ul li.active").index("#tabs ul li");
       
        $( "#tabs" ).tabs({
            selected:index
        });
	 
        /*$('.timetable_full .tab_item').each(function(index, element) {
            var height_l = $(this).find('.l').height()-21;
            if(height_l > 100)
            {
                $(this).find('.r').css('height',height_l);
            }
        });*/
    }
    
	
		
    /************************* mycarousel_inner **************************/
	var jCarBlog =  jQuery('.blogCarousel li').length;
	
	if(jCarBlog > 1)
	{
    jQuery(".blogCarousel").jcarousel({
        scroll: 1,
        initCallback: mycarousel_initCallback
    });
    }
	var jCarInner =  jQuery('#mycarousel_inner li').length;
	if(jCarInner > 1)
	{
    jQuery("#mycarousel_inner").jcarousel({
        scroll: 1,
        initCallback: mycarousel_initCallback
    });
	}
    jQuery("#mycarousel_inner .jcarousel-control a:first").addClass('active');
	
    var l = jQuery('#mycarousel_inner .jcarousel-control a').length-1;
	
    jQuery('#mycarousel_inner .jcarousel-prev').live('click',function(){
        var ind = jQuery('#mycarousel_inner .jcarousel-control a.active').index();
        if (ind != 0){
            jQuery('#mycarousel_inner .jcarousel-control a').removeClass('active');
            jQuery('#mycarousel_inner .jcarousel-control a').eq(ind).prev().addClass('active');
        }
    });
	
    jQuery('#mycarousel_inner .jcarousel-next').live('click',function(){
        var ind = jQuery('#mycarousel_inner .jcarousel-control a.active').index();
        if (l > ind){
            jQuery('#mycarousel_inner .jcarousel-control a').removeClass('active');
            jQuery('#mycarousel_inner .jcarousel-control a').eq(ind).next().addClass('active');
        }
    });
        
    /********************** SELECT ****************************/
    if($(".chzn-select").length>=1){
        $(".chzn-select").chosen();
    }
    /********************** exercises ****************************/
    var    bigPicDiff = 600,
    smallPicDiff = 126;
    var i;
    $('#pictures-big .pictures-big').each(function(index, element) {
        var html_this = $(this).html();
        $('#pictures-small-left, #pictures-small-right').append('<div class="pictures-small">'+html_this+'</div>')
    });
	
	
    var col = $('#pictures-big .pictures-big').length;
	
    $('#pictures-big').css('width',col * 600);


    if (parseInt($('#pictures-big').css('left')) < bigPicDiff  || 'auto' == ($('#pictures-big').css('left'))) {
        $('#arrow-left').hide();
    }

    $('#pictures-small-left').css('left',126*2);
	
    $('#arrow-right').click(function(){
        if ((parseInt($('#pictures-big').css('left')) > -((col-1) * 600)) || 'auto' == ($('#pictures-big').css('left'))) {

            $('#pictures-big').animate({
                left: '-=' + bigPicDiff
            }, function(){
                if (parseInt($('#pictures-big').css('left')) <= -$('#pictures-big').width() + bigPicDiff) {
                    $('#arrow-right').fadeOut();
                }
            });
            $('#pictures-small-left').animate({
                left: '-=' + smallPicDiff
            });
            $('#pictures-small-right').animate({
                left: '-=' + smallPicDiff
            });
            $('#arrow-left').fadeIn();

            i++;
            $('#photoLabel').text(a[i]);
        }

    });

    $('#arrow-left').click(function(){
        if (parseInt($('#pictures-big').css('left')) < 0) {
            $('#pictures-big').animate({
                left: '+=' + bigPicDiff
            }, function(){
                if (parseInt($('#pictures-big').css('left')) >= 0) {
                    $('#arrow-left').fadeOut();
                }
            });
            $('#pictures-small-left').animate({
                left: '+=' + smallPicDiff
            });
            $('#pictures-small-right').animate({
                left: '+=' + smallPicDiff
            });
            $('#arrow-right').fadeIn();

            i--;
            $('#photoLabel').text(a[i]);
        }

    });


    /******************** CALENDAR **************/
    $(function(){

        // Datepicker
        if($('.datepicker').length >= 1)
        {
            $('.datepicker').datepicker({
                showOn: "button",
                buttonImage: "/images/magnetto/calendar.png",
                buttonImageOnly: true,
                changeMonth: true,
                changeYear: true,
                prevText:'',
                nextText:'',
                minDate: '0',  
               
                onSelect: function(dateText, inst) {
                    $("#dateInput").val(dateText);
                }
            });
        }
			
    });
			
    if($('.datepicker_stat').length >= 1)
    {   
	
        $('.datepicker_stat').datepicker({
            changeMonth: true,
            changeYear: true,
            prevText:'',
            nextText:'',
            minDate: '0',
            onSelect: function(dateText, inst) {
				
                if (!$('input[name="data[new][po]"]').val()==''){
				   $('input[name="data[new][s]"]').val('');
				   $('input[name="data[new][po]"]').val('')
				   }
				if ($('input[name="data[new][s]"]').val()==''){
   			    $('input[name="data[new][s]"]').click();
				}else{
				  	 $('input[name="data[new][po]"]').click();
					 }
					 
                $(".activeCalendarInput").val(dateText);
            }
        });

		
    }
	$('.datepicker_stat .ui-datepicker-calendar a').click(function(){
		 $(this).parent().click();
	});
	$('.datepicker_stat .ui-datepicker-calendar a').toggle(
			  function(){
				   $('.datepicker_stat .ui-datepicker-calendar a').removeClass('from_day');
				   $(this).addClass('from_day');
				  },
			  function(){
			 	   $('.datepicker_stat .ui-datepicker-calendar a').removeClass('to_day');
				   $(this).addClass('to_day');
				  }
			  );
			
			
    $('#add_article_block').click(function(){
        $('.add_blog_article').toggle();
			 
        return false;
    });



    /****************** OVERLAY ************************/
    $('.close').click(function(){
        $(this).parent().parent().fadeOut();
        $('.overlay_bg').fadeOut();
    });
	
	$('body').keyup(function(e){
			if(e.which == 27) {
				$('.close_b').click();
			}
	});
	
	$('.close_b').click(function(){
        $(this).closest('.overlay').fadeOut();
        $('.overlay_bg').fadeOut();
    });
	
    $('#question_menager').click(function(){
        $('.overlay.menager, .overlay_bg').fadeIn();
 
        return false;
    });

    $('#wright_tour').click(function(){
        $('.overlay.wright_tour, .overlay_bg').fadeIn();
 
        return false;
    });

    $('#freez').click(function(){
        $('.overlay.freez, .overlay_bg').fadeIn();
 
        return false;
    });  
    
    /********************** get_there ****************************/
    $('.get_there .open').click(function(){
        $(".hidden").css({
            "display":"none"
        });
        
        $(this).next().toggle();
        return false;
    });
    /*********** ADD IMG ***************/

    $('#add_img_field').live("click",function(){
        
        var parent =  $(this).parent().parent();
        var nextIndex =parseInt($(".imgInp").last().attr("rel"))+1;
        $(parent).find(".hideImg").eq(0).slideToggle("false");
        $(parent).find(".hideImg").eq(0).removeClass("hideImg");
       
        var count = $(parent).find(".hideImg").size();
     
        if(count == 0)
        {
            $(this).css({
                "display":"none"
            });
            return false;
        }
    });
	
	
	
	
	if($.browser.msie && $.browser.version < 9)
    {
     $('header .menu > ul > li > .sbm').append('<li class="bg2_sbm"></li>');
	 $('header .menu > ul > li > .sbm').append('<li class="bg1_sbm"></li>');
    }
	if($.browser.msie && $.browser.version < 8)
    {
     $('.trener .text p:last-child').append('<img class="scb" src="/images/magnetto/scb.png" />');
    }
	
	
	
	
});

function mycarousel_initCallback(carousel) {
  
    jQuery('.jcarousel-control a').bind('click', function() {
        jQuery('.jcarousel-control a').removeClass('active');
        carousel.scroll(jQuery.jcarousel.intval(jQuery(this).index()+1));
        jQuery(this).addClass('active');
        return false;
    });

    jQuery('.jcarousel-scroll select').bind('change', function() {
        carousel.options.scroll = jQuery.jcarousel.intval(this.options[this.selectedIndex].value);
        return false;
    });

    jQuery('#mycarousel-next').bind('click', function() {
        carousel.next();
        return false;
    });

    jQuery('#mycarousel-prev').bind('click', function() {
        carousel.prev();
        return false;
    });
    
};


jQuery(document).ready(function($){
var screen_width = $(window).width();
if (screen_width > 1024){
$('html').css('overflow-x','hidden');
}else{
$('html').css('overflow-x','visible');
}

$(window).resize(function(){
var screen_width_d = $(window).width();

if (screen_width_d > 1024){
$('html').css('overflow-x','hidden');
}else{
$('html').css('overflow-x','visible');
}
});

});




