/*CVS Add-ins*/
/*
$Revision: 1.11 $
$Date: 2009/02/09 15:54:21 $
$RCSfile: behaviours.js,v $
Authors: MSC, JDE, APA
Copyright (c) A&B FACE2NET GmbH
*/

/* + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + */
var agt = navigator.userAgent.toLowerCase();
var ie  = (agt.indexOf("msie") != -1);
var sf  = (agt.indexOf("safari") != -1);

/* function toggleKeyVisual BEGINN */

var toggI = 0;

function setKeyVisual(){
	if(document.getElementById('toggle_keyvisual')){ 
		$('#toggle_keyvisual div.boxImage').addClass("jbox");
		//1. key visual anzeigen
		$("#toggle_keyvisual div.jbox:first-child").toggleClass("selected");
		//toggle durchfuehren
		set_toggle();
	}
}

function set_toggle(){ var slider = window.setTimeout("toggleKeyVisual()", 3000); }

function toggleKeyVisual(){
	if(toggI < 3){
		try{
			$("#toggle_keyvisual div.jbox:first-child").toggleClass("selected");			
		} catch(err){
		}//catch
		set_toggle();
		toggI++;
	}//if
}//slide_teaser



/* + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + */
/* Hintergrundbilder vorladen  */
function preloadImages(){
var a = new Array(
"../css/styleimages/bg_boxOeffnen_hover.gif",
"../css/styleimages/bg_boxSchliessen_hover.gif",
"../css/styleimages/bg_btn_toggle_hover.gif",
"../css/styleimages/bg_mainNavPfeilRot_hover.gif",
"../css/styleimages/bg_mehr2_hover.gif",
"../css/styleimages/bg_mehr_hover.gif",
"../css/styleimages/bg_navMainLink_hover.gif"
);
var b = new Array();
var i;
for (i = 0; i < a.length; i++) {
    b[i] = new Image();
    b[i].src = a[i];
}
}

/* + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + */
/* optimierte getElementsByClassName (wp) */
document.getElementsByClassName = function(className) {
  var children = document.getElementsByTagName('*') || document.all;
  var elements = new Array();
  for (var i = 0; i < children.length; i++) {
    var child = children[i];
    var classNames = child.className.split(' ');
    for (var j = 0; j < classNames.length; j++) {
      if (classNames[j] == className) {
        elements.push(child);
        break;
      }
    }
  }
  return elements;
}




/* + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + */
/* function accessibleToggleBox BEGINN */
function accessibleToggleBox(){

/* ein paar abfragen */
if(!document.getElementsByTagName || !document.getElementById || !document.getElementById("boxControl")) return false;

/* alle navigationspunkte und content boxen */
var boxControl = document.getElementById("boxControl").getElementsByTagName("a");
var boxContent = document.getElementById("boxContent").getElementsByTagName("div");
/* immer erst alles zuruecksetzen */
function resetAll(){
    var i = 0;
    for (i=0;i<boxControl.length;i++){
    boxContent[i].style.display = "none";
    boxControl[i].className = "default";
    }
}

/* Init: Beim ersten Aufruf nur #1 einblenden */
resetAll();
if(boxControl.length >= 1){
    boxContent[0].style.display = "block";
    boxControl[0].className = "btnAktiv";

    /*extend object with function method and property index with a loop*/
    for (var z=0;z<boxControl.length;z++) {
        boxControl[z].index = z;
        boxControl[z].onclick = function () {
        resetAll();
        boxContent[this.index].style.display = "block";
        boxControl[this.index].className = "btnAktiv";
        return false;
        }
    }
 }
return true;
}
/* function accessibleToggleBox ENDE */
/* + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + */

/* function accessibleTextBox */
/* + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + */
function accessibleTextBox(){
    /* check for browser support */
    if(!document.getElementsByTagName || !document.getElementById || !document.getElementById("content")) return false;

    /*box Teaser*/
    /*all div elements of the content element in an array*/
    var boxContentDivs = document.getElementById("content").getElementsByTagName("div");
    /*split up into arrays*/
    var boxTextDivs = new Array();
    var boxControlDivs = new Array();
    var y;

    /*push all elements into the respective array and store it*/
    for (y=0;y<boxContentDivs.length;y++) {
        if (boxContentDivs[y].className=="boxTeaserText") {
            boxTextDivs.push(boxContentDivs[y]) ;
        }
        if (boxContentDivs[y].className=="boxTeaserButton") {
            boxControlDivs.push(boxContentDivs[y]);
        }
    }
    //alert(boxControlDivs.length);

    /*hide all  an create opener links*/
    function init () {
    var i;
    for (i=0;i<boxTextDivs.length;i++) {
        boxTextDivs[i].style.display="none";
        /* create anchor*/
        var anchorElement = document.createElement("a");
        anchorElement.setAttribute("name","boxTextAnchor"+i);
        boxTextDivs[i].parentNode.insertBefore(anchorElement,boxTextDivs[i].parentNode.getElementsByTagName("h2")[0]);
        /* create anchor and opener links*/
        boxControlDivs[i].innerHTML="<a href=\"#boxTextAnchor"+i+"\" class=\"oeffnen\">weiter lesen<\/a>";
        }
    }
init();
/*extend object with function method and property index*/
    for (var x=0;x<boxControlDivs.length;x++) {
        boxControlDivs[x].index = x;
        boxControlDivs[x].onclick = function () {
            if (boxTextDivs[this.index].style.display=="none") {
                boxTextDivs[this.index].style.display="block";
                boxControlDivs[this.index].firstChild.childNodes[0].data="schliessen";
                }
            else {
                boxTextDivs[this.index].style.display="none";
                boxControlDivs[this.index].firstChild.childNodes[0].data="weiter lesen";
                }
        }
    }

return true
}
/* function accessibleTextBox END */
/* + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + */

