/*
Concession JS pour Moto85
Copyright(c) 2009, Skalpel.

Author : Hervé Weltzer

Note :
	-
ToDo :
	-
*/
SKjs.DetailBike = new Class ({
	Implements: [Events, Options],
	options: {
		bigPicture:		'bigPicture',
		thumbsList:     'thumbs'
	},

	/*
	Property :
		Initialisation de la Class
	*/
	initialize: function(options) {
		this.setOptions(options);

		this.dom = {};

		this.initDom();
		this.initEvents();
	},

    /*
    Property :
        Initialisation du dom
     */
	initDom: function() {
		this.dom.bigPicture		= $(this.options.bigPicture);
		this.dom.thumbsList     = $(this.options.thumbsList);

        if (this.dom.thumbsList !== null) {
            this.dom.thumbs         = this.dom.thumbsList.getElements('li img');
        } else {
            this.dom.thumbs         = null;
        }
	},

    /*
    Property :
        Initialisation des evenements
     */
	initEvents: function() {
        if (this.dom.thumbs !== null) {
            this.dom.thumbs.each(function (image) {
                image.addEvent('click', this.changeBigPicture.bind(this, image.getProperty('src')));
            }, this);
        }
	},

    /*
    Property :
        Mise a jour de la grande image
     */
    changeBigPicture: function(src) {

        // Change the big picture source
        var newsrc  = src.replace('front/', '');
        
		this.dom.bigPicture.set('src', newsrc);

        // Changes the thumb selected
        if (this.dom.thumbs !== null) {
            this.dom.thumbs.each(function (image) {
                if (image.getProperty('src') === src) {
                    image.getParent().addClass('selected');
                } else {
                    image.getParent().removeClass('selected');
                }
            }, this);
        }
    }
});
