bxb.nxe = function(){
	ignoreNext = false;
	  return{
		init: function(){
			this.reflexHeight = 40;
			//if(Ext.isIE){
			//	addIEReflex();
			//} else {
			//	addReflex();
			//}
			this.box = Ext.get('dash');
			this.els = this.box.select('div.channel', true);
			this.boxTL = this.box.getXY();
			//if(Ext.isIE){
//				addRoundedIECorners();
			//} else {
//				addRoundedCorners();
			//}
				
			this.box.on('click', this.handleBoxClick, this);
				
			this.controls = this.box.down('div.controls').show();
			this.controls.setXY([this.boxTL[0]+660, this.boxTL[1]+220], false);
			this.controls.on('click', this.handleControlClick, this);
			
			this.els.each(function(el, ar, idx){
				//this.setPos(el, idx, anim);
				el.addClassOnOver('over');
				//if(Ext.isIE){
				//	el.theImage = el.first().id;
				//	cvi_reflex.add(Ext.get(el.theImage).dom, {iwidth: this.calcPos(idx).width, iheight:this.calcPos(idx).iheight, height: this.reflexHeight, distance: 1, tilt: 'none'});
				//} else {
				//	cvi_reflex.add(el.first().dom, {height: this.reflexHeight, distance: 1, tilt: 'none'});
				//}
				el.show();
			}, this);

			this.doDisplay(false);
		},
		calcPos: function(idx){
		    this.boxTL = this.box.getXY();
		    this.sizes = {'0' : {'width': 300, 'height': 280, 'iheight': 240, 'x': this.boxTL[0],     'y': this.boxTL[1]},
				 		  '1' : {'width': 240, 'height': 232, 'iheight': 192, 'x': this.boxTL[0]+270, 'y': this.boxTL[1]+15},
				 		  '2' : {'width': 180, 'height': 169, 'iheight': 144, 'x': this.boxTL[0]+475, 'y': this.boxTL[1]+35},
				 		  '3' : {'width': 126, 'height': 115,  'iheight': 101,  'x': this.boxTL[0]+620, 'y': this.boxTL[1]+50}
			};
			return this.sizes[idx];
				
				
		},
		handleControlClick: function(ev,el){
		    if(el.alt){
			    this[el.alt]();
			}
		},
		handleBoxClick: function(ev, el){
			if(this.ignoreNext){
				return false;
			}
			var p =	Ext.get(el).up('div.channel');
			if(p){
				// get the idx of the clicked item, first one (main) is 0.
				var idx = this.els.indexOf(p);
				if(idx > 0){
					this.focusOn(idx);
				} else {
					//they have clicked on the main channel, go to it's linked article
					//window.location.href = 'viewarticle.php?id=' + p.dom.getAttribute('link');
				}
			}
		},
		focusOn: function(idx){			
			for(f=idx; f>0; f--){
				var first = this.els.first();
				this.els.removeElement(first, false);
				this.els.add(first);
			}
			this.doDisplay(true);
		},
		animOver: function(el, anim){
			el.child('div').show();
			if(anim == 0){
			    el.child('div.subheadline').show();
			}
			this.ignoreNext = false;
		},
		next: function(){
			// pop off the first el in the array and put it on the end.
			// animate the first one off the screen, then unanimate to the end of the list.
			if(this.ignoreNext){
				return false;
			}
			this.ignoreNext = true;
			//animate the first one off the page to the left
			var first = this.els.first();
			this.els.removeElement(first, false);
			this.doDisplay(true);
			this.els.add(first);
			this.setPos(first, 3, true);
		},
		previous: function(){
			if(this.ignoreNext){
				return false;
			}
			this.ignoreNext = true;
			var last = this.els.last();
			this.els.removeElement(last, false);
			this.els.elements.splice(0,0,last);
			this.doDisplay(true);
		},
		doDisplay: function(anim){
			this.els.each(function(el, ar, idx){
				this.setPos(el, idx, anim);
			}, this);
		},
		setPos: function(el, idx, anim){
			
		   // this.boxTL = this.box.getXY();
			var anim = (anim) ? {easing: 'easeOut', duration: .4} : false;
			var animL = (anim) ? {easing: 'easeOut', duration: .4, callback: function(el){this.animOver(el,idx)}, scope: this} : {duration:0, callback: function(el){this.animOver(el,idx)}, scope: this};

			el.child('div').hide();  // hide text while it resizes, looks much neater.
			el.child('div.subheadline').hide();
			el.syncFx().scale(this.calcPos(idx).width, this.calcPos(idx).height, anim).moveTo(this.calcPos(idx).x, this.calcPos(idx).y, animL).removeClass(['p1','p2','p3','p4']).addClass('p'+(idx+1));
			//if(Ext.isIE){
			//el.child('img').scale(this.calcPos(idx).width, this.calcPos(idx).height, anim);
			//el.first().scale(this.calcPos(idx).width, this.calcPos(idx).height, anim);
			
			//if(Ext.isIE){
			//	cvi_reflex.remove(Ext.get(el.theImage).dom);
			//}
			
			//if(!Ext.isIE){
				el.first().scale(this.calcPos(idx).width, this.calcPos(idx).height, anim);
			//} else {
			//	Ext.get(el.theImage).scale(this.calcPos(idx).width, this.calcPos(idx).height, anim);
				//alert(Ext.get(el.theImage).dom);
				//cvi_reflex.remove(Ext.get(el.theImage).dom);
				//cvi_reflex.modify(Ext.get(el.theImage).dom, {width: 10, title: 'right'});
				//el.first().setHeight('100%');
				//el.first().setWidth('100%');
			//}
			//el.first().setWidth(this.calcPos(idx).width, anim);
			//console.log('set '+idx+'height to '+this.calcPos(idx).height);
			//} else {
					//el.child('canvas').scale(this.calcPos(idx).width, this.calcPos(idx).height, anim);
				//}
		}
	  };
}();
