/*
 * CU xFader jQuery Plugin Version 1.0
 * (c) 2011 comunique GmbH & Co. KG: http://www.comunique.com
 *
 * $('div').cu_xFader({'fadetime' : 500,'waittime' : 4500});
 *
 */
 
(function( $ ){
    var methods = {
        init : function( opt ) { 
            return this.each(function(){
                var $this = $(this);
                if ($this.children().length == 1){return;}
                opt = $.extend({}, $.fn.cu_xFader.defaults, opt || {});
                $(this).data('cu_xFader', opt).find(":gt(0)").css({display: "none"});
                window.setInterval(function(){$(this).cu_xFader('fader',$this);}, opt.waittime);
            });
        },
        fader : function( cont ) { 
            return this.each(function(){
                var opt=cont.data('cu_xFader');
                var myobj=cont.find(":visible").fadeOut(opt.fadetime);
                ((myobj.next().length == 0)?(cont.find(":first")):(myobj.next())).fadeIn(opt.fadetime);
            });
        }
    };
    
    $.fn.cu_xFader = function( method ) {
        if ( methods[method] ) {
            return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ));
        } else if ( typeof method === 'object' || ! method ) {
            return methods.init.apply( this, arguments );
        } else {
            $.error( 'Method ' +  method + ' does not exist on jQuery.cu_xFader' );
        }    
    };
    $.fn.cu_xFader.defaults = {
        'fadetime' : 500,
        'waittime' : 4500
    }
    
})( jQuery );


