
	$(document).ready(function()
	{
		/* REPLACE SUBMIT BUTTONS */
		
		replaceSubmitButton("#sidebar .newsletter");
		replaceSubmitButton("#frm_reactie");
		replaceSubmitButton("#frm_contact");
		replaceSubmitButton("#staf");
		replaceSubmitButton("#staf-intern");
		replaceSubmitButton("#weblog .sort");
		replaceSubmitButton("#sidebar .filter-berichten");

		
		/* ART ROTATION HOMEPAGE */
		
		if ($('.more-art img').length > 0) $('.more-art img').artAnimation();

		
		/* CAPTCHA REFRESH */
		
		$('#captcha_refresh').click(function()
		{
			var rand_no = Math.ceil(1000*Math.random())
			$('#captcha_image').attr('src', 'http://dev.solv.nl/captcha/captcha.php?'+rand_no);
			return false;
		});

		
		/* FIX FOR TYPEFACE JS MARGIN */
		
		$('.sifr').css({ marginTop: '5px' });

		
		/* SHOW PRINT BUTTON */

		if (window.print)
		{
			$('#printstaf .print').click(function(){ window.print(); return false; }).css({ display: 'block' });
		}

		/* EXTERNAL LINKS: USE rel=external */
		
		$('a[@rel$=external]').click(function()
		{
			this.target = '_blank';
		})
		.addClass('external');
		
		
		/* SEND TO A FRIEND */
		
		// show send to a friend link
		$('#printstaf .staf').css({ display: 'block' });
		
		// show send to a friend form
		$('#printstaf .staf a').click(function()
		{
			$('#staf').css({ display: 'block' }).fadeIn();

			$('#staf .close').click(function()
			{
				$('#staf .inpt').val('');
				$('#staf').fadeOut();
				return false;
			});
			
			$('#staf').submit(function()
			{
				// validate empty fields
				$("input[value='']", this).addClass('error');
				$("input[value!='']", this).removeClass('error');

				// validate email fields
				if (!validateEmail($("input[name='staf_r_email']", this)))
				{
					$("input[name='staf_r_email']", this).addClass('error');
				}
				else
				{
					$("input[name='staf_r_email']", this).removeClass('error');
				}
				
				if (!validateEmail($("input[name='staf_s_email']", this)))
				{
					$("input[name='staf_s_email']", this).addClass('error');
				}
				else
				{
					$("input[name='staf_s_email']", this).removeClass('error');
				}

				// do not continue with errors
				if ($("input", this).hasClass('error')) return false;
				
				str = $('#staf').serialize();

				$.ajax(
				{
					type: 'POST',
					url: 'ajax/staf.php',
					data: str,
					beforeSend: function()
					{
						 offset = $('#staf').offset();
					
						$('<div></div>').attr(
						{
							id: 'staf_overlay' 
						})
						.css(
						{
							position: 'absolute',
							top: offset['top'],
							left: offset['left'],
							height: $('#staf').outerHeight(),
							width: $('#staf').outerWidth(),
							zIndex: '9999',
							opacity: '0',
							background: '#bbbbbb url(img/loader.gif) no-repeat center center'
						})
						.appendTo('body')
						.fadeTo(200, 0.7);
					},
					success: function(msg)
					{
						$('#staf div').css({ display: 'none' });
						$('#staf .success').fadeIn();
						$('#staf_overlay').css({ display: 'none' });
					}
				});
				
				return false;

			});
			
			return false;
		});
		
		
		$('#blog-post .staf a').click(function()
		{
			//$('#staf-intern').fadeIn();
			//$('#staf-intern').slideDown("slow");
			$('#staf-intern').show('slow');
			
			$('#staf-intern').submit(function()
			{
				// validate empty fields
				$("input[value='']", this).addClass('error');
				$("input[value!='']", this).removeClass('error');

				// validate email fields
				if (!validateEmail($("input[name='staf_r_email']", this)))
				{
					$("input[name='staf_r_email']", this).addClass('error');
				}
				else
				{
					$("input[name='staf_r_email']", this).removeClass('error');
				}
				
				if (!validateEmail($("input[name='staf_s_email']", this)))
				{
					$("input[name='staf_s_email']", this).addClass('error');
				}
				else
				{
					$("input[name='staf_s_email']", this).removeClass('error');
				}

				// do not continue with errors
				if ($("input", this).hasClass('error')) return false;
				
				str = $('#staf-intern').serialize();

				$.ajax(
				{
					type: 'POST',
					url: 'ajax/staf.php',
					data: str,
					beforeSend: function()
					{
						 offset = $('#staf').offset();
					
						$('<div></div>').attr(
						{
							id: 'staf_overlay' 
						})
						.css(
						{
							position: 'absolute',
							top: offset['top'],
							left: offset['left'],
							height: $('#staf-intern').outerHeight(),
							width: $('#staf-intern').outerWidth(),
							zIndex: '9999',
							opacity: '0',
							background: '#bbbbbb url(img/loader.gif) no-repeat center center'
						})
						.appendTo('body')
						.fadeTo(200, 0.7);
					},
					success: function(msg)
					{
						$('#staf-intern div').css({ display: 'none' });
						$('#staf-intern .success').fadeIn();
						$('#staf_overlay').css({ display: 'none' });
					}
				});
				
				return false;

			});
			
			return false;
		});

		
		/* MENSEN TOOLTIP */
		
		$('#mensen ul.mensen li').hover(function(e)
		{
			pos = $(this).offset();
			
			// css hover simulation which IE6 does not support
			$('img', this).css({ marginTop: '-80px' });
			// show tooltip
			$('div', this).css({  top: pos['top']+91, left: pos['left']+45 }).fadeIn(500);
		},
		function()
		{
			// css hover simulation which IE6 does not support
			$('img', this).css({ marginTop: '0' });
			// hide tooltip
			$('div', this).fadeOut(100)
		});

		
		/* ART-DETAIL CAROUSSEL */
		
		if ($('#arts .carrousel').length > 0)
		{
			$("#arts .carrousel").jCarouselLite(
			{
				btnNext: ".carr-next",
				btnPrev: ".carr-prev",
				visible: 5,
				circular: false				
			});
			
			$('#arts .carrousel a').click(function()
			{
				$(this).parents().find('.active').removeClass('active');
				$(this).parents('li').addClass('active');
				$('.vsl img').attr('src', $(this).attr('href'));
				$('.copyright').text($(this).attr('name'));
				
				return false;
			});
		}
		
		
		/* MENS AGENDA DETAIL */
		
		if ($('#mens .agenda').length > 0)
		{
			$('#mens .agenda ul a').click(function() {
				ajaxGetAgendaItems($(this).attr('rel'));
				return false;
			});
		}
		
	});
	
	
	function ajaxGetAgendaItems(agenda_item) {
		$.ajax(
		{
			type: 'POST',
			url: 'ajax/agenda.php',
			data: 'agenda_item='+agenda_item,
			beforeSend: function()
			{
				$('#mens .agenda .items').html('Agendaitem wordt geladen...');
			},
			success: function(msg)
			{
				$('#mens .agenda .items').html(msg);
				
			},
			complete: function ()
			{
				_typeface_js.replaceText(document.getElementById("ajaxAgendaItems"));
				$('#mens .agenda .items h2').css({ visibility: 'visible' });
			}
		});
		
		return false;
	}
	
	
	/* FUNCTION FOR REPLACING SUBMIT BUTTONS WITH TEXT */
	
	function replaceSubmitButton(obj)
	{
		var obj = $(obj);
	
		if (obj.length > 0)
		{
			$("input[type='submit']", obj).replaceWith(
				$('<a tabindex=0"></a>').html($("input[type='submit']", obj).val()).click(function()
				{
					obj.submit();
				})
				.addClass('sbmt_replaced')
				.attr('tabindex', '0')
				.focus(function(){ $(this).css('outline', 'black dotted thin'); })
				.blur(function(){ $(this).css('outline', '0'); })
				.keypress(function(e)
				{
					if (e.which == 13) obj.submit();
				})
			);
		}
	}

	
	/* FUNCTION FOR VALIDATING EMAIL */
	
	function validateEmail(elm)
	{
		regexp_mail = /^[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)*@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/;
		return regexp_mail.test($(elm).val());
	}
