// fCMS-Klötze

function pinboard_start() {
  return true;
}

jQuery.noConflict();

function cmswin( name, url, w, h ) {
  mw = window.open(url,name,'width='+w+',height='+h+',scrollbars=yes,resizable=yes,dependent=yes,top=10,left=10');
  mw.resizeTo(w,h); 
  mw.focus(0); 
}

// Superscript

    function chgVideoLink () {

      jQuery(".superscript").each(function(){
        var text = jQuery(this).html();
        jQuery(this).html("");
        if ( text.length > 3 ) {
          var superscript = text.split(",");
          superscript.shift();
          if (jQuery(this).parent().find("UL").length == 0){
            var linkbox = "<ul>";          
            for (i=0;i<superscript.length/5;i++){
              var title = superscript[i*5].substring(1,superscript[i*5].lastIndexOf("'"));
              var bctid = superscript[i*5+3];
              linkbox += "<li class=\"video\"><a href=\"/media/videos/index.html?bctid="+bctid+"\"><h4>Video: </h4><h5>"+title+"</h5></a></li>";
            }
            jQuery(this).parent().html(linkbox+"</ul>");
          } else {
            for (i=0;i<superscript.length/5;i++){
              var title = superscript[i*5].substring(1,superscript[i*5].lastIndexOf("'"));
              var bctid = superscript[i*5+3];
              jQuery(this).parent().find("UL").append("<li class=\"video\"><a href=\"/media/videos/index.html?bctid="+bctid+"\"><h4>Video: </h4><h5>"+title+"</h5></a></li>");
            }
          }
        }
      });

    }

  jQuery(document).ready(function(){

    jQuery("DIV[name=themenbox]").each(function(){
      jQuery(this).find("IMG").eq(0).css("cursor","pointer");
      jQuery(this).find("IMG").eq(0).click(function(){
        var link = jQuery(this).parent().find("A").eq(0).attr("href");
        window.location.href = link;
      });
    });

    chgVideoLink();

  });

  // Menümodifizierung

  function menuMod() {
    var fotoservice = "http://fotoservice."+window.location.hostname.split(".")[1]+".de/fotoservice_new/";
    jQuery("#topNavi A[href$='/media/']").attr("href",fotoservice);
    jQuery("#topNavi A[href$='/media/bilder/']").attr("href",fotoservice);
    jQuery("#topNavi ul.lv2 > li").each(function(){ if ( jQuery(this).find("ul.lv3 LI").length == 0 ) jQuery(this).addClass("single"); });
    if ( jQuery("ul.lv3visible LI").length == 0 ) jQuery("ul.lv3visible").detach();
  }

  jQuery(document).ready(function(){

    // Anpassung der Zeilenhöhe

    var hoeheLinks = jQuery("#contentLeft").height();
    var hoeheRechts = jQuery("#contentRight").height();

    if ( hoeheRechts > hoeheLinks-600 && window.location.href.indexOf(",") != -1) {
      jQuery("#contentLeft").css("height",hoeheRechts+600);
    } else if ( hoeheRechts > hoeheLinks ) {
      jQuery("#contentLeft").css("height",hoeheRechts);
    }

    // Grossesbild wird ausgeblendet wenn kein Thumb vorhanden
    if ( jQuery('.grossesBild IMG').length == 0 ) jQuery('.grossesBild').css("display","none");

    // Eine zu lange Thumbliste wird mit einer Scrollbar angezeigt

    if ( jQuery('.grossesBild .thumbs TD').length > 6 ) {
      jQuery('.grossesBild .thumbs').css("width",44*6);
      jQuery('.grossesBild .thumbs').css("height",64);
    }
     
  });

// Klick ins Suchfeld

  jQuery(document).ready(function(){ 
    jQuery(".suche .text").click(function () {          
      if ( jQuery(this).val() == "Suche" ) {
        jQuery(this).val("");
        jQuery(this).css("color","#000000");  
        jQuery(this).css("font-weight","normal");  
      }
    });    
    jQuery(".suche .text").blur(function () {          
      if ( jQuery(this).val() == "" ) {
        jQuery(this).css("color","#999999");  
        jQuery(this).css("font-weight","bold");  
        jQuery(this).val("Suche");  
      }
    });    
  }); 
  
// Verlinkte Elemente bekommen beim Klicken keinen gepunkteten Rahmen
  
  jQuery(document).ready(function(){ 
    jQuery("A").click(function () {          
      jQuery(this).blur();
    });    
  });    


