﻿//Author: KoolKabin
//Email: koolkabin@live.com
//GPL: Can be used by any one with the above lines included
//Release Date: 2011 March 26

function KoolFader(arrOptions) {
    var strSelector = arrOptions.selector;
    var width = arrOptions.width || $(strSelector).parent().css('width') || 100;
    var height = arrOptions.height || $(strSelector).parent().css('height') || 100;
    var speed = arrOptions.speed || 3000;
    //Set the CSS Attribs:
    $(strSelector).css('display', 'none').css('max-width', width).css('max-height', height).css('overflow', 'hidden').css('position', 'absolute').css('left', 0).css('top', 0).parent().css('position', 'relative').css('height', height);
    var myObj = {
        numImages: $(strSelector).size(),
        currentImage: (this.numImages > 0) ? 1 : 0,
        changeImage: function() {
            $(strSelector + ':nth-child(' + this.currentImage + ')').fadeOut(this.speed);
            this.currentImage = (this.currentImage >= this.numImages) ? 1 : this.currentImage + 1;
            $(strSelector + ':nth-child(' + this.currentImage + ')').fadeIn(this.speed);
        }
    }
    $(strSelector + ':first').show();
    return myObj;
}
