/*----FCC scripts 2009  --- */

/*add all window listeners*/
window.addEvent('domready', function() {
									 var sitemap = new Smap('sitemap_btn');
									 Cufon.replace('#mastheadtext  > h1:')('p.promo_message');
									 var alert = new confirm();
									 if($('mastheadtext')){
									 $('mastheadtext').getChildren('h1').setStyle('display', 'block');
									 $('mastheadtext').getChildren('p').setStyle('display', 'block');
									 }
									 if($('help_Questions')){
										 var faqs= new FaqList('help_Questions', {titles:'h2'});
									 }
									 if($('termshide')){
										 var faqs= new FaqList('termshide', {showall:false});
									 }
									 if($('choose_team')){
										var choose= new getClub('choose_team');
									 }
									   if($('choose_team_rewards')){
										var choose= new getClub('choose_team_rewards',{'button':'btn_choose_go_white.gif','miss':['thfc','whfc']});
									 }
									 if($('faqbannerlink')&&$('responselinktop')){
										
		var theFAQs=new OverlayIframe({id:['faqbannerlink','responselinktop'], url:'https://ecollector.responsetek.com/eKnowledge/ekBrowser.aspx?PGUID=58499E58&CGUID=932C1654&aut=1&ReferPage=FootballCreditCards - Dynamic FAQ',opacity:'0.8', speed:350,size:{width:660, height:460}});
		
								 }
									

  								 });

/*handle sitemap at top of page*/
var Smap =new Class({
					Implements: [Options, Events], 
					initialize: function(id) { 
					this.pane=$('sitemap');this.button= $(id); 
					this.button.addEvent('click', this.sopen.bind(this));
					},
					sopen:function(){
						var myEffect = new Fx.Morph(this.pane, {duration: 250, transition: Fx.Transitions.Sine.easeOut});
						myEffect.start({'height': [130]});this.button.setStyle('background-position', '0 -32px');
						this.button.removeEvents('click', this.sopen.bind(this)); 
						this.button.addEvent('click', this.sclose.bind(this)); 
						return false;
						},sclose:function(){var myEffect = new Fx.Morph(this.pane, {duration: 220, transition: Fx.Transitions.Sine.easeOut});myEffect.start({'height': [3]});this.button.removeEvents('click', this.sclose.bind(this)); this.button.setStyle('background-position', '0 0px');
						this.button.addEvent('click', this.sopen.bind(this));
						return false;
						}});

var FaqList =new Class({
Implements: [Options, Events], 
options: {
        showall: true,
        titles: 'h3'
       
    },
initialize: function(container, options) { 

this.setOptions(options);

this.container=$(container);
this.show=new Element('p', {'html': 'Show all topics', 'class': 'show_all'});
this.show.addEvent('click', this.toggleall.bind(this));
if(this.options.showall){
this.show.inject(this.container,'top');
}
this.container.getElements(this.options.titles).each(function(item, index){item.getNext().setStyles({display:'none',overflow:'hidden',height:0});	item.getNext().set('opacity',0);item.addEvent('click', function(e){if(item.getNext().getStyle('display')=='block'){item.toggleClass('selected');var myEffect = new Fx.Morph(item.getNext(), {duration: 150, transition: Fx.Transitions.Sine.easeOut, onComplete:function(){ item.getNext().setStyle('display','none');}});myEffect.start({'height': [0],'opacity':0})	;}else{ item.toggleClass('selected');item.getNext().setStyle('display','block');var myEffect = new Fx.Morph(item.getNext(), {duration: 250, transition: Fx.Transitions.Sine.easeOut});var size=0;item.getNext().getChildren().each(function(item, index){size+=item.getSize().y;});myEffect.start({'height': [size],'opacity':1 })}});});},toggleall:function(){if(this.show.get('text')=='Hide all topics'){this.show.set('text', 'Show all topics');this.container.getElements(this.options.titles).each(function(item, index){if(item.hasClass('selected')){item.removeClass('selected');}var myEffect = new Fx.Morph(item.getNext(), {duration: 350, transition: Fx.Transitions.Sine.easeOut, onComplete:function(){ item.getNext().setStyle('display','none');}});myEffect.start({'height': [0],'opacity':0});});}else{this.show.set('text', 'Hide all topics');this.container.getElements(this.options.titles).each(function(item, index){if(!item.hasClass('selected')){item.addClass('selected');}item.getNext().setStyle('display','block');var myEffect = new Fx.Morph(item.getNext(), {duration: 350, transition: Fx.Transitions.Sine.easeOut});var size=0;item.getNext().getChildren().each(function(item, index){size+=item.getSize().y;});myEffect.start({'height': [size],'opacity':1})});} }});