/* Volltext */
/* -------------------------------------------------------------------------- */

  // Icons werden farbig bzw. grau

  jQuery(document).ready(function(){

    var url = document.location.href;
    var title = jQuery("#volltext H2").html();

    var link;

    link = "http://www.mister-wong.de/index.php?action=addurl&bm_url="+url+"&bm_description="+title;
    jQuery("#volltext .icons A[title='mrwong']").attr("href",link);

    link = "http://www.webnews.de/einstellen?url="+url+"&title="+title;
    jQuery("#volltext .icons A[title='webnews']").attr("href",link);

    link = "http://www.yigg.de/neu?exturl="+url+"&exttitle="+title;
    jQuery("#volltext .icons A[title='yigg']").attr("href",link);

    link = "http://del.icio.us/post?url="+url+"&title="+title;
    jQuery("#volltext .icons A[title='del.icio.us']").attr("href",link);

    link = "http://linkarena.com/bookmarks/addlink/?url="+url+"&title="+title;
    jQuery("#volltext .icons A[title='linkarena']").attr("href",link);

    link = "http://de.facebook.com/sharer.php?u="+url+"&t="+title;
    jQuery("#volltext .icons A[title='facebook']").attr("href",link);

    link = "http://google.com/bookmarks/mark?op=edit&bkmk="+url+"&title="+title;
    jQuery("#volltext .icons A[title='google']").attr("href",link);

    link = "http://twitter.com/home?status="+url;
    jQuery("#volltext .icons A[title='twitter']").attr("href",link);

    jQuery("#volltext .icons A IMG").mouseover(function(){
      var source = jQuery(this).attr("src");
      var greyTag = source.lastIndexOf("_grey");
      if ( greyTag != -1 ) {
        source = source.substring(0,greyTag)+source.substring(greyTag+5);
        jQuery(this).attr({src:source});
      }    
    });

    jQuery("#volltext .icons A IMG").mouseout(function(){
      var source = jQuery(this).attr("src");
      var dotTag = source.lastIndexOf(".");
      if ( source.indexOf("_grey") == -1 ) {
        source = source.substring(0,dotTag)+"_grey"+source.substring(dotTag);
        jQuery(this).attr({src:source});     
      }
    });    
    
  });    

  // Artikel Drucken POPUP

  jQuery(document).ready(function(){
    jQuery("#volltext .drucken A").click(function(){
      window.open(jQuery(this).attr("href"), "druckansicht", "width=510,height=500,scrollbars=yes,menubar=no,resizable=no,status=no,toolbar=no,dependent=yes")
      return false;
    });
  });

  // Previewbilder für großes Bild

  jQuery(document).ready(function(){
    var grossesBild = jQuery("#article .grossesBild");
    var overlay = grossesBild.find(".overlay");
    var images = overlay.find("IMG");
    images.click(function(){
      images.removeClass();
      jQuery(this).addClass("active");
      var image = jQuery(this).parent().find("IMG").eq(1).attr("src");
      var text = jQuery(this).parent().find("SPAN").html();
      grossesBild.find("IMG").eq(0).attr("src",image);
      grossesBild.find("H2").html(text);
    });
    var TDs = overlay.find("DIV.thumbs TD");
    if ( TDs.length > 1 ) {
      var firstId = images.eq(0).attr("src");
      firstId = firstId.substr(firstId.lastIndexOf("/")+1);
      firstId = firstId.substr(0,firstId.indexOf("_"));
      TDs.each(function(){
        if ( TDs.index(jQuery(this)) != 0 ) {
          var thisId = jQuery(this).find("IMG:eq(0)").attr("src");
          thisId = thisId.substr(thisId.lastIndexOf("/")+1);
          thisId = thisId.substr(0,thisId.indexOf("_"));
          if ( thisId == firstId ) jQuery(this).remove();
        }
      });
    }
    if ( jQuery('.grossesBild .thumbs TD').length > 1 ) jQuery('.grossesBild .thumbs').css("display","block");
  });


  function getCmbild(str) {
    var cmbild = 0;
    var url = str.split("?");
    url = url[1].split("&");
    for ( i=0; i<url.length; i++ ) {
      url[i] = url[i].split("=");
      if ( url[i][0] == "_CMBILD" ) cmbild = jQuery.trim(url[i][1]);
    }
    return cmbild;
  }

  // Fotostrecke in Volltext
  
  jQuery(document).ready(function(){

    jQuery("A[name='DIASHOW']").each( function() {
      jQuery(this).attr("name","");
      var link = jQuery(this).attr("href");
      var diaid = 0;
      var param = link.split("?");
      param = param[1].split("&");
      for ( i=0; i<param.length; i++ ){
        param[i] = param[i].split("=");
        if ( param[i][0] == "_CMTREE" ) {
          diaid = param[i][1];
          break;
        }
      }
      var artlink = window.location.href;
      artlink = artlink.substring(artlink.lastIndexOf("/")+1);
      artlink = artlink.split(",");
      artlink = artlink[0]+","+artlink[1];
      var obj = jQuery(this);
      jQuery(this).replaceWith("<div class=\"gallery\" id=\"gallery"+diaid+"\"></div>");
      jQuery("#gallery"+diaid).load("/media/ajax_60x60/cme"+diaid+",1.html?_FRAME=33 .gallery > *", function () {

        jQuery("#gallery"+diaid+" A").eq(0).attr("href",artlink+",C");

        var cmbild = getCmbild(jQuery("#gallery"+diaid+" A").eq(1).attr("href"));
        jQuery("#gallery"+diaid+" H3 A").attr("href",artlink+",C?"+cmbild);

        jQuery("#gallery"+diaid+" IMG").mouseover(function(){
          var imgsrc = jQuery(this).attr("src");
          var pos = jQuery(this).position();
          var cmbild = getCmbild(jQuery(this).parent().attr("href"));
          if ( cmbild != 0 ) {
            var url = artlink+",C?"+cmbild;
            jQuery("#gallery"+diaid+" .overlay").html("<a href=\""+url+"\"><img src=\""+imgsrc+"\" width=\"120\" height=\"120\"></a>");
            jQuery("#gallery"+diaid+" .overlay").css("top",pos.top-30);
            jQuery("#gallery"+diaid+" .overlay").css("left",pos.left-30);      
            jQuery("#gallery"+diaid+" .overlay").fadeIn("slow");
          }
        });

        jQuery("#gallery"+diaid+" .overlay").mouseout(function(){
          jQuery("#gallery"+diaid+" .overlay").css("display","none");
        });

      });
    });
  });

  // RollOver bei Bewertungssternen

  
  jQuery(document).ready(function(){
    var ratingTimeout = 0;
    var ratingOrig;
    jQuery("#rating DIV").each(function() {
      if ( jQuery(this).attr("class") == "active" ) ratingOrig = Array(jQuery("#rating DIV").index(this),jQuery("#rating SPAN").eq(5).text());  
    });
    jQuery("#rating DIV").mouseover(function(){
      if ( ratingTimeout != 0 ) {
        window.clearTimeout(ratingTimeout);
        ratingTimeout = 0;
      }
      var index = jQuery("#rating DIV").index(this);
      var text = jQuery("#rating SPAN").eq(index).text();
      var text = jQuery(this).text();
      jQuery("#rating DIV").removeClass();      
      for( i = 0; i <= index; i++ ){
        jQuery("#rating DIV").eq(i).addClass("active");
      }
      jQuery("#rating SPAN").eq(5).text(text);
    });    
    jQuery("#rating DIV").mouseout(function(){
      ratingTimeout = window.setTimeout(function(){
        jQuery("#rating DIV").removeClass();      
        for( i = 0; i <= ratingOrig[0]; i++ ){
          jQuery("#rating DIV").eq(i).addClass("active");
        }
        jQuery("#rating SPAN").eq(5).text(ratingOrig[1]);
      },500);
    });
  });  


/* Gallerylist im Contentbereich */
/* -------------------------------------------------------------------------- */

  // Modifizierungen bei eingeschaltetem JavaScript

  jQuery(document).ready(function(){
    
    // Wenn Javascript aktiviert ist, werden Steuerelemente in der Gallerylist
    // eingeblendet
    
    jQuery(".fotostrecken .links").css("display","block");
    jQuery(".fotostrecken .rechts").css("display","block");
    jQuery(".fotostrecken .bilder").css("width","424px");    
    jQuery(".fotostrecken .bilder").css("height","170px");    
    jQuery(".fotostrecken .bilder").css("overflow","hidden");
    jQuery(".fotostrecken TD").css("cursor","pointer");    

    jQuery(".fotostrecken .bilder").scrollLeft(0);

    jQuery(".fotostrecken A").focus(function(){ jQuery(this).blur(); });

    jQuery(".fotostrecken TD").click(function(){
      var link = jQuery(this).children("A").eq(0).attr("href");
      top.location.href = link;
    });

  });

  // Button rechts
  
  function scrollGallerylistRight (obj) {
    var jump = 3;
    var buttons = jQuery(".fotostrecken .rechts A");
    var width = 0;
    for ( i = 0; i < buttons.length; i++ ){
      if(buttons[i] == obj) {
        width = jQuery(".fotostrecken").eq(i).find(".bilder TABLE").outerWidth();
        break;
      }
    }
    var cellwidth = jQuery(".fotostrecken").eq(i).find(".bilder TD").eq(0).innerWidth();
    var scrollpos = jQuery(obj).parent().prev().scrollLeft();
    scrollpos = Math.ceil(scrollpos/cellwidth+3)*cellwidth;
    var max = width-cellwidth*jump;
    if (scrollpos > max) scrollpos = max;
    jQuery(obj).parent().prev().animate( { scrollLeft:scrollpos }, 500 );  
  }

  // Button links
  
  function scrollGallerylistLeft (obj) {
    var jump = 3;
    var buttons = jQuery(".fotostrecken .links A");
    var width = 0;
    for ( i = 0; i < buttons.length; i++ ){
      if(buttons[i] == obj) {
        width = jQuery(".fotostrecken").eq(i).find(".bilder TABLE").outerWidth();
        break;
      }
    }
    var cellwidth = jQuery(".fotostrecken").eq(i).find(".bilder td").eq(0).innerWidth();
    var scrollpos = jQuery(obj).parent().next().scrollLeft();
    scrollpos = Math.floor(scrollpos/cellwidth-jump)*cellwidth;
    if (scrollpos < 0) scrollpos = 0;
    jQuery(obj).parent().next().animate( { scrollLeft:scrollpos }, 500 );  
  }

