(function($) {	
	if (!JS_AB) {var JS_AB = new Object();}
	
	JS_AB.tickets = {
		debug : false,
		init: function()
		{
			if(typeof jsEsro != 'undefined')
			{
				setConcertID(concertId);
				setTicketAmount($('#ticketsAmount').val());
				setTicketEventID(concertGUId);
				
				// put this in setInterval, so it updates the area/price IDs even when the user is not refreshing.
				getEventDescription();
				setInterval('getEventDescription()', (60 * 1000));
	
				$('a.tickets').live('click', JS_AB.tickets.addToBasketHandler);
			}
		},
		
		addToBasketHandler: function()
		{
			var self = $(this);
			var eventID = self.attr('rel');
			var amount = parseInt($('#ticketsAmount').val());

			setLastAction('add');
			jsTicketing.addToBasket(eventID, amount, JS_AB.tickets.addToBasketSuccessHandler);
		},
		
		
		addToBasketSuccessHandler: function(data)
		{
			if(data.status.code == 200)
			{
				var amount = parseInt(data.content.concert.basket_amount);
				var title = data.content.concert.name;
	
				var showMessageClass = (amount > 1) ? '.multiple' : '.one';
				var messageBox = $('#addedTicketsContent').find(showMessageClass);
				
				// hide both the single and the multiple-tickets messages
				messageBox.parent().find('p[class!="navigation"]').hide();

				// fill in the right values for amount/concert
				var newText = messageBox.html().replace('\[amount\]', amount).replace('\[concert\]', title);

				// parse the new text into the right messagebox, and display it
				messageBox.html(newText);
				messageBox.show();
	
				// show the modal confirming the addition of tickets
				//$('#addedTickets').show();
			}
			else
			{
				// parse the new text into the right messagebox, and display it
				var messageBox = $('#addedTicketsError p');
				
				// overwrites the message when debug is on
				if(JS_AB.tickets.debug)
				{
					messageBox.text(data.status.text);
				}
				
				messageBox.show();
				
				// show the modal confirming the addition of tickets
				//$('#addedTicketsError').show();
			}
		},
		
		eoo: true
	}
	
	JS_AB.concerts = {
		debug : false,
		init : function() {
			JS_AB.concerts.hilightSelectedHandler.init();
			JS_AB.concerts.quickSearchHandler.init();
			JS_AB.concerts.quickFriendSearchHandler.init();
			JS_AB.concerts.commentsHandler.init();
			JS_AB.concerts.crowdHandler.init();
			JS_AB.concerts.inviteHandler.init();
			JS_AB.concerts.carpoolHandler.init();
			JS_AB.concerts.ticketsHandler.init();
			JS_AB.concerts.sendMessageHandler.init();
			JS_AB.concerts.readmore.init();
			JS_AB.concerts.flickrHandler.init();
			JS_AB.concerts.rating.init();
			JS_AB.concerts.ticketnumbers.init();
		}
	}
	JS_AB.concerts.ticketnumbers = {
		ticketnumberblob : '<dd><input type="text" id="ids{id}" name="ids[]" value="{value}" class="input-text"/> <a href="#" title="{$lblDelete}" class="deleteTicketnumber" rel="ids{id}">{$lblDelete}</a></dd>',
		init : function() {
			if($('#id').length)
			{
				if ($('#addTicketnumber').length > 0) {
					$('#addTicketnumber').bind('click', JS_AB.concerts.ticketnumbers._addValue);
					$('#id').attr("autocomplete", "off").bind('keypress', function(evt) {
						if (evt.which == 13) {
							evt.preventDefault();
							evt.stopPropagation();
							JS_AB.concerts.ticketnumbers._addValue(evt);
						}
					});
					$('.deleteTicketnumber').bind('click', JS_AB.concerts.ticketnumbers._deleteValue);
				}
			}
		},
		_addValue : function(evt) {
			evt.preventDefault();
			var lastField = $('#addTicketnumberWrapper').prev().find('input');
			if(lastField.length > 0) { nextId = parseInt(lastField.attr('id').substr(3)) + 1; }
			else { nextId = 1; }
			$('#addTicketnumberWrapper').before( JS_NETLASH.utils.string.replaceAll(JS_NETLASH.utils.string.replaceAll(JS_AB.concerts.ticketnumbers.ticketnumberblob, '{value}', $('#id').val()), '{id}', nextId) );
			$('.deleteTicketnumber').unbind('click').bind('click', JS_AB.concerts.ticketnumbers._deleteValue);
			$('#id').val('').focus();
		},
		_deleteValue : function(evt) {
			evt.preventDefault();
			if (confirm('{$msgAreYouSure}')) { $('#' + $(this).attr('rel')).parent().remove(); }
		},
		_eoo : true
	}
	JS_AB.concerts.readmore = {
		init : function() {
			if($('#toggle-full-text').length > 0) {
				$('#toggle-full-text').bind('click', function(evt) {
					evt.preventDefault();
					if($('#concert-text #full').is(':visible')) {
						$('#concert-text #truncated').show();
						$('#concert-text #full').hide();
					} else {
						$('#concert-text #truncated').hide();
						$('#concert-text #full').show();
					}
				});
			}
		},
		_eoo : true
	}
	JS_AB.concerts.hilightSelectedHandler = {
		init : function() {
			$('.calendar td.event a').bind('click', function(evt) {
				var id = $(this).attr('href').split('#')[1];
				var fadeColor = '#FFFFCC';
				var originalColor  = $('#' + id).css('background-color');
				if(originalColor == 'transparent') originalColor = '#F4F4F4';
				$('#' + id + ' td').animate( {backgroundColor: fadeColor}, 1000).animate( {backgroundColor: originalColor}, 1000);
			});
		},
		_eoo : true
	}
	JS_AB.concerts.quickSearchHandler = {
		minChars : 1,
		maxItemsToShow : 50,
		init : function() {
			if ($('#search').length > 0) {
				$('#search').autocomplete("/ajax.php?module=concerts&action=autocomplete", {
					matchContains : true,
					minChars : JS_AB.concerts.quickSearchHandler.minChars,
					dataType : 'json',
					maxItemsToShow : JS_AB.concerts.quickSearchHandler.maxItemsToShow,
					parse : JS_AB.concerts.quickSearchHandler._parseAutoComplete
				});
				$('#search').result(JS_AB.concerts.quickSearchHandler._handleAutoComplete);
				$('#searchArtists').bind('submit', function(evt) {
					evt.preventDefault();
					window.location = $('#searchArtists').attr('action') + JS_NETLASH.utils.string.urlise($('#search').val());
				});
			}
		},
		_parseAutoComplete : function(json) {
			if (JS_AB.concerts.debug) console.log(json);
			var parsed = [];
			if (json.content.count > 0) {
				for (i in json.content.data) {
					var entryName 	= JS_NETLASH.utils.string.html_entity_decode(json.content.data[i].name);
					var entryUrl	= json.content.data[i].url;
					parsed[parsed.length] = {
						data	: [entryName],
						value	: entryUrl,
						result	: entryName
					};
				}
			}
			return parsed;
		},
		_handleAutoComplete : function(event, data, formatted) {if (formatted)	window.location = formatted;},
		_eoo : true
	}
	JS_AB.concerts.quickFriendSearchHandler = {
		minChars : 1,
		maxItemsToShow : 50,
		blob : '<li id="tl_buddies_{id}"><img src="/modulefiles/profiles/avatars/24x24/{avatar}" width="24" height="24" /><p>{username}</p><a class="deleteTag tag" href="#">x</a><span class="hidden">{email}</span></li>',
		init : function() {
			if ($('#friend').length > 0) {
				$('#friend').autocomplete("/ajax.php?module=profiles&action=autocomplete_friends", {
					multiple : false,
					matchContains : true,
					minChars : JS_AB.concerts.quickFriendSearchHandler.minChars,
					dataType : 'json',
					maxItemsToShow : JS_AB.concerts.quickFriendSearchHandler.maxItemsToShow,
					parse : JS_AB.concerts.quickFriendSearchHandler._parseAutoComplete
				});
				$('#friend').result(JS_AB.concerts.quickFriendSearchHandler._handleAutoComplete);
			}
		},
		_parseAutoComplete : function(json) {
			if (JS_AB.concerts.debug) console.log(json);
			var parsed = [];
			if (json.content.count > 0) {
				for (i in json.content.data) {
					var entry = json.content.data[i];
					parsed[parsed.length] = {
						data : [entry.username, entry.id, entry.url, entry.avatar, entry.email],
						value : entry.id,
						result : ''
					};
				}
			}
			return parsed;
		},
		_handleAutoComplete : function(event, data, formatted) {
				event.preventDefault();
				event.stopPropagation();
				if ($.trim(data[0]) == '') {
					$('#friend').val('').focus();
					return;
				}
				var friendSelected = false;
				$('#tl_buddies .tag-' + data[0]).each(function(i) {friendSelected = true;});
				if (friendSelected) {
					$('#friend').val('').focus();
					return;
				}
				data = {'username' : data[0], 'id' : data[1], 'url' : data[2], 'avatar' : data[3], 'email' : data[4]};
				toInsert = JS_NETLASH.utils.string.assignFromObject(JS_AB.concerts.quickFriendSearchHandler.blob, data);
				$('#tl_buddies').append(toInsert);
				$('.deleteTag').bind('click', function(evt) {JS_AB.concerts.inviteHandler._deleteTag(evt)});
				JS_AB.concerts.inviteHandler._storeTags();
				$('#friend').val('').focus();
		},
		_eoo : true
	}
	JS_AB.concerts.commentsHandler = {
		blob : '<div class="shoutbox-comment secondarycontent clearfix"><div class="avatar"><a href="{url}" class="noborder" title="{nick}"><img src="/modulefiles/profiles/avatars/48x48/{avatar}" alt="{nick}" title="{nick}" /></a></div><div class="message"><p class="user"><a href="{url}" title="{nick}">{nick}</a></p><p>{text}</p></div></div>',
		spinner	: '<img src="/modules/core/layout/images/spinner.gif" id="spinner_{id}" alt="" title="" />',
		init : function() {
			if ($('#btnAddComment.concerts').length > 0) {$('#btnAddComment').removeAttr('disabled').bind('click', JS_AB.concerts.commentsHandler._initAddComment);}
			$('p.flagLink a').bind('click', JS_AB.concerts.commentsHandler._initFlagComment);
			$('p.deleteLink a').bind('click', JS_AB.concerts.commentsHandler.deleteComment);
		},
		_initAddComment : function(evt) {
			evt.preventDefault();
			$('#btnAddComment').attr('disabled','disabled');
			$('#spinner').css('visibility','visible');
			postData = $('#addCommentForm').serialize();
			JS_AB.concerts.commentsHandler._doAddComment(postData)
		},
		_doAddComment : function(postData)
		{
			$.ajax({
				url: '/ajax.php?module=concerts&action=add_comment',
				type: 'post',
				dataType: 'json',
				cache: false,
				data: postData,
				success: function(json) {JS_AB.concerts.commentsHandler._doneAddComment(json);},
				error: function(xhr,err,e) {
					alert(err + ' ' + e, 'Critical Error');
					//window.location.reload();
				}
			});
		},
		_doneAddComment : function(json) {
			if (JS_AB.concerts.debug) console.log(json);
			switch (parseInt(json.status.code)) {
				case 200:
				case 400:
					toInsert = JS_NETLASH.utils.string.assignFromObject(JS_NETLASH.utils.string.assignFromObject(JS_AB.concerts.commentsHandler.blob, json.content.user), json.content.comment);
					if (JS_AB.concerts.debug)	console.log(toInsert);
					if ($('#no_sidebar_comments')) {$('#no_sidebar_comments').remove();}
					$('#shoutbox-comments').prepend(toInsert);
					$('#addCommentForm').get(0).reset();
				break;
				case 500:
				default:
					alert(json.status.text);
				break;
			}
			$('#btnAddComment').removeAttr('disabled');
			$('#spinner').css('visibility','hidden');
		},
		_initFlagComment : function(evt) {
			evt.preventDefault();
			if (JS_AB.concerts.debug)	console.log(evt);
			var id = evt.target.id.toString().substring(13);
			$(evt.target).parent().html(JS_NETLASH.utils.string.replaceAll(JS_AB.concerts.commentsHandler.spinner, '{id}', id));
			postData = 'comment_id=' + id;
			JS_AB.concerts.commentsHandler._doFlagComment(postData, id);
		},
		_doFlagComment : function(postData, id) {
			$.ajax({
				url: '/ajax.php?module=concerts&action=flag_comment',
				type: 'post',
				dataType: 'json',
				cache: false,
				data: postData,
				success: function(json) {JS_AB.concerts.commentsHandler._doneFlagComment(json, id);},
				error: function(xhr,err,e) {
					alert(err + ' ' + e, 'Critical Error');
					//window.location.reload();
				}
			});
		},
		_doneFlagComment : function(json, id) {
			if (JS_AB.concerts.debug) console.log(json);
			switch (parseInt(json.status.code)) {
				case 200:
					$('#flagLink_' + id).html(json.status.text);
				break;
				case 400:
					$('#flagLink_' + id).html(json.status.text);
				break;
				case 500:
				default:
					alert(json.status.text);
					//window.location.reload();
				break;
			}
		},
		deleteComment: function(evt) {
			evt.preventDefault();
			if(confirm('Ben je zeker?')) {
				var id = $(this).attr('id').replace('delete_comment_', '');
				$.ajax({ url: '/ajax.php?module=concerts&action=delete_comment', 
						type: 'post', dataType: 'json', cache: false, 
						data: 'comment_id='+ id,
						success: function(json) { $('#comment-' + id).slideUp(); }
				});
			}
		},
		_eoo : true
	}
	JS_AB.concerts.crowdHandler = {
	 	concertId : 0,
		timeToFade : 250,
	 	listBlob : '<ul id="crowd-avatar-list" class="reset clearfix secondarycontent {class}"></ul>',
		listItemBlob : '<li id="crowd_{id}"><div class="avatar avatar-48"><a class="noborder" href="{url}" title="{nick}"><img src="/modulefiles/profiles/avatars/48x48/{avatar}" alt="{nick}" title="{nick}" /></a></div><p><a href="{url}">{nick}</a></p></li>',
		listItemBlobExt : '<li id="crowd_{id}"><div class="avatar avatar-48"><a href="{url}" title="{nick}"><img src="/modulefiles/profiles/avatars/48x48/{avatar}" width="48" height="48" title="{nick}" alt="{nick}" /></a></div>' +
		 					'<div class="info"><p><a href="{url}" title="{nick}">{nick}</a><br />{age} {sex}{city}</div></li>',
		spinner : '<img src="/modules/core/layout/images/spinner.gif" id="spinner_togglecrowd" alt="" title="" />',
		init : function() {
			if ($('.toggleCrowd').length > 0) {
				$('.toggleCrowd').bind('click', JS_AB.concerts.crowdHandler._initToggleMe);
				JS_AB.concerts.crowdHandler.concertId = concertId;
			}
		},
		_initToggleMe : function(evt) {
			evt.preventDefault();
			
			var id = JS_AB.concerts.crowdHandler.concertId;
			var status = ($('.toggleCrowd').hasClass('nocrowd') ? 0 : 1);
			postData = 'concert_id=' + id + '&status=' + status;
			$('.toggleCrowd').hide().after(JS_AB.concerts.crowdHandler.spinner);
			
			if($('#attendOnFacebook').length > 0 && status == 0) 
			{
				$('#attendOnFacebook').show();
				$('#attendOnFacebookCancel').bind('click', function(evt) {
					evt.preventDefault();
					$('#attendOnFacebook').hide();
					JS_AB.concerts.crowdHandler._doToggleMe(postData + '&publish_on_facebook=N');
				});
			}
			else
			{
				JS_AB.concerts.crowdHandler._doToggleMe(postData);
			}
		},
		_doToggleMe : function(postData) {
			$.ajax({
				url: '/ajax.php?module=concerts&action=toggle_crowd',
				type: 'post',
				dataType: 'json',
				cache: false,
				data: postData,
				success: function(json) {JS_AB.concerts.crowdHandler._doneToggleMe(json);},
				error: function(xhr,err,e) {
					alert(err + ' ' + e, 'Critical Error');
					//window.location.reload();
				}
			});
		},
		_doneToggleMe: function(json) {
			if (JS_AB.concerts.debug) console.log(json);
			if($('.toggleCrowd').attr('rel') == 'reload') window.location.reload();
			switch (parseInt(json.status.code)) {
				case 200:
					switch(parseInt(json.content.crowd.direction)) {
						case 0:
							if($('#crowd-avatar-list').length == 0) {$('#crowd-wrapper').html(JS_AB.concerts.crowdHandler.listBlob.replace('{class}', $('#nocrowd').attr('class')));}
							toInsert = JS_NETLASH.utils.string.assignFromObject(JS_AB.concerts.crowdHandler.listItemBlob, json.content.user);
							toInsert2 = JS_NETLASH.utils.string.assignFromObject(JS_AB.concerts.crowdHandler.listItemBlobExt, json.content.user);
							$('#crowd-avatar-list').append(toInsert);
							$('#crowd-detail').append(toInsert2);
							$('.toggleCrowd span').html(json.content.crowd.text);
							$('.toggleCrowd').removeClass('nocrowd').addClass('iscrowd').next().remove().end().show();
							if($('#crowd-avatar-list > li').length > 0) {
								$('#full-crowd').show();
								$('#nocrowd').hide();
								$('#crowd-avatar-list').removeClass('notice');
							}
						break;
						case 1:
							if ($('#crowd_' + json.content.user.id).length > 0) {
								$('#crowd_' + json.content.user.id).animate({opacity: 0}, JS_AB.concerts.crowdHandler.timeToFade, function() {
									$('#crowd_' + json.content.user.id).remove();
									if($('#crowd-avatar-list > li').length == 0) {
										$('#full-crowd').hide();
										$('#nocrowd').show();
									}
								});
							}
							$('.toggleCrowd span').html(json.content.crowd.text);
							$('.toggleCrowd').removeClass('iscrowd').addClass('nocrowd').next().remove().end().show();
						break;
					}
				break;
				case 500:
				default:
					alert(json.status.text);
					//window.location.reload();
				break;
			}
		},
		_eoo : true
	}
	JS_AB.concerts.inviteHandler = {
	 	concertId : 0,
		spinner : '<img src="/modules/core/layout/images/spinner.gif" id="spinnerInformYourFriends" alt="" title="" />',
		listBlob : '<li id="{email_flat}"><img src="/modules/core/layout/images/email.gif" class="mail-icon" /><p>{email}</p><a class="deleteTag tag" href="#">x</a><span class="hidden">{email}</span></li>',
		init : function() {
			if ($('#informYourFriendsLink').length > 0) {
				JS_AB.concerts.inviteHandler.concertId = concertId;
				JS_NETLASH.tlHandler.init();
				$('#addEmail').bind('click', JS_AB.concerts.inviteHandler._addEmail);
				$('#informYourFriendsForm').bind('submit', function(evt) {evt.preventDefault();});
				$('#friend').attr("autocomplete", "off").bind('keypress', function(evt) {
					if (evt.which == 13) {
						evt.preventDefault();
						JS_AB.concerts.inviteHandler._addEmail(evt);
						$('#invalidEmail').hide();
					}
				});
				$('#btnInformYourFriends').removeAttr('disabled').bind('click', JS_AB.concerts.inviteHandler._initInformYourFriends);
			}
		},
		_addEmail : function(evt) {
			evt.preventDefault();
			if (JS_NETLASH.utils.form.isEmail($('#friend'))) {
				$('#invalidEmail').hide();
				var eFlat = 'tl_buddies_' + $('#friend').val().replace('@','-at-').replace('.','-dot-').toLowerCase();
				if ($('#' + eFlat).size() == 0) {$('#tl_buddies').append(JS_NETLASH.utils.string.replaceAll(JS_NETLASH.utils.string.replaceAll(JS_AB.concerts.inviteHandler.listBlob, '{email}', $('#friend').val()), '{email_flat}', eFlat));}
				$('#friend').val('').focus();
				JS_NETLASH.tlHandler.init();
			} else {
				$('#invalidEmail').show();
				$('#friend').focus();
			}
			$('.deleteTag').bind('click', function(evt) {JS_AB.concerts.inviteHandler._deleteTag(evt)});
			JS_AB.concerts.inviteHandler._storeTags();
		},
		_storeTags : function() {
			var self = this;
			if (($('#tl_buddies').length == 0) || ($('#tl_buddies li').length == 0)) {$('#buddies').html('').val('');} 
			else {
				toStore = '';
				$('#tl_buddies li').each(function() {toStore += ',' + $(this).find('span').html();});
				$('#buddies').val(toStore.substr(1));
			}
		},
		_deleteTag : function(evt) {
			var self = this;
			evt.preventDefault();
			$(evt.target).parent().remove();
			JS_AB.concerts.inviteHandler._storeTags();
		},
		_initInformYourFriends : function(evt) {
			evt.preventDefault();
			$('#btnInformYourFriends').attr('disabled','disabled');
			$('#spinnerInformYourFriends').css('visibility','visible');
			JS_NETLASH.tlHandler.buildIt();
			postData = $('#informYourFriendsForm').serialize() + '&concert_id=' + JS_AB.concerts.inviteHandler.concertId;
			JS_AB.concerts.inviteHandler._doInformYourFriends(postData)
		},
		_doInformYourFriends : function(postData) {
			$.ajax({
				url: '/ajax.php?module=concerts&action=inform_friends',
				type: 'post',
				dataType: 'json',
				cache: false,
				data: postData,
				success: function(json) {JS_AB.concerts.inviteHandler._doneInformYourFriends(json);},
				error: function(xhr,err,e) {alert(err + ' ' + e, 'Critical Error');}
			});
		},
		_doneInformYourFriends : function(json) {
			if (JS_AB.concerts.debug) console.log(json);
			switch (parseInt(json.status.code)) {
				case 200:
					$('#informYourFriendContent').html(json.content.text);
				break;
				case 400:
					alert(json.status.text);
					$('#btnInformYourFriends').removeAttr('disabled');
					$('#spinnerInformYourFriends').css('visibility','hidden');
				break;
				case 500:
				default:
					alert(json.status.text);
					$('#btnInformYourFriends').removeAttr('disabled');
					$('#spinnerInformYourFriends').css('visibility','hidden');
				break;
			}
		},
		_eoo : true
	}
	JS_AB.concerts.flickrHandler = {
		init : function() { 
			if($("a[rel^='prettyPhoto']").length > 0) {
				$("a[rel^='prettyPhoto']").prettyPhoto({
					showTitle: false,
					allowresize: false,
					counter_separator_label: '/',
					theme: 'light_square'
				});
			}
			
			if ($('#show-all').length > 0) {
				$('#show-all').bind('click', function(evt) {
					evt.preventDefault();
					$('#concertpast-flickr li:hidden').slideDown();
				});
			}
		},
		_eoo : true
	}
	JS_AB.concerts.carpoolHandler = {
		init : function() {
			if($('#carpoolForm').length > 0) {
				$('#carpoolFormSeekButton').bind('click', function(e) {
					e.preventDefault();
					$('#type').val('SEEK');
					JS_AB.concerts.carpoolHandler.reloadShizzle();
				});
				$('#carpoolFormGiveButton').bind('click', function(e) {
					e.preventDefault();
					$('#type').val('GIVE');
					JS_AB.concerts.carpoolHandler.reloadShizzle();
				});
				JS_AB.concerts.carpoolHandler.reloadShizzle();
				JS_AB.concerts.carpoolHandler.sendMessageStuff();
				
				$('#number').bind('change', function(evt) {
					JS_AB.concerts.carpoolHandler.showPrintButton();
					JS_AB.concerts.carpoolHandler.showBoxes();
				});
				
			}
			JS_AB.concerts.carpoolHandler.showPrintButton();
			JS_AB.concerts.carpoolHandler.showBoxes();
			JS_AB.concerts.carpoolHandler.removeRequest();
		},
		showBoxes: function() {
			var numberOfBoxes = parseInt($('#number').val()) + 1;
			var numberOfExistingBoxes = parseInt($('#passenger-boxes li input').length);
			
			if(numberOfBoxes >= numberOfExistingBoxes) {
				numberOfBoxes = numberOfBoxes - numberOfExistingBoxes;
				var html = '';
				for(var i=numberOfExistingBoxes; i<numberOfBoxes+numberOfExistingBoxes; i++) {
					html += '<li>'
						+ '	<input id="passenger'+ i +'" class="input-text profile-complete ac_input" type="text" maxlength="255" value="" name="passenger'+ i +'" />'
						+ '	</li>';
				}
				$('#passenger-boxes').append(html);
			}			
		},
		showPrintButton: function() {
			var counter = 0;
			$('#passenger-boxes input').each(function(){
				if($(this).val() != '') counter++;
			});
			if(counter >= 2) $('#passenger_print').show();
			else $('#passenger_print').hide();			
		},
		removeRequest : function() {
			$('.remove-request').bind('click', function(e) {
				e.preventDefault();
				var concertId = $(this).attr('rel');
				$.ajax({
					url: '/ajax.php?module=concerts&action=delete_message',
					type: 'post',
					dataType: 'json',
					cache: false,
					data: 'concert_id=' + concertId,
					success: function(json) { // window.location.reload();
					
					},
					error: function(xhr,err,e) {alert(err + ' ' + e, 'Critical Error');}
				});
			});
		},
		reloadShizzle : function() {
			if($('#type').length > 0) {
				var val = $('#type').val().toLowerCase();
				switch(val) {
					case 'seek':
					case 'give':
						$('.success-message').fadeOut(5000);
						$('#carpoolFormIntro').hide();
						$('#carpoolFormForm').show();
						$('.' + ((val == 'seek')?'give':'seek')).hide();
						$('.' + val).show();
						$('#carpoolForm' + ((val == 'seek')?'Seek':'Give') + 'Button').addClass('button-selected');
						$('#carpoolForm' + ((val == 'seek')?'Give':'Seek') + 'Button').removeClass('button-selected');
					break;
					default:return;
				}
			}
		},
		sendMessageStuff : function() {
			$('.sendMessage').bind('click', function(e) {
				$('#receiverId').val($('#r_' + $(this).attr('id')).find(".peopleId").html());
				$('#profileNick').html($('#r_' + $(this).attr('id')).find(".peopleNick").html());
			});
		},
		_eoo : true
	}
	JS_AB.concerts.ticketsHandler = {
		init : function() {
			if ($('#ticketsForm').length > 0) {
				$('#ticketsFormSeekButton').bind('click', function(e) {
					e.preventDefault();
					$('#type').val('SEEK');
					JS_AB.concerts.ticketsHandler.reloadShizzle();
				});
				$('#ticketsFormGiveButton').bind('click', function(e) {
					e.preventDefault();
					$('#type').val('GIVE');
					JS_AB.concerts.ticketsHandler.reloadShizzle();
				});
				JS_AB.concerts.ticketsHandler.reloadShizzle();
				JS_AB.concerts.carpoolHandler.sendMessageStuff();
			}
			JS_AB.concerts.ticketsHandler.removeRequest();
			$('a.delete-ticket').bind('click', JS_AB.concerts.ticketsHandler.deleteTicket);
		},
		deleteTicket: function(evt) {
			evt.preventDefault();
			if(confirm('Ben je zeker?')) {
				var id = $(this).attr('id').replace('delete_', '');
				var concertId = $(this).attr('rel');
				$.ajax({ url: '/ajax.php?module=concerts&action=delete_ticket', type: 'post', dataType: 'json', cache: false,
					data: 'concert_id=' + concertId +'&profile_id='+ id,
					success: function(json) {
						$('#r_seek_'+ id).slideUp();
						$('#r_give_'+ id).slideUp();
					}
				});
			}
		},
		removeRequest : function() {
			$('.remove-ticket-request').bind('click', function(e) {
				e.preventDefault();
				var id = $(this).attr('id').replace('seek_delete_', 'r_seek_');
				if(id == $(this).attr('id')) id = $(this).attr('id').replace('give_delete_', 'r_give_');
				var concertId = $(this).attr('rel');
				$.ajax({
					url: '/ajax.php?module=concerts&action=delete_ticket_request',
					type: 'post',
					dataType: 'json',
					cache: false,
					data: 'concert_id=' + concertId,
					success: function(json) {$('#'+ id).slideUp();},
					error: function(xhr,err,e) {alert(err + ' ' + e, 'Critical Error');}
				});
			});
		},
		reloadShizzle : function() {
			if($('#type').length > 0) {
				var val = $('#type').val().toLowerCase();
				switch(val) {
					case 'seek':
					case 'give':
						$('#ticketsFormIntro').hide();
						$('#ticketsFormForm').show();
						$('.' + ((val == 'seek')?'give':'seek')).hide();
						$('.' + val).show();
						$('#ticketsForm' + ((val == 'seek')?'Seek':'Give') + 'Button').addClass('button-selected');
						$('#ticketsForm' + ((val == 'seek')?'Give':'Seek') + 'Button').removeClass('button-selected');
					break;
					default:return;
				}
			}
		},
		sendMessageStuff : function() {
			$('.sendMessage').bind('click', function(e) {
				$('#receiverId').val($('#r_' + $(this).attr('id')).find(".peopleId").html());
				$('#profileNick').html($('#r_' + $(this).attr('id')).find(".peopleNick").html());
			});
		},
		_eoo : true
	}
	JS_AB.concerts.sendMessageHandler = {
		init : function() {
			if ($('.sendMessage').length > 0) {
				$('.sendMessage').click(function() {
					$('#sendMessageContentSuccess').hide();
					$('#sendMessageContent').show();
				});
				$('#sendMessageForm').bind('submit', function(evt) {evt.preventDefault();});
				$('#btnSendMessage').removeAttr('disabled').bind('click', JS_AB.concerts.sendMessageHandler._initSendMessage);
			}
		},
		_initSendMessage : function(evt) {
			evt.preventDefault();
			$('#btnSendMessage').attr('disabled','disabled');
			postData = $('#sendMessageForm').serialize();
			JS_AB.concerts.sendMessageHandler._doSendMessage(postData)
		},
		_doSendMessage : function(postData) {
			$.ajax({
				url: '/ajax.php?module=concerts&action=send_message',
				type: 'post',
				dataType: 'json',
				cache: false,
				data: postData,
				success: function(json) {JS_AB.concerts.sendMessageHandler._doneSendMessage(json);},
				error: function(xhr,err,e) {alert(err + ' ' + e, 'Critical Error');}
			});
		},
		_doneSendMessage : function(json) {
			if (JS_AB.concerts.debug) console.log(json);
			switch (parseInt(json.status.code)) {
				case 200:
					$('#sendMessageContentSuccess').html(json.content.text).show();
					$('#sendMessageContent').hide();
					$('#message_subject').val('');
					$('#message_content').val('');
					$('#btnSendMessage').removeAttr('disabled');
				break;
				case 400:
					alert(json.status.text);
					$('#btnSendMessage').removeAttr('disabled');
				break;
				case 500:
				default:
					alert(json.status.text);
					$('#btnSendMessage').removeAttr('disabled');
				break;
			}
		},
		_eoo : true
	}
	JS_AB.concerts.rating = {

		concertId: null,

		yourRatingWidth: 0,

		init: function() {
			// Store original text (e.g. 'your rating')
			var originalText = $('#concertRating .ratingTextYours span').html();

			$('#concertRating .ratingYours .rateInt').each(function(index) {

				// Store rating text (e.g. 'Good')
				var ratingText = $(this).html();

				$(this).click(function(evt) {

					// Prevent default action
					evt.preventDefault();

					// Change stars to reflect vote
					switch(index)
					{
						case 0:
							$(this).parent().find('.ratingOverlay').show().css('width', '13px');
							JS_AB.concerts.rating.yourRatingWidth = 13;
							break;
						case 1:
							$(this).parent().find('.ratingOverlay').show().css('width', '25px');
							JS_AB.concerts.rating.yourRatingWidth = 25;
							break;
						case 2:
							$(this).parent().find('.ratingOverlay').show().css('width', '37px');
							JS_AB.concerts.rating.yourRatingWidth = 37;
							break;
						case 3:
							$(this).parent().find('.ratingOverlay').show().css('width', '48px');
							JS_AB.concerts.rating.yourRatingWidth = 48;
							break;
						case 4:
							$(this).parent().find('.ratingOverlay').show().css('width', '61px');
							JS_AB.concerts.rating.yourRatingWidth = 61;
							break;
					}

					// handle ajax call
					JS_AB.concerts.rating.initSendRating(index + 1);

				});

				// Show rating text when hovering over one of the rating stars
				$(this).hover(function(evt) {
					JS_AB.concerts.rating.yourRatingWidth = $(this).parent().find('.ratingOverlay').width();
					$(this).parent().find('.ratingOverlay').hide();
					$(this).parent().next('.ratingTextYours').find('span').html(ratingText);
				}, function() {
					$(this).parent().find('.ratingOverlay').show().width(JS_AB.concerts.rating.yourRatingWidth + 'px');
					$(this).parent().next('.ratingTextYours').find('span').html(originalText);
				});

			});

		},
		
		initSendRating : function(rating) {
			JS_AB.concerts.rating.concertId = concertId;
			JS_AB.concerts.rating.doSendRating({'rating': rating, 'concert_id': JS_AB.concerts.rating.concertId});
		},

		doSendRating : function(postData) {
			$.ajax({
				url: '/ajax.php?module=concerts&action=send_rating',
				type: 'post',
				dataType: 'json',
				cache: false,
				data: postData,
				success: function(json) {
					JS_AB.concerts.rating.doneSendRating(json);
					JS_AB.concerts.crowdHandler._doneToggleMe(json);
				},
				error: function(xhr,err,e) {alert(err + ' ' + e, 'Critical Error');}
			});
		},

		doneSendRating: function(json) {
			$('.ratingTextYours span').html(json.content.successMessage);

			// update main rating
			var width = Math.floor(json.content.rating) * 20;
			$('.rating .ratingOverlay').width(width);
			$('.ratingText span').html(Math.floor(json.content.count) + ' ' + json.content.countText);
		},

		_eoo: true
	}
	$(document).ready(function()
	{
		JS_AB.concerts.init();
		JS_AB.tickets.init();
	});
})(jQuery)
