var wsServer = 'http://www.wdr.de';
var webServer = 'http://www.wdr.de';
var wsTestServer = 'https://otti.wdr.de';
var mediaArr = [];
function mediaObj(k) {
   this.nodeId = k;
   this.arrIdx = mediaArr.length;
   this.pluginHash = {
      video : {
         width : 512, height : (288 + 24), wmode : 'window'}
      , audio : {
         width : 400, height : 24, wmode : 'opaque'}
      };
   this.init = function() {
      this.isOpened = false;
      this.node = document.getElementById(this.nodeId);
	  this.contextArt = 'Liste';
      //this.contextArt = (this.node.tagName == 'DIV' && checkClassName(this.node.className, 'wsTeaser')) ? 'Teaser':((this.node.tagName == 'DIV' && checkClassName(this.node.className, 'wsEmbedPlayerModul')) ? 'PlayerModul':((this.node.tagName == 'SPAN' && (checkClassName(this.node.className, 'wsILLInner') || checkClassName(this.node.className, 'wsLLInner'))) ? 'Liste':null));
      var a = this.node.getElementsByTagName('a')[0];
      var b = a.getAttribute('href');
      this.playerQuery = b.substring(1 + b.indexOf('?'));
      this.mediaType = (this.playerQuery.toLowerCase().indexOf('.flv') !=- 1) ? 'Video':((this.playerQuery.toLowerCase().indexOf('.mp3') !=- 1) ? 'Audio':null);
      this.headerText =  this.node.getElementsByTagName('p')[0].innerHTML;
	  var re1 = new RegExp("<a.*>(.*?)</a.*>", "g");
	  var re2 = new RegExp("<[^>]*>", "g");	
	  this.headerText = this.headerText.replace(re1, "");
	  this.headerText = this.headerText.replace(re2, "");
      this.srcText = a.getAttribute('title').substring(0, a.getAttribute('title').indexOf('; Flash'));
      this.playerNode = document.createElement('span');
      this.playerNode.className = 'ws' + this.mediaType + 'Player';
      if(this.mediaType != null) {
         this.setOnClickEvents()}
      this.tmpClassName = this.node.className};
   this.open = function() {
      closeAllOpenPlayer();
      if(!this.isOpened) {
         this.isOpened = true;
         this.tmpNode = this.node.cloneNode(true);
         var a = document.createElement('a');
         a.innerHTML = 'Schlie&szlig;en <img src="../img/but_schliessen_video.gif" />';
         a.setAttribute('title', 'Player schließen');
         var b = this.arrIdx;
         a.onclick = function() {
            mediaArr[b].close()};
         var c = document.createElement('span');
         c.className = 'wsClose';
         c.appendChild(a);
         this.playerNode.innerHTML = getFlashPlayerHTML(this.playerQuery, 'ws' + this.mediaType + '', (this.mediaType == 'Video') ? this.pluginHash['video'] : this.pluginHash['audio']);
         /*if(this.contextArt == 'Teaser') {
            this.node.getElementsByTagName('h3')[0].innerHTML = this.node.getElementsByTagName('h3')[0].getElementsByTagName('a')[0].innerHTML;
            var d = this.node.getElementsByTagName('img')[0].cloneNode(true);
            this.node.insertBefore(d, this.node.getElementsByTagName('img')[0].parentNode);
            this.node.removeChild(this.node.getElementsByTagName('img')[1].parentNode);
            var e = document.createElement('span');
            e.innerHTML = this.node.getElementsByTagName('p')[0].getElementsByTagName('a')[0].innerHTML;
            this.node.getElementsByTagName('p')[0].insertBefore(e, this.node.getElementsByTagName('p')[0].getElementsByTagName('a')[0]);
            this.node.getElementsByTagName('p')[0].removeChild(this.node.getElementsByTagName('p')[0].getElementsByTagName('a')[0])}
         else if(this.contextArt == 'Liste') {
            this.listenArt = (this.node.parentNode.parentNode.parentNode.parentNode.parentNode != null && this.node.parentNode.parentNode.parentNode.parentNode.parentNode.tagName == 'DIV' && this.node.parentNode.parentNode.parentNode.parentNode.parentNode.className == 'wsService') ? 'halbeListe':'dflt';
            if(this.listenArt != null && this.listenArt == 'halbeListe' && this.node.parentNode.parentNode != null && this.node.parentNode.parentNode.tagName == 'UL') {
               this.tmpUL = this.node.parentNode.parentNode.cloneNode(true)}
            this.node.innerHTML = '<span class="wsMediaTitle"><strong>' + this.node.getElementsByTagName('a')[0].innerHTML + '<\/strong><\/span>'}
         if(this.listenArt != null && this.listenArt == 'halbeListe' && this.node.parentNode != null && this.node.parentNode.style != null) {
            this.node.parentNode.style.width = '85%';
            this.node.parentNode.style.cssFloat = 'none';
            this.node.parentNode.style.clear = 'both';
            this.node.parentNode.style.display = 'block';
            if(this.node.parentNode.nextSibling != null && this.node.parentNode.nextSibling.style != null) {
               this.node.parentNode.nextSibling.style.cssFloat = 'none';
               this.node.parentNode.nextSibling.style.clear = 'both';
               this.node.parentNode.nextSibling.style.display = 'block'}
            }*/
         this.getSibling();
         if(this.mediaType == 'Audio') {
			this.playerNode.style.top = (this.node.offsetTop * 0.0625)+'em';
			this.playerNode.style.left = '1em';
            this.playerNode.insertBefore(c, this.playerNode.firstChild);
/*            if(this.contextArt == 'PlayerModul') {
               this.node.getElementsByTagName('p')[0].innerHTML = this.node.getElementsByTagName('p')[0].getElementsByTagName('a')[0].innerHTML;
               this.node.getElementsByTagName('div')[1].getElementsByTagName('strong')[0].innerHTML = this.node.getElementsByTagName('div')[1].getElementsByTagName('strong')[0].getElementsByTagName('a')[0].innerHTML;
               this.node.className += ' wsAudioPlayerModul'}
            else {*/
               var f = document.createElement('span');
               f.className = 'wsAudioSrc';
               f.innerHTML = '[' + this.srcText + ']';
               this.playerNode.appendChild(f);//}
            (this.sibling != 'append') ? this.node.insertBefore(this.playerNode, this.sibling) : this.node.appendChild(this.playerNode)}
         else if(this.mediaType == 'Video') {
            var g = document.createElement('span');
            g.setAttribute('id', 'wsInvSquare');
            //if(this.contextArt != 'PlayerModul') {
               var h;
               h = document.createElement('div');
               //var i = document.createElement('div');
               //i.className = 'wsRubrik';
			   //i.innerHTML = '';
               //i.innerHTML = '<strong>Video<\/strong>';
               var j = document.createElement('span');
               j.className = 'wsEPMSpan';
               j.innerHTML += '<img src="https://www.wdr.de/themen/global/flashplayer/skins/wdrde/video.gif" alt="Video: " class="wsIcon" />';
               j.innerHTML += '<span>' + this.headerText + '<\/span>';
               //j.innerHTML += '<span class="wsMediaSource">[' + this.srcText + ']<\/span>';
               //h.appendChild(i);
               h.appendChild(c);
               h.appendChild(this.playerNode);
               h.appendChild(j);
               h.className = 'wsBGLiteColor wsVideoPlayerModul';
			   h.style.top = (this.node.parentNode.offsetTop * 0.0625)+'em';
			   h.style.left = '1em';
               (this.sibling != 'append') ? this.node.insertBefore(h, this.sibling) : this.node.appendChild(h);
               (this.sibling != 'append') ? this.node.insertBefore(g, this.sibling) : this.node.appendChild(g)}
            /*else {
               (this.sibling != 'append') ? this.node.insertBefore(c, this.sibling) : this.node.appendChild(c);
               (this.sibling != 'append') ? this.node.insertBefore(this.playerNode, this.sibling) : this.node.appendChild(this.playerNode);
               this.node.getElementsByTagName('div')[1].getElementsByTagName('strong')[0].innerHTML = this.node.getElementsByTagName('div')[1].getElementsByTagName('strong')[0].getElementsByTagName('a')[0].innerHTML;
               this.node.removeChild(this.node.getElementsByTagName('p')[0]);
               this.node.className += ' wsVideoPlayerModul';
               (this.node.nextSibling != null) ? this.node.parentNode.insertBefore(g, this.node.nextSibling) : this.node.parentNode.appendChild(g)}*/
            //}
         }
      };
   this.close = function() {
      if(this.isOpened) {
         var a = document.getElementById(this.nodeId).getElementsByTagName('object')[0];

         if(typeof a.stopAllMedia == 'function') {
            a.stopAllMedia()}
         /*if(this.mediaType == 'Video' && this.contextArt == 'PlayerModul') {
            this.node.parentNode.removeChild(document.getElementById('wsInvSquare'))}*/
         this.node.innerHTML = this.tmpNode.innerHTML;
         this.node.className = this.tmpClassName;
         /*if(this.listenArt != null && this.listenArt == 'halbeListe' && this.tmpUL != null) {
            this.node.parentNode.parentNode.innerHTML = this.tmpUL.innerHTML}*/
         this.playerNode.innerHTML = '';
         this.tmpUL = null;
         this.tmpNode = null;
         this.isOpened = false;
         for(var i = 0; i < mediaArr.length; i++) {
            mediaArr[i].init(i)}
         }
      };
   this.setOnClickEvents = function() {
      var a = this.arrIdx;
      /*if(this.contextArt == 'Teaser') {
         this.node.getElementsByTagName('h3')[0].getElementsByTagName('a')[0].onclick = function() {
            mediaArr[a].open();
            return false};
         this.node.getElementsByTagName('img')[0].parentNode.onclick = function() {
            mediaArr[a].open();
            return false};
         this.node.getElementsByTagName('p')[0].getElementsByTagName('a')[0].onclick = function() {
            mediaArr[a].open();
            return false}
         }
      else if(this.contextArt == 'PlayerModul') {
         this.node.getElementsByTagName('a')[0].onclick = function() {
            mediaArr[a].open();
            return false};
         this.node.getElementsByTagName('a')[1].onclick = function() {
            mediaArr[a].open();
            return false}
         }
      else if(this.contextArt == 'Liste') {*/
         this.node.getElementsByTagName('a')[0].onclick = function() {
            mediaArr[a].open();
            return false}
         //}
      };
   this.getSibling = function() {
      /*switch(this.contextArt) {
         case'Teaser':this.sibling = (this.node.getElementsByTagName('p')[(this.node.getElementsByTagName('p').length - 1)] != null && this.node.getElementsByTagName('p')[(this.node.getElementsByTagName('p').length - 1)].nextSibling != null) ? this.node.getElementsByTagName('p')[(this.node.getElementsByTagName('p').length - 1)].nextSibling : 'append';
         break;
         case'PlayerModul':this.sibling = (this.node.getElementsByTagName('div')[1] != null) ? this.node.getElementsByTagName('div')[1] : 'append';
         break;
         case'Liste':default : */this.sibling = (this.node.getElementsByTagName('span')[0] != null && this.node.getElementsByTagName('span')[0].nextSibling != null) ? this.node.getElementsByTagName('span')[0].nextSibling : 'append'//}
      }
   };
