// Global Init for con_rnd
var gl_prev_rnd_item;
var gl_rnd_control = 1;


// Switch linguas

function switch_lingua (lingua, filename, de, en) {
    //check for existing linguas and generate filename
    if (filename == '/cgi-bin/fts_search.pl')
        filename = '/index.html.' + lingua; 
    else if ((lingua == "de" && de) || (lingua == "en" && en)) 
        filename = filename + "." + lingua;
    else 
        filename = "/index.html."+lingua;
    window.location.href = filename;
}



// Adjust width of the Buttonlinks

function adjust_buttonlink (id) {
    var content = document.getElementById(id);   
    if (!content) return;
    
    var button = document.getElementById('box_' + id);
    if (!button) return;
    
    var pixel = 20;
  
    /* If the element is currently invisible, we have to make the
     * element that has the display css property set to "none"
     * visible for a short time, so that we can calculate the clientWidth.
     */
    var parent = content.parentNode;
    while (parent) {        
    	if (parent.style && parent.style.display) {
		if ('none' == parent.style.display) {
			parent_elem = parent;
			parent.style.display = 'block';
		} else {
			parent = null;
		}
		break;
	}
	parent = parent.parentNode;
    }

    var width = content.offsetWidth + pixel;
    if (parent) {
        parent.style.display = 'none';
    }
       
    button.style.width = width + 'px';

}

//Random Control

function con_rnd() {
    //generate random value in a scope from 0 to 3
    var rnd_item = Math.round((Math.random()*10)/3);
    
    //check for illegal values
    switch (rnd_item) {
      case 0:
        return false;
      case gl_prev_rnd_item:
        return false;
      default:
        gl_prev_rnd_item = rnd_item;
        return rnd_item;
    }
}

//Subnvigation

function con(nav_id,rnd_control,flex) {
    // init

    // check for random control
    var rnd_item = false;
    if (nav_id == 0 && (!isNaN(rnd_control) && rnd_control != 0)) {
      //get legal random Value
      while (!rnd_item) rnd_item = con_rnd();
      //generate random nav_id
      nav_id = flex + rnd_item; 
    }

    // random control trigger
    gl_rnd_control = rnd_control;
    con_id = nav_id + 'c';
    nav_item = document.getElementById(nav_id);
    con_item = document.getElementById(con_id).style;
    
    // read nav-elements (li) in container
    nav_elements = nav_item.parentNode.parentNode.getElementsByTagName("li");
    for (i=0; i < nav_elements.length; i++) {
    // check each nav-element for active class
    if (nav_elements[i].firstChild.className = "active") {
        // deactivate active nav-element and content
        nav_elements[i].firstChild.className = "";
        con_active = nav_elements[i].firstChild.id + 'c';
        document.getElementById(con_active).style.display = "none";
        }
    }
    
    // activate current nav-element and content
    nav_item.className = "active";
    con_item.display = "block";

    // check for random control and set item rotation interval
    if (gl_rnd_control == 1) {
        window.setTimeout(function() { con(0,1,flex) }, 10000);
    }
}

// USP Slider
function usp_anime(id) {
    var usp_slider = id;
    var usp_nav_right = usp_slider + '_right';
    var usp_nav_left = usp_slider + '_left';
    var usp_p1 = usp_slider + '_p1';
    var usp_p2 = usp_slider + '_p2';  
  
    $("#"+usp_nav_right+","+"#"+usp_p2).click(function(){
        $("#"+usp_slider).animate({marginLeft:'-860px'},800);
        $("#"+usp_nav_right).addClass('disabled');
        $("#"+usp_nav_left).removeClass('disabled');
        $("#"+usp_p2).addClass('active');
        $("#"+usp_p1).removeClass('active');
    });
    
    $("#"+usp_nav_left+","+"#"+usp_p1).click(function(){
        $("#"+usp_slider).animate({ marginLeft: '0'},800);
        $("#"+usp_nav_left).addClass('disabled');
        $("#"+usp_nav_right).removeClass('disabled');
        $("#"+usp_p1).addClass('active');
        $("#"+usp_p2).removeClass('active');
    });
}

//USP Navigation

function usp_nav(id) {
    var link = document.getElementById(id);    
    if (!link) return;
    
    var p = document.getElementById('p_' + id);    
    if (!p) return;
    
    var img = document.getElementById('img_' + id);
    if (!img) return;

    var nav_elements = link.parentNode.parentNode.getElementsByTagName("li"); 
    
    for (i=0; i < nav_elements.length; i++) {
        if (nav_elements[i].className = "active") {                       
            nav_elements[i].className = "";            
            var p_active = 'p_' + nav_elements[i].firstChild.id;
            document.getElementById(p_active).style.display = "none";            
            var img_active = 'img_' + nav_elements[i].firstChild.id;
            document.getElementById(img_active).style.display = "none";
        }
    }
    
    link.parentNode.className = "active";
    p.style.display = "block";
    img.style.display = "block";       
}