/* Shop */
/* -------------------------------------------------------------------------- */

jQuery(document).ready(function(){  
  var warenkorbText = "";
  var warenkorbTotal = 0;
  var c = cookieToArray();
  jQuery("#warenkorbSpacer LI").each(function(){
    var id = jQuery(this).attr("id");
    if ( typeof(c["item"+id]) != "undefined" ) {
      if ( c["item"+id] != "NaN" ) {
        warenkorbText += c["item"+id];
        warenkorbText += " x\t";
        warenkorbText += jQuery(this).find("H2").html();
        warenkorbText += "\r\n";
        warenkorbText += "\t";
        warenkorbText += makeEuro(parseInt(c["item"+id])*c["price"+id]);
        warenkorbText += "\r\n";
        warenkorbText += "\r\n";
        warenkorbTotal += parseInt(c["item"+id])*c["price"+id];
      }
    }
  });
  if ( warenkorbTotal > 0 ) {
    warenkorbText += "\tPauschale für Versand und Verpackung";
    warenkorbText += "\r\n";
    warenkorbText += "\t";
    warenkorbText += "3,50 EUR";
    warenkorbText += "\r\n";
    warenkorbText += "\r\n";
    warenkorbText += "------------------------------------------------\r\n";
    warenkorbText += "\r\nGESAMT\t"+makeEuro(warenkorbTotal+3.50);
    jQuery("#volltext TEXTAREA").eq(0).attr("value",warenkorbText);
    jQuery("#volltext TEXTAREA").eq(0).focus(function(){ jQuery(this).blur(); });
    jQuery("#volltext TEXTAREA").eq(0).attr("wrap","hard");
    jQuery("#volltext TEXTAREA").eq(0).css("font-family","'Courier New'");
  }
});

function makeEuro ( int ) {
  var euro = Math.round(int*100)/100;
  euro = euro.toString().split(".");
  if (parseInt(euro[1]) < 10) euro[1] = euro[1]+0;
  euro = euro.join(",")+" EUR";
  return euro;
}

function toCart(quantity,id){
  if ( quantity == 0) {
    document.cookie = 'item'+id+'=0; expires=Thu, 01-Jan-70 00:00:01 GMT;';
  } else {
    if ( quantity == "input" ) quantity = parseInt(jQuery("DIV.cart INPUT").attr('value'));
    var c = cookieToArray();
    if ( typeof(c["item"+id]) != "string" ) {
      var items = quantity;
    } else {
      if ( c["item"+id] == "NaN" ) {
        var items = quantity;
      } else {
        var items = parseInt(c["item"+id])+quantity;
      }
    }
    if ( items < 0 ) items = 0;
    if ( items == 0 ) {
      document.cookie = 'item'+id+'=0; expires=Thu, 01-Jan-70 00:00:01 GMT;';
    } else {
      document.cookie = 'item'+id+'='+items+';';
    }
  }
  var c = cookieToArray();
  var total = 0;
  jQuery(".cart LI:not(.total):not(.empty)").each(function(){
    var id= jQuery(this).attr('id');
    if( typeof(c["item"+id]) == "undefined"){
      jQuery(this).css("display","none");
    } else {
      var quantity = parseInt(c["item"+id]);
      if ( quantity > 0 ) {
        jQuery(this).css("display","block");
        jQuery(this).find("span").html(c["item"+id]+" x ");
        var price = parseFloat(c["price"+id]);
        jQuery(this).find("DIV").html(makeEuro(price*quantity));
        total += price*quantity;
      } else {
        jQuery(this).css("display","none");
      }
    }
  });
  if ( total > 0 ) {
    jQuery(".cart .total").css("display","block");
    jQuery(".cart .empty").css("display","none");
    jQuery(".cart .total DIV").html(makeEuro(total));
  } else {
    jQuery(".cart .total").css("display","none");
    jQuery(".cart .empty").css("display","block");
  }
}


function cookieToArray(){
  var obj = new Object();
  var c = document.cookie;
  c = c.split(";");
  for ( var i=0;i<c.length;i++ ) {
    var value = c[i].split("=");
    var key = value[0].replace(/^\s+/, '').replace (/\s+$/, '');
    value = value[1];
    obj[key] = value;
  }
  return obj;
}

function readCookie() {
  c = cookieToArray();
  for ( key in c ) {
    var value = c[key];
  }
}

jQuery(document).ready(function(){
  c = cookieToArray();
  var total = 0;
  jQuery(".cart LI:not(.total)").each(function(){
    var id = jQuery(this).attr('id');
    jQuery(this).find("img").eq(0).click(function () { toCart(1,id); });
    jQuery(this).find("img").eq(1).click(function () { toCart(-1,id); });
    jQuery(this).find("img").eq(2).click(function () { toCart(0,id); });
    if( jQuery(this).find("DIV").length != 0 && jQuery(this) ) {
      var price = parseFloat(jQuery(this).find("DIV").html().replace(",","."));
      document.cookie = 'price'+id+'='+price+';';
      if( typeof(c["item"+id]) != "undefined" ){
        jQuery(".cart .empty").css("display","none");
        var quantity = parseInt(c["item"+id]);
        if ( quantity > 0 ) {
          jQuery(this).css("display","block");
          jQuery(this).find("span").html(c["item"+id]+" x ");
          jQuery(this).find("DIV").html(makeEuro(price*quantity));
          total += price*quantity;
        }
      }
    }
  });
  if ( total > 0 ) {
    jQuery(".cart .total").css("display","block");
    jQuery(".cart .total DIV").html(makeEuro(total));
  } else {
    jQuery(".cart .total").css("display","none");
    jQuery(".cart .empty").css("display","block");
  }
});

