jQuery(document).ready(function() {
  Drupal.hoverTarget = new HoverTarget();
});


/**
 * hover targets could be any of a number of things. This attempts to find something plausable given the layout. It looks for 
 * -- an image slide show (rotator)	
 * -- a special div of the class product-detail-image
 */
HoverTarget = function(){
	this.init();
	var currentTarget = null;
}

HoverTarget.prototype = {
	/*
	 * initialize the targets if necessary
	 */
	init: function(){	 
        var allDetailImages = [];
        $('.product-detail-image').each(function(i, selected){
            allDetailImages[i] = $(selected);
        });
		if (allDetailImages.length > 0) {
			this.currentTarget = allDetailImages.shift();
			this.currentTarget.show();
		}
	},
	/*
	 * update the target display with the specified image 
	 */
	update: function(fid){
		if($.views_rotator){
			$.views_rotator.pause(null, fid);
			return;
		}	
		if($.innerfade){
			$.innerfade.pause(fid);
			return;
		}
		var nextTarget = $("#image-"+fid);
		if(nextTarget){		
			if(this.currentTarget)
				this.currentTarget.hide();
			this.currentTarget = nextTarget;
			this.currentTarget.show();
			return;
		}	    	
  	},
    /*
     * reset the target display, if applicable
     */
  	reset: function(fid){
	  	if ($.views_rotator) {
			$.views_rotator.resume();
			return;
		}
		if($.innerfade){
			$.innerfade.resume();
			return;
		}	
    }   
};