var Pagination = new Class({

	initialize: function(pagination) {
		this.pagination = $(pagination);
		this.addPagination();
    },
		
	addPagination: function() {
		this.pagination.getChildren().each(function(el) {
			el.addEvent('click', function(event) {
				event.stop();
				window.location = this.getFirst().getProperty('href');
			});
			
			if (el.getProperty('class') == 'pagenormal') {
				el.addEvent('mouseover', function(event) {
					this.setProperty('class','pageactive');				
				});
				
				el.addEvent('mouseout', function(event) {
					this.setProperty('class','pagenormal');				
				});
			}
		});
	}
});

var Mailer = new Class({
	initialize: function(fullmailform,fullmailinput,sessionid) {
		this.fullmailform = $(fullmailform);
		this.fullmailinput = $(fullmailinput);
		this.sessionid = sessionid;
		
		this.fullmailform.addEvent('submit',function(event) {
			event.stop();
					
			new Request({
				method: 'get',
				url: '../ajax/mail.php',
				data: {
					'email' : this.fullmailinput.getProperty('value'),
					'sessionid'  : this.sessionid,
					'rand' : (Math.random()*10000).ceil()
				},
							
				onSuccess: function(mailResponse) {
					if (mailResponse == 'OK') {
						alert("Je hebt nu een e-mail ontvangen in je mailbox!");
					} else if (mailResponse == 'INVALID') {
						alert("Ongeldig e-mail adres ingevoerd!");
					} else if (mailResponse == 'NOTAVAILABLE') {
						alert("Deze film is niet beschikbaar!");
					} else {
						alert("Probeer het nogmaals, er ging iets niet goed!");
					}
				}.bind(this),
				
				onFailure: function() {
					alert("Probeer het nogmaals, er ging iets niet goed!");
				}
				
			}).send();
						
		}.bind(this));
		
	}
});

var Niches = new Class({

	initialize: function(niches) {
		this.niches = $(niches);
		this.addNiches();
    },
		
	addNiches: function() {
		this.niches.getChildren().each(function(el) {
			if (el.getProperty('class') == 'leftmenu') {
				el.addEvent('click', function(event) {
					event.stop();
					window.location = this.getFirst().getProperty('href');
				});
				
				if (el.getProperty('class') == 'leftmenu') {
					el.addEvent('mouseover', function(event) {
						this.setProperty('class','leftmenuhover');				
					});
					
					el.addEvent('mouseout', function(event) {
						this.setProperty('class','leftmenu');				
					});
				}
			}
		});
	}
});

var Tabs = new Class({
	initialize: function(payconsole,paytableft,paytabright,vaspaymethods,leftwebsiteid,rightwebsiteid,relation,vod) {
		this.payconsole = $(payconsole);
		this.paytableft = $(paytableft);
		this.paytabright = $(paytabright);
		this.vaspaymethods = $(vaspaymethods);
		this.leftwebsiteid = leftwebsiteid;
		this.rightwebsiteid = rightwebsiteid;
		this.relation = relation;
		this.vod = vod;
		
		this.addTab('left');
		this.addTab('right');
    },
		
	addTab: function(position) {
		if (position == 'right') {
			var paytabactive = this.paytabright;
			var paytabinactive = this.paytableft;
			var posx = '-308px';
		} else {
			var paytabactive = this.paytableft;
			var paytabinactive = this.paytabright;
			var posx = '0px';
		}
		
		paytabactive.setStyle('cursor','pointer');
		paytabinactive.setStyle('cursor','pointer');
				
		paytabactive.addEvent('click', function(event) {
			event.stop();
			// raplace image
			this.payconsole.setStyle('background-position',posx);
			
			// set active tab
			paytabactive.getChildren().each(function(el) {
				if (el.hasClass('paytablength')) {
					el.removeClass('paytablengthnot');
					var paytablength = el.getFirst().getFirst();
					paytablength.set('text','');
					paytablength.set('text','Lengte:');
				} else if (el.hasClass('paytabprice')) {
					el.removeClass('paytabpricenot');
				}
			});
			
			//set inactive tab
			paytabinactive.getChildren().each(function(el) {
				if (el.hasClass('paytablength')) {
					el.addClass('paytablengthnot');
					el.getFirst().getFirst().set('text','');
				} else if (el.hasClass('paytabprice')) {
					el.addClass('paytabpricenot');
				}
			});
			
			// update vas links
			this.vaspaymethods.getChildren('a').each(function(el) {
				if (position == 'right') {
					el.setProperty('href',el.getProperty('href').replace('GROUP','SINGLE'));	
				} else {
					el.setProperty('href',el.getProperty('href').replace('SINGLE','GROUP'));		
				}
			});
			
			// update website ids and relation for ppcpm
			if (position == 'right') {
				this.vod.setOptions({
					websiteid : this.rightwebsiteid,
					relation : 'SINGLE'
				});
			} else {
				this.vod.setOptions({
					websiteid : this.leftwebsiteid,
					relation : 'GROUP'
				});
			}
		}.bind(this));

	}					 
});