function ratingsBar(rating,barLength) {
    if (barLength == '100') { increment = 20; }
    if (barLength == '80') { increment = 16; }
    if (barLength == '50') { increment = 10; }
    if (rating == '--') {
        document.write('<div class="no-rating">n/a</div>');
    } else {
        var barValue = rating * increment;
        barValue = parseInt(barValue);
        document.write('<div class="ratings-container-' + barLength + '"><div class="ratings-bar" style="width: ' + barValue + 'px;"></div><div class="ratings-value">' + rating + '</div></div>');
    }
}

jQuery(document).ready(function() {

    jQuery('div.content-tab').hide();
    jQuery('#overall-tab').show();
    jQuery('ul#tabNavigation').filter(':first').addClass("nav-on");

    jQuery('ul#tabNavigation a').click(function () {
        jQuery('div.content-tab').hide().filter(this.hash).show();
        jQuery('ul#tabNavigation li').removeClass("nav-on");
        jQuery(this).parent().addClass('nav-on');
        return false;
    }).filter(':first').click();

    $("#sortTable").tablesorter({ 
        // sort on the first column and third column, order asc 
        sortList: [[0,0]]
    });
    $('area').cluetip({splitTitle: '|', titleAttribute:"rel",width:120});
    $('img[usemap]').maphilight({
        fill: true,
        fillColor: 'ffffff',
        fillOpacity: 0.5,
        stroke: true,
        strokeColor: '91512D',
        strokeOpacity: 1,
        strokeWidth: 1,
        fade: true,
        alwaysOn: false
    });
    $.fn.maphilight.defaults = {
        fill: true,
        fillColor: 'ffffff',
        fillOpacity: 0.5,
        stroke: true,
        strokeColor: '91512D',
        strokeOpacity: 1,
        strokeWidth: 1,
        fade: true,
        alwaysOn: false
    };
    $('div.morenabes').hide();
    $('div.morecuisines').hide();
    $('#more_nabes').click(function(){
        $('div.morenabes').toggle('fast');
        $('#more_nabes').text(($('#more_nabes').text() == 'more') ? 'less' : 'more');
    });
    $('#more_cuisines').click(function(){
        $('div.morecuisines').toggle('fast');
        $('#more_cuisines').text(($('#more_cuisines').text() == 'more') ? 'less' : 'more');
    });
    $("#tabs").tabs();
    $("#tabs").tabs( 'select' ,0);

    var user = getCommenterName();
    if (user.length>0) {
        $('#registerpromo').hide();
    }
    
    // Neighborhood List
    $('#nabe_list').append('<ul class="more" style="display: none"></ul><p class="toggle"><a style="outline: none;" href="#">more...</a></p>');
    $('#nabe_list ul li:gt(4)').appendTo("#nabe_list ul.more");
    $('#nabe_list .toggle a').toggle(
      function () {
          $("#nabe_list ul.more").slideDown();
          $(this).text("less...")
          return false;
      },
      function () {
          $("#nabe_list ul.more").slideUp();
          $(this).text("more...")
          return false;
      }
    );
    
    // Cuisines
    $('#cuisines_list').append('<ul class="more" style="display: none"></ul><p class="toggle"><a style="outline: none;" href="#">more...</a></p>');
    $('#cuisines_list ul li:gt(4)').appendTo("#cuisines_list ul.more");
    $('#cuisines_list .toggle a').toggle(
      function () {
          $("#cuisines_list ul.more").slideDown();
          $(this).text("less...")
          return false;
      },
      function () {
          $("#cuisines_list ul.more").slideUp();
          $(this).text("more...")
          return false;
      }
    );
    
    // Top Tens
    $('.top_ten ul').hide();
    $('.top_ten > strong').each(function () {
        $(this).replaceWith('<a style="cursor: pointer;">' + $(this).text() + '</a>');
    });
    $('.top_ten > a').click(function () {
        if ($(this).siblings('ul:visible').length) {
            $(this).siblings('ul').slideUp();
        } else {
            $('.top_ten ul').slideUp();
            $(this).siblings('ul').slideDown();
        };
        return false;
    });
    
});
