
function test110307(cur_img,cur_gal_id) {
	$(cur_img).each(function(idx){
	    $(this).attr('id', 'slide_'+cur_gal_id+'_'+idx);
	    
	    var imgW = $(this).width();
	    var imgH = $(this).height();
	    
	    //alert('W: '+imgW+' | H: '+imgH);
	    
	    if ((imgH > imgW)&&(imgH > 294)) {
	    	if (294 * ($(this).width() / $(this).height()) < 462) {
	    		var newWidth = 294 * ($(this).width() / $(this).height());
	    		
	    		$(this).height(294);
	    		$(this).width(newWidth);
	    		imgW = newWidth;
	    		imgH = 294;
	    	} else {
	    		var newHeight = 462 * ($(this).height() / $(this).width());
	    		
	    		$(this).height(newHeight);
	    		$(this).width(462);
	    		imgW = 462;
	    		imgH = newHeight;
	    	}
	    } else if ((imgH < imgW)&&(imgW > 462)) {
	    	if (462 * ($(this).height() / $(this).width()) < 294) {
	    		var newHeight = 462 * ($(this).height() / $(this).width());
	    		
	    		$(this).height(newHeight);
	    		$(this).width(462);
	    		imgW = 462;
	    		imgH = newHeight;
	    	} else {
	    		var newWidth = 294 * ($(this).width() / $(this).height());
	    		
	    		$(this).height(294);
	    		$(this).width(newWidth);
	    		imgW = newWidth;
	    		imgH = 294;
	    	}
	    }
	    
	    var imgX = (462 - imgW) / 2 + 10;
	    var imgY = (294 - imgH) / 2;
	    $(this).css('position','absolute').css('left',imgX).css('top',imgY).css('z-index','0');
	    
	    if(idx == '0'){$(this).addClass('aktiv').css('z-index','10');}else{$(this).css('display','none');}
	});
} //test


