/////////////////////////
/* Animation Variables */
/////////////////////////

var $t;
var $animationCount = 0;
var $animationsFinished = 0;
var $requestAnimationsFinished = 'false';
var $subNavAnimationCount = 0;
var $subNavAnimationsFinished = 0;
var $subSubNavAnimationCount = 0;
var $subSubNavAnimationsFinished = 0;
var mainNavChange;
var $slideInSubMenuTimer;
var $slideInSubSubMenuTimer;
var level1Change = false;
var level2Change = false;
var level3Change = false;
var cleanUrlLevel1 = false;
var cleanUrlLevel2 = false;
var cleanUrlLevel3 = false;
var url;

/////////////////////////
/* Animation Functions */
/////////////////////////

/**
 * Slides in the Sub-Menu
 * @param subnav_id
 * @param pad_out
 * @param pad_in
 * @param time
 * @param multiplier
 */
function slideInSubMenu(subnav_id, pad_out, pad_in, time, multiplier) {
	//clear Timer for firs-run delay
    clearTimeout($slideInSubMenuTimer);

    $(".subnavelement").css("margin-left","-200px");
    $("#subnav").show();

	// creates the target paths
	var list_elements = subnav_id + " li.subnavelement";

	// initiates the timer used for the sliding animation
	var slideInTimer = 0;

	// creates the slide animation for all list elements
	$(list_elements).each(function(i)
	{
		// updates timer
		slideInTimer = (slideInTimer*multiplier + time);
		$(this).stop(true, true).animate({ marginLeft: "0"}, slideInTimer);
	});

}

/**
 * Slides in the Sub-Sub-Menu
 * @param subSubNav_id
 * @param pad_out
 * @param pad_in
 * @param time
 * @param multiplier
 */
function slideInSubSubMenu(subSubNav_id, pad_out, pad_in, time, multiplier) {
	//clear Timer for firs-run delay
    clearTimeout($slideInSubSubMenuTimer);

    $(".subSubNavElement").css("margin-left","-200px");
    $("#subSubNav").show();

	// creates the target paths
	var list_elements = subSubNav_id + " li.subSubNavElement";

	// initiates the timer used for the sliding animation
	var slideInTimer2 = 0;

	// creates the slide animation for all list elements
	$(list_elements).each(function(i)
	{
		// updates timer
		slideInTimer2 = (slideInTimer2*multiplier + time);
		$(this).stop(true, true).animate({ marginLeft: "0"}, slideInTimer2);
	});

}

/**
 * Slides Out the Sub-Menu
 * @param subnav_id
 * @param time
 * @param multiplier
 */
function slideOutSubMenu(subnav_id, time, multiplier) {
    $subNavAnimationCount = 0;
    $subNavAnimationsFinished = 0;
	// creates the target paths
	var list_elements = subnav_id + " li.subnavelement";

	// initiates the timer used for the sliding animation
	var subSlideOutTimer = 0;

	//count up animationCounter
	$(list_elements).each(function(i)
	{
	   $subNavAnimationCount = $subNavAnimationCount+1;
	   $animationCount = $animationCount+1;
	});

	if ($subNavAnimationCount == 0) {$("#subnav").hide();}

	// creates the slide animation for all list elements
	$(list_elements).each(function(i)
	{
		// updates timer
		subSlideOutTimer = (subSlideOutTimer*multiplier + time);
		$(this).stop(true, true).animate({ marginLeft: "-200px"}, subSlideOutTimer, function() {
            $animationsFinished = $animationsFinished+1;
            $subNavAnimationsFinished = $subNavAnimationsFinished+1;
            animationsFinished();
            slideOutSubMenuFinished();
        });
	});

}

/**
 * Hides Sub-Menu when SlideOut is finished
 * @param f
 */
function slideOutSubMenuFinished(f) {

    if ($subNavAnimationCount == $subNavAnimationsFinished) {
        $("#subnav").hide();
    }
}

/**
 * Slides Out the Sub-Sub-Menu
 * @param subsubnav_id
 * @param time
 * @param multiplier
 */
