/*************************************************************

	Class:    	rdFader 
	Author:   	RossCo-Designs
	Website:    #
	Version:  	1.0.1
	Date:     	28/09/2010 21:10
	Built For:  Mootools 1.3
	Notes : 	The use of this code is under license and under conditions defined by Rossco-Designs.com.  
				The purchaser, or licensee, is given the right to use the software under certain conditions,
				but restricted from other uses, such as modification, further distribution, or reverse engineering.
				This code is Proprietary to RossCo-Designs.com.  
				Under no circumstances is this script allowed to be used without prior agreement with Rossco-Designs.com.
				
			


*************************************************************/
 
var rdFader = new Class({

    //implements
    Implements: [Options, Events],

    //options
    options: {
        fadeHolder: 'imgFader',
        imagePath: 'assets/components/gallery/files/',
        imageHolderClass: 'imgHolder',
        feedUrl: '[[~563]]'

    },

    //initialization
    initialize: function(options, getFeed) {
        //set options
        this.setOptions(options);
        this.fadeHolder = this.options.fadeHolder;
        this.imagePath = this.options.imagePath;
        this.imageHolderClass = this.options.imageHolderClass;
        this.feedUrl = this.options.feedUrl;
        var fadeHolder = this.fadeHolder;
        var path = this.imagePath;

        this.getSlider();
    },

    //a method that does whatever you want
    addImages: function(imgs) {
        var self = this;
        imgs.each(function(img, i) {
            var el = new Element('li', {
                'class': self.imageHolderClass + ' loading'
            });


            //alert(image.image);
            var loadSkin = new Asset.images('assets/resource/images/gallerymask.png', {
                onComplete: function() {
                    var myImages = new Asset.images(img.src, {
                        onComplete: function() {
                            el.removeClass('loading');
                            (function() {
                                images.morph({
                                    'opacity': 1
                                })
                            }).delay(300);
                        }
                    });

                }
            });

            el.inject(self.fadeHolder);

        });
    },

    getSlider: function updateLines() {
        var self = this;
        var showDuration = 5000;
        var container = $('imgFader');
        var lines = $$('.imgHolder');
        var currentIndex = 0;
        var interval;
        lines.each(function(e, i) {
            if (i > 0) {
                e.setStyles({
                    'opacity': 0,
                    'display': 'none'
                });
            }
        });

        var show = function() {
            lines[currentIndex].set('tween', {
                duration: '3000'
            }).fade('out');
            lines[currentIndex = currentIndex < lines.length - 1 ? currentIndex + 1 : 0].set('tween', {
                duration: '2000'
            }).fade('in').setStyle('display', 'block');
        };
        interval = show.periodical(showDuration);

    }

});
