oMsgBoxParams = {
	inline:			true,
	href:			'.colorboxMsg',
	title:			"Enjoy the Ride",
	opacity:		0.5,
	initialWidth:	100,
	initialHeight:	50,
	onClosed:		function()
					{
						$('div.colorboxMsg').remove();
						$('a.cboxMsg').remove();
					}
}


$(document).ready(function()
{


	/*
	 * Add a colorbox for adding comment to a route or rides, function and params from ajaxforms.js
	 */
	addFormCBox({
		node:			'a.addcomment',
		title:			'Geef je reactie',
		formId:			'addcomment',
		focus:			'#comment_comment',
		ajaxFormParams:	oRouteCommentParams
	});

	/*
	 * Add a colorbox for adding images and movies to a route
	 */
	addFormCBox({
		node:			'a.uploadLatest',
		title:			'Upload een YouTube video of afbeelding',
		formId:			'uploadImg',
		focus:			'#comment_comment',
		ajaxFormParams:	oRouteImgUploadParams
	});

	/*
	 * Add a colorbox for changing my horses
	 */
	addFormCBox({
		node:			'a[href^="/lightbox/horseManager/"]',
		title:			'Mijn paarden',
		formId:			'manageHorses',
		focus:			'#title',
		ajaxFormParams:	oManageMyHorses
	});

	/*
	 * Add a colorbox for editing ride reports
	 */
	addFormCBox({
		node:			'a.rideReport',
		title:			'Mijn rittenverslag',
		formId:			'rideReport',
		focus:			'#text_report',
		ajaxFormParams:	oRideReport
	});

	/**
	 * Execute some functions
	 * These are needed elsewhere, so are not defined in doc. ready
	 */
	addImgMask('img.mask');

	/*
	 * Add an span to a/h2.tab button/ image mask
	 */
	addButtons();

	/*
	 *
	 */
	$(document).bind('cbox_complete', function()
	{
		var $img = $('img[src="' + $.colorbox.element().attr('href') + '"]')

		if ($img.length == 0)
		{
			return;
		}

		$img.addClass('mask green bg_dark-green no-border ');

		addImgMask($img);
	});

	/*
	 * Choosing a route for a ride, possible to choose no route
	 */
	$('#selectRoute').change(function() {
		if ($(this).val() == '')
		{
			$('#no_route').attr('checked', true);
		}
		else
		{
			$('#no_route').attr('checked', false);
		}
	});

	$('#no_route').click(function() {
		if ($(this).attr('checked'))
		{
			$('#selectRoute').val('');
		}
	});

	/*
	 * Remove unwanted (empty) elements
	 * For instance when template holds <p> tpl content </p>, but user content enters <p> user content </p>,
	 * HTML will parse as:
	 * <p></p>
	 * <p>user content</p>
	 *
	 * The top <p> will get removed by this script
	 */
	$('p').each(function()
	{
		var html = $(this).html().replace(/ /gi, '');
		if (html.length == 0)
		{
			$(this).remove();
		}
	});

	/*
	 * Replace page content headers with header images
	 */
	$('.page_content, .page_content_colorbox').find('h1, h2, h3').each(function()
	{
		// Get header content, strip out HTML tags
		var sHeaderTxt 	= $(this).html().replace(/<\/?[^>]+>/gi, '');

		// Get the node name (the header)
		var sNodeName	= this.nodeName.toLowerCase();

		// Get the block color (background for the header)
		var sBlockColor = $(this).parents('div.block').attr('class');
		sBlockColor 	= sBlockColor.split(' ');
		sBlockColor 	= sBlockColor[1].replace('-', '');		// block color allways second position

		// If not allready an image, create the header image
		// Replace the header text by the image
		if (sHeaderTxt.indexOf('<img') == -1 && sHeaderTxt.length > 0)
		{
			var sImage = '<img src="/gfx/text/' + sNodeName + '/' + sBlockColor + '/' + sHeaderTxt +'.png" alt="' + sHeaderTxt + '" />';

			$(this).html(sImage);
		}
	});

	/*
	 * Clear and replace default value on focus/blur on input fields
	 */
	$('form.autotext input.input_text').focus(function()
	{
		// Catch a password field (switch it for the real field)
		// Default value should be 'password', but when editing should it be dots (***)
		// Look at block_login.html
		var sReplace = $(this).attr('id').replace('-mask', '');
		var $replacement = $('input#' + sReplace + '-replace');

		if ($replacement.length > 0)
		{
			$(this).addClass('displayNone');
			$replacement.removeClass('displayNone');
			$replacement.focus();
		}
		else
		{
			// Clear default value
			if (this.value == this.defaultValue)
			{
				$(this).val('');
			}
		}
	});

	$('form.autotext input.input_text').blur(function()
	{
		var sVal = $(this).val().replace(/ /gi, '');

		if ($(this).val() == this.defaultValue || sVal == '')
		{
			var sReplace = $(this).attr('id').replace('-replace', '');
			var $replacement = $('input#' + sReplace + '-mask');

			if ($replacement.length > 0)
			{
				$(this).addClass('displayNone');
				$replacement.removeClass('displayNone');
			}
		}

		if (sVal == '')
		{
			$(this).val(this.defaultValue);
		}
	});

	/*
	 * Delete a reaction
	 */
	$('a.delReaction').live('click', function()
	{
		if (!loggedIn())
		{
			msg('Je moet ingelogd zijn om je reactie te kunnen verwijderen.')
		}
		else
		{
			msg('Weet je zeker dat je deze reactie wilt verwijderen?<a class="button red" style="margin: 12px 0 0 135px;" href="#" onClick="delReaction($(\'a#'+$(this).attr('id')+'\'));return false"><img src="/gfx/text/button/red/Verwijderen.png" alt="Verwijderen" /></a><br class="brclear" />')
			addButtons();
		}

		return false;
	});



	/*
	 * Foto scrollers
	 * http://flowplayer.org/tools/scrollable.html
	 */
	$('.profile_scroller').scrollable({clickable: false, size: 1}).circular().autoscroll({autoplay: true});
	$('.profile_scroller_static').scrollable({clickable: false, size: 3});
	$('.latest_photo_scroller').scrollable({clickable: false, size: 3});
	$('.ride_scroller').scrollable({clickable: false, size: 3});
	$('.club_my_ride_scroller').scrollable({clickable: false, size: 2});
	$('div.route_linked_shopitems div.scrollable').scrollable({clickable: false, size: 3});

	$('.profile_scroller li[id^="siteuser_"]').live('click' , function(){
		document.location = '/enjoy_the_ride_club/' + $(this).attr('id').replace('siteuser_' , '');
	});

	/**
	 * Star rating
	 */
	$('.general_find_route input.rateit').rating({/*required:true*/});
	$('.route_map input.rateit').rating({required:true});

	/**
	 * Colorboxes
	 * Note that more colorboxes get called in route.js
	 */
	// Default colorbox
	$('a.colorbox').addClass('cboxelement').colorbox(
	{
		opacity:		0.5,
		title:			"Enjoy the Ride"
	});

	$('a.colorbox.img').colorbox(
	{
		opacity:		0.5,
		title:			"Enjoy the Ride",
		maxWidth:		500,
		maxHeight:		500
	});

	/**
	 * Algemene voorwaarden colorbox
	 */
	$('a[href^="/lightbox/algemene_voorwaarden/"]').colorbox({
		opacity:		0.5,
		title:			"Algemene voorwaarden"
	});


	/*
	 * Latest photo colorbox
	 */
	$('a.photo.latest').live('mousedown', function()
	{

		$('a.photo.latest').addClass('cboxelement').colorbox(
		{
			opacity:		0.5,
			title:			"Enjoy the Ride",
			maxWidth:		745,
			maxHeight:		750,
			onComplete:		function()
							{
								// Hide some elements
								$('#cboxContent .latest_photo_scroller').parent().find('h2').remove();
								$('#cboxContent a.uploadLatest').remove();

								// Add buttons and masks
								addImgMask('img.mask_large');
								addImgMask('img.mask');
								addButtons();

								// Init the scroller
								//$('.latest_photo_scroller').scrollable({clickable: false, size: 3}).navigator();
								$('.latest_photo_scroller').scrollable({clickable: false, size: 3}).click(function()
								{
                                    setTimeout(function()
                                    {
										$.colorbox.resize(
										{
											maxWidth:		745,
											maxHeight:		750
										});
									}, 1000);
								});

							}
		});
	});

	/* Inside the latest photo colorbox */
	// Show more photo's for this route
	$('#cboxContent a.showmore').live('click', function()
	{
		var aItem 		= $(this).attr('id').split('-');
		var sMediatype	= aItem[0];
		var iItemId		= aItem[1];

		$.getJSON('/ajax/ajax_getJson.php' , {
				action: 	'paging',
				ident: 		'home_latest_photos',
				pageNum: 	0,
				mediatype:	sMediatype,
				itemId: 	iItemId
			},
			function(data)
			{
				if (typeof(data.html) != 'undefined')
				{
					var $identifier = $('#cboxContent div.home_latest_photos').children('div.block_content');

					$identifier.fadeOut('slow' , function()
					{
						$identifier.html(data.html);

						// Hide some elements
						$('#cboxContent .latest_photo_scroller').parent().find('h2').remove();
						$('#cboxContent a.uploadLatest').remove();

						// Add buttons and masks
						addImgMask('img.mask_large');
						addImgMask('img.mask');
						addButtons();

						// Init the scroller
						//$('.latest_photo_scroller').scrollable({clickable: false, size: 3}).navigator();
						$('.latest_photo_scroller').scrollable({clickable: false, size: 3});

						// fading makes the page jump
						$identifier.show();
					});
				}
			});

		return false;
	});


	/* Inside the add movies/images colorbox */
	// Choose the type of upload
	$('select.choose_type').live('change', function()
	{
		var sSelected 	= $(this).val()

		var $form		= $(this).parent().find('form#uploadImg');
		var $out 		= $(this).parent().find('div.formpart:not(#' + sSelected + ')');
		var $in			= $('div#' + sSelected);

		$(this).parent().find('input#formaction').val(sSelected);

		if (sSelected == 'uploadImage')
		{
			$form.attr('enctype', 'multipart/form-data');
		}
		else
		{
			$form.removeAttr('enctype');
			$form.find('#upload_image').val('');
		}

		$out.fadeOut('fast', function()
		{
			$in.fadeIn('medium');
		});
	});

	/* add a disabeld class to disabled items and unbind */
	$('input:disabled').unbind().addClass('disabled');

	/*
	 * Blocks
	 */
	$("div.home_aankomend_verlopen").each(function()
	{
		var $block 	= $(this).children('.block_content');
		var $tabs	= $block.children('.tabs');

		$tabs.children('h2').click(function()
		{
			var $tab = $(this);
			var iTabId = $tab.attr('id').replace('tab-','');

			$tabs.children('h2').removeClass('active');
			$tab.addClass('active');

			$block.find('div.ride.active').fadeOut('medium', function()
			{
				$(this).removeClass('active');
				$block.find('div#cont-'+iTabId).fadeIn('medium', function(){
					addImgMask('img.mask');
				}).addClass('active');


			});
		});
	});

	/*
	* Filtering
	*/
	$('form[name^=filter_]').each(function()
	{
		var $form = $(this);
		$form.find('a.button').bind('click' , function(){
			$(this).parents('form:first').submit();
			return false;
		});

		$form.submit(function(){
			var $form = $(this);
			var sIdentifier = $(this).attr('name').replace('filter_' , '');
			var oParameters = {
				action: 'filter',
				ident: sIdentifier
			};

			$form.find('select,input').each(function()
			{
				var $element = $(this);

				switch($element.attr('type'))
				{
					case 'checkbox':
						oParameters[this.name] = $element.attr('checked') == true ? true : false;
					break;

					default:
						oParameters[this.name] = $element.val();
				}
			});


			$.getJSON('/ajax/ajax_getJson.php' ,
				oParameters
			,
			function(data)
			{
				if (typeof(data.html) != 'undefined')
				{
					var $identifier = $('div.' + sIdentifier).children('div.block_content');
					$identifier.fadeOut('slow' , function(){
						$identifier.html(data.html);
						addButtons();
						addImgMask('.mask');
						$identifier.fadeIn('slow');

					});
				}
			});
			return false;
		});
	});

	$('div.paging a').children().andSelf().live('click' , function(c)
	{
		var href 		= $(this).attr('href');
		var aIdentifier = href.substr(1, href.length).split('=');
		var sIdentifier = aIdentifier[0].replace('page_','');
		var iPagenum 	= parseInt(aIdentifier[1]);

		var aItems 		= $(this).parent('.paging').attr('class').split(' ');
		var iItemId 	= aItems[2].replace('itemId-', '');

		$.getJSON('/ajax/ajax_getJson.php' , {
				action: 	'paging',
				ident: 		sIdentifier,
				pageNum: 	iPagenum,
				itemId: 	iItemId
			},
			function(data)
			{
				if (typeof(data.html) != 'undefined')
				{
					var $identifier = $('div.' + sIdentifier).children('div.block_content');

					$identifier.fadeOut('slow' , function()
					{
						$identifier.html(data.html);

						// Add some styles
						addButtons();
						addImgMask('img.mask');

						// fading makes the page jump
						$identifier.show();
					});
				}
			});

		return false;
	});

	/* Tip page
	 *
	 */

	$("div.tip_page_javascript div.block div.block_content a.view").live('click' , function()
	{
		var $container = $(this).parent('div.block_content');

		$container.children('div.tip').slideDown('medium');
		$container.find('a.view').fadeOut('fast');
	});

	$("div.tip_page_javascript div.block div.block_content a.hide").live('click' , function()
	{
		var $container = $(this).parent();

		$container.slideUp('medium');
		$container.parent().find('a.view').fadeIn('fast');
	});

	/*
	 * Button functions
	 */

	/* Newsletter (right side of page) */
	$('#newletter_activation').click(function(){

		var sFNameDefault = $(this).parent().find('#firstname')[0].defaultValue;
		var sLNameDefault = $(this).parent().find('#lastname')[0].defaultValue;
		var sEmailDefault = $(this).parent().find('#email')[0].defaultValue;

		var sFName = $(this).parent().find('#firstname').val();
		var sLName = $(this).parent().find('#lastname').val();
		var sEmail = $(this).parent().find('#email').val();

		var bValFName = sFName == sFNameDefault || sFName == '' ? false : true;
		var bValLName = sLName == sLNameDefault || sLName == '' ? false : true;
		var bValEmail = sEmail == sEmailDefault || sEmail == '' ? false : true;

		if (bValFName && bValLName && bValEmail)
		{
			$.getJSON('/ajax/ajax_getJson.php' , {
				action: 	'newsletteractivation',
				fname:		sFName,
				lname:		sLName,
				email:		sEmail
			},
			function(data)
			{
				if (typeof(data.error) != 'undefined')
				{
					msg(data.error);
				}
				else if (typeof(data.success) != 'undefined')
				{
					msg(data.success);

					$('#firstname').val(sFNameDefault);
					$('#lastname').val(sLNameDefault);
					$('#email').val(sEmailDefault);
				}
				else
				{
					msg('Er is iets mis gegaan bij het inschrijven. Probeer het	opnieuw of neem contact op met Enjoy the Ride');
				}

			});
		}
		else
		{
			msg('Je moet alle velden invullen om je in te schrijven voor de nieuwsbrief.');
		}

	});

	$('a.uploadRoute').click(function()
	{
		if (!loggedIn())
		{
			msg('Je moet ingelogd zijn om een route te kunnen toevoegen');
			return false;
		}
	});


	/* Rides */
	$('.ride_join').click(function()
	{
		if (loggedIn())
		{
			var iRideId = $(this).attr('id').replace('join-','');

			if (iRideId > 0)
			{
				$.getJSON('/ajax/ajax_getJson.php' , {
					action: 	'ridesignup',
					id:			iRideId
				},
				function(data)
				{
					if (typeof(data.error) != 'undefined')
					{
						msg(data.error);
					}
					else if (typeof(data.redirect) != 'undefined')
					{
						msg('Een moment geduld...');
						window.location = data.redirect;
					}
					else if (typeof(data.success) != 'undefined')
					{
						if(data.success == 'go_to_cart')
						{
							/*redirect to cart*/
							data.success = 'Een moment geduld...';
							msg(data.success);
							window.location = "/shop/winkelwagen-detail"
						}
						else
						{
							msg(data.success);
						}
					}
					else
					{
						msg('Er is iets mis gegaan bij je inschrijving. Probeer het	opnieuw of neem contact op met Enjoy the Ride');
					}

				});
			}
			else
			{
				msg('Voor deze route is er nog geen rit. Klik op \'Organiseer een rit\' om zelf een rit te organiseren.');
			}
		}
		else
		{
			msg('Je moet ingelogd zijn om je in te schrijven voor deze rit.');
		}
	});

	$('.ride_org').click(function()
	{
		if (loggedIn())
		{
			return true;
		}
		else
		{
			msg('Je moet ingelogd zijn om een rit te kunnen organiseren.');
			return false;
		}
	});

	/* Profile page */
	$('.makefavorite').live('click', function()
	{
		if (!loggedIn())
		{
			msg('Je moet ingelogd zijn om je paard favoriet te kunnen maken.');
		}
		else
		{
			$.getJSON('/ajax/ajax_getJson.php' , {
				action: 	'makefavorite',
				item_id:	$(this).attr('id').replace('horse-', '')
			},
			function(data)
			{
				if (typeof(data.error) != 'undefined')
				{
					msg(data.error);
				}
				else if (typeof(data.success) != 'undefined')
				{
					msg(data.success);
					$('.myfav').removeClass('displayNone').show('fast');
					$('.makefavorite').hide('fast');
				}

				return false;
			});
		}
	});

	$('.deleteHorse').live('click', function()
	{
		if (!loggedIn())
		{
			msg('Je moet ingelogd zijn om je paard te kunnen verwijderen.');
		}
		else
		{
			msg('<span class="currmsg">Weet je zeker dat je dit paard wilt verwijderen?<br /><br /><a class="button green popdelete" style="margin-left:130px;" id="'+$(this).attr('id')+'"><img src="/gfx/text/button/green/Verwijderen.png" alt="Verwijderen" /></a><br /></span>');
			addButtons('a.popdelete');
			$('a.popdelete').click(function()
			{
				$.getJSON('/ajax/ajax_getJson.php' , {
					action: 	'deleteHorse',
					ident:		'club_my_horses',
					item_id:	$(this).attr('id').replace('horse-', ''),
					mediatype:	'horse'
				},
				function(data)
				{
					if (typeof(data.error) != 'undefined')
					{
						msg(data.error);
					}
					else
					{
						$('.colorboxMsg').remove();
						msg('Het paard is verwijderd.');

						//$('div.block.club_my_horses').find('.block_content').html(data.html);

						var $identifier = $('div.club_my_horses').children('div.block_content');

						$identifier.fadeOut('slow' , function()
						{
							$identifier.html(data.html);
							$identifier.show();
						});

						setTimeout(function()
						{
							$('#cboxClose').click();
						}, 2000);
					}

					return false;
				});
			});
		}
	});
	
	$('.deleteRide').live('click', function()
	{
		if (!loggedIn())
		{
			msg('Je moet ingelogd zijn om je paard te kunnen verwijderen.');
		}
		else
		{
			msg('<span class="currmsg">Weet je zeker dat je deze rit wilt verwijderen?<br /><br /><a class="button green popdelete" style="margin-left:130px;" id="'+$(this).attr('id')+'"><img src="/gfx/text/button/green/Verwijderen.png" alt="Verwijderen" /></a><br /></span>');
			addButtons('a.popdelete');
			$('a.popdelete').click(function()
			{
				$.getJSON('/ajax/ajax_getJson.php' , {
					action: 	'remove_ride',
					ident:		'club_my_created_rides',
					item_id:	$(this).attr('id').replace('ride-', ''),
					mediatype:	'ride'
				},
				function(data)
				{
					if (typeof(data.error) != 'undefined')
					{
						msg(data.error);
					}
					else
					{
						$('.colorboxMsg').remove();
						msg('De rit is verwijderd.');
						
						$identifier = $('.myrides');
						$identifier.fadeOut('slow' , function()
						{
							$identifier.html(data.html);
							$identifier.show();
						});
						
						setTimeout(function()
						{
							$('#cboxClose').click();
						}, 2000);
					}

					return false;
				});
			});
		}
	});
	
	$('.club_my_next_rides a.btn_cancel').click(function()
	{
		var $link = $(this);
		var iRideId = $link.attr('name').split('_').pop();
		sIdentifier = 'club_my_next_rides';

		Confirm('Weet je zeker dat je je deelname wilt annuleren?', function()
		{
			$('.colorboxMsg a:first').click(function()
			{
				$.getJSON('/ajax/ajax_getJson.php' , {
					action: 		'cancel_ride_siteuser',
					ident: 			sIdentifier,
					ride_id:        parseInt(iRideId)
				},
				function (data)
				{
					if (typeof(data.error) == 'string')
					{
						$('#cboxClose').click();
						return msg(data.error);
					}

					if (typeof(data.message) == 'string')
					{
						$('#cboxClose').click();
						msg(data.error);
					}

					var $identifier = $('div.' + sIdentifier).children('div.block_content');

					$identifier.fadeOut('slow' , function()
					{
						//$('#cboxClose').click();

						$identifier.html(data.html);

						// Add some styles
						addButtons();
						addImgMask('img.mask');

						// fading makes the page jump
						$identifier.show();

						$('#cboxClose').click();
					});
				});
			});
			$('.colorboxMsg a:last').click(function()
			{
				$('#cboxClose').click();
			});
		});
	});

	/* Ritopties */
	if ($('div.block.rideoption').length > 0)
	{
		$('div.block.rideoption a.btn_remove').live('click', function()
		{
			var $rideoption = $(this).parents('.rideoption')
			$rideoption.fadeOut('slow', function()
			{
				var iRideoptionID = $rideoption.attr('id').replace('rideoption_','');
				var bNewOption = true;
				if (!isNaN(iRideoptionID))
				{
					$rideoption.append('<input type="hidden=" name="rideoption[' + iRideoptionID + '][remove]" value="' + iRideoptionID + '" />');
				}
				else
				{
					/* remove the new block */
					bNewOption = false;
					$rideoption.remove();
				}

				if ($('div.block.rideoption:visible').length == 0 && bNewOption)
				{
					getNewRideOption();
				}
			});
		});

		$('a[name=add_rideoption]').click(function()
		{
			getNewRideOption();
		});

		$('div.block.rideoption input[name*=price]').live('focus', function()
		{
			this.value = this.value.replace('€ ', '');
			$(this).select();
		});

		$('div.block.rideoption input[name*=price]').live('change', function(){
			$(this).blur();
		});
		$('div.block.rideoption input[name*=price]').live('blur', function()
		{
			if (this.value.length == 0)
			{
				return false;
			}
			else if (this.value.replace(/\D/g,'').length == 0)
			{
				msg('Dit is een ongelding getal: ' + this.value);
				this.value = '';
				return false;
			}

			this.value = '€ ' + formatMoney(this.value);
		});
	}
	/* order rideoption */
	$('input[type=checkbox][name^=rideoption]').each(function()
	{
		var $input = $(this);
		$input.click(function()
		{
			var $input = $(this);
			if ($input.hasClass('clicked'))
			{
				return false;
			}
			/* Double click fix */
			$input.addClass('clicked');
			setTimeout(function(){
				$input.removeClass('clicked');
			}, 200);
		});
		$input.parents('div.block:first').click(function()
		{
			var $input = $('input[type=checkbox][name^=rideoption]' , this);

			if (!$input.hasClass('clicked'))
			{
				$(this).find('input[type=checkbox][name^=rideoption]').click();
			}
		});
	});

	/* Shopping cart */
	/* Works with jQuery 1.4!! */
	if ($('div.shop_cart_detailpage').length > 0)
	{
		$('div.shop_cart_detailpage a.removeProducts').live('click', function(e)
		{
			var that = this;
			var iId = $(that).attr('rel');
			var sIdentifier = 'shop_cart_detailpage';

			$.getJSON('/ajax/ajax_getJson.php' , {
				action: 		'removeFormCart',
				ident: 			sIdentifier,
				id:             iId
			},
			function (data)
			{
				if(data.error == 'reload')
				{
					window.location.reload();
				}
				else
				{
					$.getJSON('/ajax/ajax_getJson.php' , {
						action: 		'totalCart'
					},
					function (data)
					{
						//$('#totaalCart').html(data.totaal);
						//var parrendDiv = $(that).closest('tr');
						//parrendDiv.remove();

						/*DO RELOAD to Fasiletate foto deliverie cost*/
						window.location.reload();

					});
				}
			});
		});

		$('input[name^=numProducts]').live('change', function()
		{
			var $input  = $(this);
			var iId     = $input.attr('name');
			var iAmount = $input.val().replace(/\D/g , '');

			sIdentifier = 'shop_cart_detailpage';

			if (isNaN(parseInt(iAmount)))
			{
				msg('U heeft een verkeerd aantal ingevoerd');
				return false;
			}

			$.getJSON('/ajax/ajax_getJson.php' , {
				action: 		'changeCart',
				ident: 			sIdentifier,
				id:             iId,
				amount:         iAmount
			},
			function (data)
			{
				if (typeof(data.error) != 'undefined')
				{
					msg(data.error);
				}
				else if (typeof(data.html) != 'undefined')
				{
					var $identifier = $('div.' + sIdentifier).children('div.block_content');

					$identifier.fadeOut('slow' , function()
					{
						//$('#cboxClose').click();

						$identifier.html(data.html);

						// Add some styles
						addButtons();
						addImgMask('img.mask');

						// fading makes the page jump
						$identifier.show();
					});
				}
				else
				{
					/*reload page to show new prize*/
					//	msg('Aantal aangepast');
					window.location.reload();
				}
			});
		});

		$('div.shop_cart_detailpage a[name=emptyCart]').live('click', function()
		{
			var sMsg = 'Wilt u de winkelwagen legen?';
			var sIdentifier = 'shop_cart_detailpage';
			Confirm(sMsg, function()
			{
				$('.colorboxMsg a:first').click(function()
				{
					$.getJSON('/ajax/ajax_getJson.php' , {
						action: 		'clearCart',
						ident: 			sIdentifier
					},
					function (data)
					{
						var $identifier = $('div.' + sIdentifier).children('div.block_content');

						$identifier.fadeOut('slow' , function()
						{
							//$('#cboxClose').click();

							$identifier.html(data.html);

							// Add some styles
							addButtons();
							addImgMask('img.mask');

							// fading makes the page jump
							$identifier.show();

							$('div.shop_ride_suggestions').fadeOut('slow', function()
							{
								$(this).remove();
							});

							$('#cboxClose').click();
						});
					});
				});
				$('.colorboxMsg a:last').click(function()
				{
					$('#cboxClose').click();
				});
			});

		});
	}
	//show products !!
	showProduct();

	//show difrent in put on change in ride options
	showDifrentWhitRide();
});



