function SC_Easyroll(){if(SC_Easyroll.singleton==null){SC_Easyroll.singleton=new SC_EasyrollClass;}return SC_Easyroll.singleton;}function SC_EasyrollClass(){this.UNKNOWN="UNKNOWN";this.CUSTOM="CUSTOM";this.JW_PLAYER="JW_PLAYER";this.FLOW_PLAYER="FLOW_PLAYER";this.YOUTUBE="YOUTUBE";this.DAILY_MOTION="DAILY_MOTION";this.VIMEO="VIMEO";this.SILVERLIGHT="SILVERLIGHT";this.WINDOW_MEDIA_PLAYER="WINDOWS_MEDIA_PLAYER";this.PLAYER_TYPES={UNKNOWN:{},CUSTOM:{},JW_PLAYER:{start:["sendEvent",["PLAY","true"]],stop:["sendEvent",["PLAY","false"]]},FLOW_PLAYER:{start:["fp_play",[]],stop:["fp_pause",[]]},YOUTUBE:{start:["playVideo",[]],stop:["pauseVideo",[]]},DAILY_MOTION:{start:["playVideo",[]],stop:["pauseVideo",[]]},VIMEO:{start:["api_play",[]],stop:["api_pause",[]]},SILVERLIGHT:{},WINDOWS_MEDIA_PLAYER:{}};this.debugLayer=document.getElementById("SC_DEBUGLAYER");this.playerId="";this.browser="UNKNOWN";this.playerType=this.UNKNOWN;this.opacity=0.01;this.mediaPlayerClassId="6BF52A52-394A-11D3-B153-00C04F79FAA6";this.flashClassId="D27CDB6E-AE6D-11CF-96B8-444553540000";this.baseUrl="http://cdn.smartclip.net/easyroll";this.silverlightElementName="";this.videoAdUrl="";this.backgroundColor="000000";this.layerLeftOffset=0;this.layerTopOffset=0;this.layerWidth=0;this.layerHeight=0;this.audioVolume=100;this.layer=null;this.clickLayer=null;this.autostart=false;this.countDown=null;this.startCall=null;this.startCallParams=null;this.stopCall=null;this.stopCallParams=null;this.force=false;this.init=function(){this.debug("init()");if(typeof this.playerId=="undefined"||this.playerId==null||this.playerId==""){this.debug("Player identification not set!");return;}else if(typeof this.videoAdUrl=="undefined"||this.videoAdUrl==null||this.videoAdUrl==""||!this.videoAdUrl.match(/^https?:\/\//)){this.debug("Preroll url not set!");return;}var onLoad=this.addEvent(window,"load",SC_onLoad);var onResize=this.addEvent(window,"resize",SC_onResize);var onScroll=this.addEvent(window,"scroll",SC_onResize);var flashVer=this.getFlashVersion();if(!onLoad||!onResize||!onScroll||flashVer<9||!this.detectBrowser()){this.removeEvent(window,"load",SC_onLoad);this.removeEvent(window,"resize",SC_onResize);this.removeEvent(window,"scroll",SC_onResize);this.endAd();}else{this.findPlayer(null);}};this.setPlayerType=function(_playerType){this.debug("setPlayerType("+_playerType+")");this.playerType=this.UNKNOWN;for(var t in this.PLAYER_TYPES){if(t==_playerType){this.playerType=_playerType;break;}}return this;};this.setForce=function(_force){this.force=_force;return this;};this.setBaseUrl=function(_url){this.baseUrl=_url;return this;};this.setVideoAdUrl=function(_url){this.videoAdUrl=_url;return this;};this.setPlayerId=function(_id){this.playerId=_id;return this;};this.setSilverlightElementName=function(_name){this.silverlightElementName=_name;return this;};this.getSilverlightElementName=function(){return this.silverlightElementName;};this.setLayerLeftOffset=function(_left){this.layerLeftOffset=parseInt(_left);if(isNaN(this.layerLeftOffset)){this.layerLeftOffset=0;this.debug("Redefining invalid left offset "+_left+" with "+this.layerLeftOffset+".");}return this;};this.setLayerTopOffset=function(_top){this.layerTopOffset=parseInt(_top);if(isNaN(this.layerTopOffset)){this.layerTopOffset=0;this.debug("Redefining invalid top offset "+_top+" with "+this.layerTopOffset+".");}return this;};this.setLayerWidth=function(_width){this.layerWidth=parseInt(_width);if(isNaN(this.layerWidth)){this.layerWidth=320;this.debug("Redefining invalid width "+_width+" with "+this.layerWidth+".");}return this;};this.setLayerHeight=function(_height){this.layerHeight=parseInt(_height);if(isNaN(this.layerHeight)){this.layerHeight=250;this.debug("Redefining invalid height "+_height+" with "+this.layerHeight+".");}return this;};this.setBackgroundColor=function(_color){this.backgroundColor=_color;if(this.backgroundColor==null||typeof this.backgroundColor.match=="undefined"||!this.backgroundColor.match(/^[A-Fa-f0-9]{6}$/)){this.backgroundColor="000000";this.debug("Redefining invalid color "+_color+" with "+this.backgroundColor+".");}return this;};this.setAudioVolume=function(_volume){this.audioVolume=_volume;if(isNaN(this.audioVolume)){this.audioVolume=100;this.debug("Redefining invalid volume "+_volume+" with "+this.audioVolume);}return this;};this.setAutostart=function(_autostart){this.autostart=_autostart;return this;};this.addCountDown=function(_position,_text,_textColor,_color,_opacity){this.countDown=[_position,_text,_textColor,_color,_opacity];return this;};this.setCountDown=function(_position,_text,_textColor,_color,_opacity){return this.addCountDown(_position,_text,_textColor,_color,_opacity);};this.setStartCall=function(_call,_params){this.startCall=_call;this.startCallParams=_params;this.playerType=this.CUSTOM;return this;};this.setStopCall=function(_call,_params){this.stopCall=_call;this.stopCallParams=_params;this.playerType=this.CUSTOM;return this;};this.findPlayer=function(_try){this.debugLayer=document.getElementById("SC_DEBUGLAYER");this.player=this.find(this.playerId,document);this.debug("findPlayer("+_try+","+this.loaded+","+this.player+")");if(this.player==null&&!this.loaded){window.setTimeout(function(){SC_Easyroll().findPlayer();},500);this.debug("- this.player = "+this.player);}else if(this.player==null&&this.loaded){if(_try==null){window.setTimeout(function(){SC_Easyroll().findPlayer(50);},500);}else if(_try>0){window.setTimeout(function(){SC_Easyroll().findPlayer(_try-1);},500);}}if(this.player!=null){this.prepare();}};this.onLoad=function(){this.debug("onLoad()");this.loaded=true;};this.prepare=function(){this.debug("prepare()");if(this.player!=null){window.setTimeout(function(){SC_Easyroll().checkPlayer(0);},1000);}else{this.debug("Player object not found!");}};this.getPlayer=function(){return this.player;};this.detectBrowser=function(){var agent=navigator.userAgent;if(agent.match(/Firefox.(\d.\d)/i)!=null){this.browser="FIREFOX";return true;}else if(agent.match(/MSIE.(\d.\d)/i)!=null){this.browser="IE";return true;}else if(agent.match(/Opera.(\d.\d)/i)!=null){this.browser="OPERA";return true;}else if(agent.match(/Safari.(\d)/i)!=null){this.browser="SAFARI";return true;}return false;};this.addEvent=function(_obj,_event,_func){if(_obj.addEventListener){_obj.addEventListener(_event,_func,false);return true;}else if(_obj.attachEvent){return _obj.attachEvent("on"+_event,_func);}return false;};this.removeEvent=function(_obj,_event,_func){if(typeof _obj.removeEventListener!="undefined"){_obj.removeEventListener(_event,_func,false);return true;}else if(typeof _obj.detachEvent!="undefined"){return _obj.detachEvent("on"+_event,_func);}return false;};this.getLeft=function(_obj){var left=0;if(_obj){if(_obj.offsetParent){left=_obj.offsetLeft+this.getLeft(_obj.offsetParent);}else if(_obj.x){left=_obj.x;}}return left;};this.setLeft=function(_obj,_left){_obj.style.left=_left+"px";};this.getTop=function(_obj){var top=0;if(_obj){if(_obj.offsetParent){top=_obj.offsetTop+this.getTop(_obj.offsetParent);}else if(_obj.y){top=_obj.y;}}return top;};this.setTop=function(_obj,_top){_obj.style.top=_top+"px";};this.getWidth=function(_obj){var width=0;var attr=null;if(_obj){width=parseInt(_obj.width);if(isNaN(width)){width=parseInt(_obj.offsetWidth);if(isNaN(width)){width=parseInt(_obj.style.width);}}}return width;};this.getHeight=function(_obj){var height=0;var attr=null;if(_obj){height=parseInt(_obj.height);if(isNaN(height)){height=parseInt(_obj.offsetHeight);if(isNaN(height)){height=parseInt(_obj.style.height);}}}return height;};this.hideOrShow=function(_obj,_show){if(_show){_obj.style.visibility="visible";}else{_obj.style.visibility="hidden";}};this.setOpacity=function(_obj,_value){if(this.browser=="IE"){_obj.style.filter="alpha(opacity="+_value*100+")";}else{_obj.style.opacity=_value;}};this.getDocument=function(_frame){if(_frame.contentDocument!=null){return _frame.contentDocument;}else if(_frame.contentWindow){return _frame.contentWindow.document;}else if(_frame.document){return _frame.document;}return null;};this.find=function(_id,_document){var object=_document.getElementById(_id);if(object==null){var iframes=_document.getElementsByTagName("iframe");for(var i=0;object==null&&i<iframes.length;i++){var doc=this.getDocument(iframes[i]);if(doc!=null){object=this.find(_id,doc);}}}return object;};this.getPositionAndDimension=function(){var left,top,width,height;if(this.player!=null){left=this.getLeft(this.player)+this.layerLeftOffset;top=this.getTop(this.player)+this.layerTopOffset;width=this.layerWidth>0?this.layerWidth:this.getWidth(this.player);height=this.layerHeight>0?this.layerHeight:this.getHeight(this.player);return[left,top,width,height];}return null;};this.addLayerToPage=function(){var data=this.getPositionAndDimension(this.player);if(this.browser=="IE"){this.layer=document.createElement("<div style=\"filter:alpha(opacity="+this.opacity*100+"); z-index:100; background-color:#"+this.backgroundColor+"; left:"+data[0]+"px; top:"+data[1]+"px; width:"+data[2]+"px; height:"+data[3]+"px; position:absolute; visibility:hidden;\">");}else{this.layer=document.createElement("div");this.layer.setAttribute("style","opacity:"+this.opacity+"; z-index:100; background-color:#"+this.backgroundColor+"; left:"+data[0]+"px; top:"+data[1]+"px; width:"+data[2]+"px; height:"+data[3]+"px; position:absolute; visibility:hidden;");}if(this.browser=="IE"){this.internalPlayer=document.createElement("<object id=\"SC_INTERNAL_PLAYER\" classid=\"clsid:"+this.flashClassId+"\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0\" width=\"100%\" height=\"100%\" type=\"application/x-shockwave-flash\">");}else{this.internalPlayer=document.createElement("object");this.internalPlayer.setAttribute("id","SC_INTERNAL_PLAYER");this.internalPlayer.setAttribute("width","100%");this.internalPlayer.setAttribute("height","100%");this.internalPlayer.setAttribute("type","application/x-shockwave-flash");this.internalPlayer.setAttribute("data",this.getMiniPlayerUrl());}this.internalPlayer.appendChild(this.createParam("movie",this.getMiniPlayerUrl()));this.internalPlayer.appendChild(this.createParam("menu","false"));this.internalPlayer.appendChild(this.createParam("scale","noscale"));this.internalPlayer.appendChild(this.createParam("wmode","transparent"));this.internalPlayer.appendChild(this.createParam("bgcolor","#"+this.backgroundColor));this.internalPlayer.appendChild(this.createParam("allowScriptAccess","always"));if(this.countDown!=null){this.internalPlayer.appendChild(this.createParam("flashvars","ad_countdown=true&ad_countdown_position="+this.countDown[0]+"&ad_countdown_text="+escape(this.countDown[1])+"&ad_countdown_text_color="+this.countDown[2]+"&ad_countdown_color="+this.countDown[3]+"&ad_countdown_opacity="+this.countDown[4]));}if(this.browser=="IE"){this.clickLayer=document.createElement("<div style=\"filter:alpha(opacity=0.0); z-index:101; background-color:#"+this.backgroundColor+"; left:0px; top:0px; width:"+data[2]+"px; height:"+data[3]+"px; position:absolute;\" onclick=\"SC_run()\">");}else{this.clickLayer=document.createElement("div");this.clickLayer.setAttribute("style","opacity:0.0; z-index:101; background-color:#"+this.backgroundColor+"; left:0px; top:0px; width:"+data[2]+"px; height:"+data[3]+"px; position:absolute;");this.clickLayer.addEventListener("click",SC_run,false);}this.layer.appendChild(this.internalPlayer);this.layer.appendChild(this.clickLayer);document.body.appendChild(this.layer);};this.getMiniPlayerUrl=function(){return this.baseUrl+"/player.swf";};this.createParam=function(_name,_value){var param=null;if(this.browser=="IE"){param=document.createElement("<param name=\""+_name+"\" value=\""+_value+"\">");}else{param=document.createElement("param");param.setAttribute("name",_name);param.setAttribute("value",_value);}return param;};this.checkPlayer=function(_try){var type=this.player.getAttribute("type");var data=this.player.getAttribute("data");var classid=this.player.getAttribute("classid");var result=false;var error=false;var video=null;this.debug("checkPlayer("+_try+")");if(type!=null){type=type.toLowerCase();}if(data!=null){data=data.toLowerCase();}if(classid!=null){classid=classid.toUpperCase();}if(this.playerType==this.UNKNOWN){if(this.browser=="IE"&&classid!=null&&classid.indexOf(this.mediaPlayerClassId)!=-1){this.playerType=this.WINDOWS_MEDIA_PLAYER;}else if(type!=null&&type.indexOf("x-silverlight")!=-1||data!=null&&data.indexOf("x-silverlight")!=-1){this.playerType=this.SILVERLIGHT;}else if(type!=null&&type.indexOf("x-shockwave-flash")!=-1||classid!=null&&classid.indexOf(this.flashClassId)!=-1){if(typeof this.player.sendEvent!="undefined"){this.playerType=this.JW_PLAYER;}else if(typeof this.player.Pause!="undefined"||typeof this.player.fp_pause!="undefined"){this.playerType=this.FLOW_PLAYER;}else if(typeof this.player.pauseVideo!="undefined"){this.playerType=this.YOUTUBE;}}if(this.playerType!=this.UNKNOWN){this.debug("- player type detected = "+this.playerType);}else{this.debug("- player type not detected");}}else{this.debug("- player type provided = "+this.playerType);}if(this.playerType==this.SILVERLIGHT){result=this.checkSilverlightPlayer();}else if(this.playerType==this.WINDOW_MEDIA_PLAYER){result=this.checkWindowsMediaPlayer();}else if(this.playerType==this.DAILY_MOTION){result=this.checkFlashPlayer();if(result){video=this.getDailyMotionVideoUrl()!=null;if(video==null){this.debug("- Did not find video id of the Daily Motion player");}result=video!=null;}}else if(this.playerType!=this.UNKNOWN){result=this.checkFlashPlayer();}this.debug("- result = "+result);if(!error&&!result&&_try<50){window.setTimeout(function(){SC_Easyroll().checkPlayer(++_try);},500);}else if(result){this.show();}};this.checkFlashPlayer=function(){var name="";var value="";var wmode=false;var script=false;var node=this.player.nodeName.toLowerCase();var calls=this.hasStartCall()&&(!this.autostart||this.hasStopCall());var params=null;if(node=="object"){params=this.player.getElementsByTagName("param");}else{params=this.player.attributes;}for(var j=0;params!=null&&j<params.length;j++){name=params[j].name.toLowerCase();value=params[j].value.toLowerCase();if(name=="wmode"&&value=="transparent"){wmode=true;}if(name=="allowscriptaccess"&&value=="always"){script=true;}}if(!wmode){this.debug("- Flash parameter \"wmode\" is not set or not set to \"transparent\"");}if(!script){this.debug("- Flash parameter \"allowscriptaccess\" is not set or not set to \"always\"");}if(!calls){this.debug("- Could not determine start/stop method for the player");}return wmode&&script&&(calls||this.force);};this.checkWindowsMediaPlayer=function(){return this.force;};this.checkSilverlightPlayer=function(){var name="";var value="";var background=false;var windowless=false;var opera=this.browser=="OPERA";var element=typeof this.player.Content!="undefined"?this.player.Content.FindName(this.silverlightElementName):null;var playing=element!=null&&element.CurrentState=="Playing"&&element.BufferingProgress==1;this.debug("- playing = "+playing+" ("+(element!=null?element.CurrentState:"-")+", "+(element!=null?element.BufferingProgress:"-")+")");var params=this.player.getElementsByTagName("param");for(var i=0;params!=null&&i<params.length;i++){name=params[i].name.toLowerCase();value=params[i].value.toLowerCase();if(name=="background"&&value=="transparent"){background=true;}if(name=="windowless"&&value=="true"){windowless=true;}}if(!background){this.debug("Silverlight parameter \"background\" is not set or not set to \"transparent\"");}if(!windowless){this.debug("Silverlight parameter \"windowless\" is not set or not set to \"true\"");}if(opera){this.debug("Silverlight is not fully supported in Opera yet as the \"windowless\" parameter does not work.");}return background&&windowless&&opera&&((!this.autostart||playing)||this.force);};this.onResize=function(){this.debug("onResize()");var data=this.getPositionAndDimension(this.player);if(data!=null&&this.layer!=null){this.setLeft(this.layer,data[0]);this.setTop(this.layer,data[1]);}};this.show=function(){this.debug("show()");this.addLayerToPage();this.hideOrShow(this.layer,true);};this.initDone=function(){this.debug("initDone("+this.autostart+")");if(this.autostart){this.stopExternalPlayer(0);}};this.run=function(){this.debug("run("+this.videoAdUrl+")");try{var data=this.getPositionAndDimension(this.player);if(data!=null){this.internalPlayer.loadVideoAd(this.videoAdUrl,data[2],data[3],this.audioVolume);}else{this.endVideoAd();}}catch(exc){this.debug(exc);}};this.startingVideoAd=function(){this.debug("startingVideoAd()");this.setOpacity(this.layer,1);this.hideOrShow(this.clickLayer,false);};this.endVideoAd=function(){this.debug("endVideoAd");this.hideOrShow(this.layer,false);this.startExternalPlayer();};this.buildCall=function(_call,_params){var custom=_call+"(";for(var i=0;_params!=null&&i<_params.length;i++){custom+="'"+_params[i]+"'";if(i<_params.length-1){custom+=",";}}custom+=")";this.debug("- building call = "+custom);return custom;};this.hasStartCall=function(){var params=[this.startCall,this.startCallParams];if(this.playerType!=this.CUSTOM){params=this.PLAYER_TYPES[this.playerType].start;}return this.hasCall(params);};this.hasStopCall=function(){var params=[this.stopCall,this.stopCallParams];if(this.playerType!=this.CUSTOM){params=this.PLAYER_TYPES[this.playerType].stop;}return this.hasCall(params);};this.hasCall=function(_params){if(_params!=null&&_params.length>0){var func=eval("this.player."+_params[0]);return typeof func!="undefined";}return false;};this.startExternalPlayer=function(){this.debug("startExternalPlayer");var call=null;if(this.playerType==this.SILVERLIGHT){try{this.player.Content.FindName(this.silverlightElementName).Play();}catch(exc){}}else if(this.playerType==this.WINDOW_MEDIA_PLAYER){try{player.controls.play();}catch(exc){}}else if(this.playerType==this.CUSTOM){try{call="this.player."+this.buildCall(this.startCall,this.startCallParams);eval(call);}catch(exc){}}else if(this.playerType==this.DAILY_MOTION){try{if(!this.autostart){this.player.loadVideoByUrl(this.getDailyMotionVideoUrl());}else{this.player.playVideo();}}catch(exc){}}else if(this.playerType!=this.UNKNOWN){try{call="this.player."+this.buildCall(this.PLAYER_TYPES[this.playerType].start[0],this.PLAYER_TYPES[this.playerType].start[1]);eval(call);}catch(exc){}}};this.stopExternalPlayer=function(_try){this.debug("stopExternalPlayer("+_try+", "+this.playerType+")");var stopped=false;var runFunc=null;var code="";if(this.playerType==this.SILVERLIGHT){try{runFunc=function(){SC_Easyroll().getPlayer().Content.FindName(SC_Easyroll().getSilverlightElementName()).Pause();SC_Easyroll().run();};stopped=true;}catch(exc){}}else if(this.playerType==this.WINDOW_MEDIA_PLAYER){try{runFunc=function(){SC_Easyroll().getPlayer().controls.pause();SC_Easyroll().run();};stopped=true;}catch(exc){}}else if(this.playerType==this.DAILY_MOTION){try{if(this.player.getPlayerState()==1){runFunc=function(){SC_Easyroll().getPlayer().pauseVideo();SC_Easyroll().run();};stopped=true;}}catch(exc){}}else if(this.playerType==this.CUSTOM){try{code="runFunc = function() { SC_Easyroll().getPlayer()."+this.buildCall(this.stopCall,this.stopCallParams)+"; SC_Easyroll().run(); }";eval(code);stopped=true;}catch(exc){}}else if(this.playerType!=this.UNKNOWN){try{code="runFunc = function() { SC_Easyroll().getPlayer()."+this.buildCall(this.PLAYER_TYPES[this.playerType].stop[0],this.PLAYER_TYPES[this.playerType].stop[1])+"; SC_Easyroll().run(); }";eval(code);stopped=true;}catch(exc){}}if(!stopped&&_try<50){window.setTimeout(function(){SC_Easyroll().stopExternalPlayer(++_try);},500);}else if(stopped){runFunc();}};this.getFlashVersion=function(){var isIE=navigator.appVersion.indexOf("MSIE")!=-1?true:false;var isWin=navigator.appVersion.toLowerCase().indexOf("win")!=-1?true:false;var isOpera=navigator.userAgent.indexOf("Opera")!=-1?true:false;var descr=null;var versions=null;if(navigator.plugins!=null&&navigator.plugins.length>0){if(navigator.plugins['Shockwave Flash 2.0']||navigator.plugins['Shockwave Flash']){descr=navigator.plugins["Shockwave Flash"+(navigator.plugins['Shockwave Flash 2.0']?" 2.0":"")].description.split(" ");versions=descr[2].split(".");return versions[0];}}else if(isIE&&isWin&&!isOpera){try{versions=(new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7")).GetVariable("$version").split(",");return versions[0].substr(4);}catch(exception){}}return 7;};this.debug=function(_message){if(this.debugLayer!=null){if(this.debugLayer.innerHTML==""){this.debugLayer.innerHTML=_message;}else{this.debugLayer.innerHTML=this.debugLayer.innerHTML+"<br>"+_message;}}};this.getDailyMotionVideoUrl=function(){var url=this.player.getAttribute("data");if(url==null){var params=null;var node=this.player.nodeName.toLowerCase();var name="";if(node=="object"){params=this.player.getElementsByTagName("param");}else{params=this.player.attributes;}for(var j=0;params!=null&&j<params.length;j++){name=params[j].name.toLowerCase();url=params[j].value.toLowerCase();if(name=="movie"){break;}}}return url.replace(/\/swf/,"");};}function SC_onLoad(){SC_Easyroll().onLoad();}function SC_initDone(){SC_Easyroll().initDone();}function SC_onResize(){SC_Easyroll().onResize();}function SC_run(){SC_Easyroll().run();}function SC_startingVideoAd(){SC_Easyroll().startingVideoAd();}function SC_endVideoAd(){SC_Easyroll().endVideoAd();}
