bxb.fp = function(){
	  return{
	  	perPage: 5,
	  	itemHeight: 54,
		init: function(cfg){
			Ext.apply(this, cfg);
			
			Cufon.now();		
			var h = Ext.getBody().query('span.planetestyle');
			Cufon.replace(h, {fontFamily: 'Planet Estyle'});		
		
			/*
			var c =	Ext.get('openeditor');
			if(c){
				c.on('click', function(){
					var n  = new bxb.frontPageCustomiser({width:800, height:400});
					n.show();
				});
			}
			*/
			
			
			// add a shadowbox link to any game images in the article body.
			var e = Ext.getBody().select('div.body').first();
			if(e){
				var a = e.select('a');
				if(a){
					var p = '/images/games/';
					a.each(function(link){
						if(!link.dom.rel || link.dom.rel !== 'shadowbox[game]'){
							var f=link.first();
							if(f){
								if(f.is('img')){
									if(f.dom.src.match(p)){
										link.dom.rel = 'shadowbox[game]';
									}
								}
							}
						}
					});
				}
			}
			
			
			
			
			this.themeList = Ext.get('themepicker');
			if(this.themeList){
				this.themeList.enableDisplayMode().hide();
				this.themeTrigger = Ext.get('themepicker-trigger');
				this.themeList.anchorTo(this.themeTrigger, 'tl-bl');
				this.themeTrigger.on('click', function(){
					this.themeList.show().alignTo(this.themeTrigger, 'tl-bl');
				}, this);
				this.themeList.down('div').on('click', function(){this.themeList.hide()}, this);
			
				var th = this.themeList.select('a.theme_icon', true);
				th.each(function(el){
					el.on('click', function(){
						var themeID = el.first().dom.alt;
						if(bxb.css == themeID){
						// 	do nothing, already has this style applied
						} else {
						// 	request change style to the server, if success then switch stylesheet.
							this.themeList.mask('Changing Theme now');
							Ext.Ajax.request({
								method: 'POST',
								url: '/scripts/setTheme.php',
								params: {theme: themeID},
								success: function(o){
									var r = Ext.decode(o.responseText);
									this.themeList.unmask();
									if(r.success){
										bxb.css = r.theme;
										Ext.util.CSS.swapStyleSheet('theme', r.css);
									} else {
										alert(r.msg);
									}
								},
								scope:this
							});
						}
					}, this);
				}, this);
			}
			

			var sb = Ext.get('searchbox');
			if(sb){
				var sec = {1: 'news', 2: 'reviews', 3: 'previews', 4: 'features', 5: 'podcasts', 7:'games'};
				var w = (this.section == "search") ? 910 : 200;
				var sn = (sec[this.section]) ? 'search '+sec[this.section] : 'search britxbox';
				var searchBox = new Ext.form.TextField({
					renderTo: sb,
					allowBlank: false,
					minLength: 3,
					section: this.section,
					emptyText: sn,
					width: w,
					listeners: {
						'specialkey' : {fn:function(fld, ev){
								if(Ext.EventObject.getKey(ev) == Ext.EventObject.ENTER){
									if(!fld.isValid()){
									 	return false;
									}
									var val = Ext.util.Format.trim(fld.getValue());
									if(val.length > 2){
										if(this.section){
											window.location = 'search.php?query='+val+'&filter='+this.section;
										} else {
											window.location = 'search.php?query='+val;
										}
									}
								}
							}
						}
					}
				});	
			}
		
		
			var sp = Ext.get('main').select('div.panel_scroller_body', true);
			var sc = Ext.get('main').select('.panel_scroller_control', true);
			var ft = Ext.get('main').select('div.panel_scroller_footer', true);
			var hd = Ext.get('main').select('div.panel_scroller_header', true);
			sp.scrollTo('top', 0).unselectable();
			
			hd.addClass('pfdisabled');
			ft.addClassOnOver('pfover');
			hd.addClassOnOver('pfover');
			
			sc.each(function(el){
				this.pagers = el.select('div.page_control', true);
				this.maxPages = el.pagers.getCount()-1;
				this.pagers.item(0).addClass('active');
				this.pagers.addClassOnOver('over');
				this.curPage = 0;
			});
			
			sc.on('click', function(ev,el){
				var i = sc.indexOf(el.parentNode.id);
				var ct = sc.item(i);
				var pg = ct.pagers.indexOf(el.id);
				var pc = sp.item(i);				
				var d = (this.perPage * this.itemHeight) * pg;
				pc.scrollTo('top', d, {easing:'easeIn'});
				ct.pagers.removeClass('active');
				ct.pagers.item(pg).addClass('active');
				ct.curPage = pg;
				if(ct.curPage < ct.maxPages){
					ft.item(i).removeClass('pfdisabled');
				} else {
					ft.item(i).addClass('pfdisabled');
				}
				if(ct.curPage > 0){
					hd.item(i).removeClass('pfdisabled');
				} else {
					hd.item(i).addClass('pfdisabled');
				}
			}, this);
			
			ft.on('click', function(ev,el){
				var i = ft.indexOf(el.id);
				// clicked page footer for panel i
				var pc = sp.item(i);
				var ct = sc.item(i);
				if(ct.curPage < ct.maxPages){
					var pg = ct.curPage + 1;
					var d = (this.perPage * this.itemHeight) * pg;
					pc.scrollTo('top', d, {easing:'easeIn'});
					ct.pagers.removeClass('active');
					ct.pagers.item(pg).addClass('active');
					ct.curPage = pg;
					if(ct.curPage < ct.maxPages){
						ft.item(i).removeClass('pfdisabled');
					} else {
						ft.item(i).addClass('pfdisabled');
					}
					if(ct.curPage > 0){
						hd.item(i).removeClass('pfdisabled');
					} else {
						hd.item(i).addClass('pfdisabled');
					}
				}
			}, this);
			
			hd.on('click', function(ev,el){
				var i = hd.indexOf(el.id);
				// clicked page header for panel i
				var pc = sp.item(i);
				var ct = sc.item(i);
				if(ct.curPage > 0){
					var pg = ct.curPage - 1;
					var d = (this.perPage * this.itemHeight) * pg;
					pc.scrollTo('top', d, {easing:'easeIn'});
					ct.pagers.removeClass('active');
					ct.pagers.item(pg).addClass('active');
					ct.curPage = pg;
					if(ct.curPage < ct.maxPages){
						ft.item(i).removeClass('pfdisabled');
					} else {
						ft.item(i).addClass('pfdisabled');
					}
					if(ct.curPage > 0){
						hd.item(i).removeClass('pfdisabled');
					} else {
						hd.item(i).addClass('pfdisabled');
					}
				}
			}, this);
		}
	  };
}();