function showProduct()
{
	$('.showProduct').click(function(e)
	{
		var iId = $(this).attr('id');

		//get data ajax !
		$.getJSON('/ajax/ajax_getJson.php' , {
			action: 		'getProduct',
			id:             iId
		},function(data)
		{
			msg(data.html);
		});


		e.preventDefault();
		//return false;
	});

}

function showDifrentWhitRide()
{
	$('.rideOption').change(function()
	{
		var sName = $(this).attr('name').replace('][option]', '').replace('rideExtra[', '');
		var sValue =$(this).attr('value');

		if(sValue == 'anders')
		{
			$("input[name='rideExtra["+sName+"][anders]']").css('display', 'inline');
		}
		else
		{
			$("input[name='rideExtra["+sName+"][anders]']").css('display', 'none');
		}

		//console.log(sName);
		//console.log(sValue);

	});
}

/*
 * Check if a user is logged in at server side.
 * Not hack proof, one could manipulate this function (using firebug) to allways return true.
 * Not to be used for validation
 */
function loggedIn()
{
	var sResp = $.ajax(
	{
		url:	'/ajax/ajax_loggedin.php',
		async:	false
	}).responseText;

	return sResp == 'true' ? true : false;
}

/*
 * Display a message box usging color box.
 * Creates the same kind of message as when calling $oTpl->assign('msg', 'My message');
 */