function videoZu(){
var downloadOptions = document.getElementById("downloadOptions");
var flashVideo = document.getElementById("flashVideo");
var btnAufZu = document.getElementById("btnAufZu");
    flashVideo.style.display = "none";
    downloadOptions.style.display = "none";
    btnAufZu.innerHTML = '<a class="boxOeffnen" href="javascript:videoAuf()">Video ansehen<\/a>';
}

function videoAuf(){
var downloadOptions = document.getElementById("downloadOptions");
var flashVideo = document.getElementById("flashVideo");
var btnAufZu = document.getElementById("btnAufZu");
    flashVideo.style.display = "block";
    downloadOptions.style.display = "block";
    btnAufZu.innerHTML = '<a class="boxSchliessen" href="javascript:videoZu()">schliessen<\/a>';
}

/* + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + */
/* function aufZu BEGINN */
function aufZu(){

/* ein paar abfragen */
if(!document.getElementsByTagName || !document.getElementById || !document.getElementById("btnAufZu")|| !document.getElementById("flashVideo")|| !document.getElementById("downloadOptions")) return false;

var downloadOptions = document.getElementById("downloadOptions");
var flashVideo = document.getElementById("flashVideo");
var btnAufZu = document.getElementById("btnAufZu");
    flashVideo.style.display = "none";
    downloadOptions.style.display = "none";
    btnAufZu.innerHTML = '<a class="boxOeffnen" href="javascript:videoAuf()">Video ansehen<\/a>';
return true;
}
/* function aufZu ENDE */
/* + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + */

function newWindow(adr) {
  MeinFenster = window.open(adr, "eMagazin", "width=1000,height=700,left=0,top=0,toolbar=no,location=no,scrollbars=no,status=no,resizable=yes,fullscreen=yes");
  MeinFenster.focus();
}


function prepare_FAQ(){
	if(document.getElementById("jfaqContent")) { 
		var currentHash= String(showHash());
		if(currentHash.indexOf("faq_frage")>=0){
			var currentNr = currentHash.split("frage_")[1];  
			set_currentEntry(currentNr);
			bind_onclick(currentNr);
		}else{
			var currentDefault = $("#jfaqContent div.jfaq:first").attr("id");
			var currentNr = currentDefault.split("antwort_")[1];  
			set_currentEntry(currentNr);
			bind_onclick(currentNr);
		}
	}
}

function bind_onclick(currentNr){
	$("#jfaqContent h4#faq_frage_"+currentNr).addClass("current_entry");
	$("#jfaqContent h4.jfaq:not(#faq_frage_"+currentNr+")").each(function(i){
		var current_id = $(this).attr("id");
		if(current_id.indexOf("faq_frage_")>=0){
			$(this).wrapInner('<a href="#faq_frage_'+current_id.split("frage_")[1]+'" onclick="toggleFAQ('+current_id.split("frage_")[1]+')"></a>');
		}
	});
	
}

function set_currentEntry(currentNr){
	$("#jfaqContent div.jfaq").addClass("hide");
  $("#faq_antwort_"+currentNr).removeClass("hide").addClass("show");
	$("#faq_frage_"+currentNr).focus();
}


function toggleFAQ(nextNr){
	var currentNr = $("#jfaqContent h4.current_entry").attr("id").split("frage_")[1];
	$("#jfaqContent div.jfaq").removeClass("show").addClass("hide");
  $("#jfaqContent #faq_antwort_"+nextNr).removeClass("hide").addClass("show");
	$("#jfaqContent #faq_frage_"+nextNr+" a").replaceWith($("#jfaqContent #faq_frage_"+nextNr+" a").text());
	$("#jfaqContent h4.current_entry").wrapInner('<a href="#faq_frage_'+currentNr+'" onclick="toggleFAQ('+currentNr+')"></a>');
	$("#jfaqContent h4.jfaq").removeClass("current_entry");
	$("#jfaqContent #faq_frage_"+nextNr).addClass("current_entry");
	$("#faq_frage_"+nextNr).focus();
}

function get_jumplinks(){
	$("#jfaqContent div.jfaq a")
		.filter(function (index){
			return $(this).attr("href").indexOf("faq_frage")>=0
		})
		.bind("click", function(e){
      toggleFAQ($(this).attr("href").split("frage_")[1]);
    });

}

function showURL () {
  //alert ('URI des aktuellen Dokuments: ' + document.URL);
  return document.URL;
}

function showHash () {
 //alert ('Hashwert: ' + location.hash);
 return location.hash;
}

function showPath () {
 //alert(('Pfad: ' + location.pathname));
 return location.pathname;
}





/* Funktionen zum oeffnen und schliessen des Meinungen Formulares ENDE */
/* + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + */
window.onload = function(){
setKeyVisual();
accessibleTextBox();
accessibleToggleBox();
aufZu();
preloadImages();
showHash();
showPath();
get_jumplinks();
prepare_FAQ();

}
