$(document).ready(function() {
	
	
	///////////////////////////////// GENERAL /////////////////////////////////
	
	// Replace Headlines with Frutiger-Font
	Cufon.replace('h3, h4, h5, #welcomeText .colMain h2, #welcomeText .colMain p', { fontFamily: 'Frutiger 57Cn'});	
	Cufon.replace('.welcome h5', { fontFamily: 'Frutiger 67BoldCn'});	
	
	// Links
	$('a.external').attr('target', '_blank');
	
	
	///////////////////////////////// WELCOME /////////////////////////////////
	
	// ----------- MainNav - Show Active Parent -----------
	$('ul.topNav li ul li ul li').hover(function() {
		$(this).parent().parent().children('a').addClass('active');
	}, function() {
		$(this).parent().parent().children('a').removeClass('active');
	});
	
	
	// ----------- Slider - Success Stories -----------
	// Presets
	$('ul#teaserWrap').css('width', ($('ul#teaserWrap').children('li').length * 335)+'px');
	if($('ul#teaserWrap').children('li').length > 1) {
		$('div#teaserImage div#teaserImageOverlay a.next').show();
	}
	
	// Controls
	$('div#teaserImage div#teaserImageOverlay a').click(function() {
		if($(this).hasClass('prev')) {
			var value = 335;
		} else if($(this).hasClass('next')) {
			var value = -335;
		}
		moveTeaser(value);
		return false;
	});
	
	// Slide-Function
	function moveTeaser(value) {
		var moveCont = $('ul#teaserWrap');
		
		if(!moveCont.is(':animated')) {
			var oldPos = parseInt(moveCont.css('left'));
			var newPos = oldPos+value+'px';
			var maxLength = (($('ul#teaserWrap').children('li').length-1) * -335)+'px';
			
			moveCont.stop().animate({
				left: newPos
			}, 450, 'swing');
			
			if(newPos == '0px') {
				$('div#teaserImage div#teaserImageOverlay a.prev').hide().siblings('a.next').show();
			} else if(newPos == maxLength) {
				$('div#teaserImage div#teaserImageOverlay a.next').hide().siblings('a.prev').show();
			} else {
				$('div#teaserImage div#teaserImageOverlay a').show();
			}
		}
	}
	
	
	// ----------- Teaser Products List -----------
	
	$('ul#teaserProducts li div.colMain ul').each(function() {
		$(this).show().attr('getAttr', $(this).height()).css('height', 0).hide().prev('p').attr('getAttr', $(this).prev('p').height());
	});
	
	$('ul#teaserProducts > li').hover(function() {
		Cufon.replace($(this).children('div.colMain').children('h5'), { color: '#E23427'});
		$(this).children('div.colMain').children('p').stop(false, false).animate({ opacity: 0, height: 0 }, 200 );
		$(this).children('div.colMain').children('ul').stop(false, false).animate({ opacity: 1, height: $(this).children('div.colMain').children('ul').attr('getAttr') }, 200 );
	}, function() {
		Cufon.replace($(this).children('div.colMain').children('h5'), { color: '#3E3E3E'});
		$(this).children('div.colMain').children('p').stop(false, false).animate({ opacity: 1, height: $(this).children('div.colMain').children('p').attr('getAttr') }, 200 );
		$(this).children('div.colMain').children('ul').stop(false, false).animate({ opacity: 0, height: 0 }, 200 );	
	});
	
	///////////////////////////////// SUBSITES /////////////////////////////////
	
	// ----------- ACCORDEON Right Col -----------
	var countH5 = 1;
	$('body.sub #wrapper #pageBody #colRight h5').each(function() {
		$(this).css('cursor', 'pointer');
		if(countH5 > 2) {
			$(this).addClass('closed');
			$(this).next('ul').hide();
		}
		countH5++;
	});
	
	$('body.sub #wrapper #pageBody #colRight h5').click(function() {
		if($(this).hasClass('closed')) {
			$(this).next('ul').stop(true, true).slideToggle(400);
			$(this).removeClass('closed');
		} else {
			$(this).next('ul').stop(true, true).slideToggle(400);
			$(this).addClass('closed');
		}
	});
	
});


