
﻿
(function($){$.fn.anythingSliderVideo=function(options){var defaults={videoID:'asvideo'};return this.each(function(){var video,tmp,service,sel,base=$(this).data('AnythingSlider');if(!base){return;}
video=base.video={};video.options=$.extend({},defaults,options);video.hasSwfo=(typeof(swfobject)!=='undefined'&&swfobject.hasOwnProperty('embedSWF')&&typeof(swfobject.embedSWF)==='function')?true:false;video.list={};video.hasVid=false;video.hasEmbed=false;video.services=$.fn.anythingSliderVideo.services;video.len=0;video.hasEmbedCount=0;video.hasiframeCount=0;video.$items=base.$items.filter(':not(.cloned)');for(service in video.services){if(typeof(service)==='string'){sel=video.services[service].selector;video.$items.find(sel).each(function(){tmp=$(this);tmp.attr('id',video.options.videoID+video.len);video.list[video.len]={id:video.options.videoID+video.len++,panel:tmp.closest('.panel')[0],service:service,selector:sel,status:-1};video.hasVid=true;if(sel.match('embed|object')){video.hasEmbed=true;video.hasEmbedCount++;}else if(sel.match('iframe')){video.hasiframeCount++;}});}}
$.each(video.list,function(i,s){var tmp,$tar,vidsrc,opts,$vid=$(s.panel).find(s.selector),service=video.services[s.service],api=service.initAPI||'';if(video.hasEmbed&&video.hasSwfo&&s.selector.match('embed|object')){$vid.each(function(){$tar=($(this).parent()[0].tagName==='OBJECT')?$(this).parent():$(this);vidsrc=($tar[0].tagName==='EMBED')?$tar.attr('src'):$tar.find('embed').attr('src')||$tar.children().filter('[name=movie]').attr('value');opts=$.extend(true,{},{flashvars:null,params:{allowScriptAccess:'always',wmode:base.options.addWmodeToObject,allowfullscreen:true},attr:{'class':$tar.attr('class'),'style':$tar.attr('style'),'data-url':vidsrc}},service.embedOpts);$tar.wrap('<div id="'+s.id+'"></div>');swfobject.embedSWF(vidsrc+(api===''?'':api+s.id),s.id,$tar.attr('width'),$tar.attr('height'),'10',null,opts.flashvars,opts.params,opts.attr,function(){if(service.hasOwnProperty('init')){video.list[i].player=service.init(base,s.id,i);}
if(i>=video.hasEmbedCount){base.$el.trigger('swf_completed',base);}});});}else if(s.selector.match('iframe')){$vid.each(function(i,v){vidsrc=$(this).attr('src');tmp=(vidsrc.match(/\?/g)?'':'?')+'&wmode='+base.options.addWmodeToObject;$(this).attr('src',function(i,r){return r+tmp+(api===''?'':api+s.id);});});}});video.gup=function(n,s){n=n.replace(/[\[]/,"\\[").replace(/[\]]/,"\\]");var p=(new RegExp("[\\?&]"+n+"=([^&#]*)")).exec(s||window.location.href);return(p===null)?"":p[1];};video.postMsg=function(data,vid){var $vid=$('#'+vid);if($vid.length){$vid[0].contentWindow.postMessage(data,$vid.attr('src').split('?')[0]);}};video.message=function(e){if(e.data){if(/infoDelivery/g.test(e.data)){return;}
var data=$.parseJSON(e.data);$.each(video.list,function(i,s){if(video.services[video.list[i].service].hasOwnProperty('message')){video.services[video.list[i].service].message(base,data);}});}};video.control=function(toDo){var i,s=video.list,slide=(toDo==='pause')?base.$lastPage[0]:base.$currentPage[0],isPlaying=false;for(i=0;i<video.len;i++){if(s[i].panel===slide&&video.services[s[i].service].hasOwnProperty(toDo)){isPlaying=video.services[s[i].service][toDo](base,s[i].id,i);}}
return isPlaying;};if(video.hasiframeCount){if(window.addEventListener){window.addEventListener('message',video.message,false);}else{window.attachEvent('onmessage',video.message,false);}}
base.$el.bind('slide_init',function(){video.control('pause');}).bind('slide_complete',function(){video.control('cont');});base.options.isVideoPlaying=function(){return video.control('isPlaying');};});};$.fn.anythingSliderVideo.services={video:{selector:'video',cont:function(base,vid,index){var $vid=$('#'+vid);if($vid.length&&$vid[0].paused&&$vid[0].currentTime>0&&!$vid[0].ended){$vid[0].play();}},pause:function(base,vid){$('video').each(function(){if(typeof(this.pause)!=='undefined'){this.pause();}});},isPlaying:function(base,vid,index){var $vid=$('#'+vid);return($vid.length&&typeof($vid[0].pause)!=='undefined'&&!$vid[0].paused&&!$vid[0].ended)?true:false;}},vimeo1:{selector:'iframe[src*=vimeo]',initAPI:'&api=1&player_id=',cont:function(base,vid,index){if(base.options.resumeOnVisible&&base.video.list[index].status==='pause'){base.video.postMsg('{"method":"play"}',vid);}},pause:function(base,vid){$('iframe[src*=vimeo]').each(function(){base.video.postMsg('{"method":"pause"}',this.id);});},message:function(base,data){var index,vid=data.player_id||'';if(vid!==''){index=vid.replace(base.video.options.videoID,'');if(data.event==='ready'){base.video.postMsg('{"method":"addEventListener","value":"play"}',vid);base.video.postMsg('{"method":"addEventListener","value":"pause"}',vid);base.video.postMsg('{"method":"addEventListener","value":"finish"}',vid);}
if(base.video.list[index]){base.video.list[index].status=data.event;}}},isPlaying:function(base,vid,index){return(base.video.list[index].status==='play')?true:false;}},vimeo2:{selector:'object[data-url*=vimeo], embed[src*=vimeo]',embedOpts:{flashvars:{api:1}},cont:function(base,vid,index){if(base.options.resumeOnVisible){var $vid=$('#'+vid);if(typeof($vid[0].api_play)==='function'&&$vid[0].api_paused()&&$vid[0].api_getCurrentTime()!==0&&($vid[0].api_getDuration()-$vid[0].api_getCurrentTime())>2){$vid[0].api_play();}}},pause:function(base,vid){$('object[data-url*=vimeo], embed[src*=vimeo]').each(function(){var el=(this.tagName==='EMBED')?$(this).parent()[0]:this;if(typeof(el.api_pause)==='function'){el.api_pause();}});},isPlaying:function(base,vid,index){var $vid=$('#'+vid);return(typeof($vid[0].api_paused)==='function'&&!$vid[0].api_paused())?true:false;}},youtube1:{selector:'iframe[src*=youtube]',initAPI:'&iv_load_policy=3&enablejsapi=1&playerapiid=',cont:function(base,vid,index){if(base.options.resumeOnVisible&&base.video.list[index].status===2){base.video.postMsg('{"event":"command","func":"playVideo"}',vid);}},pause:function(base,vid,index){$('iframe[src*=youtube]').each(function(){base.video.postMsg('{"event":"command","func":"pauseVideo"}',vid);});},message:function(base,data){if(data.event==='infoDelivery'){return;}
if(data.info&&data.info.videoUrl){var url=base.video.gup('v',data.info.videoUrl),v=$('iframe[src*='+url+']'),vid,index;if(v.length){vid=v[0].id;index=vid.replace(base.video.options.videoID,'');if(data.event==='onReady'){base.video.postMsg('{"event":"listening","func":"onStateChange"}',vid);}
if(data.event==='onStateChange'&&base.video.list[index]){base.video.list[index].status=data.info.playerState;}}}},isPlaying:function(base,vid,index){var status=base.video.list[index].status;return(status===1||status>2)?true:false;}},youtube2:{selector:'object[data-url*=youtube], embed[src*=youtube]',initAPI:'&iv_load_policy=3&enablejsapi=1&version=3&playerapiid=',cont:function(base,vid,index){if(base.options.resumeOnVisible){var $vid=$('#'+vid);if($vid.length&&typeof($vid[0].getPlayerState)==='function'&&$vid[0].getPlayerState()>0){$vid[0].playVideo();}}},pause:function(base,vid){$('object[data-url*=youtube], embed[src*=youtube]').each(function(){var el=(this.tagName==='EMBED')?$(this).parent()[0]:this;if(typeof(el.getPlayerState)==='function'&&el.getPlayerState()>0){el.pauseVideo();}});},isPlaying:function(base,vid){var $vid=$('#'+vid);return(typeof($vid[0].getPlayerState)==='function'&&($vid[0].getPlayerState()===1||$vid[0].getPlayerState()>2))?true:false;}}};})(jQuery);jQuery(window).load(function(){jQuery('.anythingBase').anythingSliderVideo();});