/* TED */
/* -------------------------------------------------------------------------- */

function showTed(tedid) {

  var Adresse = "/_/tools/tedstat.html?_CMELEM="+tedid;
  var tedGrafik = window.open(Adresse, "tedGrafik", "width=760,height=400,scrollbars=yes");
  tedGrafik.focus();
}

/* Brightcove SingleWidget */
/* -------------------------------------------------------------------------- */

function singleWidget () {
  var arguments = singleWidget.arguments;
  var anzahl = (arguments.length - 1) / 5;
  for ( x = 0; x < anzahl; x++ ) {
    var i = x * 5 +1;
    var title = singleWidget.arguments[i];
    var playerId = singleWidget.arguments[i+1];
    var playlistId = singleWidget.arguments[i+2];
    var videoId = singleWidget.arguments[i+3];
    var sPlayerId = singleWidget.arguments[i+4];
    bc_widget_single({'token':'gPVgciZpiW8xZzAfOe8t6W0uP9xs6Y_gLbNA4ZH5LaQ.','postfix':'','width':475,'dir':'','playerIds':[sPlayerId],'videoIds':[videoId]});
  }
}

/* HWS Brightcove */
/* -------------------------------------------------------------------------- */

function hwsBrightcove ( playerId ) {

  jQuery(document).ready(function(){

/*

    var link = "http://api.brightcove.com/services/library?command=find_playlists_for_player_id&player_id="+playerId+"&page_size=1&get_item_count=true&token=gPVgciZpiW8xZzAfOe8t6W0uP9xs6Y_gLbNA4ZH5LaQ.";

    $.get(link, function(data){

      alert("Data Loaded: " + data);

    });

*/

    var flickr = "http://api.flickr.com/services/feeds/photos_public.gne?tags=cat&tagmode=any&format=json&jsoncallback=?";

    $.get(flickr, function(data){

      alert("Data Loaded: " + data);

    });

  });

}

/* hideVideoTab */
/* -------------------------------------------------------------------------- */


function hideVideoTab() {
  var arguments = hideVideoTab.arguments;
  if ( arguments.length == 1 ) {
    var volltextHeader = document.getElementById("volltextHeader");
    if ( typeof ( volltextHeader ) != "undefined" ) {
      var tabs = volltextHeader.getElementsByTagName("LI");
      for ( i = 0; i < tabs.length; i++ ) {
        if ( tabs[i].getElementsByTagName("A")[0].innerHTML == "Videos" ) {
          tabs[i].style.display = "none";
        }
      }
    }
  }
}

/* linkCounter */
/* -------------------------------------------------------------------------- */


jQuery(document).ready(function(){

  var linkCount = new Object();

  jQuery("DIV[name='linkCounter'] A").each(function(){
    var id = jQuery(this).attr("id");
    if ( jQuery(this).find('IMG').length != 0 ) {
      var title = jQuery(this).find('IMG').eq(0).attr('alt');
    } else {
      var title = jQuery(this).find("H5").html();
    }
    var url = jQuery(this).attr("href");
    if(url.indexOf("?")!= -1)
    {
      url = url.split("?");
      url = url[1].split("&");
      for ( i = 0; i < url.length; i++ ){
        url[i] = url[i].split("=");
        if ( url[i][0] == "url" ) {
          var link = "http://vertrieb.medienhaus-bauer.de/forward.php?id="+id+"&name="+title+"&url="+url[i][1];
          jQuery(this).attr("href",link);
          jQuery(this).attr("onclick","");
          if ( typeof(linkCount[id]) == "undefined" ) {
            linkCount[id] = new Image();
            linkCount[id].src = "http://vertrieb.medienhaus-bauer.de/pixel.php?id="+id+"&name="+title;
          }
          break;
        }
      }
    }
  });


});

// Minilogin für Registrierung

jQuery(document).ready(function(){
  var InitalOffset = jQuery("FORM.kommentarFormular").height();
  jQuery("DIV.minilogin").eq(1).css("display","none");

  jQuery("FORM.kommentarFormular UL.menue LI").click(function(){

    var index = jQuery("FORM.kommentarFormular UL.menue LI").index(this);

    jQuery("FORM.kommentarFormular DIV.minilogin").css("display","none");
    jQuery("FORM.kommentarFormular UL.menue LI").removeClass();
    jQuery("FORM.kommentarFormular DIV.minilogin").eq(index).css("display","block");
    jQuery("FORM.kommentarFormular UL.menue LI").eq(index).addClass("active");
    if (navigator.appName == 'Microsoft Internet Explorer' && navigator.appVersion.substring(22, 23) != "8") {
      jQuery("FORM.kommentarFormular").css("height","auto");
      var StdOffset = '390px';
      var OldOffset = jQuery("FORM.kommentarFormular").height();
      if ( index === 1 ) {
        var NewOffset = OldOffset - 327;
        jQuery("FORM.kommentarFormular").css("height",NewOffset+"px");
      }
      else {
        jQuery("FORM.kommentarFormular").css("height",StdOffset);
      }
    }
  });

  if ( jQuery("FORM.kommentarFormular .fcms-error-messages").length == 1 || jQuery("FORM.kommentarFormular .fcms-other-messages").length == 1 ) {
    jQuery("FORM.kommentarFormular DIV.minilogin").css("display","none");
    jQuery("FORM.kommentarFormular LI").removeClass();
    jQuery("FORM.kommentarFormular DIV.minilogin").eq(1).css("display","block");
    jQuery("FORM.kommentarFormular LI").eq(1).addClass("active");    
  }
})

function tabNavPosAnz ( anzahl ) {
  jQuery(document).ready(function(){
    jQuery("UL.navtabbox A").each(function(){
      if ( jQuery(this).html() == "Kommentare" ) {
        jQuery(this).html("Kommentare ("+anzahl+")");
        jQuery(".linkbox").css("display","block");
      }
    })
  });
}

// Brightcove Videowidget

var bc_pids = new Object();

bc_pids["recklinghaeuser-zeitung"] = new Object();
bc_pids["recklinghaeuser-zeitung"]["neueste-videos"] = 34627945001;
bc_pids["recklinghaeuser-zeitung"]["lokales"]        = 34823942001;
bc_pids["recklinghaeuser-zeitung"]["nachrichten"]    = 34619051001;
bc_pids["recklinghaeuser-zeitung"]["vermischtes"]    = 34627947001;
bc_pids["recklinghaeuser-zeitung"]["sport"]          = 34823946001;
bc_pids["recklinghaeuser-zeitung"]["kino"]           = 34616332001;
bc_pids["recklinghaeuser-zeitung"]["auto"]           = 34616334001;
bc_pids["recklinghaeuser-zeitung"]["literatur"]      = 36496823001;
bc_pids["recklinghaeuser-zeitung"]["top-videos"]     = 34626220001;

