//
// Created by ThisSideUp Software Inc.
//
// Copyright 2010 ThisSideUp Software Inc. http://www.thissideupsoftware.com
// All Rights Reserved. Permission to use, copy, modify, and distribute this
// software is hereby granted provided that the full text of this copyright
// notice appears in all copies.
//
// THIS SOFTWARE AND DOCUMENTATION IS PROVIDED "AS IS," AND COPYRIGHT HOLDERS
// MAKE NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO, WARRANTIES OF MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR
// PURPOSE OR THAT THE USE OF THE SOFTWARE OR DOCUMENTATION WILL NOT INFRINGE
// ANY THIRD PARTY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS.
//
// COPYRIGHT HOLDERS WILL NOT BE LIABLE FOR ANY DIRECT, INDIRECT, SPECIAL OR
// CONSEQUENTIAL DAMAGES ARISING OUT OF ANY USE OF THE SOFTWARE OR
// DOCUMENTATION.
//

var loadJumpRopeImg = function() {
   $(this).unbind("load", loadJumpRopeImg);
   $(this).unbind("error", errJumpRopeImg);
   $(this).fadeIn(300);
}

var errJumpRopeImg = function() {
   $(this).unbind("load", loadJumpRopeImg);
   $(this).unbind("error", errJumpRopeImg);
   if ($(this).complete) {
      $(this).fadeIn(300);
   }
}

function replaceImage(elem) {
   var found = false;
   var parentElem = elem.parent();
   while (!found) {
      if (parentElem.attr('class') == 'parent-div') found = true
      else parentElem = parentElem.parent();
   }
   var imgElem = parentElem.find('img').first();
   var imgSrc = elem.attr('href');
   if (imgSrc == imgElem.attr('src')) return;
   imgElem.fadeOut(300, function() {
      $(this)
         .load(loadJumpRopeImg)
         .error(errJumpRopeImg)
         .attr("src", imgSrc);
   });
}

