$(document).ready(function () {
    /* make customers height of largest customer description */
    var customers_box = $('#l-home-strip div.app\\/home\\/customers div.customers');
    var customers = customers_box.find('div.customer');
    customers_box.addClass('temp');
    var max_height = 0;
    customers.each(function () {
        var tmp_height = $(this).height();
        max_height = (tmp_height > max_height) ? tmp_height : max_height;
    });
    var cur_height = customers_box.height();
    var diff = max_height - cur_height;
    if (diff >= 0)
    {
        customers_box.css({"height":(cur_height+diff)+'px'});
    }
    customers_box.removeClass('temp');
    
    /* rotate customers */
    var cust_moving = 0;
    var clicked = false;
    var rotating = true;
    var switch_cust = function (l)
        {
            if (l.hasClass('active'))
            {
                return;
            }
            if (cust_moving > 0)
            {
                return;
            }
            cust_moving = 2;
            var prev_l = customers_box.find('div.active');
            //prev_l.removeClass('active');
            //l.addClass('active');
            
            // begin animation for hiding current story
            prev_l.animate({
                opacity : 0.0
            }, function () { cust_moving -= 1; prev_l.removeClass('active'); } );
            // begin animation for showing new story
            l.css({ opacity : 0.0, display : 'block' }).animate({
                opacity : 1.0
            }, function () { cust_moving -= 1; l.addClass('active'); } );
        }
    // start rotating
    var rotate_time = 5000;
    var timer;
    var rotate = function ()
        {
            // show the next customer and reschedule
            var cur_l = customers_box.find('div.active');
            var next = cur_l.next();
            if (next.size())
            {
                switch_cust(next);
            }
            else
            {
                switch_cust(cur_l.siblings().slice(0,1));
            }
            timer = window.setTimeout(rotate, rotate_time);
        };
    timer = window.setTimeout(rotate, rotate_time);
    
    /* equalize home box heights */
    var boxes = $('#l-home-strip div.home-box-proper');
    var max_height = 0;
    boxes.each(function () {
        var tmp_height = $(this).outerHeight();
        max_height = (tmp_height > max_height) ? tmp_height : max_height;
    });
    boxes.each(function () {
        var tmp_height = $(this).outerHeight();
        var diff = max_height - tmp_height;
        if (diff <= 0) return;
        var cur_height = $(this).height();
        $(this).css({"height":(cur_height+diff)+'px'});
    });
});