bc_pids["dattelner-morgenpost"] = new Object();
bc_pids["dattelner-morgenpost"]["neueste-videos"]    = 34619046001;
bc_pids["dattelner-morgenpost"]["lokales"]           = 34840875001;
bc_pids["dattelner-morgenpost"]["nachrichten"]       = 34448633001;
bc_pids["dattelner-morgenpost"]["vermischtes"]       = 34627943001;
bc_pids["dattelner-morgenpost"]["sport"]             = 34830097001;
bc_pids["dattelner-morgenpost"]["kino"]              = 34626212001;
bc_pids["dattelner-morgenpost"]["auto"]              = 34619045001;
bc_pids["dattelner-morgenpost"]["literatur"]         = 36546182001;
bc_pids["dattelner-morgenpost"]["top-videos"]        = 34626211001;

bc_pids["hertener-allgemeine"] = new Object();
bc_pids["hertener-allgemeine"]["neueste-videos"]     = 34627944001;
bc_pids["hertener-allgemeine"]["lokales"]            = 34823944001;
bc_pids["hertener-allgemeine"]["nachrichten"]        = 34626215001;
bc_pids["hertener-allgemeine"]["vermischtes"]        = 34616330001;
bc_pids["hertener-allgemeine"]["sport"]              = 34823947001;
bc_pids["hertener-allgemeine"]["kino"]               = 34626218001;
bc_pids["hertener-allgemeine"]["auto"]               = 34616335001;
bc_pids["hertener-allgemeine"]["literatur"]          = 36546183001;
bc_pids["hertener-allgemeine"]["top-videos"]         = 34619054001;

bc_pids["marler-zeitung"] = new Object();
bc_pids["marler-zeitung"]["neueste-videos"]          = 34616326001;
bc_pids["marler-zeitung"]["lokales"]                 = 34823943001;
bc_pids["marler-zeitung"]["nachrichten"]             = 34616329001;
bc_pids["marler-zeitung"]["vermischtes"]             = 34626217001;
bc_pids["marler-zeitung"]["sport"]                   = 34840876001;
bc_pids["marler-zeitung"]["kino"]                    = 34627949001;
bc_pids["marler-zeitung"]["auto"]                    = 34627950001;
bc_pids["marler-zeitung"]["literatur"]               = 36496823001;
bc_pids["marler-zeitung"]["top-videos"]              = 34626221001;

bc_pids["stimberg-zeitung"] = new Object();
bc_pids["stimberg-zeitung"]["neueste-videos"]        = 34616327001;
bc_pids["stimberg-zeitung"]["lokales"]               = 34823941001;
bc_pids["stimberg-zeitung"]["nachrichten"]           = 34626214001;
bc_pids["stimberg-zeitung"]["vermischtes"]           = 34619052001;
bc_pids["stimberg-zeitung"]["sport"]                 = 34875813001;
bc_pids["stimberg-zeitung"]["kino"]                  = 34616331001;
bc_pids["stimberg-zeitung"]["auto"]                  = 34619053001;
bc_pids["stimberg-zeitung"]["literatur"]             = 37654301001;
bc_pids["stimberg-zeitung"]["top-videos"]            = 34757231001;

bc_pids["waltroper-zeitung"] = new Object();
bc_pids["waltroper-zeitung"]["neueste-videos"]        = 34627946001;
bc_pids["waltroper-zeitung"]["lokales"]               = 34830096001;
bc_pids["waltroper-zeitung"]["nachrichten"]           = 34616328001;
bc_pids["waltroper-zeitung"]["vermischtes"]           = 34626216001;
bc_pids["waltroper-zeitung"]["sport"]                 = 34823945001;
bc_pids["waltroper-zeitung"]["kino"]                  = 34627948001;
bc_pids["waltroper-zeitung"]["auto"]                  = 34616333001;
bc_pids["waltroper-zeitung"]["literatur"]             = 37624616001;
bc_pids["waltroper-zeitung"]["top-videos"]            = 34626219001;


