$(document).ready (function ()
{

	$('.email').each (function ()
	{
		address = $(this).text ();
		new_address = address.replace("{at}", "@");
		$(this).text (new_address);
		$(this).attr ('href', 'mailto:' + new_address);
	});
	
	if ($("#portfolio-slider").length)
	{
		$("#portfolio-slider").codaSlider({
			dynamicArrows: false,
			dynamicTabs: false,
			autoSlideStopWhenClicked: true
		});
		
		$('.panel').quickFlip({
			closeSpeed : 250,
			openSpeed : 250
		});
		
		for ( var i = 0; i < $.quickFlip.wrappers.length; i++ ) {
			var thisOne = $.quickFlip.wrappers[i];

			$( thisOne.wrapper ).click( function(ev) {
				var $target = $(ev.target);
				if ( !$target.hasClass('panel') ) $target = $target.parent();
				
				$target.quickFlipper();
				
			}, function() {});
		}
	}
	
	$('#name').required();
	$('#email').required();
	$('#subject').required();
	$('#message').required();
	
	if ($('#contactform').length)
	{
		jQuery.validator.addMethod("req", function(value, element) 
		{
			if ($(element).val () == 'Dit is een verplicht veld')
				return false;
			return true;
		},
		'ERROR');
		
		$("#contactform").validate({
			rules: {
				name: {
					required: true,
					req: true
				},
				email: {
					required: true,
					email: true,
					req: true
				},
				subject: {
					required: true,
					req: true
				},
				message: {
					required: true,
					req: true
				}
			},
			
			messages: {
				name: "ERROR",
				email: "ERROR",
				subject: "ERROR",
				message: "ERROR"
			},
			
			errorPlacement: function(error, element) {
			console.log('error');
				error.appendTo( element.parent().next() );
			},
			
			highlight: function(element, errorClass) {
				$(element).addClass (errorClass);
				// $(element).addClass(errorClass).parent().prev().children("select").addClass(errorClass);
			}
		});
	}
	
	
	// $("a").click(function(event){
		// event.preventDefault();
		// $('.next-page-slide').css ('background', '#000000')
		// $('.next-page-slide').css ('width', $(document).width());
		
		// $(".next-page-slide").stop().animate({
			// marginLeft: '-'+$(document).width()
		// }, 500, function(){
			// $('.page-slide').remove ();
			// $(this).removeClass ('next-page-slide');
			// $(this).addClass ('page-slide');
			
			// $(this).children(".header-stat:last").after($(this).children(".header-stat:first"));
			// $(this).css("marginLeft", 0);
		// });
	// });
	
	$('.newwindow').each (function ()
	{
		$(this).attr ('target', '_blank');
	});
	
});


jQuery.fn.required = function ()
{

	return this.each(function ()
	{
		$(this).css ('color', '#a1a1a1');
		$(this).css ('font-style', 'italic');
		$(this).val ('Dit is een verplicht veld');

		$(this).blur (function ()
		{
			if ($(this).val () == '')
			{
				$(this).css ('color', '#a1a1a1');
				$(this).css ('font-style', 'italic');
				$(this).val ('Dit is een verplicht veld');
			}

		});

		$(this).focus (function ()
		{
			if ($(this).val () == 'Dit is een verplicht veld')
			{
				$(this).val ('');
				$(this).css ('color', '#000000');
				$(this).css ('font-style', 'normal');
			}
		});
	});
}
