$(document).ready(function() {

	$("#searchtext").click(function() {
		if ($(this).val() == "Search") {
			$(this).val("");
		}
	}).blur(function() {
		if ($(this).val() == "") {
			$(this).val("Search");
		}
	});

	$("#contactform").formvalidate();
	$(".slideshow").slideshow();

});

/**
 * Slideshow
 */
(function($) {
	$.fn.slideshow = function() {
		
		return this.each(function() {
			
			var $this = $(this);
			var imgs = $this.find("img");

			$this.find("img:first")
				.show()
				.addClass("act");

			setInterval("autoplay()", 4500);

			autoplay = function() {

				var act = $this.find(".act");

				var next = act.next();
				if (! next.length) {
					next = $this.find("img:first");
				}

				imgs.fadeOut(300);
				next.fadeIn(300);

				imgs.removeClass("act");
				next.addClass("act");
			}
		});
	}
})(jQuery);

/**
 * Formvalidation
 */
(function($) {
	$.fn.formvalidate = function() {
		
		return this.each(function() {
			
			var $this = $(this);
			
			$this.submit(function() {
				
				var valid = true;
				
				$this.find('.notempty').each(function() {
					if ($.trim($(this).val()) == '') {
						$(this).addClass('error');
						valid = false;
					}
					else {
						$(this).removeClass('error');
					}
				});
				
				$this.find('.email').each(function() {
					if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test($(this).val())) {
						$(this).removeClass('error');
					}
					else {
						$(this).addClass('error');
						valid = false;
					}
				});
				
				if (!valid) {
					return false;
				}
			})
		});
	}
}) (jQuery);



