/**
 * NetDirector Image Rotator
 * This is a proxy designed to allow other image rotators to be used easily.
 *
 * This version uses the jquery.cycle rotator
 */

netdirector.imageRotator = {
	settings: {},

	add: function (settings) {
		this.settings['ir_'+ settings.id] = settings;
	},

	onReady: function() {
		var self = this;
        var first = true;

		$('.imageRotator').each(function(index, entry) {
			var id = $(entry).attr('id');
			var settingsKey = id.replace('imageRotator_', '');
			var config = self.settings['ir_'+ settingsKey];

			$('#'+ id +' .rotator img')
				.css('width', config.width +'px')
				.css('height', config.height +'px');

			$('#'+ id +' .rotator')
				.css('width', config.width +'px')
				.css('height', config.height +'px');
            if ( first ) {          
			    $('#'+ id +' .rotator').cycle(
                { 
                    fx:     'fade', 
                    speed:  3000,
                    timeout: 3000,
                    pager:  '#bannerControls'
                }
                );
                
                first = false;
            } else {
                $('#'+ id +' .rotator').cycle('fade', 2000);
            }
		});
	}
}

$().ready(function () {
	netdirector.imageRotator.onReady();
});

