

/*-
  Author: Andrew Warner (andrew707@gmail.com)
  Copyright © 2012 Andrew Warner.  All rights reserved. 
-*/





V8u2=function(a){this.init(a)};V8u2.players={};V8u2.scriptTagIds={};V8u2.scriptTagCallBacks={};V8u2.register=function(b,a){V8u2.players[b]={player:new V8u2(a),ytReady:0};return};V8u2.setYTReady=function(a){V8u2.players[a].ytReady=1};V8u2.getPlayer=function(b,a){if(typeof b=="undefined"){for(b in V8u2.players){break}}if(!a){return V8u2.players[b].player}else{return V8u2.players[b]}};V8u2.getPlayerByScriptId=function(c,b){for(var a in V8u2.scriptTagIds){if(V8u2.scriptTagIds[a]==c){return V8u2.getPlayer(a,b)}}return null};V8u2.setCallBacksByScriptId=function(b,a){V8u2.scriptTagCallBacks[b]=a};V8u2.Util={toggle:function(a){if(visible(a)){hide(a)}else{V8u2.Util.show(a)}},invisible:function(a){a.style.visibility="hidden"},hide:function(a){a.style.display="none"},show:function(a){a.style.display="";a.style.visibility=""},visible:function visible(a){return a.style.display!="none"},_niceExtend:function(b,f){if(!f){return b}if(f.html){b.innerHTML=f.html;delete f.html}if(f.css){b.className=f.css;delete f.css}if(f.attr){var c=f.attr;for(var a in c){b.setAttribute(a,c[a])}delete f.attr}if(f.style){var e=b.style,c=f.style;for(var a in c){e[a]=c[a]}delete f.style}for(var a in f){b[a]=f[a]}return b},create:function(c,a){if(c=="text"){return document.createTextNode(a||"")}else{var b=document.createElement(c);if(a){if(typeof a=="string"){b.innerHTML=a}else{V8u2.Util._niceExtend(b,a)}}return b}},getElementsByClass:function(g,e,a){if(e==null){e=document}if(a==null){a="*"}if(document.getElementsByClassName){return e.getElementsByClassName(g)}var d=new Array();var c=e.getElementsByTagName(a);var b=c.length;var f=new RegExp("(^|\\\\s)"+g+"(\\\\s|$)");for(i=0,j=0;i<b;i++){if(f.test(c[i].className)){d[j]=c[i];j++}}return d},cookie:{set:function(c,e,a,h,d,g){var b=new Date();b.setTime(b.getTime());if(a){a=a*1000*60*60*24}var f=new Date(b.getTime()+(a));document.cookie=c+"="+escape(e)+((a)?";expires="+f.toGMTString():"")+((h)?";path="+h:"")+((d)?";domain="+d:"")+((g)?";secure":"")},get:function(c){var d=document.cookie.indexOf(c+"=");var a=d+c.length+1;if((!d)&&(c!=document.cookie.substring(0,c.length))){return null}if(d==-1){return null}var b=document.cookie.indexOf(";",a);if(b==-1){b=document.cookie.length}return unescape(document.cookie.substring(a,b))}}};V8u2.Events={add:function(d,c,b){if(this.customEvents){var a=this.customEvents[c]}if(typeof a==="function"){if(a.call(d,b)){return}}if(d.addEventListener){d.addEventListener(c,b,false)}else{d.attachEvent("on"+c,function(){b.call(d,window.event)})}},remove:function(c,b,a){if(c.removeEventListener){c.removeEventListener(b,a,false)}else{c.detachEvent("on"+b,a)}}};V8u2.Animate=function(a,c,b){this.el=a;this.prop=c;if(b){this.setConfig(b)}};V8u2.Animate.prototype={isAni:false,_setStyle:function(a){switch(this.prop){case"opacity":this.el.style[this.prop]=a;this.el.style.filter="alpha(opacity="+a*100+")";break;default:this.el.style[this.prop]=a+"px";break}},setConfig:function(a){this.el=this.el||a.elem;this.from=a.from;this.to=a.to;this.time=a.time;this.callback=a.callback;this.animDiff=this.to-this.from},stop:function(){window.clearInterval(this.timer)},getVal:function(){return this.val},_animate:function(){var a=this;this.now=new Date();this.diff=this.now-this.startTime;if(this.diff>this.time){this._setStyle(this.to);this.isAni=false;if(this.callback){this.callback.call(this)}window.clearInterval(this.timer);return}this.percentage=(Math.floor((this.diff/this.time)*100)/100);this.val=(this.animDiff*this.percentage)+this.from;this._setStyle(this.val)},start:function(){var a=this;this.startTime=new Date();this.isAni=true;this.timer=window.setInterval(function(){a._animate.call(a)},4)}};V8u2.Animate.canTransition=function(){var a=document.body||document.documentElement;var e=a.style;var f="transition";var c=["Moz","Webkit"];f=f.charAt(0).toUpperCase()+f.substr(1);for(var d=0;d<c.length;d++){if(typeof e[c[d]+f]=="string"){return true}}return false}();V8u2.prototype={init:function(a){constructor:V8u2,this.cfg=a;this.YTstate=null;var c=this.cfg.scriptTagId||"__fc";V8u2.scriptTagIds[this.cfg.uniqueId]=c;var b=this;this.cfg.opts={fadeIn:50,fadeOut:150,timedInterval:15000,timedDuration:3250};(function(){var q=document.getElementById(c),l=V8u2.Util.create;var d=window.navigator.userAgent;if(d.indexOf("MSIE ")>0){this.isIE=1}(new Image()).src=b.cfg.origin+b.cfg.overlaySpritedData.src;q=q||document.getElementById("__fd");var p=b.cfg.width;var s=l("div",{attr:{id:"v8u2-widget-container-"+b.cfg.uniqueId},style:{width:p+"px",position:"relative"}});b.playerContainer=l("div",{attr:{id:"v8u2-player-container-"+b.cfg.uniqueId},style:{position:"relative",cursor:"pointer",zIndex:3000}});if(typeof b.cfg.cfgFileOpts.banner!="undefined"){var h="w"+b.cfg.width;var o=b.cfg.cfgFileOpts.banner[h];if(o){var n=l("div",{attr:{id:"v8u2-banner-top"+b.cfg.uniqueId},style:{width:o.top.width+"px",height:o.top.height+"px",zIndex:5500,position:"absolute",top:"0px",}});if(o.bottom){var f=l("div",{attr:{id:"v8u2-banner-bottom"+b.cfg.uniqueId},style:{width:o.bottom.width+"px",height:o.bottom.height+"px",zIndex:5500,position:"absolute",bottom:"35px",opacity:0.7,color:"#FFFFFF",backgroundColor:"#005BBB"}})}n.innerHTML=o.top.html;if(o.bottom){f.innerHTML=o.bottom.html}b.playerContainer.appendChild(n);if(o.bottom){b.playerContainer.appendChild(f)}}}if(b.cfg.cb_preAll){b.cfg.cb_preAll(b)}var g=l("div",{attr:{id:b.cfg.uniqueId},style:{width:b.cfg.width+"px",height:b.cfg.height+"px"}});b.playerContainer.appendChild(g);s.appendChild(b.playerContainer);if(b.cfg.tplHtml){var r=l("div",{attr:{id:"v8u2-html-tpl-"+b.cfg.uniqueId}});r.innerHTML=b.cfg.tplHtml;s.appendChild(r)}if(!q){if(b.cfg.insertBeforeId){var m=document.getElementById(b.cfg.insertBeforeId);m.parentNode.insertBefore(s,m)}else{document.getElementsByTagName("body")[0].appendChild(s)}}else{if(b.cfg.cb_preScript){b.cfg.cb_preScript(s,q,b)}else{q.parentNode.insertBefore(s,q)}}})();if(this.cfg.mo){this.moveEventCatcher=this._moveEventCatcher();this.overlayFadeInOut=this._overlayFadeInOut()}else{this.moveEventCatcher=function(){}}this.onPlayerStateChange=this._onPlayerStateChange();this.fireAtTimePoint=this._fireAtTimePoint(this.cfg.tp);window.onYouTubePlayerAPIReady=function(d){V8u2.youtubePlayerAPIReady=true};if(!V8u2.youtubePlayerAPIReady){if(!V8u2.ytplayer_api_loading){V8u2.ytplayer_api_loading=true;(function(){var f="//www.youtube.com/player_api";var e=document.createElement("script");e.src=f;e.async=true;var d=document.getElementsByTagName("script")[0];d.parentNode.insertBefore(e,d)})()}(function(){if(V8u2.youtubePlayerAPIReady){b.initPlayer();return}else{setTimeout(arguments.callee,50)}})()}else{this.initPlayer()}},getOverLay:function(){var g=this;var f=V8u2.Util.create;var k=this.cfg.overlaySpritedData;var c=this.cfg.socialSitesInfo;var p=[];for(var e in k.order){p.push(c[k.order[e]])}var o={width:k.width,height:k.height,margin:k.margin};function b(){return{style:{backgroundImage:"url("+g.cfg.origin+k.src+")",backgroundRepeat:"no-repeat",height:k.height+"px",width:k.width+"px",margin:k.margin+"px",cursor:"pointer"},attr:{}}}var n=(p.length*(k.height+k.margin))+k.margin;var l=f("div",{attr:{id:"overlay-"+this.cfg.uniqueId},style:{backgroundColor:"transparent",position:"absolute",overflow:"hidden",height:n+"px",top:"50%",left:"100%",marginLeft:"-"+(o.width+(2*o.margin)+3)+"px",marginTop:"-"+(n/2)+"px",marginRight:"0px",padding:"0px",opacity:1,filter:"alpha(opacity=0)",zIndex:5000}});if(!k.offset){k.offset=[0,0]}if(!k.grid){k.grid=k.height}for(var e=0;e<p.length;e++){var a=k.order_in_sprite[p[e].id];var m=b();if(k.direction=="v"){m.style.backgroundPosition=k.offset[0]+"px -"+((k.offset[1]+k.grid)*a)+"px"}else{m.style.backgroundPosition="-"+((k.offset[0]+k.grid)*a)+"px "+k.offset[1]+"px"}var h=f("div",m);V8u2.Events.add(h,"click",(function(d){return function(){g.pw(d)}})(p[e].op));l.appendChild(h)}return l},_moveEventCatcher:function(){var c=this;var b=true;var a=this.cfg.height-43;this.evtCatcher=V8u2.Util.create("div",{attr:{id:"catcher-"+this.cfg.uniqueId},style:{cursor:"pointer",position:"absolute",overflow:"hidden",height:a+"px",width:"95%",top:"0px",left:"0px",padding:"0px",margin:"0px",display:"block",zIndex:4000}});V8u2.Events.add(this.evtCatcher,"mousemove",function(){c.overlayFadeInOut.init()});V8u2.Events.add(this.evtCatcher,"click",function(d){c.player.pauseVideo();c.moveEventCatcher("out")});return function(d){d=d||"in";if(d=="out"){this.evtCatcher.style.zIndex=-9999}else{if(b){this.playerContainer.appendChild(this.evtCatcher);b=false}this.evtCatcher.style.zIndex=4000}}},_overlayFadeInOut:function(){var f=this;var c=0;var h,d;var b=new V8u2.Animate(null,"opacity");var g=this.getOverLay();this.playerContainer.appendChild(g);var a=function(){if(d||0){return}if(!h||0){return}var k=1;if(b.isAni){k=b.getVal();b.stop()}b.setConfig({elem:g,from:k,to:0,time:f.cfg.opts.fadeOut,callback:function(){if(h!=0){h=0;g.style.zIndex=-8000}}});b.start()};var e=function(){var k;if(b.isAni){b.stop();window.clearTimeout(c)}k=b.getVal();k=k||0;if(h!=1){h=1;g.style.zIndex=5500}b.setConfig({elem:g,from:k,to:1,time:f.cfg.opts.fadeIn,callback:function(){if(d||0){window.clearTimeout(c)}else{if(f.YTstate!=YT.PlayerState.PAUSED){c=window.setTimeout(function(){a()},f.cfg.opts.timedDuration)}}}});b.start()};return{init:function(){e()},interrupt:function(){if(f.YTstate==YT.PlayerState.PAUSED){d=true;window.clearTimeout(c);e()}else{if(f.YTstate==YT.PlayerState.PLAYING){d=false;if(h!=0){c=window.setTimeout(function(){a()},100)}}else{if(YT.PlayerState.CUED){d=true;window.clearTimeout(c);e()}}}}}},pw:function(f){var d=this.cfg.cfgFileOpts.trackers||false;if(d&&d.actions){var e=this.cfg.socialSitesLookUp[f];if(d.actions[e]){if(typeof d.actions[e]=="object"){for(var c=0;c<d.actions[e].length;c++){this.fireOnceMonitor(null,null,d.actions[e][c])}}else{this.fireOnceMonitor(null,null,d.actions[e])}}}var b=this.cfg.origin+"/r.php?id="+this.cfg.vid+"&op="+f+"&pub_id="+this.cfg.pub_id+"&unique_id="+this.cfg.uniqueId+"&h="+this.cfg.h;var a=window.open(b,"name","height=400,width=700");if(window.focus){a.focus()}},thumbUrl:function(){return"http://img.youtube.com/vi/"+this.cfg.videoId+"/0.jpg"},fire_s2s:function(){(new Image()).src=this.cfg.origin+"/s2s.php?"+this.cfg.ss},_fireAtTimePoint:function(h){var b=false;var f;var e=this;var a=0;var g=-100;var c=0;var d=0;return{isValid:function(){return d},start:function(){var k=(new Date).getTime();if(e.YTstate!=g){if(e.YTstate!=1&&g==1){c=c+(k-a)}g=e.YTstate;a=k}if(b){return true}var l=e.player.getCurrentTime();if(typeof f=="undefined"||f==0){f=Math.round(e.player.getDuration());if(!f){return}if(h=="mid"){h=Math.round(f/2)}}if(h==Math.round(l)){c=c+(k-a);b=true;if(e.cfg.ss){if(e.cfg.vv&&((c/1000)/h<0.8)){}else{e.fire_s2s.call(e);d=1}}}}}},initPlayer:function(){var a=this;this.player=new YT.Player(this.cfg.uniqueId,{height:this.cfg.height,width:this.cfg.width,videoId:this.cfg.videoId,origin:this.cfg.origin,playerVars:{controls:this.cfg.controls,wmode:"opaque",rel:0,fs:0,autoplay:this.cfg.autoplay,showinfo:this.cfg.showinfo,hd:this.cfg.hd},events:{onReady:function(b){a.onPlayerReady(b)},onStateChange:function(b){a.onPlayerStateChange(b)}}})},monitor:function(c,a,d){if(c==-1){return}c+="";a+="";var b=[];b[b.length]="unique_id="+this.cfg.uniqueId;b[b.length]="video_id="+this.cfg.vid;b[b.length]="yt_video_id="+this.cfg.videoId;b[b.length]="state="+c;b[b.length]="vtime="+a;b[b.length]="first_play="+d;b[b.length]="pub_id="+this.cfg.pub_id;b[b.length]="refer="+encodeURIComponent(this.cfg.refer);b[b.length]="refer_path="+encodeURIComponent(this.cfg.referPath);b[b.length]="ip="+this.cfg.ipAddress;b[b.length]="time="+(+(new Date()));b[b.length]="h="+this.cfg.h;(new Image()).src=this.cfg.monitorUrl+"?"+b.join("&")+this.cfg.extraQSdata},fireOnceMonitor:function(c,b,a){(new Image).src=a+((a.indexOf("?")!=-1)?"&_cache=":"?")+(+(new Date()))},tk:function(l){var e=this.cfg.vid,c=V8u2.Util.cookie,h=null,b=null,m=false;var f=(l==1)?"V8u2-vi":"V8u2-vp";h=c.get(f);if(h){b=h.split(",");for(var g=0;g<b.length;g++){if(b[g]==e){m=1;break}}if(!m){h+=(e+",");c.set(f,h,14,"/")}}else{h=e+",";c.set(f,h,14,"/")}},onPlayerReady:function(c){if(V8u2.players[this.cfg.uniqueId].ytReady){return}var k=this;var l=this.cfg;var n=l.cb_ready;var m=l.cfgFileOpts.trackers;if(l.tk){this.tk(1)}var d=V8u2.scriptTagIds[this.cfg.uniqueId];var o=V8u2.scriptTagCallBacks;if(o[d]){if(o[d].ready){var h=o[d].ready;if(n){if(typeof n!="object"){n=[n]}n.push(h)}else{n=h}}if(o[d].eventLoop){var h=o[d].eventLoop;setInterval(function(){h(k)},250)}}if(n){if(typeof n=="object"){for(var g=0;g<n.length;++g){n[g](this)}}else{n(this,c)}}if(this.cfg.cb_eventLoop){setInterval(function(){k.cfg.cb_eventLoop(k)},250)}if(m&&m.impr){for(var e=0;e<m.impr.length;e++){this.fireOnceMonitor(c.data,null,m.impr[e])}}V8u2.setYTReady(k.cfg.uniqueId)},_onPlayerStateChange:function(){var k=0;var f=-100;var g=0;var h;var c=true;var e={3:0,5:0,0:0,2:0,1:0};var b={};var d=V8u2.scriptTagIds[this.cfg.uniqueId];var l=V8u2.scriptTagCallBacks;function a(q){var m=this.cfg;if((this.player.getPlayerState()==1&&q==0)||q==1){var n=this.player.getCurrentTime();var p=Math.floor(n/5);if(typeof b[p]=="undefined"){(new Image()).src=this.cfg.origin+"/watchtime.php?vid="+m.vid+"&pid="+m.pub_id+"&vtime="+n+"&sess_id="+m.uniqueId+"&ts="+m.timestamp+"&ip="+m.ipAddress+"&h="+m.h+"&cache="+(+(new Date()));b[p]=true}var o=this;setTimeout(function(){a.call(o,0)},(c)?2500:5000)}}return function(r){var n=(new Date).getTime();var o=n-k;var q=this;if(o<=400&&(r.data==YT.PlayerState.PAUSED||r.data==YT.PlayerState.BUFFERING)){return}e[r.data]++;this.YTstate=r.data;if(r.data!=YT.PlayerState.PLAYING&&f==YT.PlayerState.PLAYING){g=g+(n-k)}k=n;f=r.data;if(typeof r.target.getCurrentTime=="function"){var s=this.getCurrentTime()}else{var s=null}if(this.cfg.mo){this.overlayFadeInOut.interrupt()}if(l[d]){if(l[d].stateChange){l[d].stateChange(this,r)}}switch(r.data){case YT.PlayerState.PAUSED:this.moveEventCatcher("out");this.monitor(r.data,s,"0");a.call(this,1);break;case YT.PlayerState.PLAYING:if(this.cfg.mo){this.moveEventCatcher("in")}a.call(this,0);if(e[YT.PlayerState.PLAYING]==1){if(this.cfg.eventUrl){window.setTimeout(function(){if(q.player.getPlayerState()==YT.PlayerState.PLAYING){s=q.player.getCurrentTime();var t=q.player.getPlayerState();q.fireOnceMonitor(t,s,q.cfg.eventUrl);q.monitor(t,s,"1")}},this.cfg.eventUrlDelay)}else{this.monitor(r.data,s,"1")}if(this.cfg.cb_start){this.cfg.cb_start(this)}var m=this.cfg.cfgFileOpts.trackers;if(m&&m.play){for(var p=0;p<m.play.length;p++){this.fireOnceMonitor(r.data,s,m.play[p])}}if(this.cfg.tp){window.setInterval(q.fireAtTimePoint.start,250)}if(this.cfg.tk){this.tk(2)}c=false}else{}if(this.cfg.cb_playing){this.cfg.cb_playing(this)}break;case YT.PlayerState.ENDED:a.call(this,1);this.monitor(r.data,s,"1");e[YT.PlayerState.PLAYING]=0;e[YT.PlayerState.PAUSED]=0;h=Math.round(this.getDuration());if(!this.cfg.tp){if(this.cfg.vv&&((g/1000)/h<0.85)){alert("Please watch entire video to earn your credits");if(this.cfg.vv<2){this.cueVideoByYtId()}}else{if(this.cfg.ss){this.fire_s2s()}if(this.cfg.eventUrl&&this.cfg.events.end){this.fireOnceMonitor(r.data,s)}}}else{if(!this.fireAtTimePoint.isValid()){alert("Please watch entire video to earn your credits")}}if(this.cfg.cb_end){this.cfg.cb_end(this)}k=0;f=-100;g=0}}},play:function(){this.player.playVideo()},getVideoByYtId:function(a){this.player.loadVideoById(a)},cueVideoByYtId:function(a){a=a||this.cfg.videoId;this.player.cueVideoById(a)},getVideoByYtUrl:function(a){this.player.loadVideoByUrl(a)},getDuration:function(){return this.player.getDuration()},getCurrentTime:function(){return this.player.getCurrentTime()}};