	$(document).ready(function(){		
		
			/* Plugin for reversing an array */
			jQuery.fn.reverse = [].reverse;
		
			/* Plugin for Preloading Images */
			(function($) {
				  var cache = [];
				  // Arguments are image paths relative to the current page.
				  $.preLoadImages = function() {
				    var args_len = arguments.length;
				    for (var i = args_len; i--;) {
				      var cacheImage = document.createElement('img');
				      cacheImage.src = arguments[i];
				      cache.push(cacheImage);
				    }
				  }
			})(jQuery)
				
			
			/*preload dropdown background image*/
			jQuery.preLoadImages('fileadmin/templates/images/bkg_dropdown.png');
			
			/*Slideshow Home*/ 
			$('.slideshow').cycle({
				fx: 'fade',
				//timeout: 8500,
				timeout: 0,
				speed:2000
			});
		
			/*
			 * Timout for handling mouseenter and mouseleave fading
			 */
			$delayTimeout = false;
			
			/*
			 * Social Media Buttons Mousover
			 */
			$("div#footer ul.social_links li a").mouseenter(function(){
				
				$("div#footer ul.social_links li span.social_title").text($(this).attr('title'));
				$(this).children('img').attr('src', ('fileadmin/templates/images/social/'+$(this).attr('rel')+"-over.png"));
				
			});
			/*
			 * Social Media Buttons Mouseleave
			 */
			$("div#footer ul.social_links li a").mouseleave(function(){
				
				$("div#footer ul.social_links li span.social_title").text('');
				$(this).children('img').attr('src', ('fileadmin/templates/images/social/'+$(this).attr('rel')+'.png'));
				
			});			
			
			/*Fix Teasers in Content-Area, so that only 2 Teasers can be next to each other*/
			slidercounter=1;
			$("div#content div.left > div.teaser").each(function(){
				
				if(slidercounter%2==1){
					$(this).css('clear', 'both');
				}
				slidercounter++;
			
			});
			
			/*
			 * Make sure first Menu-Item of News / Seminars Catmenu and Amenu is selected
			 */
			CatMenuHasClass=false;
			$("ul.catmenu li").each(function(){
				if($(this).children('div').children('span').hasClass('active')){
					CatMenuHasClass=true;
				}			
			});
			
			
			$("ul.catmenu li.level1:first").remove();
			if(CatMenuHasClass===false){
				$("ul.catmenu li:nth-child(2)").addClass('active');
			}
			
			
			AMenuHasClass=false;
			$("ul.news_amenu li").each(function(){
				if($(this).hasClass('amenu-act')){
					AMenuHasClass=true;
				}			
			});

			if(AMenuHasClass===false){
				//$("ul.news_amenu li:nth-child(2)").addClass('amenu-act');
			}
			
			/* Dropdown menu Enter */
			$("ul.dropdown > li > a").mouseover(function () {
				
				if(!$(this).hasClass('activemenu')){
					
					//fade out all dropdown which where previous activaed
				    $('ul.sub').css('display', 'none');
				    $("ul.dropdown li div").css('display', 'none');
					$("ul.dropdown li div").css('background', '#fff');
					$("ul.dropdown li div").css('padding-right', '0px');
					
					
					
					//remove activeclass of all links to decolour them
				    $("ul.dropdown > li > a").removeClass('activemenu');
				    
				    //add activeclass to link to colour it
				    $(this).addClass('activemenu');
				    
				    //add activeclass to make the li big
				    $(this).parent().parent().addClass('activemenu');	    
				    
				    //set witdth of the absolute positioned div, but not if there is only one child UL (standard is 2 child ULs)
				    if($(this).parent().children('div').children('ul').size()>1){
				    	$(this).parent().children('div').css('width', $(this).parent().parent().css('width'));
				    
				    	//set left of the absolute position div bei getting position of menu
				    	$offsetMenu=($(this).parent().parent().offset());
				    	$offsetLi=$(this).parent().offset();
				    	
				    	$(this).parent().children('div').css('left', $offsetMenu.left - $offsetLi.left);
				    }else{
				    	$(this).parent().children('div').css('width', $(this).parent().css('width'));
				    }
					
					$(this).parent().children('div').stop(true,true).fadeIn(
							500,
							function(){
								$(this).css('background', 'url(\'fileadmin/templates/images/bkg_dropdown.png\') top right');
								$(this).css('padding-right', '7px');
							}
					);
										
					$(this).parent().children('div').children('ul').fadeIn(1);
				}
				
			});
			
			
			/* Dropdown menu Leave */
			$("ul.dropdown").mouseleave(function(){
				
				//remove activeclass to link to decolour it
			    $("ul.dropdown > li > a").removeClass('activemenu');
			    
				 //remove activeclass to make the li small again
				$("ul.dropdown").removeClass('activemenu');
				
				$("ul.dropdown li div").stop(true,true);
				$("ul.dropdown li ul").stop(true,true);
				//fade out the div with the submenu
				$("ul.dropdown li div").css('background', '#fff');
				$("ul.dropdown li div").css('padding-right', '0px');
				
				$("ul.dropdown li div").fadeOut(500);
				$("ul.dropdown li ul").fadeOut(100);
			
			});
			
			
			
			
			
			

			/* contentimage dropup menu Enter */
			$("div#contentimage > ul > li > a").mouseenter(function () {
				
				if(!$(this).hasClass('activemenu')){
					
						//fade out the ul with the submenu		
						$("div#contentimage ul li ul li").css('display', 'none');
						
						//remove activeclass of all links to decolour them
					    $("div#contentimage > ul > li > a").removeClass('activemenu');

					    //add activeclass to link 
					    $(this).addClass('activemenu');
					    
						$(this).parent().children('ul').css('display', 'block');
						
						$childElements = $(this).parent().children('ul').children('li');
						$childElements.reverse().each(function(i){
				
							$(this).delay(i*100).fadeIn(300);

						});
						
				}
				
			});

			
			/* contentimage dropup menu Leave */
			$("div#contentimage > ul > li").mouseleave(function(){

				//remove activeclass to link to decolour it
			    $("div#contentimage > ul > li > a").removeClass('activemenu');
			    
				//fade out the ul with the submenu		
				$("div#contentimage ul li ul li").fadeOut(500);

				//resume cycling starting at the first image
				
				if($delayTimeout){
					clearTimeout($delayTimeout);
				}

				$('.slideshow img').css('z-index','1');
				
			
				$delayTimeout = setTimeout(function() { 

					$('.slideshow img').stop(true).animate({
						opacity:0
					});
					
					$('.slideshow img').eq(0).css('z-index','7');
					$('.slideshow img').eq(0).css('display','block');
					$('.slideshow img').eq(0).stop(true).animate({
						opacity:1
					}, 700);
					
					$('.slideshow').cycle(0);
					$('.slideshow').cycle('resume');
				
				}, 100);
			 	
				
				

				
			});			
			
			
			
			/* contentimage dropup menu li enter for image switch */
			/*
			$("div#contentimage ul li a").mouseenter(function () {				
				
				//Wenn ein untermenü ul li ul li angeklickt wurde
				if($(this).parent().parent().parent().is('li')){
					
					//dann wird der index des parent ul li herausgefunden
					//alert($(this).parent().parent().index());
					$parentIndex = $(this).parent().parent().parent().index();
					
					if($parentIndex>0){
						$imageIndex = ($(this).parent().size()-$(this).parent().index())+5;
					}else{
						$imageIndex = ($(this).parent().size()-$(this).parent().index())+2;
					}

				}else{
					
					//sonst wird der index des momentanen li herausgefunden
					//alert($(this).index());
					$parentIndex = $(this).parent().index();
					
					//wenn es nicht das allererste Element ist wird die Anzahl der Kinder der vorherigen Elemten addiert
					if($parentIndex>0){
						$imageIndex = $(this).parent().index()+3;
					}else{
						$imageIndex = $parentIndex+1;
					}
					
				}
				
				if($delayTimeout){
					clearTimeout($delayTimeout);
				}
						
				$('.slideshow').cycle('pause');
				
				//$delayTimeout = setTimeout(function() { 
				//	$('.slideshow').cycle($imageIndex); 
				//}, 700);
			
				$('.slideshow img').css('z-index','1');
				

				
				$('.slideshow img').stop(true).animate({
					opacity:0
				}, 700);
				
	
				$('.slideshow img').eq($imageIndex).css('z-index','7');
				$('.slideshow img').eq($imageIndex).css('display','block');
				$('.slideshow img').eq($imageIndex).stop(true).animate({
					opacity:1
				}, 700);

			
			});
			*/
			

			/* contentmenu lawyer menu li enter for image switch */
			
			$("div.left ul.contentmenu > li > a").click(function () {
	
				$imageIndex = $(this).parent().index();
				
				if($delayTimeout){
					clearTimeout($delayTimeout);
				}
				
				if($('#contentimage-small img').eq($imageIndex).css('opacity')==1&&$('#contentimage-small img').eq($imageIndex).css('z-index')==7){
					
					$('#contentimage-small img').stop(true).animate({
						opacity:0
					});
					
					$('#contentimage-small img').eq(5).css('z-index','7');
					$('#contentimage-small img').eq(5).css('display','block');
					$('#contentimage-small img').eq(5).stop(true).animate({
						opacity:1
					}, 700);
					return false;
				}

				$('#contentimage-small img').eq($imageIndex).css('opacity',0);					
			
				
				$('#contentimage-small img').stop(true).animate({
					opacity:0
				}, 700);
				
				$('#contentimage-small img').eq($imageIndex).css('z-index','7');
				$('#contentimage-small img').eq($imageIndex).css('display','block');
				$('#contentimage-small img').eq($imageIndex).stop(true).animate({
					opacity:1
				}, 700);
			
			});		

			/* contentmenu lawyer menu li leave for image switch 
			$("div.left ul.contentmenu > li").mouseleave(function () {
	
				if($delayTimeout){
					clearTimeout($delayTimeout);
				}

				$('#contentimage-small img').css('z-index','1');
				
			
				$delayTimeout = setTimeout(function() { 

					$('#contentimage-small img').stop(true).animate({
						opacity:0
					});
					
					$('#contentimage-small img').eq(5).css('z-index','7');
					$('#contentimage-small img').eq(5).css('display','block');
					$('#contentimage-small img').eq(5).stop(true).animate({
						opacity:1
					}, 700);
				
				
				}, 100);
				
			
			});					
			*/
			
			
			/*Image with Imagetext enter*/
			$("div#contentimage-small").mouseenter(function(){
				if($(".bottomside")){
					$(".bottomside").fadeIn(300);
				}
			});

			
			/*Image with Imagetext leave*/
			$("div#contentimage-small").mouseleave(function(){
				if($(".bottomside")){
					$(".bottomside").fadeOut(300);
				}
			});
			
			
			
			/*Quicklink menu enter and leave*/
			$("div.quicklinks a").click(function () {
				
				if($(this).hasClass('activemenu')){
					
					$(this).removeClass('activemenu');
					$(this).parent('div').animate({
						height:'40px'
					});
					return false;
					
				}else if(!$(this).hasClass('arrow')){
					
					$(this).addClass('activemenu');
					$(this).parent('div').animate({
						height:'157px'
					});
					return false;
				}
				
				
				
			});
			
			/*Quicklink input enter*/
			$("div.quicklinks input").focus(function(){
				
				$(this).css('color','#666');
				
				if($(this).val()=="Nummer eingeben"){
					$(this).val("");
				}
				
			});
			
			/*Quciklink input blur*/
			$("div.quicklinks input").blur(function(){
				if($(this).val()==""){
					$(this).css('color','#ccc');
					$(this).val("Nummer eingeben");
				}
			});
			
			/*Aufklapp Teaser Form*/
			$('div.right .tx-powermail-pi1').css('display','none');
			$('div.right .tx-powermail-pi1').prev('.csc-header').addClass('clickable');
			$('div.right .tx-powermail-pi1').prev('.csc-header').click(function(){
				if($(this).hasClass('active')){
					$(this).removeClass('active');
					$(this).next('.tx-powermail-pi1').slideUp();
				}else{
					$(this).addClass('active');
					$(this).next('.tx-powermail-pi1').slideDown();
				}
				
			})
			
			$('div.right .powermail_submit').click(function(){
				
				
				if($('div.right .powermail_text').attr('value')==""){
					$('div.right .powermail_text').css('border', '1px solid #9b2e30');
					$('div.right .powermail_text').css('height', '18px');
					return false;
				}
			})
			
			$.fn.unwrap = function() {
			  this.parent(':not(body)')
			    .each(function(){
			      $(this).replaceWith( this.childNodes );
			    });
			
			  return this;
			};


			//$('ul.catmenu > a > li').unwrap();
			
			
			/*Contentmenu with default open Menulist*/
			$("ul.contentmenu > li.open > ul").css('display', 'block');
			
			
			
			/*Contentmenu Toogle Fader | Lawyersmenu */
			$("ul.contentmenu > li > a").click(function(event){

				/*Fade Toggle the white background of the Title */
				$("ul.contentmenu > li.open > div").fadeToggle('middle');
				
				var finishedAnimation = false;
				
				$("ul.contentmenu > li.open").animate({
				    paddingBottom: 0
				  }, 500);
				  
				/*Fade Out and hide all opened*/
				$("ul.contentmenu > li.open > ul").animate({
				    opacity: 0,
				    height: 'toggle'
				  }, 500, function(){

						$(this).parent().removeClass('open');
					  	/*$(this).parent().css('');*/
						
				  });
				
			
				/*If clicked element isnt open then open it up*/
				if(!$(this).parent().hasClass('open')){
					
					$(this).parent().animate({
					    paddingBottom: '20px'
					  }, 500);
					
					$(this).parent().find('ul').animate({
					    opacity: 1,
					    height: 'toggle'
					  }, 500);
					
					//$(this).parent().toggleClass('open');
					$("ul.contentmenu > li").removeClass('open');
					$(this).parent().addClass('open');
					$(this).parent().find('div').fadeToggle('slow');
				}
				
				
				/*Return False so that the clicked link doesnt change the URL */
				return false;
			});	
			
			
			
			/**
			 * Lawyers Searchfield
			 */
			
			$('.lawyer_search_input').focus(function(){
			
				if($(this).val()=='Namen eingeben'){
					$(this).val('');
				}
					
			});
			
			$('#event_participant_add').click(function(){
				
				participants = 0;
				did_change = 0;
				
				$.each($('fieldset.style1'), function(){
					
					if(did_change==1){
						return true;
					}else if($(this).css('display')=='block'&&did_change==0){
						participants++;
					}else{
						participants++;
						did_change=1;
						$(this).css('display', 'block');
						return;
					}
				})
			
				$('#uid130').attr('value', participants);
				$('#event_participant_remove').css('display','block')
				//alert(participants);
				
				return false;
				
			})
	
			$('#event_participant_remove').click(function(){
				
				
				participants = $('#uid130').attr('value');
				
				participants_new = (participants - 1);
				
				participants_fieldcounter = 1;
				$.each($('fieldset.style1'), function(){
					
					if(participants_fieldcounter==participants){
						$(this).css('display', 'none');
						
						
						
						$.each($(this).children('div').children('input'), function(){
							
							$(this).attr('value','');
						});
						
						return;
					}
					participants_fieldcounter++;
				})
			
				$('#uid130').attr('value', participants_new);
				
				
				if(participants_new==0){
					$('#event_participant_remove').css('display','none');
				}
				//alert(participants);
				
				return false;
				
			})
			
			if($('#uid130').attr('value')>0){
				
				$('#event_participant_remove').css('display','block');
				
				participants = $('#uid130').attr('value');
				
				participants_fieldcounter = 1;
				$.each($('fieldset.style1'), function(){
					
					if(participants_fieldcounter<=participants){
						$(this).css('display', 'block');
						
					}
					participants_fieldcounter++;
				})
			}
			
	});
	
	

