$(document).ready(function(){	
	
	/* HÖHE VON AKTUELLES WIRD GESETZT */
	
	h=0;
	$('#contentSub li .aktuelles li').each(function() {
		x=$(this).height();
		if(parseFloat(x)>h) {
			h=parseFloat(x);
		};
	});
	$('#contentSub li .aktuelles').css('height', h+'px');
	
	
	/* AKTUELLES ITEMS WIRD GESETZT */
	var i = 1;
	$('#contentSub li .aktuelles li').each(function() {
		$(this).css({
			display: 'block',
			position: 'absolute'
		}).attr('id', 'aktuellesItem-'+i);
		
		if(i>1) {
			$(this).css('marginLeft', '215px');
		}
		i++;
	});
		
	/* AKTUELLES NAVIGATION */
	i = 1;
	$('#contentSub li .aktuelles').parent().attr('id', 'aktellesNewsBox');
	$('#aktellesNewsBox').append('<ul id="aktuellesNav" class="bullets"></ul>');
	$('#contentSub li .aktuelles li').each(function() {
		title = $(this).find('h4').text();
		$('#aktuellesNav').append('<li><a id="aktuellesNavBtn-'+i+'" title="'+title+'">'+title+'</a></li>');
		i++;
	});
	$('#aktuellesNav li:first a').addClass('active');

	aktuellesCount = $('a[id^="aktuellesNavBtn-"]').length;
	aktuellesTime = 8000;
	activeBtn = $('#aktuellesNav .active');
	nextBtn = $('#aktuellesNav .active').parent().next('li').find('a');
	
	$('[id^="aktuellesNavBtn-"]').click(function(){
		nextBtn = $(this);
		aktuellesShift();
	});

	aktuellesInterval = setInterval(aktuellesShift,aktuellesTime);
	$('#aktellesNewsBox').hover(
        function(){ clearInterval(aktuellesInterval); },
        function(){ aktuellesInterval = setInterval(aktuellesShift,aktuellesTime); }
    );
	
	
	/* ADDITIONAL INFO BOX */
	if ($('#addInfoBoxNavi').length==1) {
		$('#addInfoBox'+$('#addInfoBoxNavi li a.active').attr('href').replace('#', '')).show(1);
		$('#addInfoBoxNavi li a').click(function(){
			 $('#addInfoBoxNavi li a.active').removeClass('active');
			 $('#addInfoBoxContent li.active').hide(1000);
			 $(this).addClass('active');
			 $('#addInfoBox'+$(this).attr('href').replace('#', '')).addClass('active');
			 $('#addInfoBox'+$(this).attr('href').replace('#', '')).show(1000);
			 return false;
		});
	}

	$('#addInfoBoxFaq dl dt a').click(function(){
		 $('#addInfoBoxFaq dd.active').slideUp(1000);
		 $('#addInfoBoxFaq dd.active').removeClass('active');
		 $(this).parent().next().addClass('active');
		 $(this).parent().next().slideDown(1000);
	});

	/* TESTIMONIAL BROWSING */
	$('#testimonialSelection li:first').addClass('active');

	$('#testimonialSelection li').click(function() {
		clicked=$(this);
		id=$(this).attr('id').substring(21);
		$.get('ajax.php', {page: 'testimonialDetails', id: id}, function(data) {
			$('#testimonialWrapper').html(data);
			$('#testimonialSelection li').removeClass('active');
			clicked.addClass('active');
			$('html,body').animate({
				scrollTop: $('#testimonialWrapper').offset().top-10}, { queue:false, duration:500 });
		});
	});
	
	/* TESTIMONIAL GALLERY */
	$('#testimonialGallery').append('<ul id="testimonialGalleryNav" class="bullets"></ul>');
	i=1;
	$('#testimonialGallery img').each(function() {
		$(this).attr('id', 'testimonialGalleryImg-'+i);
		$('#testimonialGalleryNav').append('<li><a id="testimonialGalleryImgBtn-'+i+'"></a></li>');
		i++;
		});
	$('#testimonialGallery img:first').addClass('active');
	$('#testimonialGallery img:first').fadeIn(1);
	$('#testimonialGalleryNav li:first a').addClass('active');

	$('#testimonialGalleryNav a').livequery('click', function(){
		$('#testimonialGallery img').fadeOut(1000, function(){
			$(this).removeClass('active');
		});
		$('#testimonialGalleryNav li a').removeClass('active');
		$(this).addClass('active');
		$('#testimonialGalleryImg-'+$(this).attr('id').substring(25)).fadeIn(1000, function(){
			$(this).addClass('active');
		});
	});
	
	/* LAENDER GALLERY */
	$('#laenderGallery').append('<ul id="laenderGalleryNav" class="bullets"></ul>');
	i=1;
	$('#laenderGallery img').each(function() {
		$(this).attr('id', 'laenderGalleryImg-'+i);
		$('#laenderGalleryNav').append('<li><a id="laenderGalleryImgBtn-'+i+'"></a></li>');
		i++;
		});
	$('#laenderGallery img:first').addClass('active');
	$('#laenderGallery img:first').fadeIn(1);
	$('#laenderGalleryNav li:first a').addClass('active');

	$('#laenderGalleryNav a').click(function(){
		$('#laenderGallery img').fadeOut(1000, function(){
			$(this).removeClass('active');
		});
		$('#laenderGalleryNav li a').removeClass('active');
		$(this).addClass('active');
		$('#laenderGalleryImg-'+$(this).attr('id').substring(21)).fadeIn(1000, function(){
			$(this).addClass('active');
		});
	});


/* END DOCUMENT READY */
});

