﻿var textArray = [
            'registered on the site',
            'winked at a member',
            'sent a message',
            'viewed a video',
            'initiated a chat'
        ];

var preposition = "from";
var adjective = "just";

function random_array(aArray) {
    var rand = Math.floor(Math.random() * aArray.length + aArray.length);
    var randArray = aArray[rand - aArray.length];
    return randArray;
}

function activityType() {
    return random_array(textArray);
}

function addActivityItem(options, item) {
    options = jQuery.extend({ animate: true, collapse: true }, options);
    if (item == null) return false;

    var af_holder = jQuery('#carousel_ul');
    var af_item = jQuery('<li>');

    // grab the profile info
    var profile = jQuery(item);

    // append the action message
    var af_action = jQuery('<span>').attr({ 'class': 'profile_action' });
    var content_copy = "";
    var location = profile.find('span.wld_badge_item_region').html();
    if (location == '')
        location = 'London';

    content_copy += profile.find('span.wld_badge_item_name').html() + " " + preposition + " " + location;
    content_copy += " " + adjective + " " + activityType();

    af_action.html(content_copy);
    af_action.appendTo(profile);

    profile.appendTo(af_item);

    // insert into view...
    af_item.appendTo(af_holder);

    return true;
}

jQuery(document).ready(function() {
    if (typeof (customText) != 'undefined') {
        if (customText != null)
            textArray = customText;
    }
    
    if (typeof (b) == 'undefined')
        return;

    // populate from the existing list
    for (i = 0; i < b.length; i++) { addActivityItem({ compact: false, animate: false }, b[i]); }

    //speed of auto slide
    var auto_slide_seconds = 6000;

    jQuery('#carousel_ul li:first').before(jQuery('#carousel_ul li:last'));

    //change to setTimeout and reset within the slide() function?
    var timer = setInterval('slide()', auto_slide_seconds);
    jQuery('#hidden_auto_slide_seconds').val(auto_slide_seconds);

});

//slide function  
function slide() {
    var left_indent = parseInt(jQuery('#carousel_ul').css('top')) - 60;

    jQuery('#carousel_ul:not(:animated)').animate({ 'top': left_indent }, 1000, function() {
        jQuery('#carousel_ul li:last').after(jQuery('#carousel_ul li:first'));
        jQuery('#carousel_ul').css({ 'top': '0px' });
    });
}