function msg(sMsg, iTimeout, fReturn)
{
	// Clone msgbox params
	var oParams = $.extend({}, oMsgBoxParams);


	// Create the box node
	$msgBox = $('<div />')
				.addClass('colorboxMsg')
				.html(sMsg);

	// Create a node to 'click' on
	$msgClickNode = $('<a />')
						.addClass('cboxMsg')
						.colorbox(oParams)

	// Append to the DOM
	$('body')
		.append($msgBox)
		.append($msgClickNode);

	// Do a click
	$('a.cboxMsg').click();

	if (typeof(iTimeout) == 'number' && iTimeout)
	{
		setTimeout(function()
		{
			$('#cboxClose').click();
		}, iTimeout);
	}

	if (typeof(fReturn) == 'function')
	{
		return fReturn();
	}
}

Confirm = function(sMsg, oOptions, fReturn)
{
	if (typeof(oOptions) == 'function')
	{
		fReturn = oOptions;
	}
	if (typeof(oOptions) != 'object')
	{
		oOptions = {
			'true':  'Ja',
			'false': 'Nee'
		};

	}
	if (typeof(sMsg) != 'string')
	{
		return null;
	}

	sMsg += '<br /><span style="display:inline-block">';
	for (var i in oOptions)
	{
		sMsg += '<a name="button_' + i.toString() + '" class="button" title="' + oOptions[i] + '" style="visibility: visible;"><img src="/gfx/text/button/green/' + oOptions[i] + '.png" alt="' + oOptions[i] + '" /><span></span></a><div class="left">&nbsp;</div>';
	}
	sMsg += '</span>';

	return msg(sMsg, 0, fReturn);
}

