function SC_Easyroll(){if(SC_Easyroll.singleton==null){SC_Easyroll.singleton=new SC_EasyrollClass;}return SC_Easyroll.singleton;}function SC_EasyrollClass(){this.debugLayer=null;this.playerId="";this.browser="UNKNOWN";this.playerType="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.loaded=false;this.startCall=null;this.startCallParams=null;this.stopCall=null;this.stopCallParams=null;this.init=function(){this.debug(2,"init()");if(typeof this.playerId=="undefined"||this.playerId==null||this.playerId==""){this.debug(1,"Player identification not set!");return;}else if(typeof this.videoAdUrl=="undefined"||this.videoAdUrl==null||this.videoAdUrl==""||!this.videoAdUrl.match(/^https?:\/\//)){this.debug(1,"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();}};this.setStartCall=function(_call,_params){this.startCall=_call;this.startCallParams=_params;return this;};this.setStopCall=function(_call,_params){this.stopCall=_call;this.stopCallParams=_params;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(1,"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(1,"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(2,"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(2,"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(2,"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(2,"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.findPlayer=function(){this.debug(2,"findPlayer()");this.debugLayer=document.getElementById("SC_DEBUGLAYER");this.player=this.find(this.playerId,document);if(this.player==null&&!this.loaded){window.setTimeout(function(){SC_Easyroll().findPlayer();},100);}else if(this.loaded){this.player=this.find(this.playerId,document);}if(this.player!=null){this.prepare();}};this.onLoad=function(){this.debug(2,"onLoad()");this.loaded=true;};this.prepare=function(){this.debug(2,"prepare()");if(this.player!=null){this.checkPlayer(0);}else{this.debug(1,"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 name=null;var value=null;var params=null;this.debug(2,"checkPlayer("+_try+")");if(type!=null){type=type.toLowerCase();}if(data!=null){data=data.toLowerCase();}if(classid!=null){classid=classid.toUpperCase();}if(this.browser=="IE"&&classid!=null&&classid.indexOf(this.mediaPlayerClassId)!=-1){this.playerType="WMV";}else if(type!=null&&type.indexOf("x-silverlight")!=-1||data!=null&&data.indexOf("x-silverlight")!=-1){this.playerType="SILVERLIGHT";}else if(type!=null&&type.indexOf("x-shockwave-flash")!=-1||classid!=null&&classid.indexOf(this.flashClassId)!=-1){this.playerType="FLASH";}this.debug(2,"- player type = "+this.playerType);if(this.playerType=="SILVERLIGHT"){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(2,"- playing = "+playing+" ("+(element!=null?element.CurrentState:"-")+", "+(element!=null?element.BufferingProgress:"-")+")");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(1,"Silverlight parameter \"background\" is not set or not set to \"transparent\"");}if(!windowless){this.debug(1,"Silverlight parameter \"windowless\" is not set or not set to \"true\"");}if(opera){this.debug(1,"Silverlight is not fully supported in Opera yet as the \"windowless\" parameter does not work.");}error=!background||!windowless||opera;result=!error&&(!this.autostart||playing);}else if(this.playerType=="FLASH"){var wmode=false;var script=false;var node=this.player.nodeName.toLowerCase();var custom=eval("this.player."+this.startCall);var start=typeof custom!="undefined"||typeof this.player.sendEvent!="undefined"||typeof this.player.Pause!="undefined"||typeof this.player.pauseVideo!="undefined";this.debug(2,"- SendEvent()  = "+(typeof this.player.sendEvent!="undefined"));this.debug(2,"- Pause()      = "+(typeof this.player.Pause!="undefined"));this.debug(2,"- PauseVideo() = "+(typeof this.player.pauseVideo!="undefined"));this.debug(2,"- "+this.startCall+"() = "+(typeof custom!="undefined"));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(1,"- Flash parameter \"wmode\" is not set or not set to \"transparent\"");}if(!script){this.debug(1,"- Flash parameter \"allowscriptaccess\" is not set or not set to \"always\"");}if(!start){this.debug(1,"- Could not determine start method for the player");}error=!wmode||!script;result=!error&&start;}else if(this.playerType=="WMV"){error=false;result=!error;}this.debug(2,"- result = "+result);if(!error&&!result&&_try<20){window.setTimeout(function(){SC_Easyroll().checkPlayer(++_try);},500);}else if(result){this.show();}};this.onResize=function(){this.debug(2,"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(2,"show()");this.addLayerToPage();this.hideOrShow(this.layer,true);};this.initDone=function(){this.debug(2,"initDone("+this.autostart+")");if(this.autostart){this.stopExternalPlayer(0);}};this.run=function(){this.debug(2,"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(1,exc);}};this.startingVideoAd=function(){this.debug(2,"startingVideoAd()");this.setOpacity(this.layer,1);this.hideOrShow(this.clickLayer,false);};this.endVideoAd=function(){this.debug(2,"endVideoAd");this.hideOrShow(this.layer,false);this.startExternalPlayer();};this.buildCustomCall=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+=")";return custom;};this.runCustomCall=function(){var custom="this.player."+this.buildCustomCall(this.startCall,this.startCallParams);this.debug(2,"runCustomCall("+custom+")");eval(custom);};this.getCustomCallFunc=function(){var custom="runFunc = function() { SC_Easyroll().getPlayer()."+this.buildCustomCall(this.stopCall,this.stopCallParams)+"; SC_Easyroll().run(); }";this.debug(2,"getCustomCallFunc("+custom+")");return custom;};this.startExternalPlayer=function(){this.debug(2,"startExternalPlayer");if(this.playerType=="FLASH"){var custom=eval("this.player."+this.startCall);if(typeof custom!="undefined"){try{this.runCustomCall();}catch(exc){alert(exc);}}else if(typeof this.player.sendEvent!="undefined"){try{this.player.sendEvent("PLAY","true");}catch(exc){}}else if(typeof this.player.DoPlay!="undefined"){try{this.player.DoPlay();}catch(exc){}}else if(typeof this.player.playVideo!="undefined"){try{this.player.playVideo();}catch(exc){}}}else if(this.playerType=="SILVERLIGHT"){try{this.player.Content.FindName(this.silverlightElementName).Play();}catch(exc){}}else if(this.playerType=="WMV"){try{player.controls.play();}catch(exc){alert(exc);}}};this.stopExternalPlayer=function(_try){this.debug(2,"stopExternalPlayer("+_try+", "+this.playerType+")");var stopped=false;var runFunc=null;if(this.playerType=="FLASH"){var custom=eval("this.player."+this.stopCall);if(typeof custom!="undefined"){try{custom=this.getCustomCallFunc();eval(custom);stopped=true;}catch(exc){alert(exc);}}else if(typeof this.player.sendEvent!="undefined"){try{runFunc=function(){SC_Easyroll().getPlayer().sendEvent("PLAY","false");SC_Easyroll().run();};stopped=true;}catch(exc){}}else if(typeof this.player.Pause!="undefined"){try{runFunc=function(){SC_Easyroll().getPlayer().Pause();SC_Easyroll().run();};stopped=true;}catch(exc){}}else if(typeof this.player.pauseVideo!="undefined"){try{runFunc=function(){SC_Easyroll().getPlayer().pauseVideo();SC_Easyroll().run();};stopped=true;}catch(exc){}}}else if(this.playerType=="SILVERLIGHT"){try{runFunc=function(){SC_Easyroll().getPlayer().Content.FindName(SC_Easyroll().getSilverlightElementName()).Pause();SC_Easyroll().run();};stopped=true;}catch(exc){}}else if(this.playerType=="WMV"){try{runFunc=function(){SC_Easyroll().getPlayer().controls.pause();SC_Easyroll().run();};stopped=true;}catch(exc){alert(exc);}}if(!stopped&&_try<10){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(_level,_message){if(this.debugLayer!=null){if(this.debugLayer.innerHTML==""){this.debugLayer.innerHTML=_message;}else{this.debugLayer.innerHTML=this.debugLayer.innerHTML+"<br>"+_message;}}};}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();}