if(top.location != self.location){
  top.location = self.location.href;
}

(function($){
  $.fn.preload = function(options){
    var settings = {};
    return this.each(function(){
        if(options){
          $.extend(settings,options);
        }
        $(this).each(function(ind){
            var i = new Image();
            i.src = $(this).attr('href');
          });
      });
  };
})(jQuery);

$(document).ready(function(){
    var total = 0, dim = 32; // 82;
    $('#preview a').each(function(el){
        var pos = el+1, col = (el === 0 ? '#f00' : '#009');
        total++;
        $('#preview').append('<p class="ff pb" style="color: ' + col + ';" title="' + $('#preview a:eq(' + el + ')').text() + '" >' + pos + '</p>');
      });
    if(total === 1){
      $('#preview p').hide();
    }
    dim += ($('.pb').height() + 14)*total;
    $('#preview').append('<div class="ff ppc" style="bottom: ' + dim + 'px;">1. ' + $('#preview a:eq(0)').text() + '</div>');
    $('#preview p').click(function(el){
        var pos = $(this).text() -1;
        $('#preview p').css('color','#009');
        $(this).css('color','#f00');
        $('#preview img').attr('src',$('#preview a:eq(' + pos + ')').attr('href'));
        var cap = $('#preview a:eq(' + pos + ')').text();
        if(/\S/.test(cap)){
          var curr = pos + 1;
          cap = curr + '. ' + cap;
          $('#preview div').text(cap).show();
        }else{
          $('#preview div').hide();
        }
      });
    $('#preview a').hide();
    if(!/\S/.test($('#preview a:eq(0)').text())){
      $('#preview div').hide();
    }
    $('#preview a:gt(0)').preload();
});

/* Local Variables: */
/* mode: c++ */
/* indent-tabs-mode: nil */
/* End: */

