/**
 * @package tsVideoList/externalAd
 * @author Tony Simbine
 * @version 2011.01.28.TS05, updated 2011.02.01 13:44
 * Copyright (c) 2009-2011 and developed by Tony Simbine <ejantos (at) yahoo.com>
 * Copyright (c) 2009-2011 OMS Online Marketing Service GmbH & Co. KG
 * @link http://www.oms.eu/
**/
var collapsedID='bc_ad_728x90';var brightcoveID='myExperience';var bc_player,bc_experience,bc_advertising;var _brightcoveAd=new Object();var _companionAds=new Object();function onTemplateLoaded(){bc_player=brightcove.getExperience(brightcoveID);bc_experience=bc_player.getModule(APIModules.EXPERIENCE);bc_experience.addEventListener(BCExperienceEvent.CONTENT_LOAD,tsOnContentLoad);bc_advertising=bc_player.getModule(APIModules.ADVERTISING);bc_advertising.addEventListener(BCAdvertisingEvent.EXTERNAL_AD,tsOnExternalAd);}
function tsOnContentLoad(){bc_advertising.enableExternalAds();}
function tsOnExternalAd(pAdString,callback){new ExternalAd(pAdString,{type:'collapsedBanner',collapsedId:collapsedID});}
function ExternalAd(pXML,pOptions){if(document.getElementById(collapsedID))document.getElementById(collapsedID).innerHTML='';var showAd=true;var hideBanner=true;if(pOptions){_brightcoveAd.expandedId=(pOptions.expandedId)?pOptions.expandedId:'expandedBanner';_brightcoveAd.collapsedId=(pOptions.collapsedId)?pOptions.collapsedId:'collapsedBanner';_brightcoveAd.type=(pOptions.type)?pOptions.type:'expandedBanner';}else{_brightcoveAd.expandedId='expandedBanner';_brightcoveAd.collapsedId='collapsedBanner';_brightcoveAd.type='expandedBanner';}
this.buildAd=function(pXML){try{if(pXML.ad.indexOf('<a ')!==-1){showAd=false;bc_advertising.resumeAfterExternalAd();return;}
if(window.ActiveXObject){var adXML=new ActiveXObject('Microsoft.XMLDOM');adXML.async=false;adXML.loadXML(pXML.ad);}else if(window.XMLHttpRequest){var adXML=(new DOMParser()).parseFromString(pXML.ad,'text/xml');}
var ad=new Object();ad.type='videoAd';var nodeItems=adXML.firstChild.childNodes.length;var currentNode=adXML.firstChild.firstChild;ad.duration=(adXML.firstChild.getAttribute('duration')!=='')?Number(adXML.firstChild.getAttribute('duration')):15;if(adXML.firstChild.getAttribute('trackStartURLs')&&adXML.firstChild.getAttribute('trackStartURLs')!=='')
ad.trackStartURLs=adXML.firstChild.getAttribute('trackStartURLs').split(',');if(adXML.firstChild.getAttribute('trackMidURLs')&&adXML.firstChild.getAttribute('trackMidURLs')!=='')
ad.trackMidURLs=adXML.firstChild.getAttribute('trackMidURLs').split(',');if(adXML.firstChild.getAttribute('trackEndURLs')&&adXML.firstChild.getAttribute('trackEndURLs')!=='')
ad.trackEndURLs=adXML.firstChild.getAttribute('trackEndURLs').split(',');if(adXML.firstChild.getAttribute('trackPointURLs')&&adXML.firstChild.getAttribute('trackPointURLs')!=='')
ad.trackPointURLs=adXML.firstChild.getAttribute('trackPointURLs').split(',');ad.trackPointTime=(adXML.firstChild.getAttribute('trackPointTime')&&(adXML.firstChild.getAttribute('trackPointTime')!==''))?Number(adXML.firstChild.getAttribute('trackPointTime')):0;if(adXML.firstChild.getAttribute('trackFirstQuartileURLs')&&adXML.firstChild.getAttribute('trackFirstQuartileURLs')!=='')
ad.trackFirstQuartileURLs=adXML.firstChild.getAttribute('trackFirstQuartileURLs').split(',');if(adXML.firstChild.getAttribute('trackThirdQuartileURLs')&&adXML.firstChild.getAttribute('trackThirdQuartileURLs')!=='')
ad.trackThirdQuartileURLs=adXML.firstChild.getAttribute('trackThirdQuartileURLs').split(',');if(adXML.firstChild.getAttribute('trackFullscreenURLs')&&adXML.firstChild.getAttribute('trackFullscreenURLs')!=='')
ad.trackFullscreenURLs=adXML.firstChild.getAttribute('trackFullscreenURLs').split(',');if(adXML.firstChild.getAttribute('trackExitFullscreenURLs')&&adXML.firstChild.getAttribute('trackExitFullscreenURLs')!=='')
ad.trackExitFullscreenURLs=adXML.firstChild.getAttribute('trackExitFullscreenURLs').split(',');if(adXML.firstChild.getAttribute('trackPauseURLs')&&adXML.firstChild.getAttribute('trackPauseURLs')!=='')
ad.trackPauseURLs=adXML.firstChild.getAttribute('trackPauseURLs').split(',');if(adXML.firstChild.getAttribute('trackResumeURLs')&&adXML.firstChild.getAttribute('trackResumeURLs')!=='')
ad.trackResumeURLs=adXML.firstChild.getAttribute('trackResumeURLs').split(',');if(adXML.firstChild.getAttribute('trackMuteURLs')&&adXML.firstChild.getAttribute('trackMuteURLs')!=='')
ad.trackMuteURLs=adXML.firstChild.getAttribute('trackMuteURLs').split(',');if(adXML.firstChild.getAttribute('trackUnmuteURLs')&&adXML.firstChild.getAttribute('trackUnmuteURLs')!=='')
ad.trackUnmuteURLs=adXML.firstChild.getAttribute('trackUnmuteURLs').split(',');var isOverlay=false;for(var i=0;i<nodeItems;i++){if(currentNode.nodeName=='videoURL'&&currentNode.firstChild)ad.videoURL=currentNode.firstChild.nodeValue;if(currentNode.nodeName=='videoClickURL'&&currentNode.firstChild)ad.videoClickURL=currentNode.firstChild.nodeValue;if(currentNode.nodeName=='expandedBannerURL'&&currentNode.firstChild){if(_brightcoveAd.type=='collapsedBanner'){ad.type='synchedBanner728x90';ad.expandedBannerURL=currentNode.firstChild.nodeValue;if(currentNode.attributes.length>0){if(currentNode.getAttribute('trackStartURLs')&&currentNode.getAttribute('trackStartURLs')!=='')
ad.expandedBannerTrackStartURLs=currentNode.getAttribute('trackStartURLs').split(',');if(currentNode.getAttribute('duration')&&currentNode.getAttribute('duration')!==''&&Number(currentNode.getAttribute('duration'))>0)
ad.expandingBannerDuration=Number(currentNode.getAttribute('duration'));}}else{_companionAds.expandedBannerURL=currentNode.firstChild.nodeValue;_companionAds.expandedBannerTrackStartURLs=[];if(currentNode.attributes.length>0){if(currentNode.getAttribute('trackStartURLs')&&currentNode.getAttribute('trackStartURLs')!=='')
_companionAds.expandedBannerTrackStartURLs=currentNode.getAttribute('trackStartURLs').split(',');if(currentNode.getAttribute('duration')&&currentNode.getAttribute('duration')!==''&&Number(currentNode.getAttribute('duration'))>0)
_companionAds.expandingBannerDuration=Number(currentNode.getAttribute('duration'));}}}
if(currentNode.nodeName=='expandedBannerClickURL'&&currentNode.firstChild){if(_brightcoveAd.type=='collapsedBanner')ad.expandedBannerClickURL=currentNode.firstChild.nodeValue;else _companionAds.expandedBannerClickURL=currentNode.firstChild.nodeValue;}
if(currentNode.nodeName=='collapsedBannerURL'&&currentNode.firstChild){_companionAds.collapsedBannerURL=currentNode.firstChild.nodeValue;_companionAds.collapsedBannerTrackStartURLs=[];if(currentNode.attributes.length>0&&currentNode.getAttribute('trackStartURLs')&&currentNode.getAttribute('trackStartURLs')!=='')
_companionAds.collapsedBannerTrackStartURLs=currentNode.getAttribute('trackStartURLs').split(',');}
if(currentNode.nodeName=='collapsedBannerClickURL'&&currentNode.firstChild)_companionAds.collapsedBannerClickURL=currentNode.firstChild.nodeValue;if(currentNode.nodeName=='overlayURL'&&currentNode.firstChild){isOverlay=true;ad.overlayURL=currentNode.firstChild.nodeValue;}
if(currentNode.nodeName=='overlayClickURL'&&currentNode.firstChild)ad.overlayClickURL=currentNode.firstChild.nodeValue;if(currentNode.nodeName=='bannerURL'&&currentNode.firstChild){_companionAds.collapsedBannerURL=currentNode.firstChild.nodeValue;hideBanner=false;}
if(currentNode.nodeName=='bannerClickURL'&&currentNode.firstChild)_companionAds.collapsedBannerClickURL=currentNode.firstChild.nodeValue;currentNode=currentNode.nextSibling;}
if(isOverlay){ad.type='synchedOverlay728x90';}else if(!ad.videoURL){showAd=false;}
return ad;}catch(e){bc_advertising.resumeAfterExternalAd();showAd=false;return null;}}
this.createSwf=function(ibanner){if(!document.getElementById(ibanner.id))return true;var tsAdTxt='';for(var i=0;i<ibanner.trackUrls.length;i++)
tsAdTxt+='<img width="1" height="1" src="'+ibanner.trackUrls[i]+'" />';ibanner.srcURL+=((ibanner.srcURL.indexOf('?')!==-1)?'&':'?')+'clickTag='+encodeURIComponent(ibanner.clickURL);tsAdTxt+='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,47,0" width="728" height="90" type="application/x-shockwave-flash" id="bannerAd" data="'+pURL+'" align="middle">'+"\n";tsAdTxt+='<param name="allowScriptAccess" value="always" /><param name="movie" value="'+ibanner.srcURL;tsAdTxt+='" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" /><param name="wmode" value="transparent" />';tsAdTxt+='<param name="FlashVars" value="clickTag='+ibanner.clickURL+'" />'+"\n";tsAdTxt+='<embed src="'+ibanner.srcURL+'" quality="high" bgcolor="#ffffff" width="728" height="90" name="collapsedBanner" align="middle" allowScriptAccess="always" wmode="transparent" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" FlashVars="clickTag='+ibanner.clickURL+'" />'+"\n";tsAdTxt+='</object>';document.getElementById(pId).innerHTML=tsAdTxt;}
this.createImage=function(ibanner){if(!document.getElementById(ibanner.id))return true;var tsAdTxt='';for(var i=0;i<ibanner.trackUrls.length;i++)
tsAdTxt='<img width="1" height="1" src="'+ibanner.trackUrls[i]+'" />';document.getElementById(ibanner.id).innerHTML='<a href="'+ibanner.clickURL+'" target="_blank" ><img src="'+ibanner.srcURL+'" /></a>'+tsAdTxt+"\n";}
this.createBanner=function(pAd){var externalAds={};switch(_brightcoveAd.type){case'expandedBanner':if(pAd.expandedBannerURL)externalAds['expandedBanner']={clickURL:pAd.expandedBannerClickURL,srcURL:pAd.expandedBannerURL,id:_brightcoveAd.expandedId,type:'expandedBanner',trackUrls:_companionAds.expandedBannerTrackStartURLs};break;case'collapsedBanner':if(pAd.collapsedBannerURL)externalAds['collapsedBanner']={clickURL:pAd.collapsedBannerClickURL,srcURL:pAd.collapsedBannerURL,id:_brightcoveAd.collapsedId,type:'collapsedBanner',trackUrls:_companionAds.collapsedBannerTrackStartURLs};break;case'both':if(pAd.expandedBannerURL)externalAds['expandedBanner']={clickURL:pAd.expandedBannerClickURL,srcURL:pAd.expandedBannerURL,id:_brightcoveAd.expandedId,type:'expandedBanner',trackUrls:_companionAds.expandedBannerTrackStartURLs};if(pAd.collapsedBannerURL)externalAds['collapsedBanner']={clickURL:pAd.collapsedBannerClickURL,srcURL:pAd.collapsedBannerURL,id:_brightcoveAd.collapsedId,type:'collapsedBanner',trackUrls:_companionAds.collapsedBannerTrackStartURLs};break;}
for(var i in externalAds){var banner=externalAds[i];(banner.srcURL.indexOf('.swf')!==-1)?this.createSwf(banner):this.createImage(banner);}}
var ad=this.buildAd(pXML);this.createBanner(_companionAds);if(showAd){bc_advertising.showAd(ad);}else if(document.getElementById(_brightcoveAd.collapsedId)&&hideBanner){document.getElementById(_brightcoveAd.collapsedId).innerHTML='';bc_advertising.resumeAfterExternalAd();}else{bc_advertising.resumeAfterExternalAd();}}
