jQuery.preloadImages = function() {
    for(var i = 0; i<arguments.length; i++)
    {
          jQuery("<img>").attr("src", arguments[i]);   
    } 
}
$(document).ready(function(){

    /* Новости */
    function news_rotate(num, max_num){
        $('.newsn').fadeOut().delay(310).filter(".nn-"+num).fadeIn();
        var new_num=num+1;
        if( new_num==(max_num) ) {new_num=0;}
        setTimeout(function(){
            news_rotate(new_num, max_num);
        }, 7000);
    }
    news_rotate(0, 3);

	/*select-box*/
    $(".j-container .slide").jCarouselLite({
        visible: 3,
        speed: 500,
        btnNext: ".next",
        btnPrev: ".prev",
        beforeStart: function(a) {
            var active_id = $(".slide li.active").attr("rel");
            $('[rel='+active_id+']').addClass('active');
        }
    });
		loadTwitter();
        
        if($('#scrollbar1').length!=0){$('#scrollpane').height(383).jScrollPane({showArrows:true,verticalDragMinHeight:24,verticalDragMaxHeight:24,arrowScrollOnHover:true});}

        /********************NEW!! UPLOAD THIS PART!!!***************************************************************/

    
        if ($('.comp-list li').length!=0) $('.comp-list li').bind('click',toggleCategory);
    
        if ($("#scroller1").length!=0){
            $("#scroller1").simplyScroll({
                className: 'vert',
                horizontal: false 
            });
        }
        if ($("#scroller2").length!=0){
            $("#scroller2").simplyScroll({
                className: 'vert',
                horizontal: false
            });
        }
        if ($("#scroller3").length!=0){
            $("#scroller3").simplyScroll({
                className: 'vert',
                horizontal: false
            });
        }
        if ($("#scroller4").length!=0){
            $("#scroller4").simplyScroll({
                className: 'vert',
                horizontal: false
            });
        }
        $('#scroller1').css('visibility','visible');$('#scroller1').parent().parent().css('visibility','visible');
    
    $('.simply-scroll-list').each(function(){
        
        h=$(this).height();
        //console.log(h);
        //alert(h);
        if (h<177){$(this).parent().parent().find('.simply-scroll-btn-up, .simply-scroll-btn-down').css('display','none');}
    });

    
function toggleCategory(){
    if($(this).hasClass('c1')){$('.comp-list li').removeClass('active'); $(this).addClass('active');$('#scroller2, #scroller3, #scroller4').parent().parent().css('visibility','hidden'); $('#scroller1').parent().parent().css('visibility','visible');$('#scroller2, #scroller3, #scroller4').css('visibility','hidden'); $('#scroller1').css('visibility','visible');}
    if($(this).hasClass('c2')){$('.comp-list li').removeClass('active'); $(this).addClass('active');$('#scroller1, #scroller3, #scroller4').parent().parent().css('visibility','hidden'); $('#scroller2').parent().parent().css('visibility','visible');$('#scroller1, #scroller3, #scroller4').css('visibility','hidden'); $('#scroller2').css('visibility','visible');}
    if($(this).hasClass('c3')){$('.comp-list li').removeClass('active'); $(this).addClass('active');$('#scroller2, #scroller1, #scroller4').parent().parent().css('visibility','hidden'); $('#scroller3').parent().parent().css('visibility','visible');$('#scroller2, #scroller1, #scroller4').css('visibility','hidden'); $('#scroller3').css('visibility','visible');}
    if($(this).hasClass('c4')){$('.comp-list li').removeClass('active'); $(this).addClass('active');$('#scroller2, #scroller1, #scroller3').parent().parent().css('visibility','hidden'); $('#scroller4').parent().parent().css('visibility','visible');$('#scroller2, #scroller1, #scroller3').css('visibility','hidden'); $('#scroller4').css('visibility','visible');}
}    
    
    /**************************************************************************/
    
    
    
    
    
    /*NEW!! UPLOAD THIS PART!!!*/


	$('.header .navbar li ul li ul li:nth-child(11)').css('border-bottom','1px solid #a0a2a7');
	$('.header .navbar li ul li ul li:nth-child(11) a').css('line-height','20px');
	/*select-box*/
	$('.select-box ul').hide();
	
	$('.select-box:not(".disabled") .select-value').click(function(){
		
		$(this).parents('.select-box').addClass('active').find('ul').show();
		return false;
	});
	
	$('.select-box ul a').click(function(){
		$(this)
		.parents('.select-box').find('.select-value').html($(this).html())
		.parents('.select-box').find('input').val($(this).html())
		.parents('.select-box').removeClass('active').find('ul').hide();
		
    window.location.href = $(this).attr("href");
    
		return false;
	})
	
	$('.select-box').hover(null, function(){
		if ($(this).find('ul').is(':visible')) $(this).find('ul').hide();
		$(this).find('.select-value').blur();
		$(this).removeClass('active');
	});



    //Select
    $("div.people-list div.people").each(function() {
        $(this).css('z-index',1);
    });

    $("#sel").jqTransform({imgPath:"images/"});
    $("#sel2").jqTransform({imgPath:"images/"});
    $("#sel3").jqTransform({imgPath:"images/"});
    $("#sel4").jqTransform({imgPath:"images/"});

    $('#sel ul a').live('click',function(){
        var selIndex=$(this).parent().index();
        document.location.href=$('#sel select option').eq(selIndex).attr('value');
    });
    
    $("div.jqTransformSelectWrapper").hover(function() {
        if ($(this).parent('form').attr('id')=='sel') {
            $(this).addClass("selactiv");
            $(this).find('ul:first').slideDown(100);
        }        
    }, function() {
        if ($(this).parent('form').attr('id')=='sel') {
            $(this).removeClass("selactiv");
            $("div.jqTransformSelectWrapper ul").slideUp(10);
        }        
    });
    
    $("#sel ul,#sel2 ul,#sel3 ul").each(function(){
        $(this).find('li:first').hide();      
        $(this).find("li:eq(1)").addClass("lastsel");  
    });
    //BoxC
    $(".cimg").click(function(){
        $(this).css("position", "relative");
        $(this).find(".datac").show();
    });

    $(".cimg").hover(function(){

    },
    function() {
        $(this).css("position", "static");
        $(this).parent().find(".datac").hide();
    });

    //NavTop
    $(".navbar li").hover(function (){
		$(this).find(".subnav").show();
        $(this).addClass("hover");
        var hsubnav = $(this).find(".subnav ul").height();
        
        $(this).find(".navbgl:first").css("height", hsubnav+37);
    },
    function() {
        $(this).removeClass("hover");
        $(this).find(".subnav").hide();
    }
    );

    $(".navbar .subnav ul li").hover(function (){
        if($(this).find("ul").css("display") == "none") {
            $(".navchild").show();
        }
        $(this).find("ul").show();
        
        var hsubnav2 = $(this).parent().height();
        
        $(this).find("ul").css("height", hsubnav2);
        $(this).addClass("navcur");
    },
    function(){
        if($(this).find("ul").css("display") != "none") {
            $(".navchild").hide();
        }
        $(this).removeClass("navcur");
        $(this).find("ul").hide();
    });

    $(".navbar .subnav ul li ul li ").hover(function (){
        $(".navchild").show();
    },
    function() {
        $(".navchild").show();
    });

    

    //HomeSlide
    
    if ($(".slidebox .slide").attr('id')!=null) {
    
    $(".slidebox .slide").jCarouselLite({
        visible: 1,
        speed: 500,
        auto: 6000,
        btnNext: ".next",
        btnPrev: ".prev",
        btnGo:
        [".i1",".i2",".i3",".i4"]
    });
    }
    
//    $("a.lookimage").fancybox({'titleShow':false});
    //$("a.lookimage, a[rel=gallery], a[rel^=gallery-]").css('cursor','default').click(function(){return false;});
    $("a.lookimage").css('cursor','default').click(function(){return false;});
    
    $("a#youtube_fancy").fancybox({
        'titleShow'     : false,
        'width'         : 960,
        'height'        : 570,
        'type'          : 'swf',
        'swf'           : {
            'wmode'		: 'transparent',
            'allowfullscreen'	: 'true'
        }        
    });
    
    $("a[rel=gallery],a[rel^=gallery-]").fancybox({
        'transitionIn':'none',
        'transitionOut':'none',
        'titlePosition':'over',
        'titleFormat':function(title, currentArray, currentIndex, currentOpts) {
            return '<span id="fancybox-title-over">Изображение ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
        }
    });

    /*
    $("a[rel=gallery],a[rel^=gallery-]").fancybox({
        'transitionIn':'none',
        'transitionOut':'none',
        'titlePosition':'over',
        'titleFormat':function(title, currentArray, currentIndex, currentOpts) {
            return '<span id="fancybox-title-over">Изображение ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
        }
    });
    */
    
    

    
    $("a#filter-schedule").live('click',function() {
        var select_loc=new Array();
        var select_type=new Array();
        var select_level=new Array();
        
        $("[class^=service-] option:selected").each(function () {
            select_loc[select_loc.length]=$(this).val();
        });
        $("[class^=trainer-] option:selected").each(function () {
            select_loc[select_loc.length]=$(this).val();
        });
        
        $("input[id^=level-]:checked").each(function () {
            select_level[select_level.length]=$(this).val();            
        });
        
        $("div.timeinfo div[class^=col-] span.ac").each(function () {
            select_type[select_type.length]=$(this).parent().attr('class').substring(4);
        });         
        
        $.get("/body/includes/library/filter.php?filter="+select_loc+$("#getfilter").val()+'&filter_type='+select_type+'&level='+select_level, function(data){
            $("div#schedul_content").html(data);            
        });   
        
        
        return false;
    });
     
    $("a.tbut-left,a.tbut-right").live('click',function() {
        $.get("/body/includes/library/filter.php?filter="+$(this).attr('data'), function(data){
            $("div#schedul_content").html(data);
        });
        
        return false;        
    });
    
    $("a.tbut-left-lessons,a.tbut-right-lessons").click(function() {
        $.get("/body/includes/library/filter-copyright-lessons.php?filter="+$(this).attr('data'), function(data){
            $("div#schedul_content").html(data);            
        });
        
        return false;        
    });
    
    //10???? ???????
    $("input[name*='telephone']").each(function(){
        if ($(this).val()!=undefined) {
            $(this).mask("9 (999) 999-9999");
            if($(this).parents('#fact').length){
                $(this).val('');
            }
        }
    });
    if ($("input[name=user_datelife]").val()!=undefined) {
        if ($("input[name=user_datelife]")) {
            $("input[name=user_datelife]").mask("99/99/9999");
            $("input[name=user_datelife]").val('дд/мм/гггг');
        }
    }
    
    $("*").click(function(){
        if ($("input[name=user_telephone]").val()!=undefined && $("input[name=user_telephone]").val()=='') $("input[name=user_telephone]").val('');
    });
    
    function isValidEmailAddress(emailAddress) {
        var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
        return pattern.test(emailAddress);
    }
    
    $("div.info .abut").click(function () {

        error=0;
        user_name=$("#fact input[name=user_name]");
        user_email=$("#fact input[name=user_email]");
        user_telephone=$("#fact input[name=user_telephone]");
        
                    
        if (user_name.val()=='') {
          user_name.css({'background-position':'left bottom','color':'#FFFFFF'});
          error++
        }
        else user_name.css({'background-position':'left top','color':'#000000'});

        if (user_email.val()=='' || !isValidEmailAddress(user_email.val())) {
          user_email.css({'background-position':'left bottom','color':'#FFFFFF'});
          error++
        }
        else user_email.css({'background-position':'left top','color':'#000000'});

        if (user_telephone.val()=='') {
          user_telephone.css({'background-position':'left bottom','color':'#FFFFFF'});
          error++
        }
        else user_telephone.css({'background-position':'left top','color':'#000000'});

        if (error==0) $("#fact").submit();
        else return false;
    });

    $(".button_form").click(function () {
        error=0;

        $(".ch5").css({'color':'#4F616B'});

//        for (i_c=1; i_c<=3; i_c++) {
//            $(".ch"+i_c).css({'color':'#4F616B'});
//            if ($(".free_days input[id^=ch"+i_c+"]:checked").length==0) {$(".ch"+i_c).css({'color':'#FF0000'});error++}
//        }
        $('.free_days input[name^=user_]').css('background','#fff');
        $(".free_days input[name=user_sex]").next().css('background','none');
        $(".forvalidation").css('color','#000');
        if($(".free_days input[name=user_datelife]").val()=='' || $(".free_days input[name=user_datelife]").val()=='дд/мм/гггг')
            {var datelife_error=true;$(".free_days input[name=user_datelife]").css('background','#b2b2b2').parent().prev().css('color','#f00');}
        else
            {
            var birth=$(".free_days input[name=user_datelife]").val();
            var curr_d=new Date();
            var birth_arr=birth.split('/');
            var birth_d=new Date(birth_arr[2],birth_arr[1]-1,birth_arr[0],0,0,0);
            var full_years=Math.floor((curr_d-birth_d)/(1000*60*60*24*365.25));
            if(full_years<18 || full_years>80)
                {var datelife_error=true;$(".free_days input[name=user_datelife]").css('background','#b2b2b2');}
            }
        if($(".free_days input[name=user_name]").val()=='')
            {var name_error=true;$(".free_days input[name=user_name]").css('background','#b2b2b2');}
        if($(".free_days input[name=user_email]").val()=='' || !isValidEmailAddress($(".free_days input[name=user_email]").val()))
            {var email_error=true;$(".free_days input[name=user_email]").css('background','#b2b2b2');}
        if($(".free_days input[name=user_telephone_e]").val()=='')
            {var telephone_error=true;$(".free_days input[name=user_telephone_e]").css('background','#b2b2b2');}
        if($(".free_days input[name=user_sex]:checked").length==0)
            {var sex_error=true;$(".free_days input[name=user_sex]").parent().siblings('span').css('color','#f00');}

        if (datelife_error || name_error || email_error || telephone_error || sex_error) {
            $(".ch4").css({'color':'#FF0000'});
            error++;
        }
        else $(".ch4").css({'color':'#4F616B'});


        if ($(".free_days select[name=select_club] option:selected").val()==0) {$(".ch5").css({'color':'#FF0000'});error++;}

        if (error==0) $(".free_days").submit();
    });

    //?????? ??????????
    $("a#print-schedule").live('click',function() {
        var select_loc=new Array();
        var select_type=new Array();

        $("[class^=service-] option:selected").each(function () {
            select_loc[select_loc.length]=$(this).val();
        });
        $("[class^=trainer-] option:selected").each(function () {
            select_loc[select_loc.length]=$(this).val();
        });

        $("input[id^=gym-]:checked").each(function () {
            select_loc[select_loc.length]=$(this).val();
        });

        $("div.timeinfo div[class^=col-] span.ac").each(function () {
            select_type[select_type.length]=$(this).parent().attr('class').substring(4);
        });

        window.open('/print-schedule/'+$("#getprint").val()+'/'+select_loc+'/'+select_type);

        return false;
    });
    
    $("ul.navbar li ul li ul").hover(function(){        
        //$(this).parent().find('a:first').css({'color':'#0285C7'});
        $(this).parent().find('a:first').attr('style','color:#0285C7; background:#ececec url(/images/activ3.png) 229px center no-repeat !important');
        
    },function(){
        $(this).parent().find('a:first').attr('style','color:#424E54; background:#url(/images/activ_m.png) 228px center no-repeat !important');
    });
    
    $.preloadImages("/images/activ1.png","/images/activ2.png","/images/activ3.png","/images/activ4.png","/images/activ5.png","/images/subtop1.png");
    
    $("#fsearch_f a").click(function() {
        $("#fsearch_f").submit();
        return false;
    }); 
    $("img#sendform").click(function() {
        $("#sendform").submit();
        return false;
    }); 
    
        //??????? ?????? ? ??????? ??????
    $("form.recommend input.button").click(function(){
        $("input[name=user_family], input[name=user_name], input[name=user_patronymic]").css({'background':'#FFF','color':'#000'});
        
        var error=0;
        var family_error=0;
        var name_error=0;
        var patronymic_error=0;
        var telephone_error=0;        
        
        user_family=$("input[name=user_family]");
        user_name=$("input[name=user_name]");
        user_patronymic=$("input[name=user_patronymic]");
        user_d_d=$("select[name=user_d_d]");
        user_d_m=$("select[name=user_d_m]");
        user_d_y=$("select[name=user_d_y]");
        
        
        if (user_family.val().length<3) {user_family.css({'background-color':'#64757D','color':'#FFFFFF'});error++}
        if (user_name.val().length<3) {user_name.css({'background-color':'#64757D','color':'#FFFFFF'});error++}
        if (user_patronymic.val().length<3) {user_patronymic.css({'background-color':'#64757D','color':'#FFFFFF'});error++}
        
        if (user_d_d.val()==1 && user_d_m.val()==1 && user_d_y.val()==1950) {
            user_d_d.css({'background-color':'#64757D','color':'#FFFFFF'});
            user_d_m.css({'background-color':'#64757D','color':'#FFFFFF'});
            user_d_y.css({'background-color':'#64757D','color':'#FFFFFF'});
            error++;            
        } else {
            user_d_d.css({'background-color':'#FFF','color':'#000'});
            user_d_m.css({'background-color':'#FFF','color':'#000'});
            user_d_y.css({'background-color':'#FFF','color':'#000'});
        }
        
        $('input[name="friend[family][]"]').each(function(index,v){if ($(v).val().length<3) family_error++;});
        $('input[name="friend[name][]"]').each(function(index,v){if ($(v).val().length<3) name_error++;});
        $('input[name="friend[patronymic][]"]').each(function(index,v){if ($(v).val().length<3) patronymic_error++;});
        $('input[name="friend[telephone][]"]').each(function(index,v){if ($(v).val().length<3) telephone_error++;});
        
        $('input[name="friend[family][]"]:first, input[name="friend[name][]"]:first, input[name="friend[patronymic][]"]:first, input[name="friend[telephone][]"]:first').css({'background':'#FFF','color':'#000'});
        
        if (family_error==2 || name_error==2 || patronymic_error==2 || telephone_error==2) {
            if (family_error==2) $('.block-friend input[name="friend[family][]"]').css({'background':'#64757D','color':'#FFFFFF'}); 
            if (name_error==2) $('.block-friend input[name="friend[name][]"]').css({'background':'#64757D','color':'#FFFFFF'}); 
            if (patronymic_error==2) $('.block-friend input[name="friend[patronymic][]"]').css({'background':'#64757D','color':'#FFFFFF'}); 
            if (telephone_error==2) $('.block-friend input[name="friend[telephone][]"]').css({'background':'#64757D','color':'#FFFFFF'}); 
        }
        else if (error==0) {
            $("form.recommend").submit();                             
        }
        return false;
    });


    var br=$('#bestresult div.best-result');
    br.hover(function(){
        $(this).find('.nodisplay').show().prev().hide();
    },function(){
        $(this).find('.nodisplay').hide().prev().show();
    });
    
    
    
    $("div.comments-count").each(function(i){
        var ds_c=$(this)
        $.getJSON('https://graph.facebook.com/?ids='+$(this).attr('rel')+'&callback=?', function(data) {
            $.each(data, function(i, l){
                ds_c.html('<span class="likefb"><span>Comments</span></span> <span class="likefbc"><i></i>'+(l.comments?l.comments:0)+'</span>');
            });
        });
    }); 
    
    $("div.timeinfo div[class^=col-]").live('click',function(){        
        if (!$(this).find('span:first').hasClass('ac')){
            $(this).find('span:first').addClass('ac').append('<b></b>');
        }
        else {
            $(this).find('span:first').removeClass('ac').html('');
        }
        
    });
   
	
	$('.menu-second table tr td').hover(function(){
        $(this).addClass('active')
    },function(){
        $(this).removeClass('active');
    });
	
	$('body').click(function(e){
		if ($('.search-active').size() > 0) {
			if (!$(e.target).hasClass('search') && !$(e.target).parents().hasClass('search') && !$(e.target).hasClass('icon')) searchForm($('.search .icon'));
		}
	});
        
        
        // sport-stories
        
        
//	$('#showmore').click(function(){
//            var pos= $(this).attr('class').substring(3);
//            $.get('/body/includes/library/sportstories.php?pos='+pos+'&id='+$('#thisid').val(), function(data){
//                var new_pos = parseInt(pos) + parseInt( $('#sportcount').val()); 
//                if(data == 'clear'){
//                    $('#showmore').hide();
//                }
//                else{
//                    $('#update').before(data);
//                    $('.dimg-box:hidden').slideDown();
//                    $('#showmore').removeClass().addClass( 'id_'+ new_pos );
//                    if( new_pos > parseInt( $('#allrows').val())  ){
//                        $('#showmore').hide();
//                    }
//                }
//            })
//            return false;
//        }); 
        
        
       // append cool style to schedule col-6
        $('td.td-col-6').wrapInner('<div class="col6" />');
//       $('li.j-page:first').addClass('active');
        $('.j-story-biography').prepend('<img class="j-story-loader" style="display:none;position:absolute;left:50%;top:50%;margin-left:-16px;margin-top:-16px" src="/images/loader.gif" alt="" />');
        var req=false,ani=false,dat=false;
        function showContent(data){
            if(req&&ani&&dat){
                $('.j-text,.j-story-before').fadeIn(500,function(){$('li.j-page').removeClass('notactive');});
                $('#s_stats').html($(data).find('#s_stats').html());
                $('#fio').html($(data).find('#fio').html());
                $('#big_before').attr('src',$(data).find('#big_before').attr('src'));
                /*$('.j-story-loader').hide(0);*/
                $('.viewport').html($(data).find('.viewport').html()).find('#scrollpane').height(383).jScrollPane({showArrows:true,verticalDragMinHeight:24,verticalDragMaxHeight:24,arrowScrollOnHover:true});
            req=false;
            ani=false;
            dat=false;
            }
        }
        $('li.j-page:not(".active")').live('click', function(){
            if(!$(this).hasClass('notactive')){
                $('li.j-page').addClass('notactive');
                var me=$(this).addClass('active');
                me.siblings().removeClass('active');
                var id=me.attr('rel');
                $.get('/body/includes/library/sportstories.php?id='+id.substr(2, id.length), function(data){
                    req=true;
                    dat=data;
                    showContent(data);
                });
                $('.j-text,.j-story-before').fadeOut(500,function(){
                    /*if(!req)
                        $('.j-story-loader').show(0).delay(200).hide(0);*/
                    ani=true;
                    showContent(dat);
                });
                req=false;
                ani=false;
                dat=false;
                return false;
            }
        });

        if($('#right-slider').length){
            var step=0;
            var slider=$('#right-slider');
            var first=$('#right-slider').children().eq(0);
            var stepsCount = slider.children().length - 3;
            var stepPx=-171;
            var prev=$('#right-slider').prev();
            var next=$('#right-slider').next();
            if (stepsCount > 0) {
                prev.click(function(){
                    if(!$(this).hasClass('disabled')){
                        step--;
                        prev.add(next).addClass('disabled');
                        first.animate({'margin-top':step*stepPx},500,function(){
                            if(step==0)
                                next.removeClass('disabled');
                            else
                                prev.add(next).removeClass('disabled');
                        });
                    }
                });
                next.click(function(){
                    if(!$(this).hasClass('disabled')){
                        step++;
                        prev.add(next).addClass('disabled');
                        first.animate({'margin-top':step*stepPx},500,function(){
                            if(step==stepsCount)
                                prev.removeClass('disabled');
                            else
                                prev.add(next).removeClass('disabled');
                        });
                    }
                });
            }else{
                prev.add(next).css('background','none');
            }
        }

function redirect(link) {
    window.location='/'+link;
}

/*search*/

function searchForm(el){
	$(el).parents('.search').toggleClass('search-active');
	return false;

}

/*placeholder*/

function placeholderFocus(el) {
	if ($(el).val() == $(el).attr('title')) $(el).val('');
	}

function placeholderBlur(el) {
	if ($(el).val() == '') $(el).val($(el).attr('title'));
}


function switchTwitter(){
        curpos = ($(this).index())*467;
        $('.tw-bottom .bull').removeClass('active');
        $(this).addClass('active');
        $('.tw-list').animate({
            left: -curpos
        }, 300, function() {

        });
    }

function rotateTwitter(){
	currTw = $('.tw-bottom .bull.active').index();
	lengTw = $('.bull').length;
	if (currTw!=lengTw){
		$('.tw-bottom .bull.active').next().click();
	}else{
		$('.tw-bottom .bull.active').removeClass('active');
		$('.tw-bottom .bull:nth-child(2)').addClass('active');
		$('.tw-list').css('left','0px');
		$('.tw-list').animate({
			left: '-467px'
		}, 300, function() {
		});
	}
	setTimeout(function(){rotateTwitter();}, 6000);
}

function parseDate(str) {
    var v=str.split(' ');
    return new Date(Date.parse(v[1]+" "+v[2]+", "+v[5]+" "+v[3]+" UTC"));
  }
function loadTwitter(){
    var url = "http://api.twitter.com/1/statuses/user_timeline/sportlifeclub.json?count=5&include_entities=true&include_rts=true&callback=?";
    $.getJSON( url, function( data ){
        $.each(data, function(i,item){
            var text_c = item.text;

            //Ссылки
            $.each(item.entities.urls, function(i,link){
                //console.log(link);
                //url - ссылка замена
                //display_url - как смотрется будет
                //expanded_url - куда
                if (link.display_url!=undefined) {
                    text_c=text_c.replace(RegExp(link.url,"g"),'<a href="'+link.expanded_url+'">'+link.display_url+'</a>');
                }
            });
            
            date = parseDate(item.created_at);
            date = new Date(date);

			dd = date.getDate();
			dm = date.getMonth();
			dy = date.getFullYear();
			dh = date.getHours();
			dmi = date.getMinutes();
            
			dtstamp = (''+dd+'.'+dm+'.'+dy+' '+dh+':'+dmi);
            $('.tw-list').append('<li><div class="tw-text">'+text_c+'</div><div class="tw-date">'+dtstamp+'</div></li>');            
        });
            initPages();
			setTimeout(function(){rotateTwitter();}, 6000);
            

    });
}

function initPages(){
    totalelem = $('.tw-list li').length;
        //alert(totalelem);
        for(i=1; i<=totalelem; i++){
            $('.tw-bottom').append('<a nohref class="bull">&bull;</a>');
        }
        $('.tw-bottom .bull:nth-child(2)').addClass('active');
        $('.tw-bottom .bull').bind('click',switchTwitter);

	$('.tw-list li:last-child').clone().prependTo('.tw-list');
}


/***** Табы *****/
$('.a-services-tabs li').not('.nojs').bind('click',function(){    
    var cch = $(this).index('.a-services-tabs li');
    cch = cch+1;
    if (cch == 1){
        $('.tabpage1').css('display','block');
        $('.tabpage2').css('display','none');
        $('.a-services-tabs li').removeClass('active');
        $('.a-services-tabs li').eq(0).addClass('active');
    }
    if (cch == 2){
        $('.tabpage2').css('display','block');
        $('.tabpage1').css('display','none');
        $('.a-services-tabs li').removeClass('active');
        $('.a-services-tabs li').eq(1).addClass('active');
    }
});



});