function slideOutSubSubMenu(subsubnav_id, time, multiplier) {
    $subSubNavAnimationCount = 0;
    $subSubNavAnimationsFinished = 0;
	// creates the target paths
	var list_elements = subsubnav_id + " li.subSubNavElement";

	// initiates the timer used for the sliding animation
	var subSubSlideOutTimer = 0;

	//count up animationCounter
	$(list_elements).each(function(i)
	{
	   $subSubNavAnimationCount = $subSubNavAnimationCount+1;
	   $animationCount = $animationCount+1;
	});

	if ($subSubNavAnimationCount == 0) {$("#subSubNav").hide();}

	// creates the slide animation for all list elements
	$(list_elements).each(function(i)
	{
		// updates timer
		subSubSlideOutTimer = (subSubSlideOutTimer*multiplier + time);
		$(this).stop(true, true).animate({ marginLeft: "-200px"}, subSubSlideOutTimer, function() {
            $animationsFinished = $animationsFinished+1;
            $subSubNavAnimationsFinished = $subSubNavAnimationsFinished+1;
            animationsFinished();
            slideOutSubSubMenuFinished();
        });
	});

}

/**
 * Hides Sub-Sub-Menu when SlideOut is finished
 * @param f
 */
function slideOutSubSubMenuFinished(f) {

    if ($subSubNavAnimationCount == $subSubNavAnimationsFinished) {
        $("#subSubNav").hide();
    }
}

/**
 * Slides Out the Content Div
 * @param f
 */
function slideOutContent(f) {

    $animationCount = $animationCount+1;
    $("#content_layer").stop(true, true).slideUp(500, function() {
       $("#content_layer").hide();
       $animationsFinished = $animationsFinished+1;
       animationsFinished();
    });

}

/**
 * Slides Out the Scribble
 * depending on Support via FadeOut or Flash-Unload
 * @param f
 */
function slideOutScribble(f) {

    $animationCount = $animationCount+1;

    if (!FlashDetect.installed) {

    	$("#scribble").stop(true, true).fadeOut(500, function() {
	       $("#scribble").hide();
	       $animationsFinished = $animationsFinished+1;
	       animationsFinished();
	    });

    } else {

    	getSWF('scribbleFlash').unloadScribble();

    }

}

/**
 * Function is triggered from within flash to report that the Flash-Fadout-Animation is finished
 * @param f
 */
function slideOutScribbleFinished(f) {

    $animationsFinished = $animationsFinished+1;
    animationsFinished();

}

/**
 * Function checks if all Animations are finished
 * and sets the $requestAnimationsFinished Variable to true
 * and shows loader icon
 */
function animationsFinished(f) {

    if ($animationCount == $animationsFinished) {

        $requestAnimationsFinished = 'true';
        $('#loaderIcon').show(20);

    }

}

/**
 * Function clears Stage for next Ajax-Page-Load
 * Clears:
 * - Menus
 * - Content
 * - Scribble
 */
