var c_arr = new Array(); //array mit pfaden zum boxmenu
var sliding = true;
var sliderSet = false;
var current_nr = 1;
var teaserDataLength = 0;
var teaserData = new Array();


function reset_channels(){
  var defaultsrc = String($(".jquerybox #boxnavigation ul li#current_channel img.entries").attr("src")).replace(/eintrag_h/,"eintrag_d");
    if(defaultsrc != "undefined"){ $(".jquerybox #boxnavigation ul li#current_channel img.entries").attr("src",defaultsrc); }
    $("#boxnavigation li").removeClass("hover");
    $("#boxnavigation li").removeAttr("id");
}

/* + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + */
/* functions for slider */
/* + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + */

function loadTeaserData(idStartPage){
  if (typeof(idStartPage) == 'undefined') var idStartPage = 56;
    $.post('../../../../index.php?id=' + idStartPage, { func: "getFirstNews", eID: "spdstart" },
      function(data){
          //teaserData = data;
          teaserData = JSON.parse(data);
          teaserDataLength = teaserData.length;
          if(teaserData != null){
            mark_currentChannel(current_nr);
            window.setTimeout("getHTML(teaserData[1], current_nr)", 5000);
            current_nr = current_nr + 1;
          }
    }, "html");
}


function set_slider(){
  if(teaserData != null){
      var slider = window.setTimeout("slide_teaser(teaserData[current_nr])", 10000);
      sliderSet = true;
    }
}

function stop_sliding(){
  sliding = false;
}

function slide_teaser(teaserData){
  if(sliding){
    getHTML(teaserData, current_nr+1);
    //mark_currentChannel(current_nr+1);
      if(current_nr >= (teaserDataLength - 1)){
        current_nr = 0;
    } else {
        current_nr = current_nr + 1;
    }
  }
}


function getHTML(teaserData, cNr){

  if (typeof(idStartPage) == 'undefined') var idStartPage = 56;
  $.post('../../../../index.php?id=' + idStartPage, {  	func: "getTeaserContent",
                      eID: "spdstart",
                      cattitle: teaserData.cattitle,
                      actTeaserPosition: 0,
                      channelIndex: current_nr+1,
                      newsimage: teaserData.newsimage,
                      imagealttext: teaserData.imagealttext,
                      newsId: teaserData.newsId,
                      catId: teaserData.catId,
                      newsteasertext: teaserData.newsteasertext,
                      newstitle: teaserData.newstitle,
                      totalNews: teaserData.count,
                      href: teaserData.href,
                      pageId: teaserData.pageId
                    },
  function(data){
    if (sliding) {
      $("#content").fadeTo("slow", 0 ,function(){
          document.getElementById("content").innerHTML = data;
          mark_currentChannel(cNr);
          $("#content").fadeTo("slow", 1);
        });
       set_slider();
    }
  }, "html");
}

function sendInput(li, pos, catid, c, channelIndex){
  var children = li.childNodes;
  for(var i = 0; i<children.length; i++){
    if(children[i].nodeName == 'INPUT'){
      children[i].click(pos, catid, c, channelIndex);
    }
  }
}

function mark_currentChannel(current_index){
  reset_channels();
  $('.jquerybox #boxnavigation li:nth-child('+current_index+')').attr("id", "current_channel");
  var activesrc = String($(".jquerybox #boxnavigation ul li#current_channel img.entries").attr("src")).replace(/eintrag_d/,"eintrag_h");
  if(activesrc != "undefined"){ $(".jquerybox #boxnavigation ul li#current_channel img.entries").attr("src",activesrc); }
}







