var content_types = new Array();
content_types['articles'] = ['tips','recipes'];
content_types['tips'] =     ['articles','recipes'];
content_types['recipes'] =  ['articles','tips'];

/*
 * Narrow result to a specific types
 */
function narrowResults(appear_name) {
    fade_names = content_types[appear_name];
    for ( var i=0, len=fade_names.length; i<len; ++i ){
        if ( document.getElementById( fade_names[i] + '-container' ) != null ) {
            $( '#' + fade_names[i] + '-container').fadeOut(400);
        }

        var narrow_cancel = document.getElementById( fade_names[i] + '-narrow-cancel' );
        if ( narrow_cancel != null && narrow_cancel.style.display != 'none' ) {
            $( '#' + fade_names[i] + '-narrow-cancel').fadeOut(400);
        }

        $('#' + fade_names[i] + '-narrow').css( {fontWeight: 'inherit' });
    }
    
    narrowLinks(appear_name);
}

function narrowLinks( appear_name ) {
    if ( document.getElementById( appear_name + '-container' ).style.display == 'none' ) {
        $( '#' + appear_name + '-container' ).fadeIn(400);
    }

    narrow_cancel = document.getElementById( appear_name + '-narrow-cancel' );
    if ( narrow_cancel.style.display == 'none' ) {
        $( '#' + appear_name + '-narrow-cancel' ).fadeIn(400);
    }

    $( '#' + appear_name + '-narrow').css( {fontWeight: 'bold' });

    // Rewrite all pagination links to include narrow_by
    var links = $('#' + appear_name + '-container table #search-pagination a');
    for ( var i=0, len=links.length; i<len; ++i ) {
        links[i].href=links[i].href + '&narrow_by=' + appear_name;
    }
}

/*
 * Expand results to include everything
 */
function expandResults( narrowed_result ) {
    appear_names = content_types[narrowed_result];
    for ( var i=appear_names.length, len=0; i>=len; --i ){
        if ( document.getElementById( appear_names[i] + '-container' ) != null ) {
            $( '#' + appear_names[i] + '-container').fadeIn(400);
        }                
    }

    if ( document.getElementById( narrowed_result + '-narrow-cancel' ).style.display != 'none' ) {
        $( '#' + narrowed_result + '-narrow-cancel').fadeOut(400);
    }

    $('#' + narrowed_result + '-narrow').css( {fontWeight: 'inherit' });

    // Rewrite all pagination links to remove narrow_by
    var links = $('#' + narrowed_result + '-container table #search-pagination a');
    for ( var i=0, len=links.length; i<len; ++i ) {
        links[i].href=links[i].href.replace( '&narrow_by=' + narrowed_result, '');
    }
}  