$(document).ready(function(){
	
	var afEmail = true;
	
	if($('.ttprevImg > img') !== undefined || $('.ttprevImg > img') != null){
		$('.ttprevImg > img').attr('src', '/fileadmin/template/images/veranstaltung_img.gif');
	}
	
	function checkWidth() {
		if($('#wrapper.start').length == 0){
			if ( $(window).width() < '1170' ) {
				$('body').removeClass().addClass('small');
			} else if (( $(window).width() >= '1170') && ( $(window).width() <= '1278' )) {
				$('body').removeClass().addClass('medium');
			} else {
				if($('#banner').length == 0){
					$('body').removeClass().addClass('medium');
				} else {
					$('body').removeClass();
				}
			}
		} else {
			if (( $(window).width() >= '1170') && ( $(window).width() <= '1278' )) {
				$('body').removeClass().addClass('medium');
			} else {
				$('body').removeClass();
			}
		}
	}
	
	$(window).resize(checkWidth);
	checkWidth();
	
	$('#headerDropdown').hover(function(){
		$('#headerDropdown ul').show();
	}, function(){
		$('#headerDropdown ul').hide();
	});
	
	$('#suchfeld').focus(function(){
		if (afEmail == true) {
			$(this).val('');
			afEmail = false;
		}
	});
	
	if($('.hdb_galerie').length != 0){
		$('.hdb_galerie').each(function(){
		
			$('.slideshow_wrapper').removeClass('noJS');
		
			var cur_gal_id = $(this).attr('id');
			cur_gal_id = cur_gal_id.slice(12, cur_gal_id.length);
			var cur_gal = '#'+$(this).attr('id')+' ';
			var cur_img = '#'+$(this).attr('id')+' .pics img';
			var cur_desc_con = '#'+$(this).attr('id')+' .csc-textpic-caption';
			
			//if($(cur_desc_con).length != 0){
				var test = $(cur_desc_con).find('img');
				$(cur_desc_con).find('img').remove();
			
				var cur_desc = $(cur_desc_con).html();
			
				$(cur_desc_con).before(test);
				$(cur_desc_con).remove();
			/*} else {
				var cur_desc = '';
			}*/
		
			if (cur_desc != null) {
				var maxPic = $('#hdb_galerie_'+cur_gal_id+' .slideshow_wrapper img').length;
				$('#'+$(this).attr('id')+' .pics').after('<p>'+cur_desc+'</p><p class="picNumber"><span class="currentPic">1</span>/<span class="maxPic">'+maxPic+'</span></p><img class="slide_back" alt="Zurück" src="/fileadmin/template/images/prev.png" /><img class="slide_next" alt="Weiter" src="/fileadmin/template/images/next.png" />');
			} else {
				var maxPic = $('#hdb_galerie_'+cur_gal_id+' .slideshow_wrapper img').length;
				if (maxPic < '2') {
					$('#hdb_galerie_'+cur_gal_id).addClass('oneImageNoCaption');
				}
				$('#'+$(this).attr('id')+' .pics').after('<img class="slide_back" alt="Zurück" src="/fileadmin/template/images/prev.png" /><img class="slide_next" alt="Weiter" src="/fileadmin/template/images/next.png" />');
			}
			
			
			//var maxPic = $('#hdb_galerie_'+cur_gal_id+' .slideshow_wrapper img').length;
			//$('#'+$(this).attr('id')+' .slideshow_wrapper').after('<p>'+ cur_desc +'</p>').after('<p class="picNumber"><span class="currentPic">1</span>/<span class="maxPic">'+maxPic+'</span></p>');
			
			if (maxPic > 1) {
				$(cur_gal+'.slide_next').click(function(){
					var actGal = '#'+$(this).parent().attr('id');
					var actGalImg = '#'+$(this).parent().attr('id') + ' .aktiv';
					var actGalID = $(this).parent().attr('id').slice(12, $(this).parent().attr('id').length);
					var actImg = $(actGalImg).attr('id');
					actImg = actImg.slice(actImg.lastIndexOf('_') + 1, actImg.length);
					var actImg1 = actImg;
					actImg1++;
					var nextImg = actImg1;
					//alert('Old: '+actImg+' Next: '+nextImg);
					
					if($('#slide_'+actGalID+'_'+nextImg).length == 0){
						nextImg = 0;
					}
					
					$(actGal+' #slide_'+actGalID+'_'+nextImg).css('z-index','5').fadeIn('slow',function(){
						$(this).css('display','block');
					});
					$(actGal+' #slide_'+actGalID+'_'+actImg).fadeOut('slow',function(){
						$(this).removeClass('aktiv').css('z-index','0');
						$(actGal+' #slide_'+actGalID+'_'+nextImg).addClass('aktiv').css('z-index','10');
						$(actGal+' .currentPic').html(nextImg + 1);
					});
				});
				
				$(cur_gal+'.slide_back').click(function(){
					var actGal = '#'+$(this).parent().attr('id');
					var actGalImg = '#'+$(this).parent().attr('id') + ' .aktiv';
					var actGalID = $(this).parent().attr('id').slice(12, $(this).parent().attr('id').length);
					var actImg = $(actGalImg).attr('id');
					actImg = actImg.slice(actImg.lastIndexOf('_') + 1, actImg.length);
					var actImg1 = actImg;
					actImg1--;
					var nextImg = actImg1;
					//alert('Old: '+actImg+' Next: '+nextImg);
					if($('#slide_'+actGalID+'_'+nextImg).length == 0){
						var lastImg = $(actGal+' .pics img').length - 1;
						nextImg = lastImg;
					}
					$(actGal+' #slide_'+actGalID+'_'+nextImg).css({'z-index' : '5' , 'display' : 'block'});
					$(actGal+' #slide_'+actGalID+'_'+actImg).fadeOut('slow',function(){
						$(this).removeClass('aktiv').css({'z-index' : '0'});
						$(actGal+' #slide_'+actGalID+'_'+nextImg).addClass('aktiv').css({'z-index' : '10'});
						$(actGal+' .currentPic').html(nextImg + 1);
					});
				});
			} else {
				$(cur_gal+'.slide_next').remove();
				$(cur_gal+'.slide_back').remove();
				$(cur_gal+'.picNumber').remove();
			}
			/*
			$(cur_img).each(function(idx){
				$(this).attr('id', 'slide_'+cur_gal_id+'_'+idx);
				
				var imgW = $(this).width();
				var imgH = $(this).height();
				
				//alert('W: '+imgW+' | H: '+imgH);
				
				if ((imgH > imgW)&&(imgH > 294)) {
					if (294 * ($(this).width() / $(this).height()) < 462) {
						var newWidth = 294 * ($(this).width() / $(this).height());
						
						$(this).height(294);
						$(this).width(newWidth);
						imgW = newWidth;
						imgH = 294;
					} else {
						var newHeight = 462 * ($(this).height() / $(this).width());
						
						$(this).height(newHeight);
						$(this).width(462);
						imgW = 462;
						imgH = newHeight;
					}
				} else if ((imgH < imgW)&&(imgW > 462)) {
					if (462 * ($(this).height() / $(this).width()) < 294) {
						var newHeight = 462 * ($(this).height() / $(this).width());
						
						$(this).height(newHeight);
						$(this).width(462);
						imgW = 462;
						imgH = newHeight;
					} else {
						var newWidth = 294 * ($(this).width() / $(this).height());
						
						$(this).height(294);
						$(this).width(newWidth);
						imgW = newWidth;
						imgH = 294;
					}
				}
				
				var imgX = (462 - imgW) / 2 + 10;
				var imgY = (294 - imgH) / 2;
				$(this).css('position','absolute').css('left',imgX).css('top',imgY).css('z-index','0');
				
				if(idx == '0'){$(this).addClass('aktiv').css('z-index','10');}else{$(this).css('display','none');}
			});
			*/
			setTimeout('test110307(\''+cur_img+'\',\''+cur_gal_id+'\')',500);
		});
	}
});