//todo - create form redirect
var getClub = new Class({Implements: [Options, Events],
									  options:{
										  miss:null,
										  button:'btn_choose_go.jpg'
										  },
										  initialize: function(id, options) {
											  this.setOptions(options);
											  this.pane=$(id);this.pane.empty();
this.clubs=[ ['afc','Arsenal'],
	   ['avfc','Aston Villa'],
	   ['cafc','Celtic'],
	   ['cfc','Chelsea'],
	   ['eng','Official England'],
	   ['lfc','Liverpool'],
	   ['mcfc','Manchester City'],
	   ['mufc', 'Manchester United'],
	   ['rfc','Rangers'],
	   ['thfc','Tottenham'],
	   ['whfc','West Ham']

];
this.codes=[
	   ['afc','../football-credit-cards/arsenal-rewards-credit-card.php'],
	   ['avfc','../football-credit-cards/aston-villa-rewards-credit-card.php'],
	   ['cfc','../football-credit-cards/chelsea-rewards-credit-card.php'],
	   ['lfc','../football-credit-cards/liverpool-rewards-credit-card.php'],
	   ['mcfc','../football-credit-cards/manchester-city-rewards-credit-card.php'],
	   ['mufc', '../football-credit-cards/manchester-united-credit-card.php'],
	   ['mfc','../football-credit-cards/middlesborough-rewards-credit-card.php'],
	   ['nufc','../football-credit-cards/newcastle-united-rewards-credit-card.php'],
	   ['thfc','../football-credit-cards/tottenham-credit-card.php'],
	   ['whfc','../football-credit-cards/west-ham-rewards-credit-card.php'],
	   ['cafc','../football-credit-cards/celtic-credit-card.php'],
	   ['rfc','../football-credit-cards/rangers-credit-card.php'],
           ['eng','../football-credit-cards/official-england-credit-card.php']
	   ];
this.form= new Element('form', {'action': '','class':'chooseForm','events': {'submit': this.redirect.bind(this)}});
this.selectopts=new Element('select');

								 
							//alert(this.clubs.erase(item))
							//alert(item);
								
this.clubs.each(function( item,index){
					 var a=true;
						 if(this.options.miss!=null){
						 if(this.options.miss.contains(item[0])){ a=false;}}
					 if(a){
						 this.selectopts.adopt(new Element('option', {'html': item[1],'value':item[0]})); 
						 }
						 },this);
this.form.adopt(this.selectopts);
this.form.adopt(new Element('input', {'type': 'image','src':'../images/'+this.options.button,'width':'51','height':'24','alt':'Go'}));

this.pane.adopt(this.form);},redirect:function(){selected_club=this.selectopts.getSelected()[0].value;this.codes.each(function(item,index){if(item[0]==selected_club){window.location =item[1];}},this);return false;}});
	
/*---faq overlay---*/

