Ext.namespace('mm.toppanel.slideshow.base');
mm.toppanel.slideshow.base.construct = function(autoconstruct){
	this.el = $('.mm-toppanel-slideshow-base');
	this.pos = 1;
	this.slide = function(){
		this.el.find('.imagebuttons .button').removeClass('button_focus');
		if (this.pos >= (this.image_num))
		{
			this.pos = 0;
		}

		if (this.pos == 0)
		{
			this.imagebox.fadeOut(500, function(){
				this.imagebox.css({
					top: 0,
					left: 0
				});
				this.imagebox.fadeIn(1000, function(){
					var img = $(this.el.find('.imagebuttons .button')[0]);
					img.addClass('button_focus');
				}.createDelegate(this));
			}.createDelegate(this));
		}
		else
		{
			var conf = 
			{
				top: 0,
				left: (this.image_size * this.pos) * -1
			};
			this.el.find('.imagebox').animate(conf, 1000, function() {
				var img = $(this.el.find('.imagebuttons .button')[this.pos-1]);
				img.addClass('button_focus');
			  }.createDelegate(this));
		}
		
		this.pos++;
	};
	this.constructor = function()
	{
		this.imagebox = this.el.find('.imagebox');
		this.img = this.el.find('.imagebox .image');
		this.image_num = this.img.length;
		this.image_size = this.img.width();
		var config = {
			width: this.image_size * this.image_num 
		};
		this.imagebox.css(config);
		
		this.slidetask = {
			    run: this.slide.createDelegate(this),
			    interval: 6000,
			    stop: function()
			    {
			    	Ext.TaskMgr.stop(this);
			    },
			    start: function()
			    {
			    	Ext.TaskMgr.start(this);
			    }
			};

		this.el.find('.imagebuttons .button').bind('click', function(event){
			this.slidetask.stop();
			var curr = event.currentTarget;
			var buttons = this.el.find('.imagebuttons .button');
			var length = buttons.length;
			for(var i=0; i<length; i++)
			{
				if (curr == buttons[i])
				{
					this.pos = i;
					this.slide();
					break;
				}
			}
		}.createDelegate(this))
		
		var img = $(this.el.find('.imagebuttons .button')[0]);
		img.addClass('button_focus');
		var task = new Ext.util.DelayedTask(function(){
			this.slidetask.start();
		}.createDelegate(this))
		task.delay(6000);
		
		
	};
	if (typeof autoconstruct != 'undefined' && autoconstruct)
	{
		this.constructor();
	}
};
mm.toppanel.slideshow.base.construct.prototype.domname = 'mm-toppanel-slideshow-base';
mm.toppanel.slideshow.base.construct.prototype.namespace = mm.toppanel.slideshow.base;

mm.toppanel.slideshow.base.obj = new mm.toppanel.slideshow.base.construct(true);
