﻿var bookings = [
    ['Citibank', 'VOD', '$235,000', 'Complete'],
    ['Capital One', 'Line Increase', '$500', 'Complete'],
    ['Capital One', 'Line Increase', '$15,000', 'Pending'],
    ['Capital One', 'New Application', '$5,000', 'Complete'],
    ['GMAC', 'Auto Loan', '$27,000', 'Pending'],
    ['GMAC', 'Auto Loan', '$42,300', 'Complete'],
    ['GMAC', 'Auto Loan', '$35,000', 'Complete'],
    ['GMAC', 'Auto Loan', '$52,000', 'Complete'],
    ['Citibank', 'VOD', '$525,000', 'Pending'],
    ['Ford Motor', 'Auto Loan', '$27,000', 'Complete'],
    ['Ford Motor', 'Auto Loan', '$46,300', 'Pending'],
    ['Ford Motor', 'Auto Loan', '$22,600', 'Complete'],
    ['Ford Motor', 'Auto Loan', '$35,000', 'Complete'],
    ['Capital One', 'New Application', '$5,000', 'Pending'],
    ['Wells Fargo', 'VOD', '$127,000', 'Complete'],
    ['Wells Fargo', 'VOD', '$225,000', 'Complete'],
    ['Citibank', 'VOD', 'Multiple NSFs Detected', 'ALERT'],
    ['Wells Fargo', 'VOD', '$186,000', 'Complete'],
    ['Wells Fargo', 'VOD', '$202,000', 'Pending'],
    ['MetLife', 'VOD', 'Unusual Deposit Activity', 'ALERT'],
    ['MetLife', 'VOD', '$265,500', 'Complete'],
    ['Capital One', 'New Application', '$5,000', 'Pending'],
    ['Citibank', 'VOD', '$87,000', 'Complete'],
    ['MetLife', 'VOD', '$143,000', 'Complete'],
    ['MetLife', 'VOD', '$166,000', 'Complete'],
    ['Citibank', 'VOD', '$75,000', 'Pending'],

    ['Capital One', 'New Application', '$10,000', 'Pending']
];

var testimonials = [
    { 'cite': 'Truth in Lending Act (TILA)—one in particular focuses on the consumer’s ability to repay a debt (VOD) when the debt is considered high priced or nonprime.', 'author': 'Lexis Nexis' },
    { 'cite': 'Lenders seeking a defense against falsified employment, income, and other loan file documentation (Assets) should leverage third party sources with no vested interest in the financial transaction. ', 'author': 'Lexis Nexis ' },
    { 'cite': 'Real estate firm CoreLogic says more than $10 billion in loans were made with fraudulent application data in 2010.', 'author': 'Associated Press' },
    { 'cite': 'Risk-based origination pricing will be here in 2012 - AccountChek helps me manage that risk and deliver a superior product.', 'author': 'Lisa Binkley' },
    { 'cite': 'Unfortunately (and rather unbelievably), there are some lenders who continue to rely upon stated information and borrower sourced documentation. The standard for lending due diligence must be elevated.', 'author': 'Ray Petta' },
    { 'cite': 'The fraudster’s biggest weapon is your lack of real-time information and verification.', 'author': 'Ray Petta' },
    { 'cite': 'The market experienced a meltdown, housing inventories are at an all-time high and it is next to impossible to obtain credit; so why is reported fraud and misrepresentation still increasing?', 'author': 'Brent Chandler' }
];

