/* Author(s): 

John Skelton
Christopher Eaton

*/


// Toggle Accordian for right-rail content
$(document).ready(function () {
    $('.accordion').hide();
    $('.accordion-toggle').toggle(
            function () {
                $(this).next('.accordion').slideDown();
                $(this).addClass('opened');
            },
                function () {
                    $(this).next('.accordion').slideUp();
                    $(this).removeClass('opened');
                }
            ); // end toggle
    AttachNumberClimbers();
});     // end ready


// Toggle Search fields between location and route for Dealer Search Page
$(function () {
    $('#dealer-search-select-toggle').change(function () {
        if ($(this).val() == "location") {
            $('.toggle-search-route').hide();
            $('.toggle-search-location').show();
            $('input.search-box-route-start').val('');
            $('input.search-box-route-end').val('');
        } else {
            $('.toggle-search-route').show();
            $('.toggle-search-location').hide();
            $('input.search-box-location').val('');
        }
    });
});

/**********************************************
*** Number Climber (Scroller For HorsePower)
***********************************************/

var NumberClimbers = null;

function AttachNumberClimbers() {
    NumberClimbers = new Array();
    $('.info-specs-horsepower .numbers, .info-specs-gvw .numbers, .numberclimber').each(function (index) {
        //fix the size of the span
        // $(this).css('width', $(this).innerWidth());
        //$(this).css('display', 'inline-block');
        //$(this).css('text-align', 'right');
        //create number climbing interval and array entry
        var hp = parseInt($(this).text().replace(",", ""));
        var intervalMS = 30;
        var increment = Math.round(hp / 37);
        NumberClimbers[index] = [$(this), hp, 0, increment, intervalMS, null];
        $(this).text("0");
        setTimeout("NumberClimbers[" + index + "][5] = setInterval('NumberClimb(" + index + ");', " + intervalMS + ");", 500);
    });
}

function NumberClimb(index) {
    NumberClimbers[index][2] += NumberClimbers[index][3];
    if (NumberClimbers[index][2] > NumberClimbers[index][1]) {
        //done
        NumberClimbers[index][2] = NumberClimbers[index][1];
        clearInterval(NumberClimbers[index][5]);
        //$(NumberClimbers[index][0]).css('text-align', 'center');
    }
    $(NumberClimbers[index][0]).text(addCommas(NumberClimbers[index][2]));
}

function addCommas(nStr) {
    nStr += '';
    x = nStr.split('.');
    x1 = x[0];
    x2 = x.length > 1 ? '.' + x[1] : '';
    var rgx = /(\d+)(\d{3})/;
    while (rgx.test(x1)) {
        x1 = x1.replace(rgx, '$1' + ',' + '$2');
    }
    return x1 + x2;
}



/* axle hotspots (drh)*/
function hideHotSpotTip() {
    var tipClass = '.' + $(this)[0].className.split(' ')[0] + '.tip';
    $(tipClass).fadeOut(200);
}
function showHotSpotTip() {
    $('.hot-spots .tip').css("display", "none");
    var tipClass = '.' + $(this)[0].className.split(' ')[0] + '.tip';
    $(tipClass).fadeIn(260);
}
$(document).ready(function () {

    $(".hot-spots .bullet").bind('mouseover', showHotSpotTip);
    $(".hot-spots .btn").bind('mouseover', showHotSpotTip);
    $(".hot-spots .bullet").bind('mouseout', hideHotSpotTip);
    $(".hot-spots .btn").bind('mouseout', hideHotSpotTip);

});
/* end: axle hotspots */