function response(data) {

  if ( typeof ( data.items ) != "undefined" ) {
    var header = "Neueste Videos";
    var items = data.items;
  }
  if ( typeof ( data.videos ) != "undefined" ) {
    var bclid = data.id;
    var header = "Videos: "+data.name;
    var items = data.videos;
  }

  var image = '<img src="'+items[0].videoStillURL+'" width="290" />';
  var name = items[0].name;

  jQuery("#videowidget td").eq(0).append('<img src="'+image+'" width="290" />');
  jQuery("#videowidget h3").html(items[0].name);

  var hwsBox = '<div class="hwsBox">';
  hwsBox += '<h2>' + header + '</h2>';
  hwsBox += '<div class="videowidget">';
  hwsBox += '<table cellspacing="0" cellpadding="0" border="0">';
  hwsBox += '<tr>';
  hwsBox += '<td height="218" valign="middle" style="background-color:#000000">';
  hwsBox += '<div class="video">';
  hwsBox += '<div class="title">';
  hwsBox += '<h3>';
  hwsBox += name;
  hwsBox += '</h3>';
  hwsBox += '</div>';
  hwsBox += image;
  hwsBox += '</div>';
  hwsBox += '</td>';
  hwsBox += '</tr>';
  hwsBox += '<tr>';
  hwsBox += '<td>';
  hwsBox += '<img src="/pics/brightcove/videowidget_left.gif" width="14" height="14" class="button">';
  hwsBox += '<div class="thumbs">';
  hwsBox += '<table cellspacing="2" cellpadding="3" border="0"><tr>'
  for( i=0; i<items.length; i++ ){
    if ( i >= 12 ) break;
    if ( i == 0 ) {
      hwsBox += '<td class="active">';
    } else {
      hwsBox += '<td>';
    }
    if ( bclid ) {
      var link = '/media/videos/?bctid='+items[i].id+'&bclid='+bclid+'&bcpid='+bcpid;
    } else {
      var link = '/media/videos/?bctid='+items[i].id;
    }
    hwsBox += '<a href="'+link+'">';
    hwsBox += '<img src="'+items[i].thumbnailURL+'" />';
    hwsBox += '</a>';
    hwsBox += '<span name="title">'+items[i].name+'</span>';
    hwsBox += '<span name="image">'+items[i].videoStillURL+'</span>';
    hwsBox += '</td>';
  }
  hwsBox += '</tr></table>';
  hwsBox += '</div>';
  hwsBox += '<img src="/pics/brightcove/videowidget_right.gif" width="14" height="14" class="button">';
  hwsBox += '</td>';
  hwsBox += '</tr>';
  hwsBox += '</table>';
  hwsBox += '</div>';
  hwsBox += '<div class="ressortLink">';
  hwsBox += '<a href="/media/videos">Alle Videos</a>';
  hwsBox += '</div>';
  hwsBox += '</div>';
  document.write(hwsBox);

  jQuery(".videowidget:last .title").click(function() { window.location.href = jQuery(".videowidget:last .thumbs A").eq(0).attr("href"); });
  jQuery(".videowidget:last .thumbs").css("scrollLeft",0);


  jQuery(".videowidget:last .thumbs TD").mouseover(function(){
    videoDiv = jQuery(this).parents(".videowidget").find(".video");
    thisTr = jQuery(this);
    jQuery(this).parent().find("td").removeClass();
    jQuery(this).addClass("active");
    if ( jQuery(this).parents(".videowidget").find("img").eq(0).attr("src") != thisTr.find("SPAN[name='image']").html() ) {
      videoDiv.stop().fadeTo('fast',0,function () {
        var image = thisTr.find("SPAN[name='image']").html();
        var name = thisTr.find("SPAN[name='title']").html();
        var img = new Image();
        jQuery(img).load(function () {
          videoDiv.find("img").eq(0).attr("src",image);
          videoDiv.find("h3").eq(0).html(name);        
          videoDiv.fadeTo('fast',1);
        }).attr('src',image);
      });
      jQuery(this).parents(".videowidget").find(".title").click(function(){
        window.location.href = thisTr.find("a").attr("href");
      });
    }
  });

  jQuery(".videowidget:last .button").eq(1).click(function(){
    var offset1 = jQuery(this).parents(".videowidget").find(".thumbs TD").eq(0).offset();
    var offset2 = jQuery(this).parents(".videowidget").find(".thumbs TD").eq(1).offset();
    var offset = offset2.left - offset1.left;
    var bc_scrollpos = jQuery(this).parents(".videowidget").find(".thumbs TABLE").css("margin-left");
    if ( bc_scrollpos == "auto" ) bc_scrollpos = 0;
    bc_scrollpos = Math.round(parseInt(bc_scrollpos)*(-1)/offset);
    if ( bc_scrollpos >= jQuery(this).parents(".videowidget").find(".thumbs TD").length - 3 ) {
      bc_scrollpos = 0;
    } else if ( bc_scrollpos >= jQuery(this).parents(".videowidget").find(".thumbs TD").length - 5 ) {
      bc_scrollpos = jQuery(this).parents(".videowidget").find(".thumbs TD").length - 3;
    } else {
      bc_scrollpos += 3;
    }
    bcvwleft = bc_scrollpos * offset * (-1);
    if ( bc_scrollpos > jQuery(this).parents(".videowidget").find(".thumbs TD").length-3 ) bc_scrollpos = 0;
    jQuery(this).parents(".videowidget").find(".thumbs TABLE").animate({"marginLeft":bcvwleft},300);
  });

  jQuery(".videowidget:last .button").eq(0).click(function(){
    var offset1 = jQuery(this).parents(".videowidget").find(".thumbs TD").eq(0).offset();
    var offset2 = jQuery(this).parents(".videowidget").find(".thumbs TD").eq(1).offset();
    var offset = offset2.left - offset1.left;
    var bc_scrollpos = jQuery(this).parents(".videowidget").find(".thumbs TABLE").css("margin-left");
    if ( bc_scrollpos == "auto" ) bc_scrollpos = 0;
    bc_scrollpos = Math.round(parseInt(bc_scrollpos)*(-1)/offset);
    if ( bc_scrollpos <= 0 ) {
      bc_scrollpos -= jQuery(this).parents(".videowidget").find(".thumbs TD").length - 3;
    } else if ( bc_scrollpos <= 2 ) {
      bc_scrollpos = 0;
    } else {
      bc_scrollpos -= 3;
    }
    if ( bc_scrollpos < 0 ) bc_scrollpos = jQuery(this).parents(".videowidget").find(".thumbs TD").length-3;
    bcvwleft = bc_scrollpos * offset * (-1);
    jQuery(this).parents(".videowidget").find(".thumbs TABLE").animate({'margin-left':bcvwleft},300);
  });

}

function videowidget () {

  var bc_api = "http://api.brightcove.com/services/library";
  var bc_token = "gPVgciZpiW8xZzAfOe8t6W0uP9xs6Y_gLbNA4ZH5LaQ.";
  var bc_fields = "id,name,thumbnailURL,videoStillURL,playsTrailingWeek";
  var bc_sort = "plays_trailing_week";

  var bc_command = videowidget.arguments[0];
  var bc_pagesize = 12;

  if ( bc_command == 'find_all_videos') {
    var bc_src = bc_api+'?command='+bc_command+'&token='+bc_token+'&fields='+bc_fields+'&sort_by='+bc_sort+'&page_size='+bc_pagesize+'&callback=response';
    document.write('<scr'+'ipt type="text/javascript" src="'+bc_src+'"></scr'+'ipt>');
  } else if ( bc_command == 'find_playlist_by_id') {
    var playlist_id = videowidget.arguments[1];
    var domain = window.location.hostname.split(".")[1];
    bcpid = bc_pids[domain][videowidget.arguments[2]];
    var bc_src = bc_api+'?command='+bc_command+'&playlist_id='+playlist_id+'&token='+bc_token+'&callback=response';
    document.write('<scr'+'ipt type="text/javascript" src="'+bc_src+'"></scr'+'ipt>');
  }

}

function showComments ( tr_id, ar_id, comments ) {

  if ( comments == 1 ) {
    document.write ('<a href="art'+tr_id+','+ar_id+',D" class="comments">1 Kommentar</a>');
  } else if ( comments > 1 ) {
    document.write ('<a href="art'+tr_id+','+ar_id+',D" class="comments">'+comments+' Kommentare</a>');
  }
}

function insertLink ( ar_id ) {
  var link = jQuery("#ar"+ar_id+" A").eq(0).attr("href");
  jQuery("#ar"+ar_id+" P").eq(0).append('<a href="'+link+'" class="arLink">zum Artikel</a>');
  if ( insertLink.arguments.length >= 2 ) {
    var comments = parseInt(insertLink.arguments[1]);
    if ( comments == 1 ) {
      jQuery("#ar"+ar_id+" P").eq(0).append('<a href="'+link+',D" class="comments" title="1 Kommentar">1</a>');      
    } else if ( comments > 1 ) {
      jQuery("#ar"+ar_id+" P").eq(0).append('<a href="'+link+',D" class="comments" title="'+comments+' Kommentare">'+comments+'</a>');      
    }
  }
  jQuery("#ar"+ar_id+" IMG").eq(0).wrap('<a href="'+link+'"></a>');
}

/* trimTextLines */

function trimTextLines() {
 if ( trimTextLines.arguments.length == 2 ) {
    var obj = trimTextLines.arguments[0];
    var maxHeight = trimTextLines.arguments[1];
    var link = "";
    if ( obj.find("A").length != 0 ) {
      link = obj.find("A:eq(0)");
      link = ' <a href="' + link.attr("href") + '">' + link.html() + '</a>';
    }
    var objText = jQuery.trim(obj.text());
    var lastSpace = objText.lastIndexOf(" ");
    while ( obj.outerHeight() > maxHeight && lastSpace != -1 ) {
      objText = objText.substr(0,lastSpace);
      obj.html(objText + "..." + link);
      lastSpace = objText.lastIndexOf(" ");
    }
  }
}