function clearForm(form)
{
	$(':input', form).each(function() {
		var type = this.type;
		var tag = this.tagName.toLowerCase(); // normalize case

		if (type == 'text' || type == 'password' || tag == 'textarea')
		{
			this.value = "";
		}
		else
		{
			if (type == 'checkbox' || type == 'radio')
			{
				this.checked = false;
			}
			else
			{
				if (tag == 'select')
				{
					this.selectedIndex = -1;
				}
			}
		}
	});
};

function addPhoto()
{
	data = $('.addPhoto').serializeArray();

	$.getJSON('/ajax/ajax_getJson.php' , {
		action: 		'orderPhoto',
		'data':			data
	},
	function (data)
	{
		// relode to show cart
		//$('html, body').animate({scrollTop:0}, 'fast');
		// go to shop
		window.location = "/shop/winkelwagen-detail"

		//window.location.reload();
	});


}

function addImgMask(node)
{
	$(node).each(function()
	{
		var $node = $(this);
		if($node.parent('span.mask_wrapper').length == 0)
		{
			var $wrapper = $('<span />').addClass('mask_wrapper');
			var $div = $('<div />').addClass($(this).attr('class'));

			var iWidth  = $node.width();
			var iHeight = $node.height();

			if (iWidth > 0 && iHeight > 0)
			{
				$wrapper.width(iWidth).height(iHeight);
				$div.width    (iWidth).height(iHeight);
			}
			else
			{
				/* retry to set the with */
				$node.load(function(){
					var iWidth  = $node.width();
					var iHeight = $node.height();

					$wrapper.width(iWidth).height(iHeight);
					$div.width    (iWidth).height(iHeight);
				});
			}

			$div.append(' \
				<div class="mask_border_tl"></div> \
				<div class="mask_border_tr"></div> \
				<div class="mask_border_bl"></div> \
				<div class="mask_border_br"></div> \
			');

			$node.wrap($wrapper).after($div);

			return true;
		}
		else if ($node.next('div').width() == 0)
		{
			var $wrapper = 	$node.parent('span.mask_wrapper');
			var $div     =  $wrapper.children('div');

			var iWidth  = $node.width();
			var iHeight = $node.height();

			if (iWidth == 0 || iHeight == 0)
			{
				return;
			}

			$wrapper.width(iWidth).height(iHeight);
			$div.width    (iWidth).height(iHeight);
			return true;
		}
		return false;
	});
}