function clearStage(absoluteUrl) {

	//Remove Intro if visible
	if ($('#introWrapper').is(":visible")) {

		hideIntro();

	}

	//Declare needed Variables and provide the url
    var State = window.History.getState();
	url = State.url;
	cleanUrlLevel1 = HTTPLANG;
	cleanUrlLevel2 = HTTPLANG;
	cleanUrlLevel3 = HTTPLANG;
    if (url!=HTTPLANG) {
    	var cleanUrl = url.replace(HTTPLANG,''); // Url without HTTP in front
    	var cleanUrlArray = cleanUrl.split( '/' );
		cleanUrlLevel1 = HTTPLANG+cleanUrlArray[0]+'/';
		cleanUrlLevel2 = HTTPLANG+cleanUrlArray[0]+'/'+cleanUrlArray[1]+'/';
		cleanUrlLevel3 = HTTPLANG+cleanUrlArray[0]+'/'+cleanUrlArray[1]+'/'+cleanUrlArray[2]+'/';
	}
    level1Change = false;
	level2Change = false;
	level3Change = false;

	$requestAnimationsFinished = 'false';
    $animationCount = 0;
    $animationsFinished = 0;
    $.blockUI({overlayCSS:  {  backgroundColor: 'transparent' },message: null });
    $('#loader').show();

    // Check if MainNavChange
    if ( $('#nav a.ajaxy[href="'+cleanUrlLevel1+'"]').hasClass('mainMenu_active') ) { } else { level1Change = true;}
    // Check if SubNavChange
    if ( $('#subnav a.ajaxy[href="'+cleanUrlLevel2+'"]').hasClass('subMenu_active') ) { } else { level2Change = true;}
    // Check if SubSubNavChange
    if ( $('#subSubNav a.ajaxy[href="'+cleanUrlLevel3+'"]').hasClass('subSubMenuActive') ) { } else { level3Change = true;}


    if ( level1Change==true ) {

         //Main Menu Reset
         $("#nav a.mainMenu_active").each(function(){
            var backgroundPos = $(this).css("backgroundPosition");
            var backgroundPosArray=backgroundPos.split(" ");
            var backgroundPosOld = backgroundPosArray[0]+' 0px';
            $(this).removeClass('mainMenu_active');
            $(this).css('backgroundPosition', backgroundPosOld);
            var backgroundPosNew = backgroundPosArray[0]+' -37px';
            $(this).animate({ backgroundPosition: backgroundPosNew}, { duration: 3000, queue: false });
         });
         //Sub Menu Reset
         slideOutSubMenu("#slidingSubNav",400, 0.8)
         //SubSub Menu Reset
         slideOutSubSubMenu("#slidingSubSubNav",300, 0.6)
         //Content Reset
         slideOutContent();
         //Scribble Reset
         slideOutScribble();

     } else {

    	 if ( level2Change==true ) {

    		 //Sub-Menu Reset
    		 $("#subnav a.subMenu_active").each(function(){
                 $(this).animate({ backgroundColor: "#2D5D30"}, 300, function() {
					$(this).removeClass('subMenu_active');
				});
	         });
    		 //SubSub Menu Reset
             slideOutSubSubMenu("#slidingSubSubNav",300, 0.6)
	         //Content Reset
	         slideOutContent();
	         //Scribble Reset
	         slideOutScribble();

    	 } else {

    		 //Sub-Sub-Menu Reset
    		 $("#subSubNav a.subSubMenuActive").each(function(){
            	$(this).animate({ backgroundColor: "#2D5D30"}, 300, function() {
                 	$(this).removeClass('subSubMenuActive');
				});
	         });
	         //Content Reset
	         slideOutContent();
	         //Scribble Reset
	         slideOutScribble();

    	 }

     }

}

/**
 * Function loads Stage
 * @param data
 * @param textStatus
 * @param jqXHR
 */
function loadStage(data, textStatus, jqXHR) {

	if( $requestAnimationsFinished == 'false') {

    	$t=setTimeout(function(){loadStage(data, textStatus, jqXHR);},200);

	} else  {

		clearTimeout($t);

		if (cleanUrlLevel1==HTTPLANG) {

				initIntro();

		} else {

			var $dataContent = data.content;
			var $dataTitle = data.title;
			var	$menuChildren;
			var contentHtml;
			var $content = $("#content_layer");

			// Fetch the content and redirect if non proper Content is returned
			contentHtml = $dataContent;
			if ( !contentHtml ) {
				document.location.href = url;
				return false;
			}

			// Update the title
			if ( $dataTitle ) document.title = $dataTitle;

			//MAKE FADE IN DEPENDING ON REQUEST
			// MAIN MENU CHANGE
			if ( level1Change==true ) {

				showScribble(data);

				var mainMenuItem = $('#nav a.ajaxy[href*="'+cleanUrlLevel1+'"]');
				if (mainMenuItem.length > 0) {
					var backgroundPos = mainMenuItem.css("backgroundPosition");
					var backgroundPosArray=backgroundPos.split(" ");
					var backgroundPosNew = backgroundPosArray[0]+' 0px';
					mainMenuItem.animate({backgroundPosition: backgroundPosNew}, 300, function() {
						mainMenuItem.addClass('mainMenu_active');
					});
				}

				$content.stop(true,true);
				$content.html(contentHtml).ajaxify();

				$('#subnav').html(data.subnav).ajaxify();

				$("#loaderIcon").hide(20, function() {
					$('#loader').hide();
					$content.slideDown(700, function() {
						$slideInSubMenuTimer=setTimeout(function(){slideInSubMenu("#slidingSubNav", 25, 15, 400, 0.8);},500);
						initialize3rdPartyScripts();
						$.unblockUI();
					});
				});

			// SUB MENU CHANGE
			} else {

				if ( level2Change==true ) {

					showScribble(data);

					var subMenuItem = $('#subnav a.ajaxy[href*="'+cleanUrlLevel2+'"]');
					subMenuItem.animate({backgroundColor: "#0bbe14"}, 300, function() {
						subMenuItem.addClass('subMenu_active');
					});

					$content.stop(true,true);
					$content.html(contentHtml).ajaxify();
					//HIDE ALL THAT SHOULD BE HIDDEN
					//$(".hidden").hide();

					$('#subSubNav').html(data.subsubnav).ajaxify();

					$("#loaderIcon").hide(20, function() {
						$('#loader').hide();
						$content.slideDown(700, function() {
							$slideInSubSubMenuTimer=setTimeout(function(){slideInSubSubMenu("#slidingSubSubNav", 25, 15, 400, 0.8);},500);
							initialize3rdPartyScripts();
							$.unblockUI();
						});
					});

				// SUBSUB MENU CHANGE
				} else {

				 	showScribble(data);

					var subSubMenuItem = $('#subSubNav a.ajaxy[href*="'+cleanUrlLevel3+'"]');
					subSubMenuItem.animate({backgroundColor: "#0bbe14"}, 300, function() {
						subSubMenuItem.addClass('subSubMenuActive');
					});

				 	$content.stop(true,true);
					$content.html(contentHtml).ajaxify();

					$("#loaderIcon").hide(20, function() {
						$('#loader').hide();
						$content.slideDown(700, function() {
							initialize3rdPartyScripts();
							$.unblockUI();
						});
					});

				}

			}

		}

		// Inform Google Analytics of the change
		try {
			var pageTracker = _gat._getTracker("UA-21688207-1");
			pageTracker._trackPageview(url);
		} catch(err) {}

	}

 }

