var activeIndex = 0;
var actSocial = 0;
var autoScroll;
var directionSocial;
var odnoklUsers = new Array({
    'name':'Лев',
    'image':'/images/new_design/users/user-1.jpg'
},
{
    'name':'Марина',
    'image':'/images/new_design/users/user-2.jpg'
},
{
    'name':'Дмитрий',
    'image':'/images/new_design/users/user-3.jpg'
},
{
    'name':'Елизавета',
    'image':'/images/new_design/users/user-4.jpg'
},
{
    'name':'Светлана',
    'image':'/images/new_design/users/user-5.jpg'
},
{
    'name':'Ольга',
    'image':'/images/new_design/users/user-6.jpg'
},
{
    'name':'kate',
    'image':'/images/new_design/users/user-7.jpg'
},

{
    'name':'Сергей',
    'image':'/images/new_design/users/user-8.jpg'
},

{
    'name':'Александр',
    'image':'/images/new_design/users/user-9.jpg'
},

{
    'name':'Анна',
    'image':'/images/new_design/users/user-10.jpg'
},

{
    'name':'Юрий',
    'image':'/images/new_design/users/user-11.jpg'
},

{
    'name':'Анатолий',
    'image':'/images/new_design/users/user-12.jpg'
});
/*
var activeIndex = 0;
var actSocial = 0;
var actSocialDirect = true;
var autoScroll;
*/
$(function(){
    fillOdnokl();
    $('#description .small_account:eq(0)').appendTo('#description');
    $('#description .small_account:eq(0)').clone().appendTo('#description');
    $('#description .small_account').each(function(index, element) {
        var left = index*442+2;
        $(this).css('left',left+'px');
    });
    $('#description .big_types').each(function(index, element) {
        var left = -index*454+160;
        $(this).css('left',left+'px');
    });
    
    $('#types a').click(function(){
        var buttons = $('#types a');
        buttons.removeClass('active');
        $(this).addClass('active');
        var newIndex = buttons.index(this);
        var diff = activeIndex-newIndex;
        var step1 = diff*442;
        var step2 = diff*454;
        activeIndex = newIndex;
        $('#description .small_account').animate({ left : '+='+step1},1000,'easeInOutQuart');
        $('#description .big_types').animate({ left : '-='+step2},1000,'easeInOutQuart');
    }); 
    $('#description .small_account').click(function(e) {
        var index = $(this).attr('alt');
        $('#types a:eq('+index+')').click();
    });
    
    $('#net .slider>div').each(function(index, element) {
        var left = index*200;
        $(this).css('left',left+'px');
    });
    
    $('#switch a').click(function(){
        var buttons = $('#switch a');
        buttons.removeClass('active');
        $(this).addClass('active');
        var newIndex = buttons.index(this);
        var diff = actSocial-newIndex;
        var step = diff*200;
        actSocial = newIndex;
        $('#net .slider>div').animate({ left : '+='+step},1000,'easeInOutQuart');
    });
    autoScroll = setInterval(slideSocial,4000)
    $('#net').mouseenter(function(e) {
        clearInterval(autoScroll);
    }).mouseleave(function(e) {
        autoScroll = setInterval(slideSocial,4000);
    });;
});

function slideSocial(){
    if (actSocial==2) directionSocial=-1;
    if (actSocial==0) directionSocial=1;
    var newIndex = actSocial+directionSocial;    
    $('#switch a:eq('+newIndex+')').click();
}

function fillOdnokl(){
    arrayShuffle(odnoklUsers);
    var usersBlock = $('#users');
    usersBlock.empty();
    for (var i=0; i<6; i++){
        usersBlock.append('<div><img src="'+odnoklUsers[i].image+'" alt="'+odnoklUsers[i].name+'" /><br />'+odnoklUsers[i].name+'</div>');
    }
}
function arrayShuffle(theArray) {
     var len = theArray.length;
    var i = len;
     while (i--) {
         var p = parseInt(Math.random()*len);
        var t = theArray[i];
          theArray[i] = theArray[p];
          theArray[p] = t;
     }
};

/*
function slideSocial(){
    var newIndex = 0;
    if (actSocialDirect)
    {
        newIndex = actSocial + 1;
        if (newIndex > 2) 
        {
            actSocialDirect = false;
            newIndex = newIndex - 2;
        }            
    }
    else
    {
        newIndex = actSocial - 1;
        if (newIndex < 0)
        {
            actSocialDirect = true;
            newIndex = newIndex + 2;
        }            
    }
    $('#switch a:eq('+newIndex+')').click();
}
*/