/*
 * Add an span to a/h2.tab button/ image mask
 */
function addButtons()
{

	$("a.button:not(:has(span))").append("<span></span>");
	$("h2.tab:not(:has(span))").append("<span></span>");

	setTimeout(function()
	{
		$('.button')
			.css({'visibility':'visible'})
	}, 400);

}


/* Spinner functions */
function startspinner($node)
{
	if (typeof($node) == 'undefined')
	{
		$node = '#ajax_loader'
	}

	$($node).css('display','inline');

}
function stopspinner($node)
{
	if (typeof($node) == 'undefined')
	{
		$node = '#ajax_loader'
	}

	$($node).css('display','none');
}

function delReaction($clickedNode)
{
	var aItem 		= $clickedNode.attr('id').split('-');
	var mediatype 	= aItem[0].replace('del','');;
	var itemId 		= aItem[1];

	var aCmnt		= $clickedNode.next('span').attr('id').split('-');
	var cmntTbl		= aCmnt[0].replace('del','');
	var cmntId 		= aCmnt[1];

	var pageNum		= $clickedNode.next('span').attr('class');

	if ($clickedNode.parents('.club_my_reactions').length > 0)
	{
		var sIdentifier = "club_my_reactions";
	}
	else
	{
		var sIdentifier = 'general_reactions';
	}

	$.getJSON('/ajax/ajax_getJson.php' , {
		action: 		'deletereaction',
		ident: 			sIdentifier,
		pageNum: 		pageNum,
		mediatype:		mediatype,
		itemId: 		itemId,
		comment_type:	cmntTbl,
		comment_id:		cmntId
	},
	function(data)
	{
		if (typeof(data.error) != 'undefined')
		{
			msg(data.error);
		}
		else if (typeof(data.html) != 'undefined')
		{
			var $identifier = $('div.' + sIdentifier).children('div.block_content');

			$identifier.fadeOut('slow' , function()
			{
				$('#cboxClose').click();

				$identifier.html(data.html);

				// Add some styles
				addButtons();
				addImgMask('img.mask');

				// fading makes the page jump
				$identifier.show();
			});
		}
		else
		{
			msg('Je reactie kon niet worden verwijderd');
		}

	});
}