var OverlayIframe=new Class({
							Implements:[Options,Events],
							options:{url:'',id:'launcher',background:'#333333',opacity:0.7,speed:500,size:{width:100,height:100}},
							initialize:function(options){
								this.setOptions(options);
								this.options.id.each(function(item){$(item).addEvent('click',this.launch.bind(this))},this);
								this.fadeDiv=new Element('div',{'styles':{'display':'block','position':'absolute','top':0,'left':0,'width':this.getgreyoutsize().width,'height':this.getgreyoutsize().height,'background':this.options.background,'opacity':0,zindex:20}});
								this.iframeDiv=new Element('div',{'styles':{'display':'block','position':'absolute','width':this.options.size.width,'height':this.options.size.height,'opacity':1, 'top':this.getMidDivPosition().top, 'left':this.getMidDivPosition().left}});
								this.closeDiv=new Element('div',{'styles':{'width':'85px','height':'70px','display':'block', 'float':'right', 'background':'#0052C2','position':'absolute', 'top':0,'right':0,'cursor':'pointer' }, events:{'click':this.remove.bind(this)}}).adopt(new Element('p',{html:'close',styles:{'font-weight':'bold','color':'#ffffff', 'margin':'20px 0 0 25px'}}));
								this.iframeDiv.adopt(new IFrame({
    src: this.options.url,
	name:'eKnowledge',
    styles: {
        width:this.options.size.width,
		height:this.options.size.height,
        border: '0px none'
    }}));
								this.iframeDiv.adopt(this.closeDiv);
								
								},
								getMidDivPosition:function(){
								
														   var t=((window.getSize().y-this.options.size.height)/2<0)?0:(window.getSize().y-this.options.size.height)/2;
														   
														   var l=((window.getSize().x-this.options.size.width)/2<0)?0:(window.getSize().x-this.options.size.width)/2;
														   return {'left':l, 'top':t}
								}
								,getgreyoutsize:function(){
								
														  var h=($(document.body).getScrollSize().y>window.getSize().y)?$(document.body).getScrollSize().y+25:window.getSize().y+25;
														  var w=($(document.body).getScrollSize().x>window.getSize().x)?$(document.body).getScrollSize().x:window.getSize().x;
														   return {'width':w, 'height':h}
								}
								,
								
								launch:function(){
									$(document.body).adopt(this.fadeDiv);
									$(document.body).adopt(this.iframeDiv);
									this.resize_overlay();
									window.addEvent('resize',this.resize_overlay.bind(this));
									myEffect=new Fx.Morph(this.fadeDiv,{duration:this.options.speed,transition:Fx.Transitions.Sine.easeOut,onComplete:function(){this.fadeDiv.addEvent('click',this.remove.bind(this))}.bind(this)});
									myEffect.start({'opacity':[this.options.opacity]});
									return false;
									},
									
									
									remove:function(){
										this.iframeDiv.dispose();
										myEffect=new Fx.Morph(this.fadeDiv,{duration:this.options.speed,transition:Fx.Transitions.Sine.easeIn,onComplete:function(){this.fadeDiv.dispose();}.bind(this)});
										myEffect.start({'opacity':[0]});
										window.removeEvent('resize',this.resize_overlay.bind(this));},
										resize_overlay:function(){
										this.fadeDiv.setStyles({'width':this.getgreyoutsize().width,'height':this.getgreyoutsize().height});
											this.iframeDiv.setStyles({'top':this.getMidDivPosition().top, 'left':this.getMidDivPosition().left});

 }});
var confirm = new Class({
	initialize: function(){
		this.setup();
	},
	setup: function() {	
		var links = $$('a[rel=external]');
		var msg = 'You are now leaving the FootballCreditCards website, which is hosted by MBNA Europe Bank Limited.<br /><br />By clicking Continue, you will be taken to a website that is not affiliated with MBNA Europe Bank and may offer a different privacy policy and level of security.  MBNA Europe Bank is not responsible for and does not endorse, guarantee or monitor content, availability, viewpoints, products or services that are offered or expressed on other websites.<br /><br />You can click the Close button now to return.<br /><br />';
		links.each(function(link){
	new alertBox({id:link, msg:msg});
							});
	
	}
});

