// JavaScript Document
jQuery.noConflict();
jQuery(document).ready(function(){
	checkedAfterLoadContent()
});
var item;
var navNaimation = {
	queue:false,
	duration: 400,
	easing: 'easeOutCirc'
}

function checkedAfterLoadContent() {
	//  Hyphenator
	Hyphenator.config({
		displaytogglebox: 	false,
		classname: 			'content',
		minwordlength: 		4
	});
	Hyphenator.run();
	
	// Navigation
	jQuery(".nav > li").bind({
		mouseenter: function() {
			item = jQuery(this);
			var h = (item.find('li').length * 38);
			animateNav(item, h);
		},
		mouseleave: function() {
			item = jQuery(this);
			animateNav(item, 0);
		}
	});
	
	// Kontakform
	if(jQuery('input').length){
        jQuery("input:radio").uniform();
	}
	
	// Intro
	if(jQuery('#tower').length){
		//start_d4n_Projekktor();
		jQuery(".navigation").addClass("noDisplay");
		jQuery(".subnav").addClass("noDisplay");
		jQuery(".skipnav").removeClass("noDisplay");
	} else {
		jQuery(".navigation").removeClass("noDisplay");
		jQuery(".subnav").removeClass("noDisplay");
		jQuery(".skipnav").addClass("noDisplay");
	}
	jQuery('.cnt').find('h1').each(function(index, item) {
		if(jQuery(item).html() == '') {
			jQuery(item).remove();
		}
	});
	
	// Tooltips
	if (jQuery('.boxes > .tt_box').length) {
		jQuery('.boxes > .tt_box').each(function(index, item) {	
			if (jQuery(item).find('video').length){
				vidID = 'vid_'+index;
				jQuery(item).attr('rel', vidID);
				jQuery(item).find('video').attr('id', vidID);
				projekktor('#'+vidID, {
					playerFlashMP4: 'fileadmin/templates/swf/jarisplayer.swf',
					loop: true,
					autoplay: false,
					controls: false
				});
			}		
			jQuery(item).hoverIntent(function () {
				jQuery(item).children('.box').css('z-index', '500');
				jQuery(item).children('.button').css('z-index', '501');
				jQuery(item).children('.box').stop().slideToggle("fast");
				jQuery(item).children('.button').removeClass("open");
				if (jQuery(item).attr('rel')){
					projekktor('#'+jQuery(item).attr('rel')).setPlay();
				}
			}, function () {
				jQuery(item).children('.box').css('z-index', '400');
				jQuery(item).children('.button').css('z-index', '400');
				jQuery(item).children('.box').stop().slideToggle("fast");
				jQuery(item).children('.button').addClass("open");
				if (jQuery(item).attr('rel')){
					projekktor('#'+jQuery(item).attr('rel')).setPause();
				}
			});
		});
		var vimeoPlayers = document.querySelectorAll('iframe'),
			player;

		for (var i = 0, length = vimeoPlayers.length; i < length; i++) {
			player = vimeoPlayers[i];
			$f(player).addEvent('ready', readyTT);
		}
	}
	if (jQuery('.whiteboardSlidshow').length) {
		jQuery(function() {
			setInterval( "slideSwitch()", 5000 );
		});
	}
}
function addEvent(element, eventName, callback) {
	if (element.addEventListener) {
		element.addEventListener(eventName, callback, false);
	}
	else {
		element.attachEvent(eventName, callback, false);
	}
}
function readyTT(player_id) {
	var froogaloop = $f(player_id);
	var con = jQuery('#'+player_id).parent();
	jQuery(con).bind({
		mouseenter: function() {
			froogaloop.api('play');		
		},
		mouseleave: function() {
			froogaloop.api('pause');
		}
	});
}



function animateNav(it, h) {
	it.children('ul').stop().animate({
		height: h
	}, navNaimation);
}
function slideSwitch() {
	var $active = jQuery('.whiteboardSlidshow img.active');
	if ( $active.length == 0 ) $active = jQuery('.whiteboardSlidshow img:last');
	var $next =  $active.next().length ? $active.next() : jQuery('.whiteboardSlidshow img:first');
	$active.addClass('last-active').removeClass('active');
	$next.css({opacity: 0.0})
		.addClass('active')
		.animate({opacity: 1.0}, 1000, function() {
			$active.removeClass('active last-active');
		});
}

