var infoList = new Array();
function infoDetail (ele,ind) {
    this.ele = ele;
    this.ind = ind;
    this.grower = null;
    this.shrinker = null;
    this.open = false;
    var thisObj = this;
    this.grow = function() {
        thisObj.ele.style.display = 'block';
    }
    this.shrink = function() {
        thisObj.ele.style.display = 'none';
    }
}
function toggleShow(ind) {
    var showEle = document.getElementById('view_link_' + ind);
    var hideEle = document.getElementById('hide_link_' + ind);
    if (infoList[ind].open) {
        showEle.style.display = 'inline';
        hideEle.style.display = 'none';
        infoList[ind].open = false;
        checkAllState();
    } else {
        showEle.style.display = 'none';
        hideEle.style.display = 'inline';
        infoList[ind].open = true;
        checkAllState();
    }
}
function expandAll() {
    var showLayer = document.getElementById('show_all');
    var hideLayer = document.getElementById('hide_all');
    showLayer.style.display = 'none';
    hideLayer.style.display = 'block';
    for (var i=0; i<infoList.length; i++) {
        if (infoList[i]) {
            infoList[i].grow();
            if (!infoList[i].open) {
                toggleShow(i);
            }
        }
    }
}
function hideAll() {
    var showLayer = document.getElementById('show_all');
    var hideLayer = document.getElementById('hide_all');
    hideLayer.style.display = 'none';
    showLayer.style.display = 'block';
    for (var i=0; i<infoList.length; i++) {
        if (infoList[i]) {
            infoList[i].shrink();
            if (infoList[i].open) {
                toggleShow(i);
            }
        }
    }
}
function checkAllState() {
    var anyOpen = false;
    var anyClosed = false;
    for (var i=0; i<infoList.length; i++) {
        if (infoList[i]) {
            if (infoList[i].open) {
                anyOpen = true;
            }
            if (!infoList[i].open) {
                anyClosed = true;
            }
        }
    }
    if (anyOpen && anyClosed) {
        return;
    }
    if (anyOpen && !anyClosed) {
        // do Hide All
        var showLayer = document.getElementById('show_all');
        var hideLayer = document.getElementById('hide_all');
        showLayer.style.display = 'none';
        hideLayer.style.display = 'block';
    }
    if (anyClosed && !anyOpen) {
        //do View All
        var showLayer = document.getElementById('show_all');
        var hideLayer = document.getElementById('hide_all');
        hideLayer.style.display = 'none';
        showLayer.style.display = 'block';
    }
}

 function mySearchesHideExpandedInfo(expand_search) {

    var recommend_car_id = document.getElementById(expand_search); 
    if (recommend_car_id != null) {recommend_car_id.className = 'expand_info_off'}
}
 function mySearchesShowExpandedInfo(expand_search) {

    var recommend_car_id = document.getElementById(expand_search);
    if (recommend_car_id != null) {recommend_car_id.className = 'expand_info_over'}
}

