/**
 * Slideshow
 * @requires jQuery v1.3
 *
 *
 * Usage: $('div').slideshow(); 
 *
 *
 * Copyright (c) 2009 Dirk Ginader (http://ginader.de)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 * Version: 1.0
 * 
 * History:
 * * 1.0 initial release
 */


(function($) {
    var debugMode = true;
    $.fn.extend({
        bgslide: function(config) {
            var o = this;

            o.options = $.extend({
				startWithImageNo:1
            }, config);

            o.current = o.options.startWithImageNo-1;
            
            o.preload = function(){
                var loading = $('<img />').attr('src', o.options.basePath+o.options.images[o.current] );
            };
            o.next = function(el){
                var img = 'url('+o.options.basePath+o.options.images[o.current]+')';
                var ok = el.css('backgroundImage',img);
                o.current++;
                if(o.current>=o.options.images.length){
                    o.current=0;
                }
                o.preload();
                o.wait();
            };
            o.wait = function(){            
                var el = $(this);
                o.timeout = window.setTimeout(function(){
                    o.next(el);
                },o.options.showForSeconds*1000);
            };

            return o.each(function() {
                o.preload();
                o.wait();
            });
        }
    });
    // private Methods
    function debug(msg){
        if(debugMode && window.console && window.console.log){
            window.console.log(msg);
        }
    }
})(jQuery);


/*
// init
window.onload = function(){
    $('#nav .page').bgslide({
        showForSeconds:3,
        startWithImageNo:2,
        //basePath:'img/bg/',
        basePath:'http://web-output.com/download/',
        images:[
            'branding-1.jpg',
            'branding-2.jpg',
            'branding-3.jpg',
            'branding-4.jpg',
            'branding-5.jpg'
        ]
    });
};
*/