jQuery.noConflict();

function loadLbxDiashow() {
  return false;
}

/* WERBUNG */

  function loadBanner(o){

    var obj = jQuery("#"+o)

    if ( obj.length == 0 ) return false;

    var parts = obj.html().split("#");

    if(parts.length!=8) return false;

    var serverName = parts[0];
    var prefix = parts[1];
    var ressortKey = parts[2];
    var flyingAd = parts[3];
    var random = parts[4];
    var width = parts[5];
    var height = parts[6];
    var werbeplatz = parts[7];
    if(typeof(WLRCMD)=="undefined"){var WLRCMD="";}

    if(document.referrer){
      var ref = document.referrer.split("/");
      if ( ref.length == 4 ) {
        // Wird eine Übersichtsseite aufgerufen?
        if(window.location.href.length > window.location.href.lastIndexOf("/")+3){
          // Startseitenartikel
          ressortKey = "homepage";
        }
      }
    }

    var html = '<scr'+'ipt language="JavaScript" src="';
    html += serverName;
    html += '/adj/';
    html += prefix
    html += '/'
    html += ressortKey
    html += ';oms='
    html += ressortKey
    html += ';nielsen=2;';
    html += flyingAd;
    html += WLRCMD;
    html += ';sz=';
    html += width;
    html += 'x';
    html += height;
    html += ';tile=';
    html += werbeplatz;
    html += ';ord=';
    html += random;
    html += '?"><\/scr'+'ipt>';

    document.write(html);

  }

  function removeBannerTable(o){
    var obj = jQuery("#"+o);
    if ( obj.length == 0 ) return false;
    var TABLES = obj.find("TABLE");
    if ( TABLES.length != 0 ) {
      TABLES.eq(0).remove();
    }
  }

  function hideBanner(o,h){
    var obj = jQuery("#"+o);
    if ( obj.length == 0 ) return false;
    obj.css("visibility","hidden").css("position","absolute");
    jQuery(document).ready(function(){
      if ( obj.length != 1 ) return false;
      if ( obj.height() < h ) {
        obj.css("display","none");
      } else {
        obj.css("visibility","visible").css("position","relative");
      }
    });
  }

function set_active_submenue(){
  var menue_array = document.getElementById('menue').getElementsByTagName('td');
  for(i=0;i<menue_array.length;i+=2){
    if(menue_array[i].className=="menue_aktiv") {
      menue_aktiv = i;
      break;
    }
  }
}
function show_submenue(obj) {
  if(typeof(submenue_timeout) != "undefined"){
    window.clearTimeout(submenue_timeout);    
  }
  if(obj != "hold") {
    if(obj == "close") obj = document.getElementById('menue').getElementsByTagName('td')[menue_aktiv];  
    menue_array = document.getElementById('menue').getElementsByTagName('td');
    submenue_array = document.getElementById('submenue').getElementsByTagName('table');
    for(i=0;i<menue_array.length;i+=2){
      if(menue_array[i] == obj){
        menue_array[i].className = "menue_aktiv";
        submenue_array[i/2].style.display = "block";
      } else {
        menue_array[i].className = "menue_inaktiv";
        submenue_array[i/2].style.display = "none";
      }
    }
  }
}

function printwin(pwi, phe) {
     var url = document.location.href;
     url = url.replace(/#.*/,'');

     if(!pwi) pwi=640;
     if(!phe) phe=480;

     url = url + (url.indexOf('?')>-1 ? "&" : "?") + '_FRAME=33&_FORMAT=PRINT';
     var pw = window.open(url,'PRINTWIN','width='+pwi+',height='+phe+',scrollbars=1');
     // auskommentiert von fido, 26.05.05 - beisst sich mit printfoot.tpl
     // while ( ! pw.document );
     // while ( ! pw.document.body );
     // pw.document.body.onload=pw.print;
     // pw.setTimeout('window.close()',30000);
}

function active_submenue(i) {
  if(typeof(submenue_timeout) != "undefined"){
    window.clearTimeout(submenue_timeout);    
  }
  submenue_timeout = window.setTimeout("show_submenue('close')", 100);
}
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');
   if ( !mw || mw.closed ) return(false);
   mw.resizeTo(w,h); 
   mw.focus(0); 
   warr[name]=mw;
}


///////////////////////////////////////////////////////////////////
// open_popup (Dennis Bohn)                                      //
//                                                               //
// ?ffnet ein Popup                                              //
///////////////////////////////////////////////////////////////////

function open_popup (url,width,height) {
  if(typeof width  != "undefined" && typeof height == "undefined"){
    height = Math.round(width/4*3);
  } else if(typeof width  == "undefined" && typeof height != "undefined"){
    width = Math.round(height/3*4);
  } else if(typeof width  != "undefined" && typeof height != "undefined"){
    width = 780;
    height = 540;
  }
  fenster=window.open(url,"unipopup","left=0,top=0,width="+width+",height="+height+",location=no,menubar=no,resizable=no,scrollbars=no,status=no,toolbar=no");
  fenster.focus();
}

///////////////////////////////////////////////////////////////////
// Toggle_DIVS                                                   //
//                                                               //
// Ein- und Ausblenden von DIV-Containern                        //
///////////////////////////////////////////////////////////////////

var state = 'none';

function toggle_divs ( layer_ref ) {
    if (state == 'block')    state = 'none';
    else    state = 'block';

    //IS IE 4 or 5 (or 6 beta)
    if (document.all)    eval( "document.all." + layer_ref + ".style.display = state");

    //IS NETSCAPE 4 or below
    if (document.layers)    document.layers[layer_ref].display = state;

    if (document.getElementById && !document.all) {
        maxwell_smart = document.getElementById(layer_ref);
        maxwell_smart.style.display = state;
    }
}

