function validEmail(email) {
    var strReg = "^([a-zA-Z0-9\\-\\.\\_]+)(\\@)([a-zA-Z0-9\\-\\.]+)(\\.)([a-zA-Z]{2,4})$";
    var regex = new RegExp(strReg);
    return(regex.test(email));
}

$(document).ready(function() {
    
	$("#search").focus(function() {
		if ( $(this).val() == "Suche" )
		{
			$(this).val("")	;
		}
	
	});

 	$("#search").blur(function() {
 		if ( $(this).val() == "" )
		{
			$(this).val("Suche");
		}
	
	});
});

function dom_init()
{

	$('.listItem .image img').hover(function(){
		$(this).fadeTo(200, 0.8);
	}, function() {
		$(this).stop().fadeTo(200, 1);			 
	});
	
	// NAVIGATION
	/*
	$('li.current a.head').click(function(){return false});
	$('a.head').not('li.current a.head').click(function() {
		
		$('li ul').not('li.current ul').not($(this).next('ul')).hide(200);
		$(this).next('ul').slideToggle(200);
		
		return false;	
	});
	*/
	
	$('a.tipp').cluetip({
		positionBy: 'mouse',
		//sticky: true,
		//mouseOutClose: true,		
		//delayedClose: 200,
		topOffset: '20px',
		leftOffset: '35px',
		dropShadow: false,
		width: '240px', 
		showTitle: false,
		
		clickThrough:true
		//,		cluetipClass: 'jtip'
	});
	
	$(".colorbox").colorbox({width:"800", height:"600",close:"schließen",iframe:false,scrolling:false});
	$(".colorbox_i").colorbox({width:"800", height:"600",close:"schließen",iframe:true,scrolling:false});
	
	$(".colorbox_en").colorbox({width:"800", height:"600",close:"close",iframe:false,scrolling:false});
	$(".colorbox_i_en").colorbox({width:"800", height:"600",close:"close",iframe:true,scrolling:false});
	
	// MAILTO
	// <a class="mailer" rel="mail/domain.tld" href="#"></a>, <noscript></noscript>	
	$('a.mailer').each(function() {
		e = this.rel.replace('/','@');
		this.href = 'mailto:' + e;
		$(this).text(e);
		$(this).attr("title", "E-Mail schreiben");
	});
	
	
	$('#user_name').focus(function(){
		$('#user_name').removeClass("error");	
		if($('#user_name').val() == 'Name')
		{
			$('#user_name').val('');
		}
	}).blur(function(){
		if($('#user_name').val() == '')
		{
			$('#user_name').val('Name');
		}	
	});
	
	$('#user_email').focus(function(){
		$('#user_email').removeClass("error");	
		if($('#user_email').val() == 'E-Mail')
		{
			$('#user_email').val('');
		}
	}).blur(function(){
		if($('#user_email').val() == '')
		{
			$('#user_email').val('E-Mail');
		}	
	});	
	
	$('#newsletterForm').submit(function(e){
		var error = false;
	
		if($('#user_name').val() == '' || $('#user_name').val()=='Name')
		{
			$('#user_name').addClass("error");
			error = true;
		}
		else
		{
			$('#user_name').removeClass("error");		
		}
		
		if(!validEmail($('#user_email').val()))
		{
			$('#user_email').addClass("error");
			error = true;			
		}		
		else
		{
			$('#user_email').removeClass("error");		
		}

		
		if(error)
		{
			e.preventDefault();
			return false;
		}

		
		
		
	});
	
}

function changepic(bild)
{
	$("#preview").attr("src", bild);
	
	$("#ecard_bild").val(bild);
}