function toggle_visibility(id) {
    var ids = new Array ('uspI', 'uspII');
    
    for (var i = 0; i < ids.length; i++) {
        var slide_elem = document.getElementById('slide_' + ids[i]);
        var this_elem = document.getElementById(ids[i]);
        var page_elem = document.getElementById(ids[i] + '_page');
        var display = slide_elem.style.display;
        
        if (display == 'none' && id == ids[i]) {
    		slide_elem.style.display = 'block';    		
    		this_elem.className = 'uspnav uspnav_inactive';
    		page_elem.className = 'current_usppage';
    		
    	} else if (display == 'block' && id != ids[i]) {    	    
    		slide_elem.style.display = 'none';    		
    		this_elem.className = 'uspnav uspnav_active';
    		page_elem.className = '';
    	
        } else {
    	    return;
        }   	
    }    
}
//Ausklappende Liste - Replaced by ACCORDION 2.
 function toggle_visible(id) {        
	/*
    var elem = document.getElementById(id);
	var image = document.getElementById('toggle_' + id);

	if (elem) {
		if ('none' == elem.style.display) {
			elem.style.display = 'block';
			if (image) {
			image.className = 'toggle_info tohide';
			}
		} else {
			elem.style.display = 'none';
			if (image) {
			image.className = 'toggle_info toshow';
			}
		}
	}*/
}
//Basic toggle visibility Function
 function basic_toggle(id) {
	var elem = document.getElementById(id);

	if (elem) {
		if ('none' == elem.style.display) {
			elem.style.display = 'block';		
		} else {
			elem.style.display = 'none';		
		}
	}
}
// Adjust Height of the Logo Container
  function adjust_height(id) {
  var el = document.getElementById(id);
  var container = document.getElementById("container_" + id);
  var el_height = el.offsetHeight;
  //container.style.height = el_height+'px';
  }

//Equal Height
function sortNum(a,b) { return b-a} 

function fixH2(one,two,three) {
	if (document.getElementById(one)) {
		var obj=new Array(3);
		var option=[one,two,three];
		for(var i=0; i<option.length; i++) {
			document.getElementById(option[i]).style.height="auto";
			obj[i]=document.getElementById(option[i]).offsetHeight;
			nh=obj.sort(sortNum);
			}		
	 	nh1=nh.splice(1,2);
		for(var i=0; i<option.length; i++) {
			document.getElementById(option[i]).style.height=nh+"px";
			}
	}
}

function hide_el(id) {
    var el = document.getElementById(id);
    el.style.display = 'none';
}
jQuery.noConflict();
jQuery(document).ready(function($){

    // Main Navigation Animation
    jQuery('.hnav a:not(:first)').not('a.active')
    .css( {backgroundColor: "#4a4f59"} )
    .mouseover(function(){
        jQuery(this).stop().animate({backgroundColor:"#ed6600"}, {duration:250})
    })
    .mouseout(function(){
        jQuery(this).stop().animate({backgroundColor:"#4a4f59"}, {duration:250})
    });
      
		
    // ACCORDION 1
    jQuery.fn.accordion = function() { 
        jQuery(this).each(function() {
        
            var id = jQuery(this).attr('id');
            //jQuery("#" + id + " h3.accordion_title:first").addClass("accordion_active");    
        	//jQuery("#" + id + " div.accordion_body:not(:first)").hide();
        	jQuery("#" + id + " div.accordion_body").hide();
        	
    
            jQuery("#" + id + " h3.accordion_title").hover(function() {
                jQuery(this).addClass('accordion_title_hover');
            }, function() {
                jQuery(this).removeClass('accordion_title_hover');
            });
        
        	jQuery("#" + id + " h3.accordion_title").click(function(){
        		jQuery(this).next("#" + id + " div.accordion_body").slideToggle("slow")
        		.siblings("#" + id + " div.accordion_body:visible").slideUp("slow");
        		jQuery(this).toggleClass("accordion_active");
        		jQuery(this).siblings("#" + id + " h3.accordion_title").removeClass("accordion_active");
        	});
            
        }); 
       return jQuery(this); 
    };

    // ACCORDION 2
    var list5h = $('.list_5 h3, .list_6 h3');
    var list5i = $('.list_5 .toggle_info, .list_6 .toggle_info');
    
     jQuery(list5h).each(function() {
         $(this).click(function() {
            if($(this).next('div').css('display') == 'none') {
                $(this).next('div').slideDown('slow');
                $(this).prev('div').attr('class','toggle_info tohide');            
            } else {
                $(this).next('div').slideUp('slow');
                $(this).prev('div').attr('class','toggle_info toshow');           
            }
         });
     });
     
      jQuery(list5i).each(function() {
         $(this).click(function() {
            if($(this).siblings('div').css('display') == 'none') {
                $(this).siblings('div').slideDown('slow');
                $(this).attr('class','toggle_info tohide');            
            } else {
                $(this).siblings('div').slideUp('slow');
                $(this).attr('class','toggle_info toshow');           
            }
         });
     });
     
    //Scroll to the top
	$('#footer .second_row .left a').click(function () {
		$('body,html').animate({
			scrollTop: 0
		}, 1000);
		return false;
	});
    
});  