/////////////////////////
/* GENERAL FUNCTIONS   */
/////////////////////////

/**
 * Function calls ExternalInterface-Function within Flash-Loader
 * loads SWFs into loader.swf
 * @param scribbleName
 */
function loadScribble(scribbleName) {

    try {
        getSWF('scribbleFlash').asLoadScribble(scribbleName);
    }

    catch (e) {
    	//The Loader is not Loaded yet - wait for it
    	setTimeout(function(){
    		loadScribble(scribbleName);
    	}, 10);
    }

}

/**
 * Function to get Flash-Object
 * @param movieName
 * @returns FlashObject
 */
function getSWF(movieName) {
    if (navigator.appName.indexOf("Microsoft") != -1)
    {
        return window[movieName];
    }
    else
    {
        return document[movieName];
    }
}

/**
 * Initializes Intro
 * Creates a Chain for the two Videos
 * and makes shure that the transitions are smooth
 * Calls skipIntro when finished
 */
function initIntro() {

	$('#contactButton').fadeOut('0');

    if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i)) || (navigator.userAgent.match(/Android/i)) ) {

        //iOS
        $("#loaderIcon, #loader").hide();
    	$.unblockUI();

        $('#introWrapper, #introVideo2').show();
        $('#introVideo1, #introVideo1Mask, #introVideo2Mask').hide();


        jwplayer("video2").setup({
            screencolor: "FFFFFF",
            autostart: true,
            controlbar: "none",
            icons: "none",
            bgcolor: "#ffffff",
            flashplayer: HTTP+'public/plugins/jwplayer/player.swf',
            file: HTTP+"public/videos/de.mp4",
            image: HTTP+"public/videos/video.jpg",
            height: 630,
            width: 1070
        });

        jwplayer("video2").onTime(function(event) {

            if (event.position > 52.5) {
                skipIntro();
            }

        });

    } else {

        if (!FlashDetect.installed) {

            //NO Flash and NO iOS
            skipIntro();

    	} else {

    		$("#loaderIcon").hide();
    		$('#loader').hide();
    		$.unblockUI();

            $('#introVideo2Mask').fadeIn('0');
            $('#introVideo1Mask').fadeIn('0', function() {
            	$('#introVideo1').fadeIn('0');
            	$('#introVideo1').show();
            	$('#introVideo2').fadeIn('0');
            	$('#introVideo2').show();
            	$('#introWrapper').delay(1000).show();
            });

            jwplayer("video1").setup({
                screencolor: "FFFFFF",
                autostart: true,
                icons: "none",
                controlbar: "none",
                bgcolor: "#ffffff",
                flashplayer: HTTP+'public/plugins/jwplayer/player.swf',
                file: HTTP+"public/videos/intro.mp4",
                height: 630,
                width: 1070
            });

            jwplayer("video1").onPlay(function() {
               $('#introVideo1Mask').fadeOut('fast');
            });

            jwplayer("video1").onComplete(function() {
                $('#introVideo1').fadeOut('fast', function() {
                    $('#introVideo1').hide();

                    jwplayer("video2").setup({
                        screencolor: "FFFFFF",
                        autostart: true,
                        controlbar: "none",
                        icons: "none",
                        bgcolor: "#ffffff",
                        flashplayer: HTTP+'public/plugins/jwplayer/player.swf',
                        file: HTTP+"public/videos/de.mp4",
                        image: HTTP+"public/videos/video.jpg",
                        height: 630,
                        width: 1070
                    });


                    jwplayer("video2").onTime(function(event) {
                        if (event.position > 0.1) {
                            $('#introVideo2Mask').fadeOut('fast', function() {
                                $('#introControls').delay(1500).fadeIn('fast');
                            });
                        }

                        if (event.position > 52.5) {
                            skipIntro();
                        }

                    });
                });
            });
    	}

	}
}