var aktuellesCount, aktuellesInterval, nextBtn, activeBtn, aktuellesTime;
function aktuellesShift(){
	nextItm = $('#aktuellesItem-'+getBulletIDNumber(nextBtn));
	activeItm = $('#aktuellesItem-'+getBulletIDNumber(activeBtn));
	
	nextItm.animate({marginLeft: 0},700);
	activeItm.animate({marginLeft: '-215px'},700, function() {$(this).css('marginLeft', '215px');});
	
	activeBtn.removeClass('active');
	nextBtn.addClass('active');
	
	activeBtn = nextBtn;
	nextID = getBulletIDNumber(activeBtn)+1;
	if(nextID > aktuellesCount){ nextID = 1; }
	nextBtn = $('#aktuellesNavBtn-'+nextID);
}

function getBulletIDNumber(object){
	return parseInt(object.attr('id').replace('aktuellesNavBtn-', ''));
}

/* FORMULAR */

function addBewerbungsZiel() {
		var lastID = $('#bewerbungsZiele li:last-child').attr('id');
		
		if(!lastID){
			nextID = 0;}
		else {
		lastID = lastID.split('-');
		var nextID = parseInt(lastID[1])+1;
		}
		
		var content ='';
		
		content+='<li id="bewerbungsZiel-'+nextID+'">';
		content+='<select name="zielSchule[]">';
		content+='<option>High School USA</option>';
		content+='<option>Private School USA</option>';
		content+='<option>Internat/Boarding School USA</option>';
		content+='<option>High School Kanada</option>';
		content+='<option>Internat/Boarding School USA</option>';
		content+='<option>High School Nova Scotia</option>';
		content+='<option>High School Australien</option>';
		content+='<option>Internat/Boarding School Australien</option>';
		content+='<option>High School Neuseeland</option>';
		content+='<option>Internat/Boarding School Neuseeland</option>';
		content+='</select>';
		content+=' ';
		content+='<select name="austauschDauer[]">';
		content+='<option>ein Schuljahr</option>';
		content+='<option>ein Semester</option>';
		content+='<option>3 Monate (Kanada)</option>';
		content+='<option>4 Terms (AUS/NZ)</option>';
		content+='<option>3 Terms (AUS/NZ)</option>';
		content+='<option>2 Terms (AUS/NZ)</option>';
		content+='<option>1 Term (AUS/NZ)</option>';
		content+='<option>bis zum High School Diplom</option>';
		content+='</select>';
		content+=' ';
		content+='<a href="javascript: deleteBewerbungsZiel(\'bewerbungsZiel-'+nextID+'\');"><img src="img/formular/delete.png"></a>';
		content+='</li>';
		
		$('#bewerbungsZiele').append(content);
}

function deleteBewerbungsZiel(deleteID) {
		$('#'+deleteID).remove();
}