$(document).ready(function () {
    $('div.intro').each(function () {
        var $intro = $(this);

        $intro.find('ul.tabs a').first().addClass('active');
        $intro.children('div').last().addClass('active');

        $intro.find('ul.tabs a').click(function (e) {
            e.preventDefault();
            var hrefID = $(this).hrefId();
            var dest = "";
            switch (hrefID) {
                case "intro-1": dest = "Solutions.aspx";
                    break;
                case "intro-2": dest = "Mortgage.aspx";
                    break;
                case "intro-3": dest = "Credit.aspx";
                    break;
                case "intro-4": dest = "Auto.aspx";
                    break;
                case "intro-5": dest = "Contact.aspx";
                    break;
            }
            window.location.href = dest;
        }).mouseenter(function () {
            if ($(this).hasClass('active'))
                return;
            $(this).addClass('active').parent().siblings().children('a').removeClass('active');
            var $prev = $intro.children('div.active').removeClass('active');
            var z = parseInt($prev.css('z-index'), 10) + 1;
            $intro.children('div#' + $(this).hrefId()).animate({ opacity: '0' }, 0).css({ zIndex: z }).addClass('active').animate({ opacity: '1' }, 500, function () { $(this).fixIEFade(); });
            $intro.children('p').css('z-index', z + 1);
        });
    });


    var $bookings = $('ul.bookings');
    if (bookings && bookings.length && $bookings.length) {

        bookings.sort(randomSort);
        var bookingItemHTML = function (i) {
            if (bookings[i][3]=='ALERT')
                return '<li><span class="alert">' + bookings[i][0] + '</span> <em><b>' + bookings[i][1].safe() + '</b> ' + bookings[i][2].safe() + '</em> <i class="alert">' + bookings[i][3].safe() + '</i></li>'; 
                else
                    return '<li><span>' + bookings[i][0] + '</span> <em><b>' + bookings[i][1].safe() + '</b> ' + bookings[i][2].safe() + '</em> <i>' + bookings[i][3].safe() + '</i></li>'; 
        
        };

        $bookings.each(function () {
            var $bookings = $(this), pos = 5;

            $bookings.empty();
            for (var i = 0; i < pos; i++) {
                var $item = $(bookingItemHTML(i)).prependTo($bookings);

                var $span = $item.find('span');
                $span.css({ paddingTop: (($item.height() - $span.height()) / 2) + 'px' });

                var $em = $item.find('em');
                $em.css({ paddingTop: (($item.height() - $em.height()) / 2) + 'px' });
            }

            $bookings.height($bookings.height() - 1);

            var showItem = function () {

                var $item = $(bookingItemHTML(pos)).addClass('showing').prependTo($bookings);

                var $span = $item.find('span');
                $span.css({ paddingTop: (($item.height() - $span.height()) / 2) + 'px' });

                var $em = $item.find('em');
                $em.css({ paddingTop: (($item.height() - $em.height()) / 2) + 'px' });

                var h = -$item.outerHeight();

                ///var listH = -7;
                //$bookings.children('li').not('li:last').each(function() { listH += $(this).outerHeight(); });
                //$bookings.animate({height: listH + 'px'}, 1000);

                $item.css({ marginBottom: h + 'px' }).animate({ marginBottom: '-1px' }, 1000, function () {
                    $bookings.children().last().remove();
                    $item.animate({ backgroundColor: '#f9f9f9' }, 250, function () { $(this).animate({ backgroundColor: '#fff' }, 750); });
                });
                $item.removeClass('showing');

                pos++;
                if (pos >= bookings.length)
                    pos = 0;
            };

            setInterval(showItem, 5000);
        });
    }



    if (testimonials && testimonials.length)
        $('ul.testimonials').each(function () {
            var $testimonials = $(this), pos = 3, screenPos = 0;

            $testimonials.empty();

            for (var i = 0; i < pos; i++)
                $testimonials.append('<li><cite>' + testimonials[i]['cite'].safe() + '</cite> - ' + testimonials[i]['author'].safe() + '</li>');

            var showItem = function () {
                $testimonials.children().eq(screenPos).html('<cite>' + testimonials[pos]['cite'].safe() + '</cite> - ' + testimonials[pos]['author'].safe()).animate({ color: '#555' }, 1000);

                pos++;
                pos %= testimonials.length;

                screenPos++;
                screenPos %= 3;
            };

            setInterval(function () {
                $testimonials.children().eq(screenPos).animate({ color: '#fff' }, 1000, function () { showItem(); });
            }, 7000);
        });

});