function getNewRideOption()
{
	var sIdentifier = 'club_create_ride_rideoption';
	var $addButton  = $('div.add_rideoption');

	$.getJSON('/ajax/ajax_getJson.php' , {
		action: 		'getNewRideOption',
		ident:			sIdentifier
	},
	function(data)
	{
		if (typeof(data.error) != 'undefined')
		{
			msg(data.error);
		}
		else if (typeof(data.html) != 'undefined')
		{
			var $identifier = $('div.' + sIdentifier).children('div.block_content');

			$node = $(data.html);

			$block = $node.find('div.rideoption');

			$addButton.prev('br').before($block);
			$node.fadeIn('slow');
		}
	});
}

function formatMoney(sValue)
{
	sValue = sValue.replace('.',',').replace(/([^0-9,])+/g, '');

	if (sValue.indexOf(',') == -1)
	{
		/* 10 euro */
		sValue += ',00';
	}
	else
	{
		var aValue    = sValue.split(',');
		var sDecimals = aValue.pop();
		sValue 	  = aValue.join('');

		if (sValue.length === 0)
		{
			sValue = '0';
		}

		if (sDecimals.length === 0)
		{
			/* 10, euro */
			sValue += ',00';
		}
		else if (sDecimals.length === 1)
		{
			/* 10,2 euro */
			sValue += ',' + sDecimals + '0';
		}
		else if (sDecimals.length == 2)
		{
			/* 10,23 euro */
			sValue += ',' + sDecimals;
		}
		else
		{
			sValue += ',' + sDecimals.substr(0,2);
		}
	}
	return sValue
}