function checkNewsletterForm() {
	validity = true;
    var kontakt = true;
    var email = true;
    var anrede = true;
    var vorname = true;
    var nachname = true;
    var fehler = "";
    var fehlerfarbe = "#da0127";
    var okfarbe = "#516369";
    
    if (document.FormOptIn.Email.value == "") {
        document.getElementById('titel_email').style.color = fehlerfarbe;
        validity = false;
        kontakt = false;
    } else {
        var str = document.FormOptIn.Email.value;
        var filter = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
    	
        if (filter.test(str)) {
            document.getElementById('titel_email').style.color = okfarbe;
        } else {
            document.getElementById('titel_email').style.color = fehlerfarbe;
            validity = false;
            email = false;
        }
    }
    
    if (document.FormOptIn.Anrede.value == "") {
        document.getElementById('titel_anrede').style.color = fehlerfarbe;
        validity = false;
        anrede = false;
    } else {
        document.getElementById('titel_anrede').style.color = okfarbe;
    }
    
    if (document.FormOptIn.Vorname.value == "") {
        document.getElementById('titel_vorname').style.color = fehlerfarbe;
        validity = false;
        vorname = false;
    } else {
        document.getElementById('titel_vorname').style.color = okfarbe;
    }
    
    if (document.FormOptIn.Nachname.value == "") {
        document.getElementById('titel_nachname').style.color = fehlerfarbe;
        validity = false;
        nachname = false;
    } else {
        document.getElementById('titel_nachname').style.color = okfarbe;
    }
    
    if (kontakt == false) {
        fehler += "Bitte geben Sie Ihre E-Mail Adresse an.<br />";
    }
    
    if (email == false) {
        fehler += "Bitte &uuml;berpr&uuml;fen Sie Ihre E-Mail Angabe.<br />";
    }
    
    if ((anrede == false) || (vorname == false) || (nachname == false)) {
        fehler += "Bitte f&uuml;llen Sie alle Felder aus..<br />";
    }
    
    document.getElementById('errors').style.color = fehlerfarbe;
    
    if (validity == false) {
        document.getElementById('errors').innerHTML = fehler;
    } else {
        document.getElementById('errors').innerHTML = "";
    }
    
    return validity;
}