/**
 * Skips the Intro
 * includes checks for:
 * - Flash installed
 * - Ajax enabled Browser
 */
function skipIntro() {

    if (!FlashDetect.installed) {

        if ( !window.History.enabled ) {
            window.location = HTTP+LANG+'/home/';
        } else {
            $('#introWrapper').fadeOut('fast', function() {
                $('#introWrapper').hide();
                $('#introVideo2').fadeOut('0');
                $('#introVideo2').hide();
                History.pushState(null,null, HTTP+LANG+'/home/');
                $('#contactButton').fadeIn('500');
            });
        }

	} else {

	    if ( !window.History.enabled ) {
            jwplayer("video2").pause();
            window.location = HTTP+LANG+'/home/';
        } else {
            $('#introWrapper').fadeOut('fast', function() {
                $('#introWrapper').hide();
                $('#introVideo2').fadeOut('0');
                $('#introVideo2').hide();
                jwplayer("video2").remove();
                jwplayer("video1").remove();
                History.pushState(null,null, HTTP+LANG+'/home/');
                $('#contactButton').fadeIn('500');
            });
        }

	}



}

/**
 * Hide the Intro
 * includes checks for:
 * - Ajax enabled Browser
 */
function hideIntro() {

			jwplayer("video1").pause();
			jwplayer("video2").pause();

            $('#introWrapper').fadeOut('fast', function() {

            	$('#introWrapper').hide();
            	$('#introVideo2').fadeOut('0');
                $('#introVideo2').hide();
            	$('#introVideo2Mask').fadeOut('0');
        		$('#introVideo1').fadeOut('0');
        		$('#introVideo1').hide();
        		$('#introVideo1Mask').fadeOut('0');
                jwplayer("video2").remove();
                jwplayer("video1").remove();
                $('#contactButton').fadeIn('500');

            });

}

/**
 * Initializes Custom Content-Slider
 */
function initSlider() {

	if ($('#slider').length > 0) {
        $('#slider').ContentSlider({
            width : '562px',
            height : '100%',
            speed : 400,
            easing : 'easeOutQuad'
        });
    }

}

/**
 * Initializes the Custom Scrollbars with iOS Fallback
 */
function initScroller() {

    if ($('div.scroll-pane').length > 0) {
        if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i)) || (navigator.userAgent.match(/Android/i)) ) {
            	myScroll = new iScroll('scroller');
        } else {
            $('.scroll-pane').jScrollPane({showArrows:true});
        }
    }

}

/**
 * Shows Scribble during AJAX Load
 */
function showScribble(data) {

	if (!FlashDetect.installed) {

		if (data.scribbleFallback!='false') {
			$('#scribble').html(data.scribbleFallback);
			$('#scribble img').load(function() {
				$("#scribble").show();
				$("#scribble").stop(true, true).fadeIn(500);
			});
		}

	} else {

		if (data.scribble!='false') {
			getSWF('scribbleFlash').asLoadScribble(HTTP+'/public/'+data.scribble);
		}

	}

}

/**
 * Initializes the Animations on the Sub-Navigation
 */
function initSubNavHover() {

    $("#slidingSubNav li.subnavelement a").live({
        mouseenter:
           function()
           {
                $(this).stop(true, true)
    			$(this).animate({ paddingLeft: 25}, { duration: 150, queue: false });
    			if (!($(this).hasClass('subMenu_active'))) {
                    $(this).animate({ backgroundColor: "#0bbe14"}, { duration: 150, queue: false });
    			}
           },
        mouseleave:
           function()
           {
                $(this).stop(true, true)
    			$(this).animate({ paddingLeft: 15}, { duration: 150, queue: false });
    			if (!($(this).hasClass('subMenu_active'))) {
                    $(this).animate({ backgroundColor: "#2D5D30"}, { duration: 150, queue: false });
    			}
           }
       });

}

