var CosMooFadeBN = new Class({
	Extends: CosMooFade,

	/*initialize: function(div_id, img_id)
	{
		this.element = $(div_id);
		this.img = img_id;
	},
	
	init: function(nomi, dir, time, random, speed, links, targetblank)
	{
		//prima fermo eventuali altri loop
		this.stop();
		
		this.arrFoto = nomi;
		this.dir = dir+"/";
		this.time = time;
		this.random = random;
		this.speed = speed;
		if(!this.speed)
			this.speed='long';
		this.links = links;
		this.targetblank = targetblank;
	},
	
	initDiv: function(divCnt, time, random, speed, targetblank)
	{
		//prima fermo eventuali altri loop
		this.stop();
		var nomi = new Array();
		$$("#"+divCnt+" img").each(function(el){
			nomi.push(el.get('src'));
		});
		
		var links = new Array();
		$$("#"+divCnt+" a").each(function(el){
			links.push(el.get('href'));
		});
		
		this.arrFoto = nomi;
		this.dir = '';
		this.time = time;
		this.random = random;
		this.speed = speed;
		if(!this.speed)
			this.speed='long';
		this.links = links;
		this.targetblank = targetblank;
	},*/
	
	FXstart: function(show, el){
                var tween = new Fx.Tween(el, {'duration': 800});
                if(show==1) return tween.start('left', 931, 0);
                else return tween.start('left', 0, 931);

                /*
                var obj = this;
                if(!this.fxFade1)
                {
                        var fxFade1 = new Fx.Tween(el,{'duration': 800});
                        this.fxFade1 = fxFade1;
                }
                if(!this.fxFade2)
                {
                        var fxFade2 = new Fx.Tween(el,{'duration': 1});
                        this.fxFade2 = fxFade2;
                }
                if(show==1)
                        return this.fxFade1.start('left', 931, 0);
                else
                        return this.fxFade2.start('left', 0, 931);*/
        },
	
	work: function()
	{
		var obj = this;
		var json = this.arrFoto;
		if (this.count >= json.length) this.count=0;
		
		
                var nome, nomeold;
                if ($(obj.immagine)!=null)
                {
                        nomeold = $(obj.immagine).get('nome');
                        //$(obj.img).dispose();
                }
                if(!obj.random)
                {
                        nome = json[obj.count];
                        obj.count++;
                }
                else
                        nome = obj.scegliRandom(json, nomeold);
                var img, imgbn;
                if ($type(nome)=='string')
                {
                    img = new Element('img',{'src': obj.dir+nome, 'id': obj.img, 'alt':'', 'border':0});
                    img.store('nome', nome);
                    imgbn = new Element('img',{'src': obj.dir+'bn_'+nome, 'id': 'bn_'+obj.img, 'alt':'', 'border':0});
                }
                else img = nome;


                obj.immagine = img;
                var cnt = new Element('div');
                cnt.setStyle('position', 'absolute');
                cnt.setStyle('left', 931);
                img.inject(cnt);

                imgbn.setStyles({'position':'absolute', 'top':0, 'left':0});
                imgbn.inject(cnt);
                cnt.inject(obj.element);
                this.FXstart(1, cnt).chain(function()
                {
                    if (obj.cnt) {obj.cnt.destroy(); }
                    obj.cnt = cnt;
                    var bnTween = new Fx.Tween(imgbn, {'duration':2000});
                    (function(){bnTween.start('opacity', 1, 0);}).delay(1000);
                });

	},

	/*
	start: function()
	{
		this.count = 0;
		var obj = this;
		var f = function(){obj.work();}
		var delay = 0;
		//se non ci sono foto nella cartella non parte nemmeno
		if(this.arrFoto.length==0)
		{
			return;
		}
		//se c'e una foto precaricata nel div ed e la stessa unica che c'e nella cartella delle foto non fa il fade
		else if($(this.img) && this.arrFoto.length==1 && $(this.img).get('src')==this.dir+this.arrFoto[0])
		{
			return;
		}
		
		// se non c'� un'immagine precaricata il fade parte subito altrimenti prima di partire aspetta un tempo this.time
		if(!$(this.img))
		{
			obj.work();
		}
		
		if (this.arrFoto.length>1)
		{
			this.preLoadImg();
			this.go = f.periodical(this.time);
		}
	},
	
	stop: function()
	{
		$clear(this.go);	
	},
	}*/

        scegliRandom: function(nomi, nome)
	{
		var nomenew;
		var loop = true;
		do
		{
			nomenew = nomi.getRandom();
			if ($type(nome)=='element') nome = nome.retrieve('nome');

			if ($type(nomenew)=='string')
			{
				if (nomenew != nome) loop = false;
			}
			else
			{
				if (nomenew.retrieve('nome') != nome) loop = false;
			}
		}while(loop);
		return nomenew;
	},

	preLoadImg: function()
	{
                return false;
		var obj = this;
		this.arrFoto.each(function(el, index){
                    obj.arrFoto[index][1] = new Element('img',{'src': obj.dir+'bn_'+el, 'id': 'bn_'+obj.img, 'nome':el, 'alt':'', 'border':0});
                    obj.arrFoto[index][0] = new Element('img',{'src': obj.dir+el, 'id': obj.img, 'nome':el, 'alt':'', 'border':0});
                    
		});
	}
});