/**
 * @copyright (c) 2009 Eduardo D. Sada (www.coders.me)
 * @license MIT - http://es.wikipedia.org/wiki/Licencia_MIT
*/
var alertBox=new Class({
					   Implements:[Options, Events],
					   options:{url:'',id:'', msg:'', background:'#333333',opacity:0.7,speed:500,size:{width:500,height:'auto'}},
					   initialize: function(options){
						   this.setOptions(options);
						   this.options.id.addEvent('click',this.launch.bind(this));
						   this.fadeDiv=new Element('div',{'styles':{'display':'block','position':'absolute','top':0,'left':0,'width':this.getgreyoutsize().width,'height':this.getgreyoutsize().height,'background':this.options.background,'opacity':0,zindex:20}});
						   //set up message
						   
			
						   
this.alertBox = new Element('div',{'id':'alertBox-Box', 'styles':{'position':'fixed', 'width': this.options.size.width, 'height': this.options.size.height, 'display':'block','top':0, 'left':this.getMidDivPosition().left}}).adopt( new Element('div',{'id':'alertBox-InBox'}).adopt(new Element('div',{'id':'alertBox-BoxContent'}).adopt(new Element('div',{'id':'alertBox-BoxWrapper', 'html':this.options.msg}).adopt(new Element('div',{'id':'alertBox-Buttons'}).adopt(new Element('input',{'id':'BoxConfirmBtnOk', 'value':'Continue', 'type':'button',style:{'width':70}, events:{'click':this.goto.bind(this)}}),new Element('input',{'id':'BoxConfirmBtnCancel','value':'Close', 'type':'button',style:{'width':70}, events:{'click':this.remove.bind(this)}}))))));
						   
						   
					   },
					   goto:function(){
						  window.location=this.options.id.get('href');
					   },
					   getgreyoutsize:function(){
								
														  var h=($(document.body).getScrollSize().y>window.getSize().y)?$(document.body).getScrollSize().y+25:window.getSize().y+25;
														  var w=($(document.body).getScrollSize().x>window.getSize().x)?$(document.body).getScrollSize().x:window.getSize().x;
														   return {'width':w, 'height':h}
								},
								
								
								launch:function(){
									$(document.body).adopt(this.fadeDiv);
									$(document.body).adopt(this.alertBox);
									this.resize_overlay();
									window.addEvent('resize',this.resize_overlay.bind(this));
									myEffect=new Fx.Morph(this.fadeDiv,{duration:this.options.speed,transition:Fx.Transitions.Sine.easeOut,onComplete:function(){this.fadeDiv.addEvent('click',this.remove.bind(this))}.bind(this)});
									myEffect.start({'opacity':[this.options.opacity]});
									return false;
									},
									getMidDivPosition:function(){
								                          if(this.alertBox){
														  
														 var size=0;
														 this.alertBox.getChildren().each(function(item, index){size+=item.getSize().y;});
														 this.options.size.height=size;
														  }
														   var t=((window.getSize().y-this.options.size.height)/2<0)?0:(window.getSize().y-this.options.size.height)/2;
														   
														   var l=((window.getSize().x-this.options.size.width)/2<0)?0:(window.getSize().x-this.options.size.width)/2;
														   return {'left':l, 'top':t}
								}
								,
									remove:function(){
									this.alertBox.dispose();
										myEffect=new Fx.Morph(this.fadeDiv,{duration:this.options.speed,transition:Fx.Transitions.Sine.easeIn,onComplete:function(){this.fadeDiv.dispose();}.bind(this)});
										myEffect.start({'opacity':[0]});
										window.removeEvent('resize',this.resize_overlay.bind(this));},
										resize_overlay:function(){
										this.fadeDiv.setStyles({'width':this.getgreyoutsize().width,'height':this.getgreyoutsize().height});
											this.alertBox.setStyles({'top':this.getMidDivPosition().top, 'left':this.getMidDivPosition().left});

 }
								
					   
					   });