(function($){
  $.fn.fold = function(options) {
    var ie55 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 5.5") != -1);
    var ie6 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 6.0") != -1);
    
    if (ie55 || ie6) {this.remove(); return true;}
  
    options = options || {};
    
    var defaults = {
      directory: '.',         
      side: 'right',          
      turnImage: 'noble-corner.png',
      maxWidth: 160,
	  maxHeight: 240,
      starting_width: 80, 
      starting_height: 120,
      autoCurl: true
    };

    var options = $.extend(defaults, options);
    
    var turn_hideme = $('<div id="flipside-back">');
    var turn_wrapper = $('<div id="flipside-corner">');
    var turn_object = $('<div id="flipside-corner-wrapper">');
    var img = $('<img id="flipside-img" src="'+ (options.directory+'/'+options.turnImage) +'">');

    turn_object.css({
      width: options.starting_width, 
      height: options.starting_height
    });
  
  
    this.wrap(turn_wrapper).wrap(turn_object).after(img).wrap(turn_hideme);
    
    
    turn_wrapper = $('#flipside-corner');
    turn_object = $('#flipside-corner-wrapper');

    turn_wrapper.hover(
        function(){
          turn_object.stop().animate({
            width: options.maxWidth,
            height: options.maxHeight
          });
        },
        function(){
          turn_object.stop().animate({
            width: options.starting_width,
            height: options.starting_height
          });
        }
      );
  };
})(jQuery);
