/* Navigation */
var timeout    = 1000;
var closetimer = 0;
var secondNavTextId;

// Initialisierung
function sc_init_nav(){	
	//ID vergabe für die SubNavs
	$('.sc_link_second').css('display', 'inline');
	var LinkName = new Array();
	
	links = $('.first_link');
	links.each(function(){
		if($(this).next().hasClass('sc_link_second')){
			LinkName.push($(this).text());	
		}
	});
	$('.sc_link_second').each(function($i){
		if($(this).prev('.first_link')){
			$(this).attr('id', LinkName[$i]); 
		}
	});
	//SubNav wird ausgeblendet
	secondNav.css({
		'display':'none',
		'height': '172px',
		'opacity': '0'
	});
	 
	secondLink.css('display', 'none');
	
	//PageImage 
/*	secondNavPageimage = secondNav.children('.sc_nav_pageimage');
	
	var PageImageName = new Array();
	secondNavPageimage.each(function(){
			
	});*/
	
	openNav = false;
} 

function sc_secondNav_justify(){
	contentBodyPosition = $('.content_body').offset().left;
	contentBodyPosition -= 10;
	return contentBodyPosition	
}

//Überprüft ob Navigation offen ist oder nicht
function sc_nav_con(){
   	sc_nav_canceltimer();
	sc_secondNav_justify();
	if($(this).next().hasClass('sc_link_second')){
		secondNavText = $(this).text();
		
		if(openNav == false){
			secondNavTextId = secondNavText;
			secondNavId = $('#' + secondNavText);
			sc_open_nav();	
		} else {
			newText = $(this).text();
			newId = $('#' + newText);
			sc_nav_open();	
		}
	} else {
		secondNavTextId = $(this).text();
		sc_empty_link();	
	}
}

//Navigation wird geöffnet
function sc_open_nav() {
	secondNav.stop();
	if(openNav != true){
		secondNav.css({
			'left': contentBodyPosition,
			'display':'block'
		});
		secondNav.animate({
			'opacity':'1'
		}, function(){
			secondNavId.css('display', 'block');	
		});	
		$('.sc_nav_pagename').html('<p>' + secondNavText + '</p>');
	}
	openNav = true;
}

//SubLinks werden ausgetauscht
function sc_nav_open(){
	secondNav.stop();
	if(newText != secondNavTextId){
		secondLink.css('display', 'none');
		secondNavId = $('#' + secondNavTextId);
		newId.css('display','block');	
	} 
	secondNav.css('opacity', 1);
	secondNavTextId = newText;
	$('.sc_nav_pagename').html('<p>' + secondNavText + '</p>');
	return secondNavTextId;
}

function sc_empty_link() {
	openNav = false;
	secondLink.css('display', 'none');
	secondNav.animate({'opacity': '0'});
	return secondNavTextId;
}

//schließt die SubNav
function sc_nav_close(){
	openNav = false;
	secondNav.animate({
		'opacity': '0'
	}, function(){
		secondNav.css('display', 'none');
	});
	secondLink.css({
		'display': 'none'
	});
}

//Timer für das ausblenden der Navigation
function sc_nav_timer(){  
   closetimer = window.setTimeout(sc_nav_close, timeout);
}
function sc_nav_canceltimer(){  
   if(closetimer){  
      window.clearTimeout(closetimer);
      closetimer = null;
   }
}	
