var SM_LEADERBOARD_PATH="file:///vcbnr/sm_adv/startup_ui_lb_boot_ad.png";
var SM_LEADERBOARD_SERVER_JSON="file:///vcbnr/sm_adv/startup_ui_boot_ad_meta.json";
var SM_LEADERBOARD_SERVER_JSON2="file:///vcbnr/sm_adv/startup_ui_lb_boot_ad_meta.json";
var SM_LEADERBOARD_FEED_JSON="file:///vcbnr/sm_adv/startup_ui_lb_boot_ad.json";
var banner_loaded=false;
var effects={
spring:function(pos){
return 1-(Math.cos(pos*4.5*Math.PI)*Math.exp(-pos*6));},
};
SMAd=new container({});
SMAd.init=function(is_startup_fullscreen){
if(this.components.length>0)return;
var width=Math.floor(728*1.8),height=Math.floor(90*1.8);
this.translate=[0,-700,0];
this.visible_p=false;
this.components=[
this.image1=new gimage({width:width,height:height,draw_type:CIRCUMSCRIBED,src:""}),
this.footer_bg=new gbox({width:width||0,height:20,translate:[0,-height/2-10,0],color:[80,80,80,255]}),
this.footer_label=new gtext({width:width||0,translate:[0,-height/2-8,0],font_size:14,align:RIGHT,text:LANG("LT_APPS_SPONSORED_AD"),margin:[0,0,0,10],}),
];
this.from_translate=[0,-700,0];
this.to_translate=[0,-400,0];
this.timeout_cnt=0;
this.cnt=0;
this.pos=0;
this.skip_count=8;
this.stay_count=20;
this.COUNT=16;
this.enable_focus=true;
this.enable_lb_boot_ad_click=true;
this.image1.onload=function(){
SMAd.visible_p=true;
banner_loaded=true;
try{
var ret=read_file(SM_LEADERBOARD_SERVER_JSON2);
if(ret==null){
ret=read_file(SM_LEADERBOARD_SERVER_JSON);}
if(ret!=null){
var pana_meta=eval("("+ret+")");
if(pana_meta.details){
SMAd.pana_meta=pana_meta;
if(typeof pana_meta.details.enable_focus=="boolean"){
SMAd.enable_focus=pana_meta.details.enable_focus;}
if(typeof pana_meta.details.enable_lb_boot_ad_click=="boolean"){
SMAd.enable_lb_boot_ad_click=pana_meta.details.enable_lb_boot_ad_click;}
}
}
}catch(e){
console.log(e.fileName+":"+e.lineNumber,e.name,e.message);}
};
this.image1.onerror=function(){
if(SMAd.is_startup_fullscreen&&ebus.sm_advertisement&&ebus.sm_advertisement.get_vcbnr_setting()){
SMAd.visible_p=true;
for(var i=0;i<SMAd.components.length;i++){
SMAd.components[i].visible_p=false;}
SMAd_default.init();
SMAd.components.push(SMAd_default);}else {
SMAd.destroy();}
};
this.is_startup_fullscreen=is_startup_fullscreen;};
SMAd.setDestroyFunc=function(func){
this.destroyFunc=func;};
SMAd.destroy=function(){
this.free();
SMAd_default.free();
if(typeof this.destroyFunc=="function"){this.destroyFunc();}
};
SMAd.free=function(){
delete_timer(this);
this.visible_p=false;
if(this.components.length==0)return;
this.image1.src="";
setf_text(this.footer_label,"");};
SMAd.animation=function(count){
if(!this.visible_p){
this.timeout_cnt++;
if(!system.mdl_cfg.with_sm_advertisement){
this.destroy();
return false;}
if(system.get_power_status()==system.POWER_STATUS_ON&&this.image1.src==""){
this.image1.src=read_file(SM_LEADERBOARD_PATH)||SM_LEADERBOARD_PATH;}
if(this.timeout_cnt>20){
this.destroy();
}
return false;}
this.cnt++;
if(this.launching){
this.cnt=this.COUNT+this.skip_count;}
if(this.cnt<this.skip_count){
if(this.cnt==1){
try{
var ret=read_file(SM_LEADERBOARD_FEED_JSON);
if(ret!=null){
var body=ret;
body=body.replace(/^[^\{]+{/,"{");
body=body.replace(/;$/,"");
this.sm_meta=JSON.parse(body);
if(this.sm_meta&&this.sm_meta.details&&this.sm_meta.details.clickThroughUrl)
this.clickable=true;}
ret=read_file(SM_LEADERBOARD_SERVER_JSON2);
if(ret==null){
ret=read_file(SM_LEADERBOARD_SERVER_JSON);}
if(ret!=null){
this.pana_meta=eval("("+ret+")");}
}catch(e){
console.log(e.fileName+":"+e.lineNumber,e.name,e.message);}
}
return false;}else if(this.cnt==this.skip_count&&banner_loaded){
try{
banner_loaded=false;
if(this.is_startup_fullscreen){
ebus.sm_advertisement.notify_lb_boot_ad_impression();}else {
ebus.sm_advertisement.notify_lb_impression();}
}catch(e){
console.log(e.fileName+":"+e.lineNumber,e.name,e.message);}
}
if(this.cnt<=this.COUNT+this.skip_count){
if(!SU_IS_SLOW_ANIM){
this.effect(this,this.cnt-this.skip_count);}else if(this.cnt==this.COUNT){
this.effect(this,this.COUNT);}
}else if(this.cnt<this.COUNT+this.skip_count+this.stay_count){

}else if(this.cnt<this.COUNT+this.skip_count+this.stay_count+10){
if(!SU_IS_SLOW_ANIM){
this.image1.color[3]-=Math.floor(255/10*1.2);
this.footer_bg.color[3]-=Math.floor(255/10*1.2);
setf_text(this.footer_label,"");}
}else {
this.destroy();}
return true;};
SMAd.effect=function(obj,count){
if(count==obj.COUNT){
obj.translate[0]=obj.to_translate[0];
obj.translate[1]=obj.to_translate[1];
if(!SMAd_default.visible_p&&SMAd.clickable&&SMAd.enable_focus)obj.requestFocus(obj.translate,[1310,162],0,42,null);}else {
obj.pos+=1/obj.COUNT;
obj.translate[0]=obj.from_translate[0]-(obj.from_translate[0]-obj.to_translate[0])*effects.spring(obj.pos);
obj.translate[1]=obj.from_translate[1]-(obj.from_translate[1]-obj.to_translate[1])*effects.spring(obj.pos);}
};
SMAd.requestFocus=NULL_FUNCTION;
SMAd.setFocusFunc=function (focus_moveto){
if(focus_moveto instanceof Function){
this.requestFocus=focus_moveto;}
};
SMAd.launchApl=function (locked_panel,report){
if(this.cnt<this.COUNT)return true;
if(!this.clickable)return true;
if(!this.enable_lb_boot_ad_click)return true;
if(SMAd_default.visible_p)return true;
try{
this.cnt=this.COUNT+this.skip_count;
this.translate[1]=this.to_translate[1];
if(this.launching)return true;
this.launching=true;
sm_store_meta(this.sm_meta,this.pana_meta);
var args="-T -s -R -l "+(this.is_startup_fullscreen?"from_lb_boot_ad":"from_startup_ui_lb")+
" -d "+"/usr/local/apps_nv/data/home/sm_ad_url";
var me=this;
var finished=function(){
return apputil.launch_apl("0070001200000001",args,locked_panel,report);};
wait_ip_available(function(mode){
if(mode==IP_AVAIL_STAT_NG){
me.launching=false;
me.destroy();
launch_appli("network_check");
return;}else if(mode==IP_AVAIL_STAT_CANCEL){
me.launching=false;
return;}
judgeNetworkAvailable("net");
append_timer(me,1000,function(obj,cnt){
judgeNetworkAvailable("clock");
if(cnt>30){
delete_timer(obj);
me.launching=false;
me.destroy();
launch_appli("network_check");}else if(isNetworkAvailable()){
delete_timer(obj);
me.launching=false;
finished();}
});});
return apputil.CODE.WAIT_IP_AVAILABLE;}catch(e){
console.log(e.toSource());};};
var ADV_BANNER_DEFAULT_MSG1="Enjoy selected internet content with Apps for Smart VIERA.";
var ADV_BANNER_DEFAULT_MSG2="Simply press the APPS button";
var ADV_BANNER_DEFAULT_BG=APPLI_PATH+MARKETTOP_APPS+"/gadget/vcbnr_init.png";
var get_msg1=function(){
var text=LANG("LT_VC_LEAD_MES1")||ADV_BANNER_DEFAULT_MSG1;
var country=system.locale.country.substr(0,2).toUpperCase();
switch(country){
case "SA":
SMAd_default.msg1.margin_leading=-5;
break;
case "GB":
case "IE":
case "NO":
case "LV":
case "FI":
text=text.replace("for","\nfor");
break;
case "NL":
text=text.replace("voor","\nvoor");
break;
case "ID":
text=text.replace("untuk","\nuntuk");
break;
case "HU":
text=text.replace("a Smart","\na Smart");
break;
case "DE":
text=text.replace("mit","\nmit");
break;
case "IT":
text=text.replace("alle","\nalle");
break;}
return text;};
var get_msg2=function(){
return LANG("LT_VC_LEAD_MES2")||ADV_BANNER_DEFAULT_MSG2;};
var SMAd_default=new container({visible_p:false});
SMAd_default.init=function(){
if(this.components.length>0)return;
this.components=[
this.bg=new gimage({width:1400,height:200,src:ADV_BANNER_DEFAULT_BG,}),
this.msg1=new gtextbox({width:1150,height:97,translate:[0,35,0],align:CENTER,font_size:40,valign:MIDDLE,margin_leading:-9,}),
this.msg2=new gtextbox({width:1150,height:97,translate:[0,-40,0],align:CENTER,font_size:40,valign:MIDDLE,margin_leading:-9,}),
];
setf_text(this.msg1,get_msg1());
setf_text(this.msg2,get_msg2());
this.visible_p=true;};
SMAd_default.free=function(){
if(this.components.length==0)return;
this.visible_p=false;
this.bg.src="";
setf_text(this.msg1,"");
setf_text(this.msg2,"");};
