var JWPlayer=Class.create({initialize:function(containerID,options){this.options=options;this.containerID=containerID;this.base=this.options.base||"http://www.kidzbop.com";this.skin=this.options.skin||this.base+"/flash/nacht.zip";this.autostart=this.options.autostart||false;this.playlist=this.options.playlist||[];this.playerId=this.options.playerId||'jw_player';JWPlayer.prototype.image=this.options.image||'';this.dimensions={width:this.options.width||320,height:this.options.height||275};this.createPlaylist();this.createPlayer();}});JWPlayer.fn=JWPlayer.prototype;JWPlayer.fn.playlists={};JWPlayer.fn.video_ad=null;JWPlayer.fn.already_called_tracking_pixels={};JWPlayer.fn.createPlayer=function(){var flashvars={id:this.playerId,autostart:this.autostart,playlist:"none",playlistsize:"0",shuffle:false,repeat:"list",skin:this.skin,stretching:"exactfit",controlbar:"bottom",plugins:"gapro-1","gapro.accountid":"UA-10269482-1"};var params={allowfullscreen:true,allowscriptaccess:"always",wmode:"transparent",base:this.base};var attributes={id:this.playerId,name:this.playerId};swfobject.embedSWF(this.base+"/flash/jw_player.swf",this.containerID,this.dimensions.width,this.dimensions.height,"9.0.115",false,flashvars,params,attributes);};JWPlayer.fn.drawVideoAdvert=function(video_adverts,overall_freq_cap){if(overall_freq_cap==0||this.getOverallFreqCapCookieValue()<=overall_freq_cap){var ads=[];video_adverts.each(function(ad){if(ad['display_limit']==0||this.getAdCookieValue(ad['video_id'])<=ad['display_limit']){ads.push(ad);}}.bind(this));if(ads.length>0){return ads[Math.floor(Math.random()*ads.length)];}}
return null;};JWPlayer.fn.createPlaylist=function(){var list=new Array();this.playlist.each(function(e){list.push(e);}.bind(this));if(this.video_ad){this.updateAdCookieValue(this.video_ad['video_id']);setTimeout(function(){$$('body')[0].insert(this.video_ad['tracking_pixel']);}.bind(this),1000);list.unshift(this.video_ad);}
this.playlists[this.playerId]=list;};JWPlayer.fn.getAdCookieValue=function(video_id){var cookie_name='v_ad_'+video_id;var cookie=parseInt(Cookie.getCookie(cookie_name));return isNaN(cookie)?1:cookie+1;};JWPlayer.fn.getOverallFreqCapCookieValue=function(){var cookie_name='v_ad_overall';var cookie=parseInt(Cookie.getCookie(cookie_name));return isNaN(cookie)?1:cookie+1;};JWPlayer.fn.updateAdCookieValue=function(video_id){var cookie_name='v_ad_'+video_id;var date=new Date();var time_to_midnight=((23-date.getHours())*60+(60-date.getMinutes()))/(24*60);Cookie.setCookie(cookie_name,this.getAdCookieValue(video_id),time_to_midnight,'/');Cookie.setCookie('v_ad_overall',this.getOverallFreqCapCookieValue(),time_to_midnight,'/');};JWPlayer.fn.loadPlaylist=function(object_id){this.player=this.loadPlayerObject(object_id);this.player.sendEvent('LOAD',this.playlists[object_id]);};JWPlayer.fn.loadPlayerObject=function(object_id){return $(object_id);};JWPlayer.fn.addEvents=function(){this.player.addViewListener('PLAY','JWPlayer.fn.adRedirect');this.player.addModelListener('STATE','JWPlayer.fn.adMessage');this.player.addModelListener('TIME','JWPlayer.fn.playbackTracking');};JWPlayer.fn.playbackTracking=function(e){var item=this.getCurrentPlayingItem();if(item['ad']){if(!this.already_called_tracking_pixels[item['video_id']]){this.already_called_tracking_pixels[item['video_id']]={};}
var percent=e['position']/e['duration'];var place=0;[0,25,50,75,100].each(function(step){place=step==100?98:step;if(percent*100>=place&&item['tracking_pixel_'+step]&&!this.already_called_tracking_pixels[item['video_id']][step]){this.already_called_tracking_pixels[item['video_id']][step]=true;$$('body')[0].insert(item['tracking_pixel_'+step]);}}.bind(this));}};JWPlayer.fn.adRedirect=function(e){var item=this.getCurrentPlayingItem();var state=this.player.getConfig().state;if(!!item['ad']&&!!item['link']&&(state!='IDLE')&&(state!='COMPLETED')){window.location=item['link'];}};JWPlayer.fn.getCurrentPlayingItem=function(){return this.player.getPlaylist()[this.player.getConfig().item];};JWPlayer.fn.adMessage=function(e){var item=this.getCurrentPlayingItem();if(e.newstate=='PLAYING'&&item['ad']){this.player.up().insert('<div class="player_ad">Advertisement - Your content will start after this message.</div>');}else{this.player.up().select('.player_ad').each(function(e){e.remove();});}};playerReady=function(e){JWPlayer.fn.loadPlaylist(e['id']);JWPlayer.fn.addEvents(e['id']);};