// JavaScript Document

//Quelle: http://www.white-hat-web-design.co.uk/articles/js-validation.php
function validate(email) {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,6})$/;
   if(reg.test(email) == false) {
      alert('Fehlerhafte Email-Adresse.');
      return false;
   } else {
   	return true;
   }
}

var el_index = 0;

function fnCycleLogos() {
	jQuery(function($) {
		var l = $('#logoticker img').length;
		var h = $('#logoticker').height();
		var b = $('#logoticker').width();
		if (el_index > 0) {
			$('#logoticker img:eq('+(el_index-1)+')').animate({'opacity':'0'},800, function() {
				$(this).css('display','none');
			});
		}
		var top = parseInt( (h / 2) - ($('#logoticker img:eq('+el_index+')').height() / 2) , 10);
		var left = parseInt( (b / 2) - ($('#logoticker img:eq('+el_index+')').width() / 2) , 10);
		$('#logoticker img:eq('+el_index+')').css({
			'top':top,
			'left':left
		});
		$('#logoticker img:eq('+el_index+')').css('display','block').animate({'opacity':'1'},800);
		el_index++;
		if (el_index >= l) {
			$('#logoticker img:eq('+(el_index-1)+')').animate({'opacity':'0'},800, function() {
				$(this).css('display','none');
			});
			el_index = 0;
		}
	})
}

var news_index = 1;

function fnCycleNewsticker() {
	jQuery(function($) {
		var l = $('div.newsticker div.newsentry_next').length;
		var inhalt = $('div.newsticker div.newsentry_next:eq('+news_index+')').html();
		$('div.newsticker div.newsentry').fadeOut('slow', function() {
			$('div.newsticker div.newsentry').html(inhalt);
			news_index++;
			if (news_index >= l) {
				news_index = 0;
			}
		}).fadeIn('slow');
	})
}

var news_interval = null;

jQuery(function($) {
$(document).ready(function() { 
	if ($('#logoticker').length > 0) {

		$('#logoticker img').css({
			'opacity': '0'
		});
		var $logo = $('#logoticker');
		$logo.removeClass('hide');

		var h = $('#logoticker').height();
		var b = $('#logoticker').width();
		var top = parseInt( (h / 2) - ($('#logoticker img:eq('+el_index+')').height() / 2) , 10);
		var left = parseInt( (b / 2) - ($('#logoticker img:eq('+el_index+')').width() / 2) , 10);
		$('#logoticker img:eq('+el_index+')').css({
			'top':top,
			'left':left
		});

		$('#logoticker img:eq(0)').show().css('opacity',1);
		setInterval("fnCycleLogos()",3000);
	}
	
	if ($('div.newsticker').length > 0) {
		news_interval = setInterval("fnCycleNewsticker()",5000);
	}
	$('div.newsticker').hover(function() {
		clearInterval(news_interval);
	}, function() {
		news_interval = setInterval("fnCycleNewsticker()",5000);
	})

	//Mainmenu hover----------------------
		$('.mainmenu .menu a.first').hover(
      		function(){$('div.bbar_l').show();}, 
      		function(){$('div.bbar_l').hide();}
    	);
		$('.mainmenu .menu a.last').hover(
      		function(){$('div.bbar_r').show();}, 
      		function(){$('div.bbar_r').hide();}
    	);
		
		$('.mainmenu .menu a.first').blur(function(){$('div.bbar_l').hide();});
	    $('.mainmenu .menu a.first').focus(function(){$('div.bbar_l').show();});
		$('.mainmenu .menu a.last').blur(function(){$('div.bbar_r').hide();});
	    $('.mainmenu .menu a.last').focus(function(){$('div.bbar_r').show();});

		if($('.mainmenu .menu a.first').hasClass('active')) $('div.bbar_l').addClass('show');
		if($('.mainmenu .menu a.last').hasClass('active')) $('div.bbar_r').addClass('show');
		


	//Referenzen: Logos ein- und ausblenden------------------------
		$('a.ref').click(function(event) {
			event.preventDefault();
			$(this).toggleClass("active").blur();
			$(this).siblings('a.ref').removeClass('active');
			
			$('.references img').stop().fadeTo(500,1);
			
			var check = $('a.ref').hasClass('active');
			
			if( check==true ) {
				if( $(this).hasClass('merp')) {
					$("img.ref_commsult").stop().fadeTo(500,0.1);
				} else {
					$("img.ref_merp").stop().fadeTo(500,0.1);
				}
			}
		});
		
	
	//Cuf�n als Schriftersatz mit Canvas und VML
		
	Cufon.replace('a.stag', {hover: true});
	Cufon.replace('.c_left h1');
	Cufon.replace('.c_picture .bubble');
	Cufon.replace('.c_picture .bubble_small');
	Cufon.replace('#baustelle');
	Cufon.replace('.stag');

	Cufon.replace('.pagecontent h1');
	if ($('.bulletlist').length > 0) {
		Cufon.replace('.bulletlist');
	}
	if ($('.questions').length > 0) {
		Cufon.replace('.questions');
	} 
	
	
	
	//Newsletter validate------------------------------
	$('#newsletter').submit(function() {
		var email = $(this).find('#nlmail').val();
		return validate(email);
	})

});
});

