/**
 * Adds JS behaviours to certain elements on the page
 * @author José Fernández Alameda
 * @date 2010-09-17
 */


/**
 * Global variable
 */
var ProductGallery = null;

;(function($) {
	
	/**
	 * Takes control of the product gallery. When clicking over a product view it should be displayed in big size on the
	 * product description
	 */
	ProductGallery = function() {
		this.init();
	};
	ProductGallery.prototype = {
		
		/**
		 * Element to listen to
		 */
		listenElement: null,
		
		/**
		 * Class constructor
		 */
		init: function() {
			this.listenElement = $(".more-views a");
			this.addObservers();
		},
		
		/**
		 * Adds the elements observers
		 */
		addObservers: function() {
			var _this = this;
			this.listenElement.click(function(data) {
				_this.actionImageClicked(data);
			});
		},
		
		//Action callbacks
		
		/**
		 * This function is triggered when a gallery image is clicked
		 * @param data Event data object
		 */
		actionImageClicked: function(data) {
			var target = $(data.target);
			if(!target.is("a"))
				target = target.parent();
			var imgUrl = target.attr("href");
			$(".product-image img").attr("src",imgUrl);
			data.preventDefault();
		}
	};
	
	
	//This event is triggered when the background system is loaded, so we add an observer to it to perform more actions
	//over the page
	$(document).bind("backgroundControl.loaded", function() {
	});
	
}($j));
