(function ($) {
  var bp_data = {
    'rotating' : {
      'home-image-1' : {
    		'index' : '1',
    		'large-image' : 'images/home_rotate1.jpg',
    		'thumb-on' : 'images/home_thumb1_on.jpg',
    		'thumb' : 'images/home_thumb1.jpg',
    		'link' : 'college-prep-for-learning-differences',
    		'alt' : 'Structure'
      },
      'home-image-2' : {
    		'index' : '2',
    		'large-image' : 'images/home_rotate2.jpg',
    		'thumb-on' : 'images/home_thumb2_on.jpg',
    		'thumb' : 'images/home_thumb2.jpg',
    		'link' : 'student-academic-organizational-support',
    		'alt' : 'Support'
      },
      'home-image-3' : {
    		'index' : '3',
    		'large-image' : 'images/home_rotate3.jpg',
    		'thumb-on' : 'images/home_thumb3_on.jpg',
    		'thumb' : 'images/home_thumb3.jpg',
    		'link' : 'alumni',
    		'alt' : 'Success'
      }
    }
  };
  
  
  var $$;
  $$ = $.fn.bigpicture = function ($options) {
    this.each(function () {
      $('#big-picture-list ul li').each(function () {
        var opts = bp_data['rotating'][$(this).attr('id')]
        $(this).find('a').bind("click", function () {
          if ($(this).parent().hasClass('active')) {
            return false;
          }
          $.bigpicture.activate($(this).parent());
          return false;
        });
        $(this).bind("mouseenter", function () {
          $(this).find('img').attr('src', opts['thumb-on']);
        });
        $(this).bind("mouseleave", function () {
          if (!$(this).hasClass('active')) {
            $(this).find('img').attr('src', opts['thumb']);
          }
        });
      });
    });
    // $.bigpicture.activate($('.bp-nav :first-child'))
    return true;
  };

  $.extend({
    bigpicture: {
      current_i: '',
      current: '',
      scroll_pos: 0,
      activate: function (_src) {
              
        var new_i = $(_src).attr('id');
        this.current_i = new_i;
        var opts = bp_data['rotating'][new_i];

        // swap the image and link
        $('#big-picture-link').fadeOut(500, function () {
          $('#big-picture-link').find('img').load(function () {
            $('#big-picture-link').find('a').attr({
              'href': opts['link']
            });
            $('#big-picture-link').fadeIn(1500);
          }).error(function () {
            // console.log('ERROR')
          }).attr({
            'src': opts['large-image']
          });
        });

        // deactivate siblings
        $(_src).siblings('.active').each(function (i, item) {
          $(item).find('img').attr('src', bp_data['rotating'][$(item).attr('id')]['thumb']);
          $(item).removeClass('active');
        });
        // activate selected
        $(_src).addClass('active');
        $(_src).find('img').attr('src', opts['thumb-on']);

      }  
  }
  });

})(jQuery);