/**
 * Initializes the Animations on the Sub-Sub-Navigation
 */
function initSubSubNavHover() {

    $("#slidingSubSubNav li.subSubNavElement a").live({
        mouseenter:
        	function()
           {
                $(this).stop(true, true)
    			$(this).animate({ paddingLeft: 25}, { duration: 150, queue: false });
    			if (!($(this).hasClass('subSubMenuActive'))) {
                    $(this).animate({ backgroundColor: "#0bbe14"}, { duration: 150, queue: false });
    			}
           },
        mouseleave:
           function()
           {
                $(this).stop(true, true)
    			$(this).animate({ paddingLeft: 15}, { duration: 150, queue: false });
    			if (!($(this).hasClass('subSubMenuActive'))) {
                    $(this).animate({ backgroundColor: "#2D5D30"}, { duration: 150, queue: false });
    			}
           }
       }
    );

}

/**
 * Initializes the Animations on the Navigation
 */
function initMainNavHover() {


    $("li.mainnavelement a").live({
        mouseenter:
           function()
           {
                if (!($(this).hasClass('mainMenu_active'))) {
                    var backgroundPos = $(this).css("background-position");
                    var backgroundPosArray=backgroundPos.split(" ");
                    var backgroundPosNew = backgroundPosArray[0]+' 0px';
                    $(this).animate({ backgroundPosition: backgroundPosNew}, { duration: 300, queue: false });
                }
           },
        mouseleave:
           function()
           {
                if (!($(this).hasClass('mainMenu_active'))) {
                    var backgroundPos = $(this).css("backgroundPosition");
                    var backgroundPosArray=backgroundPos.split(" ");
                    var backgroundPosNew = backgroundPosArray[0]+' -37px';
                    $(this).animate({ backgroundPosition: backgroundPosNew}, { duration: 300, queue: false });
                }
           }
       }
    );

}

/**
 * Function is triggered from within flash after the Gallery-Scribble is finished drawing
 * then fades in the Galery-Content
 */
function scribbleGaleryFinished(f) {

	$('#slideshowGallery').fadeSlideShow({
        	width: 377,
        	height: 276,
        	speed: 'slow',
			interval: 3000,
			PlayPauseElement: false,
			NextElement: 'fssNext',
			PrevElement: 'fssPrev',
			ListElement: false,
			addListToId: false,
			allowKeyboardCtrl: true,
			autoplay: false,
			NextElementText: '',
			PrevElementText: ''
        });

	$('#slideshowGallery').fadeIn('slow', function() {

    });

}

/**
 * Re Initializes 3rd-Party Scripts after Ajax Load
 */
function initialize3rdPartyScripts() {

	//Activate Content-Slider
	initSlider();

	//Activate Content-Scroller
	initScroller();

}

/////////////////////////
/* DOM-READY           */
/////////////////////////

$(function() {

	//Embed Flash Loader for Scribbles (on fail do nothing and keep showing fallback markup)
	flashembed("scribble", {src: HTTP+"public/flash/loader.swf", wmode: 'opaque',w3c: true, id: 'scribbleFlash',onFail: function() {return false;}});

	//Activate 3rd-Party Scripts
	initialize3rdPartyScripts();

	//Initialize Galery if NON-Flash
	if (!FlashDetect.installed) {
		scribbleGaleryFinished();
	}

	//Bind Intro-Player-Events
	$("#introControlPlay").live("click",function(event) {
		event.preventDefault();
		jwplayer("video2").play();
	});

	$("#introControlPause").live("click",function(event) {
		event.preventDefault();
		jwplayer("video2").pause();
	});

	$("#introControlStop").live("click",function(event) {
		event.preventDefault();
		jwplayer("video2").stop();
	});

	$("#introControlVolume").live("click",function(event) {
		event.preventDefault();
		jwplayer("video2").setMute();
	});

	$("#introControlSkip").live("click",function(event) {
		event.preventDefault();
		skipIntro();
	});

	//Hide Specific DOM-Elements that should be hidden by JS
	$(".hidden").hide();

	//Wrapper for Valid XHTML External Links
	$('a[rel*=external]').live("click", function(event) {
		window.open(this.href);
		return false;
	});

	//Initialize Navigation-Animations
	initMainNavHover();
	initSubNavHover();
	initSubSubNavHover();

});
