/**
 * PST.cmp.RandomPic
 * @desc Shows a random picture
 * @author Brandon Grady
 */
Ext.ns('PST.cmp');

PST.cmp.RandomPic = Ext.extend(Ext.Panel, {
    constructor: function(config){
        // Defaults
        Ext.applyIf(config, {
            title: "Random Picture",
			height: 300,
			id: 'randompic',
			pictureUrl: 'ctrl.php?c=pic',
			refreshInterval: 5000
        });
        
        PST.cmp.RandomPic.superclass.constructor.call(this, config);
    },
    
    initComponent: function() {
        // Call the superclass.
        PST.cmp.RandomPic.superclass.initComponent.call(this);
    },
    
    afterRender: function(){
		var task = {
			run: this.updateImage,
			interval: this.refreshInterval,
			scope: this
		}
		
		var runner = new Ext.util.TaskRunner();
		runner.start(task);
		
        // this.updateImage();
        
        // Call the superclass component
        PST.cmp.RandomPic.superclass.afterRender.call(this);
    },
    
    updateImage: function(){
        this.load({
            url: this.pictureUrl,
            params: {
                width: this.width,
				height: this.height
            }
        });
    }
});