/* TopNewsSlider */

function topNewsSlider (line,active) {
  var height = parseInt ( active.find(".hiddenContent").css("height") );
  var counter = 0;
  var lineHiddenContent = line.find(".hiddenContent");
  var activeHiddenContent = active.find(".hiddenContent");
  lineHiddenContent.css("height",0).css("display","block");
  active.removeClass("active");
  var interval = window.setInterval(function(){
    counter += 6;
    var newHeight = height-counter;
    activeHiddenContent.css("height",newHeight);
    lineHiddenContent.css("height",counter);
    if ( counter >= height ) {
      lineHiddenContent.css("height",height); 
      active.css("display","none");
      activeHiddenContent.css("display","none");
      active.css("display","block");
      line.addClass("active");
      clearInterval(interval);
      if ( line.hasClass("next") == false ) {
        topNewsSlider(line.parent().find(".next"),line);
      }
    }
  },16);
}


/* initToplist */

function initToplist() {
  var toplist = jQuery(".toplist:last");
  toplist.find(".line:first").addClass("active");
  toplist.find(".line").each(function(){
    var hiddenContent = jQuery(this).find(".hiddenContent:eq(0)");
    hiddenContent.css("display","block");
    trimTextLines(jQuery(this).find("P:eq(0)"),70);
    if ( jQuery(this).hasClass("active") == false ) hiddenContent.css("display","none");
    jQuery(this).mouseover(function(){
      var active = jQuery(this).parent().find("> .active");
      var line = jQuery(this);
      jQuery(this).parent().find(".line").removeClass("next");
      line.addClass("next");
      if ( active.length != 0 && jQuery(this).hasClass("active") != true ) {
        topNewsSlider(line,active);
      }
    });
  });
}





// IndexBox

function indexBox() {

	jQuery('LI.index').hover(
		function() {
			jQuery(this).css('cursor', 'pointer');
		},
		function() {
			jQuery(this).css('cursor', 'default');
		}
	)




	jQuery("LI.index").click(function(){
//		jQuery('#navi_index').css('display','block');

      if (jQuery("#navi_index").is(":hidden")) {
     jQuery('LI.index').css('background','#21714a');
        jQuery("#navi_index").slideDown("slow");
      } else {
        jQuery("#navi_index").slideUp("slow");
        jQuery('LI.index').css('background','url(/pics/header/index.gif) repeat-x scroll center top');
        jQuery('LI.index').css('padding','3px 16px 0');css

      }
	});




	


	jQuery('#close').hover(
		function() {
			jQuery(this).css('cursor', 'pointer');
		},
		function() {
			jQuery(this).css('cursor', 'default');
		}
	);

	jQuery("#close").click(function(){
        jQuery("#navi_index").slideUp("slow");
        jQuery('LI.index').css('background','url(/pics/header/index.gif) repeat-x scroll center top');
        jQuery('LI.index').css('padding','3px 16px 0');css



//		jQuery('#navi_index').css('display','none');
	});


}



















/* OBJECT-CHECKER */

/*

function objectChecker() {
  var right = jQuery("#volltext .right");
  var objects = right.find("OBJECT");
  var width = right.width();
  objects.each(function(){
    if ( parseInt ( jQuery(this).attr("width") ) > width ) {
      jQuery("#volltext .left").remove();
      jQuery(".right").css("width",jQuery("#volltext").width());
      return false;
    }
  });
}

*/




function initDetail() {
  var commentsDiv = jQuery('#article .right .comments');
  var commentsLink = commentsDiv.find('.comLink A').attr('href');
  commentsDiv.find("A.antworten").each(function() {
    jQuery(this).attr('href',commentsLink+jQuery(this).attr('href')+"#addComment");
  });
/*  objectChecker(); */
  jQuery("#article .moreImages A").each(function(){
    if ( jQuery("#article .image").length == 0 ) {
      var html = '<div class="image"></div>';
      jQuery(this).addClass("active");
      jQuery(this).attr("name","active");
      jQuery(this).css("display","block");
      html += '<div class="imageText">';
      html += '<div class="imgLeft">links</div>';
      html += '<span>1/'+jQuery("#article .moreImages A").length+'</span>';
      html += '<div class="imgRight">rechts</div>';
      html += '<p>' + jQuery(this).find("SPAN").html() + '</p>';
      html += '</div>';
      jQuery("#tabNav").after(html);
    }
    jQuery("#article .image").append(jQuery(this));
  });
  var images = jQuery("#content .image A");
  if ( images.length > 1 ) {
    var imageText = jQuery("#article .imageText");
    imageText.find("SPAN").css("display","inline");
    imageText.find(".imgLeft, .imgRight").css("visibility","visible").css("opacity",0.4);
    jQuery(".image").mouseover(function(){ imageText.find(".imgLeft, .imgRight").css("opacity",1) }).mouseout(function(){ imageText.find(".imgLeft, .imgRight").css("opacity",0.4) });
    imageText.find(".imgLeft, .imgRight").mouseover(function(){ jQuery(this).css("visibility","visible").css("opacity",1); }).mouseout(function(){ imageText.find(".imgLeft, .imgRight").css("opacity",0.4) });      
  }

  jQuery("#article .imageText .imgRight").click(function(){
    var images = jQuery("#article .image A");
    var active = jQuery("#article .image A[name='active']");
    active.css('opacity',1).animate({opacity:0},300,function(){ jQuery(this).css("display","none"); });
    active.attr("name","");
    if ( active.next().length != 0 ) {
      var next = active.next();
    } else {
      var next = images.first();
    }
    next.css({'opacity':0,'display':'block'}).animate({opacity:1},300);
    next.attr("name","active");
    var bildnr = images.index(next)+1;
    var textBox = jQuery(this).parent();
    textBox.find("span").html(bildnr+"/"+images.length);
    textBox.find("P").remove();
    textBox.find("SPAN").after("<p>"+jQuery.trim(next.find("SPAN").text())+"</p>");
  });

  jQuery("#article .imageText .imgLeft").click(function(){
    var images = jQuery("#article .image A");
    var active = jQuery("#article .image A[name='active']");
    active.css('opacity',1).animate({opacity:0},300,function(){ jQuery(this).css("display","none"); });
    active.attr("name","");
    if ( active.prev().length != 0 ) {
      var next = active.prev();
    } else {
      var next = images.last();
    }
    next.css({'opacity':0,'display':'block'}).animate({opacity:1},300);
    next.attr("name","active");
    var bildnr = images.index(next)+1;
    var textBox = jQuery(this).parent();
    textBox.find("span").html(bildnr+"/"+images.length);
    textBox.find("P").remove();
    textBox.find("SPAN").after("<p>"+jQuery.trim(next.find("SPAN").text())+"</p>");
  });

  jQuery("#article .image A").fancybox({'transitionIn':'elastic','transitionOut':'elastic','speedIn':600,'speedOut':200,'onStart':function(){
    jQuery("#superbanner, #skyscraper, DIV.werb3anzeige, #adl_DD2A_DhtmlLayer").css("visibility","hidden");
  },'onClosed':function(){
    jQuery("#superbanner, #skyscraper, DIV.werb3anzeige, #adl_DD2A_DhtmlLayer").css("visibility","visible");
  }});

}


  function initNavi() {

    // MouseOver auf Lv1-Navigation
    var lv1Active = jQuery("#lv1Bar > UL > LI[class='active']");

    var lv1Timeout = 0;
    var lv2Timeout = 0;

    jQuery("#lv1Bar > UL > LI").mouseover(function(){
      if ( lv1Timeout != 0 ) {
        clearTimeout(lv1Timeout);
        lv1Timeout = 0;
      }
      var thisElement = jQuery(this);
      lv1Timeout = window.setTimeout(function(){
        if ( thisElement.attr("class") != "active" ) {
          jQuery("#lv1Bar > UL > LI > UL > LI > UL").removeClass();
          jQuery("#lv1Bar > UL > LI").removeClass();
          thisElement.addClass("active");
        }
      },250);
      thisElement.find("> UL > LI").mouseover(function(){
        if ( lv2Timeout != 0 ) {
          clearTimeout(lv2Timeout);
          lv2Timeout = 0;
        }
        if ( jQuery(this).find("UL").attr("class") != "active" ) {
          jQuery(this).parent().find("LI").removeClass("hover");
          jQuery(this).addClass("hover");
          jQuery(this).parent().find("LI > UL").removeClass("active");
          var dropDown = jQuery(this).find("UL");
          if ( dropDown.find("LI").length != 0 ) dropDown.addClass("active");
          if ( dropDown.length != "0" ) {
            var linkWidth = jQuery(this).find("A:eq(0)").width();
            if ( dropDown.width() < linkWidth ) {
              dropDown.css( "width", linkWidth - 6 );
            }
          }
        }
      }).mouseout(function(){
        var thisElement = jQuery(this);
        if ( lv2Timeout != 0 ) {
          clearTimeout(lv2Timeout);
          lv2Timeout = 0;
        }
        lv2Timeout = window.setTimeout(function(){
          thisElement.removeClass("hover");
          thisElement.find("UL").removeClass("active");
        },1000);
      });
    }).mouseout(function(){
      if ( lv1Timeout != 0 ) {
        clearTimeout(lv1Timeout);
        lv1Timeout = 0;
      }
      lv1Timeout = window.setTimeout(function(){
        jQuery("#lv1Bar > UL > LI").removeClass();
        lv1Active.addClass("active");
      },1000);
    });
  }



    // STAGE