function cmshelp(sub) {
    cmswin('hilfe','/_/tools/hilfe.html?'+sub,250,100);
    return(false);
}

///////////////////////////////////////////////////////////////////
// content_video (Dennis Bohn)                                   //
//                                                               //
// Erzeugt ein Brightcove-Video im Contentbereich                //
///////////////////////////////////////////////////////////////////

function content_video () {
  var checknumber = Math.round((content_video.arguments.length-1)/5);
  if((content_video.arguments.length-1)/5 == checknumber) {
    var article = content_video.arguments[0];
    var bc_linkbox = "";
    for(i=1;i<content_video.arguments.length;i+=5){
      var title = content_video.arguments[i];
      var playerId = content_video.arguments[i+1];
      var playlistId = content_video.arguments[i+2];
      var videoId = content_video.arguments[i+3];
      var sPlayerId = content_video.arguments[i+4];
      if(content_video.arguments[0] == 0) {

        if (i==1) var output = '<table cellspacing="0" cellpadding="0" border="0">';
        output += '<tr><td height="420">';
        output += '<object id="myExperience25811861001" class="BrightcoveExperience">';
        output += '<param name="autoStart" value="false" />';
        output += '<param name="bgcolor" value="#FFFFFF" />';
        output += '<param name="linkBaseURL" value="'+window.location.href+'" />';
        output += '<param name="width" value="486" />';
        output += '<param name="height" value="416" />';
        output += '<param name="playerID" value="'+sPlayerId+'" />';
        output += '<param name="publisherID" value="1863355775"/>';
        output += '<param name="isVid" value="true" />';
        output += '<param name="@videoPlayer" value="'+videoId+'" />';
        output += '</object>';
        output += '</td></tr>';
        
      } else {
        bc_linkbox += '<div class="lbx_link">Video: <a href="/videos/index.html?bcpid='+playerId+'&bclid='+playlistId+'&bctid='+videoId+'">'+title+'</a></div>';
      }
    }

    if (typeof(output) != "undefined"){
      document.write(output+"</table>");
    } else if (bc_linkbox.length > 0) {
      var linkbox = document.getElementById('lbx'+article);
      var linkspan = linkbox.getElementsByTagName('span');
      if(linkspan.length == 1){
        linkspan[0].innerHTML = bc_linkbox+linkspan[0].innerHTML;
      } else {
        linkbox.innerHTML = '<div class="lbx_headline">Mehr zu diesem Thema</div>'+bc_linkbox;
      }
      linkbox.getElementsByTagName('div')[0].style.display = "block";
    }
  }
}

/* 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","428px");    
    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).outerWidth();
    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).outerWidth();
    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 );  
  }


// UTF8 decode/encode

var Utf8 = {
 
	// public method for url encoding
	encode : function (string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";
 
		for (var n = 0; n < string.length; n++) {
 
			var c = string.charCodeAt(n);
 
			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}
 
		}
 
		return utftext;
	},
 
	// public method for url decoding
	decode : function (utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;
 
		while ( i < utftext.length ) {
 
			c = utftext.charCodeAt(i);
 
			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			}
			else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}
 
		}
 
		return string;
	}
 
}

// Videowidget

function response(data) {

  var IE7 = (navigator.appVersion.indexOf("MSIE 7.")==-1) ? false : true;

  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="300" />';
  var name = items[0].name;
  if ( IE7 ) name = Utf8["decode"](name);

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

  var hwsBox = '<div class="hws_box">';
  hwsBox += '<div class="header">' + header + '</div>';
  hwsBox += '<div class="videowidget">';
  hwsBox += '<table cellspacing="0" cellpadding="0" border="0" width="300">';
  hwsBox += '<tr>';
  hwsBox += '<td height="222" valign="middle" style="background-color:#3080A0">';
  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/ruhr/videowidget_left.gif" width="14" height="14" class="vw_button">';
  hwsBox += '<div class="thumbs">';
  hwsBox += '<table cellspacing="2" cellpadding="3" border="0"><tr>'
  for( i=0; i<items.length; i++ ){
    var name = items[i].name;
    if ( IE7 ) name = Utf8["decode"](name);
    var videoStillURL = items[i].videoStillURL;
    if ( i >= 12 ) break;
    if ( i == 0 ) {
      hwsBox += '<td class="active">';
    } else {
      hwsBox += '<td>';
    }
    if ( bclid ) {
      var link = '/videos/?bctid='+items[i].id+'&bclid='+bclid+'&bcpid='+bcpid;
    } else {
      var link = '/videos/?bctid='+items[i].id;
    }
    hwsBox += '<a href="'+link+'">';
    hwsBox += '<img src="'+items[i].thumbnailURL+'" />';
    hwsBox += '</a>';
    hwsBox += '<span name="title">'+name+'</span>';
    hwsBox += '<span name="image">'+videoStillURL+'</span>';
    hwsBox += '</td>';
  }
  hwsBox += '</tr></table>';
  hwsBox += '</div>';
  hwsBox += '<img src="/pics/ruhr/videowidget_right.gif" width="14" height="14" class="vw_button">';
  hwsBox += '</td>';
  hwsBox += '</tr>';
  hwsBox += '</table>';
  hwsBox += '</div>';
  hwsBox += '<div class="hws_linkbox">';
  hwsBox += '<div>Übersicht: <a href="/videos">Alle Videos auf einen Blick</a></div>';
  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 .vw_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({"marginLeft":bcvwleft},300);
  });

  jQuery(".videowidget:last .vw_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);
    jQuery(this).parents(".videowidget").find(".thumbs TABLE").animate({"marginLeft":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 = "PUBLISH_DATE";

  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];
    domain = domain.replace("-","");
    bcpid = 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 bc_getId() {
  return "43640351001";
}
