$(document).ready(function(){ //DocReady Start
    
/*
------------------------------------------------
	Variablen
------------------------------------------------
*/
	

var hashLoad = window.location.hash; // erkennt den hash
var selectLi = parseInt(hashLoad.substr(5, 1)); // welcher untermenupunkt waere gewaehlt
var path = location.pathname.substr(location.pathname.lastIndexOf("/")+1,location.pathname.length).split(".html")[0];

var tempUs = path.split("_E")[0];
var languageSlider = path.split(tempUs)[1];



/*
------------------------------------------------
	Startfunctions
------------------------------------------------
*/
	if (languageSlider == "_E") {
    	$('#slides').load('Contents/Sliders_E.html'); //Englischer TICKER wird geladen
	}
	else {
		$('#slides').load('Contents/Sliders.html'); //Deutscher TICKER wird geladen
	}
		
    $('.pages').hide();
    $('ul.topnav li ul').hide(); // MENU
    
	$().UItoTop({ easingType: 'easeOutQuart' }); // Scroll Up
/*
------------------------------------------------
	Device Detect
------------------------------------------------
*/
	
	var functionType = 'hover';
		
		var WinWidth = $(window).width();
		if (WinWidth < 600 || navigator.userAgent.match(/Android/i) || navigator.userAgent.match(/webOS/i) || navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPod/i)){
			functionType = 'click';
		}
		else {
			functionType = 'hover';
		}
/*
------------------------------------------------
	Hauptmenue
------------------------------------------------
*/
	if (functionType == 'hover') {		
		
		$('ul.topnav li').hover( // langsam TOP
			function() {
				$(this).find('>ul').height('auto').slideDown(150); 
				},
			function() {
				$(this).find('>ul').slideUp(80);
				}
		)
		$('ul.subnav').hover( //schnell SUB
			function() {
				$(this).stop().height('auto').slideDown(10);
				},
			function() {
				$(this).find('>ul').stop().slideUp(80);
				}
		)
		
	}
	else {
		$('ul.topnav li').click( // langsam TOP
			function() {
				$('.subnav').stop().slideUp(80);
				$(this).find('>ul').height('auto').slideDown(150); 
				}
		);
		$('ul.topnav li a').click(function(event) {
		  		event.preventDefault();
				$('.subnav').stop().slideUp(80);
				$(this).find('>ul').height('auto').slideDown(150); 
				}
		);

		$('ul.subnav').click( //schnell SUB
			function() {
				$(this).find('>ul').stop().slideUp(80);
				}
		)
		
	}

/*
------------------------------------------------
	Hash
------------------------------------------------
*/

		if (selectLi >= 0){} 
        else {selectLi = 1};
		
        if (path == 'index' || path == 'default' ) {path = 'konferenz'} // bei index und default -> konferenz 
        if (hashLoad == '') { hashLoad = '#page1'; }
		

/*
------------------------------------------------
	Menupunkt #1 wird markiert
------------------------------------------------
*/
            
    var runOnce = 0;
    if (runOnce == 0) {            
            var markLi = parseInt(selectLi-1);
            
            $('ul.topnav li.active ul.subnav li a:eq('+ markLi +')').addClass('activesub'); // Menupunkt wird markiert
            var pageToLoad = 'Contents/' + path + '/Seite_' + selectLi + '.html';
       

            $.get(pageToLoad, function(data) {
                pageContent=data;
                $("#content_container").fadeOut(50, function() {
                    $("#content_container").html(pageContent).ready(function(){
                        $("#content_container").html(pageContent).animate({
                            opacity: 'show'
                        }, 200, 'swing');
                        $("#content_container").css({
                            'background-image' : 'none'
                        });
                    });
                });
            });
            runOnce = 1;
        };

/*
------------------------------------------------
	Menu Clickfunction
------------------------------------------------
*/

    $('ul.topnav li ul.subnav li').find('a').click( function() {      
    var path = location.pathname.substr(location.pathname.lastIndexOf("/")+1,location.pathname.length).split(".html")[0];
    if (path == 'index' || path == 'default' ) {path = 'konferenz'} // bei index und default wird konferenz daraus
    var anfang = $(this).attr('href').lastIndexOf("#")+5;
	var selectPage = $(this).attr('href').substr(anfang,1); // = 1

    var selectZielPath = $(this).attr('href').substr(0,4);
    var selectQuellePath = path.substr(0,4);
    
    if (selectZielPath == selectQuellePath) {
            $('.activesub').removeClass('activesub'); // loescht alle markierungen
            $(this).addClass('activesub');
            
            var pageToLoad = 'Contents/' + path + '/Seite_' + selectPage + '.html'
            var pageContent;
        
            $.get(pageToLoad, function(data) {
                pageContent=data;
                $("#content_container").fadeOut(50, function() {
                    $("#content_container").html(pageContent).ready(function(){
                        $("#content_container").html(pageContent).animate({
                            opacity: 'show'
                        }, 200, 'swing');
                        $("#content_container").css({
                            'background-image' : 'none'
                        });
                    });
                });
            });
            return false;
    }
    else {
        location.href = $(this).attr('href');
    }
    
    });
    
/*
------------------------------------------------
	Fancybox
------------------------------------------------
*/

	$("a.iframe").fancybox({
				'width'				: 800,
				'height'			: 600,
                'autoScale'			: false,
				'transitionIn'		: 'fade',
				'transitionOut'		: 'fade',
				'type'				: 'iframe',
                'overlayOpacity'    : '0.6',
		        'overlayColor'      : '#000'
			});
    $("a.impressum").fancybox({
				'width'				: 500,
				'height'			: 600,
				'autoScale'			: false,
				'transitionIn'		: 'fade',
				'transitionOut'		: 'fade',
				'type'				: 'iframe',
                'overlayOpacity'    : '0.6',
		        'overlayColor'      : '#000'
			});
	$('.kontaktInit_ger').fancybox({
				'width'				: 500,
				'height'			: 600,
				'autoScale'			: false,
				'transitionIn'		: 'fade',
				'transitionOut'		: 'fade',
				'type'				: 'iframe',
                'overlayOpacity'    : '0.6',
				'titleShow'			: false,
		        'overlayColor'      : '#000',
				'href'				: 'https://www.netconf.org/et/Kontakt.aspx'
		});
	$('.kontaktInit_eng').fancybox({
				'width'				: 500,
				'height'			: 600,
				'autoScale'			: false,
				'transitionIn'		: 'fade',
				'transitionOut'		: 'fade',
				'type'				: 'iframe',
                'overlayOpacity'    : '0.6',
				'titleShow'			: false,
		        'overlayColor'      : '#000',
				'href'				: 'https://www.netconf.org/et/Kontakt_E.aspx'
		});



	
}); //DocReady Ende ------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    
    
    function Ref(adresse){ // JAVASCRIPT LINK
        location.href = adresse;
    }