jQuery(document).ready(function(){
    function changeStage(obj) {
      var pointerPos = obj.position().left + obj.outerWidth() / 2 - 15;
      var stage = obj.parent().parent();
      var pointer = stage.find(".pointer");
      var tab = obj.parent();
      pointer.animate({left: pointerPos}, { duration: 300, queue: false });
      if ( tab.attr("name") != "active" ) {
        stage.find(".thumb[name='active'] .article").animate({opacity: 0}, { duration: 300, queue: false, complete: function(){
            jQuery(this).css("display","none");
          }
        });
        tab.find(".article").css("opacity",0);
        tab.find(".article").animate({opacity: 1}, { duration: 300, queue: false, step: function() {
          tab.find(".article").css("display","block");          
        }});
        stage.find(".thumb").attr("name","");
        tab.attr("name","active");
      }
      var stage = obj.parent().parent();
      var pos = pointer.position();
    }

    var stageInterval = 1;

    jQuery(".stage").each(function(){
      var thisElement = jQuery(this);
      window.setInterval(function(){
        if ( stageInterval == 1 ) {
          var index = thisElement.find(".thumb").index( thisElement.find(".thumb[name='active']" ) );
          index++;
          if ( index == thisElement.find(".thumb").length ) index = 0;
          changeStage(thisElement.find(".thumb").eq(index).find("A:eq(0)"));
        }
      },10000);
    });
    
    jQuery(".stage .thumb > A").mouseover(function(){
      changeStage(jQuery(this));
    });

    jQuery(".stage .thumb").mouseover(function(){
      stageInterval = 0;
    }).mouseout(function(){
      stageInterval = 1;
    });
            
});

// AddPlayer

var videoLength = 0;

function addPlayer () {
  videoLength++;
  var cleanURL = window.location.href.substr(window.location.href.lastIndexOf("/")+1);
  if ( cleanURL.indexOf(";") != -1 ) cleanURL = cleanURL.substr(cleanURL.indexOf(";")+1);
  if ( cleanURL.indexOf("?") != -1 ) cleanURL = cleanURL.substr(0,cleanURL.indexOf("?")+1);
  if ( cleanURL.indexOf(".") != -1 ) cleanURL = "";
  var art = cleanURL.substr(0,3);
  var tab = cleanURL.substr(cleanURL.lastIndexOf(",")+1,1).toUpperCase();
  if ( addPlayer.arguments.length < 2 ) return false;
  var videoID = addPlayer.arguments[0];
  var playerID = addPlayer.arguments[1];
  var token = "gPVgciZpiW8xZzAfOe8t6W0uP9xs6Y_gLbNA4ZH5LaQ.";
  
  // ARTIKEL ?BERSICHTSSEITE 

  if ( cleanURL == "" ) {
    if ( typeof ( tsArtID ) != "undefined" ) {
      var teaser = jQuery("#"+tsArtID);
    } else {
      var teaser = jQuery("DIV.teasergross, DIV.teaser, DIV.resTeaser, DIV.article, #breakingnews, #ressortAufmacherScroller TD").last();
    }
    var link = teaser.find("A:eq(0)").attr("href");
    var span = teaser.find("P SPAN:last");
    var html = '<a href="'+link+',B" class="vid">1 Video</a>';

    if ( span.find("A.vid").length != 0 ) {
      var count = parseInt ( span.find("A.vid").html() );
      count++;
      span.find("A.vid").html(count + " Videos");
    } else {
      span.prepend(' ' + html + ' ');
    }

  // ARTIKEL VOLLTEXT
  } else if ( cleanURL.split(",").length == 2 || tab == "A" ) {
    bc_widget_single({ 'token': token,'postfix':'','width':172,'dir':'', 'videoIds': [videoID], 'playerIds': [playerID] });

  // VIDEO TAB
  } else if ( cleanURL.split(",")[2] == "B" ) {
    bc_widget_single({ 'token': token,'postfix':'','width':475,'dir':'', 'videoIds': [videoID], 'playerIds': [playerID] });
  }

}