function checkClassName(a, b) {
   var c = a.split(' ');
   for(var i = 0; i < c.length; i++) {
      if(c[i] == b) {
         return true;
         break}
      }
   return false};
function closeAllOpenPlayer() {
   for(var i = 0; i < mediaArr.length; i++) {
      if(mediaArr[i].isOpened) {
         mediaArr[i].close()}
      }
   };
function stopOpenPlayer() {
   var a = document.getElementsByTagName('object');
   for(var i = 0; i < a.length; i++) {
      if(typeof a[i].stopAllMedia == 'function') {
         a[i].stopAllMedia()}
      }
   }
function getFlashPlayerHTML(a, b, c) {
   var d = escape('' + webServer + '/tv/maus_online/kaeptnblaubaerseite/codebase/player/ef_controler.xml');
   a += '&amp;cfgFile=' + d;
   var e = {
      base : '' + webServer + '/tv/maus_online/kaeptnblaubaerseite/codebase/player/', quality : 'autolow', allowScriptAccess : 'sameDomain', allowFullScreen : 'true', wmode : c['wmode']};
   var f = '';
   for(var g in e) {
      f += '<param name="' + g + '" value="' + e[g] + '" \/>' + "\n"}
   var h = '';
   h += '<p>Unsere Audios und Videos k&ouml;nnen Sie mit dem Flash-Player ab der Version 8.0 abspielen. Den neuesten Flash-Player k&ouml;nnen Sie beim Hersteller Adobe unter folgender Adresse kostenlos downloaden:<br />';
   h += '<strong><a href="https://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" target="_blank">Adobe Flash Player<\/a><\/strong><\/p>';
   var i = '';
   i += '<object ';
  // i += '<object width="' + c['width'] + '" height="' + c['height'] + '"';
   if(isIE) {
      i += ' classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"';
      i += ' codebase="https://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0"'}
   else {
      i += ' type="application/x-shockwave-flash"';
      i += ' data="' + wsServer + '/themen/global/flashplayer/AS2/wsPlayerAS2.swf"'}
   i += ' class="' + b + '"';
   i += '>';
   i += "\n";
   if(isIE) {
      i += '<param name="movie" value="' + wsServer + '/themen/global/flashplayer/AS2/wsPlayerAS2.swf?';
      i += a;
      i += '" \/>'}
   else {
      i += '<param name="flashvars" value="';
      i += a;
      i += '" />'}
   i += "\n";
   i += f;
   i += "\n";
   i += h;
   i += "\n";
   i += '<\/object>';
   i += "\n";
   return i};
function getDim() {
   w = 800;
   h = 600;
   if(window.screen) {
      w = screen.availWidth;
      h = screen.availHeight}
   return {
      width : w, height : h}
   };
function openFullscreenFLV(a) {
   var b = '';
   b = 'width=' + getDim().width + ',height=' + getDim().height + ',top=0,left=0,resizable';
   var c = window.open(a, 'flvWin', b);
   if(window.focus) {
      c.focus()}
   };
function getScriptState() {
   return'true'};
function getReferer() {
   return escape(location.href)};
   
addLoadEvent(function() {
	for(var i = 0; i < mediaArr.length; i++) {
      mediaArr[i].init(i)}
   }
);

