<script type="text/javascript">
    $(document).ready(function() {
        $(".toggler").click(function() {
            var image = $(this);
            var currentRow = image.parents("tr");
            if(image.hasClass("closed")) {

            	if($(currentRow).attr("rowExpanded") == "Y"){
            		return false;
				}

				$(currentRow).attr("rowExpanded", "Y");
            	var detailsURL = image.attr("href");
                showDetails(currentRow, image, detailsURL);
            } else {
                collapseDetails(currentRow, image);
            }
            return false;
        });
    });

    function showDetails(currentRow,image,detailsURL) {
        $.ajax({
            url: detailsURL,
            dataType: 'json',
            type: 'GET',
            success: function(data) {
                var metrics =data.performance_metrics;
                $(currentRow).attr("count", metrics.length);
                var innerHTML = new Array();
                for (i=0;i<metrics.length;i++) {
                    innerHTML.push("<tr class='details'>");
                    innerHTML.push("<td>&nbsp;</td>");
                    innerHTML.push("<td>");
                    innerHTML.push(metrics[i].metric.Measurement_Indicator);
                    innerHTML.push("</td>");
                    innerHTML.push("<td>");
                    innerHTML.push(metrics[i].metric.Baseline);
                    innerHTML.push("</td>");
                    innerHTML.push("<td>");
                    innerHTML.push(metrics[i].metric.Fiscal_Year);
                    innerHTML.push("</td>");
                    innerHTML.push("<td>");
                    innerHTML.push(metrics[i].metric.Target);
                    innerHTML.push("</td>");
                    innerHTML.push("<td>");
                    innerHTML.push(metrics[i].metric.Result);
                    innerHTML.push("</td>");
                    innerHTML.push("<td>");
                    innerHTML.push(metrics[i].metric.Rating_Image);
                    innerHTML.push("</td>");
                    innerHTML.push("</tr>");
                }
                currentRow.after(innerHTML.join(''));
                $(image).removeClass("closed").addClass("expanded");
            }
        });
    }

    function collapseDetails(currentRow,image) {
    	$(currentRow).attr("rowExpanded", "N");
        var rowsToDelete = $(currentRow).attr("count");

        for(i = 0 ; i < rowsToDelete; i++) {
            $(currentRow).next().remove();
            //$(currentRow).next().hide();
        }
        $(currentRow).removeAttr("count");
        $(image).removeClass("expanded").addClass("closed");
    }
</script>
<?php
// $Id: views-view.tpl.php,v 1.12.2.3 2010/03/25 20:25:23 merlinofchaos Exp $
/**
 * @file views-view.tpl.php
 * Main view template
 *
 * Variables available:
 * - $classes_array: An array of classes determined in
 *   template_preprocess_views_view(). Default classes are:
 *     .view
 *     .view-[css_name]
 *     .view-id-[view_name]
 *     .view-display-id-[display_name]
 *     .view-dom-id-[dom_id]
 * - $classes: A string version of $classes_array for use in the class attribute
 * - $css_name: A css-safe version of the view name.
 * - $css_class: The user-specified classes names, if any
 * - $header: The view header
 * - $footer: The view footer
 * - $rows: The results of the view query, if any
 * - $empty: The empty text to display if the view is empty
 * - $pager: The pager next/prev links to display, if any
 * - $exposed: Exposed widget form/info to display
 * - $feed_icon: Feed icon to display, if any
 * - $more: A link to view more, if any
 * - $admin_links: A rendered list of administrative links
 * - $admin_links_raw: A list of administrative links suitable for theme('links')
 *
 * @ingroup views_templates
 */
?>
<div class="<?php print $classes; ?>">
  <?php if ($admin_links): ?>
    <div class="views-admin-links views-hide">
      <?php print $admin_links; ?>
    </div>
  <?php endif; ?>

<div class="pager-wrapper clear-block">

  <?php if ($pager): ?>
    <?php print $pager; ?>
  <?php endif; ?>

  <?php if ($exposed): ?>
    <div class="view-filters">
      <?php print $exposed; ?>
    </div>
  <?php endif; ?>
</div>

  <?php if ($header): ?>
    <div class="view-header">
      <?php print $header; ?>
    </div>
  <?php endif; ?>

  <?php if ($attachment_before): ?>
    <div class="attachment attachment-before">
      <?php print $attachment_before; ?>
    </div>
  <?php endif; ?>

  <?php if ($rows): ?>
    <div class="view-content">
      <?php print $rows; ?>
    </div>
  <?php elseif ($empty): ?>
    <div class="view-empty">
      <?php print $empty; ?>
    </div>
  <?php endif; ?>

  <?php if ($attachment_after): ?>
    <div class="attachment attachment-after">
      <?php print $attachment_after; ?>
    </div>
  <?php endif; ?>

  <?php if ($more): ?>
    <?php print $more; ?>
  <?php endif; ?>

  <?php if ($footer): ?>
    <div class="view-footer">
      <?php print $footer; ?>
    </div>
  <?php endif; ?>

  <?php if ($feed_icon): ?>
    <div class="feed-icon">
      <?php print $feed_icon; ?>
    </div>
  <?php endif; ?>

</div> <?php /* class view */ ?>
