var product_id="0387878700000031";
var png_path=APPLI_PATH+product_id+"/gadget/";
var load_failure_img=png_path+"web_browser.png";
var SM_AD_IMAGE="file:///vcbnr/sm_adv/startup_ui_boot_ad.png";
var SM_SERVER_JSON="file:///vcbnr/sm_adv/startup_ui_boot_ad_meta.json";
var SM_FEED_JSON="file:///vcbnr/sm_adv/startup_ui_boot_ad.json";
var SM_AD_READY=null;
var FULL_SCREEN=false;
var FirstTime=true;
if(system.mdl_cfg.with_vc_market==true){
var gadget=new Gadget();
gadget.Message=function(param){
this.superClass=container;
this.superClass({});
this.translate=param.translate?param.translate:[0,0,0];
this.label_text=param.label_text?param.label_text:"";
this.width=param.width?param.width:400;
this.height=param.height?param.height:40;
this.label_align=param.label_align?param.label_align:"LEFT";
this.font_size=param.font_size?param.font_size:40;
this.color_f=param.color_f?param.color_f:[0,0,0,0];
this.color_b=param.color_b?param.color_b:[200,200,200,0];
function change_font_size_gtextbox(obj,max,interval){
if(get_text_font_height(obj,obj.text)>obj.height){
for(var i=obj.font_size;i>max;i-=interval){
obj.font_size=i;
if(get_text_font_height(obj,obj.text)<=obj.height){
break;}
}
setf_text(obj,obj.text);}
};
if(param.visible_p==null){
this.visible_p=true;}else {
this.visible_p=param.visible_p;}

this.label_f=new gtextbox({translate:[0,0,0],
width:this.width,height:this.height,font_size:this.font_size,
color:this.color_f,text:this.label_text,align:this.label_align,});
this.label_b=new gtextbox({translate:[2,-2,0],
width:this.width,height:this.height,font_size:this.font_size,
color:this.color_b,text:this.label_text,align:this.label_align,});
change_font_size_gtextbox(this.label_f,14,2);
change_font_size_gtextbox(this.label_b,14,2);
this.components.push(this.label_b,this.label_f);};
gadget.Message.prototype.setAlpha=function(alpha){
this.label_f.color[3]=alpha;
this.label_b.color[3]=alpha;};
gadget.Message.prototype.getAlpha=function(){
return this.label_f.color[3];};
gadget.Message.prototype.freeResource=function(bool){
if(bool){
setf_text(this.label_f,"");
setf_text(this.label_b,"");}else{
setf_text(this.label_f,this.label_text);
setf_text(this.label_b,this.label_text);}
};
gadget.init=function(){
this._readyAdImage(false);

var icon_path=png_path+"mhs_icon.png";
var lang=system.locale.language.substr(0,5);
if(lang=="fr-CA"){
icon_path=png_path+"mhs_icon_fr-CA.png";}else if(lang=="ja-JP"){
icon_path=png_path+"mhs_icon_ja-JP.png";}
this.image=new gimage({translate:[0,0,0],width:412,height:232,
draw_type:DIRECT,
src:icon_path,});
this.components.push(this.image);
this.message_cnt=0;
this.message_show_cnt=20;
this.message_da=Math.ceil(255/this.message_show_cnt);
this.message_disp_cnt=60;
this.message_state=true;
this.message_1=new gadget.Message({translate:[0,60,0],width:320,height:80,
font_size:40,align:LC_TEXT_ALIGN,
label_text:LANG("LT_HOME_DL_NOTICE3"),});
this.components.push(this.message_1);
this.message_2=new gadget.Message({translate:[0,60,0],width:320,height:80,
font_size:40,align:LC_TEXT_ALIGN,
label_text:LANG("LT_HOME_DL_NOTICE4"),});
this.components.push(this.message_2);
this.warn_message=new gadget.Message({translate:[0,60,0],width:320,
height:80,font_size:40,color_f:[0,0,0,255],color_b:[200,200,200,255],
align:LC_TEXT_ALIGN,
visible_p:false,label_text:LANG("LT_HOME_SETTING_1"),});
this.components.push(this.warn_message);
this._ad_mode=false;
this._ad_hide=false;
this._ad_show=false;
this._message_anim=true;
this._mhs_state=true;}
gadget.animation=function(count){
if((FULL_SCREEN==true)&&(FirstTime!=false)){
if(system.get_power_status()==system.POWER_STATUS_ON){
this._readyAdImage(true);
FULL_SCREEN=false;}
}
if(this._ad_hide==true){
this._adHideAnim(count);
return true;}
if(this._ad_show==true){
this._adShowAnim(count);
return true;}
if(this._ad_mode==false){
var ret=this._messageAnim();
return ret;}
return !SU_IS_4K;};
gadget._messageAnim=function (){
if(this._message_anim==true){
this.message_cnt++;
if(this.message_cnt==this.message_show_cnt){
if(this._judgeAnimMessage()==false)return false;
if(this.message_state){
this.message_1.setAlpha(255);
this.message_2.setAlpha(0);
this.message_state=false;}else{
this.message_2.setAlpha(255);
this.message_1.setAlpha(0);
this.message_state=true;}
return true;}else if(this.message_cnt>=this.message_disp_cnt){
this.message_cnt=0;}
}else{
this.message_cnt=0;
this.message_1.setAlpha(0);
this.message_2.setAlpha(0);
this.message_state=true;
return false;}
}
gadget.launchApl=function(locked_panel,report){
if(this._getAdMode()==false){
var glob=(function(){return this;})();
var home=glob.HOME;
var ret=null;
ret=home.switchMHS(home.myscreen_op);
if(!(ret)){
this.warn_message.visible_p=true;
this._message_anim=false;
this._messageAnim();
force_redraw();}
}else if(this._getAdMode()==true){
try{
var sm_meta=null;
var pana_meta=null;
var ret=read_file(SM_FEED_JSON);
if(ret!=null){
var body=ret;
body=body.replace(/^[^\{]+{/,"{");
body=body.replace(/;$/,"");
sm_meta=JSON.parse(body);}
ret=read_file(SM_SERVER_JSON);
if(ret!=null){
pana_meta=eval("("+ret+")");}
sm_store_meta(sm_meta,pana_meta);
var args="-T -s -R -l "+"from_startup_ui"+
" -d "+"/usr/local/apps_nv/data/home/sm_ad_url";
return apputil.launch_apl("0070001200000001",args,locked_panel,report);}catch(e){
console.log(e.toSource());}
}
};
gadget.onFocus=function(is_focused,key,point_env){
if(is_focused){
this.requestFocus([0,0,1],[this.$width,this.$height],0,42,null);}else {
this.warn_message.visible_p=false;
this._message_anim=true;}
}
gadget.getStatus=function(){
return {"movable":false,"removable":false};};
gadget.freeResource=function(bool){
this.message_1.freeResource(bool);
this.message_2.freeResource(bool);
this.warn_message.freeResource(bool);
gimageResource(this.image,bool);};
gadget.voicePlay=function(){
if(this._ad_mode==true)return;
if(system.locale.country=="JP")
VoicePlay("ホームのギャラリー");
else
VoicePlay("Home Screen Collection");}
gadget.sm_timer={};
gadget.setFullscreen=function (bool){
if(bool==true){
FULL_SCREEN=true;
if(SM_AD_READY==true){
this._setFullscreen(bool);}
}
}
gadget._showVCFace=function (bool){
if(bool==true){
this.image.visible_p=true;}else {
this.image.visible_p=false;}
}
}else {
function mkt_logo_anim_icon(src,translate,width,height,alpha,
onload_func,pos){
this.superClass=container;
this.superClass({});
var self=this;
this.translate=translate;
this.width=width;
this.height=height;
this.alpha=alpha
this.src=src;
this.image=new gimage({
"src":src,
"width":width,
"height":height,
"color":[255,255,255,alpha],
"onload":onload_func,
"onerror":function(obj){
if(obj.src!=load_failure_img)obj.src=load_failure_img;},
"draw_type":INSCRIBED,
"translate":[0,0,0.1],
});
this.bg_image=new gbox({
"width":width+2,
"height":height+2,
"color":[160,160,160,120],
"round_enable":true,
"round_width":8,
"round_height":8,
});
this.shadow=new gimage({
"src":png_path+"mkt_icon_reflect.png",
"width":width+4,
"height":5,
"color":[255,255,255,alpha],
"draw_type":DIRECT,
"translate":[0,-height/2-3,0],
visible_p:true,
});
this.dx=0;
this.dy=0;
this.dz=0;
this.dw=0;
this.dh=0;
this.da=0;
this.dalpha=0;
this.RATE=0;
this.max_count=0;
this.image.load_flg_pos=(0x01<<pos);
this.image.pos=pos;
this.components.push(this.shadow,this.bg_image,this.image);};
mkt_logo_anim_icon.prototype=new container({});
mkt_logo_anim_icon.prototype.moveTo=function(x,y,z,w,h,angle,
end_func,rate,alpha,max_cnt,
src_rad,mode,center_x,radius_x){
this.RATE=0.4;
this.max_count=max_cnt;
this.count=0;
if(mode==1){

this.dz=z-this.translate[2];
this.dw=w-this.width;
this.dh=h-this.height;
this.da=angle-this.rotation[0];
this.dalpha=alpha-this.alpha;
var center_y=0;
var radius_y=10;
this.moveTo_animation=function(obj,count){
obj.count++;
obj.translate[0]=center_x+radius_x*Math.cos(src_rad+((obj.count*10*9/obj.max_count)/360*Math.PI));
obj.translate[1]=center_y+radius_y*Math.sin(src_rad+((obj.count*10*9/obj.max_count)/360*Math.PI));
obj.translate[2]+=obj.dz/obj.max_count;
var scale_factor=0.25+Math.sin(src_rad+((obj.count*10*9/obj.max_count)/ 360 * Math.PI))/2;
obj.setSize(
246*scale_factor,
172*scale_factor,
0,
obj.alpha+(obj.dalpha/obj.max_count)
);

obj.da=angle-obj.rotation[0];
obj.rotation[0]+=obj.da*obj.RATE;
if(obj.count>=obj.max_count){
obj.moveTo_animation=null;
obj.translate[0]=x;
obj.translate[1]=y;
obj.translate[2]=z;
obj.setSize(obj.width,obj.height,obj.angle,alpha);
if(typeof end_func=="function"){
end_func(obj);}
}
}
}else{

this.dx=x-this.translate[0];
this.dy=y-this.translate[1];
this.dz=z-this.translate[2];
this.dw=w-this.width;
this.dh=h-this.height;
this.da=angle-this.rotation[0];
this.dalpha=alpha-this.alpha;

this.moveTo_animation=function(obj,count){
obj.count++;
obj.translate[0]+=obj.dx/obj.max_count;
obj.translate[1]+=obj.dy/obj.max_count;
obj.translate[2]+=obj.dz/obj.max_count;
obj.setSize(
obj.width+(obj.dw/obj.max_count),
obj.height+(obj.dh/obj.max_count),
0,
obj.alpha+(obj.dalpha/obj.max_count)
);

obj.da=angle-obj.rotation[0];
obj.rotation[0]+=obj.da*obj.RATE;
if(obj.count>=obj.max_count){
obj.moveTo_animation=null;
obj.translate[0]=x;
obj.translate[1]=y;
obj.translate[2]=z;
obj.setSize(w,h,angle,alpha);
if(typeof end_func=="function"){
end_func(obj);}
}
}
}
};
mkt_logo_anim_icon.prototype.setSize=function(w,h,angle,alpha){
this.width=w;
this.height=h;
this.alpha=alpha;
this.image.width=Math.floor(this.width);
this.image.height=Math.floor(this.height);
this.image.color[3]=Math.floor(this.alpha);
this.bg_image.width=Math.floor(this.width)+2;
this.bg_image.height=Math.floor(this.height)+2;
this.shadow.width=Math.floor(this.image.width);
this.shadow.height=5;
this.shadow.color[3]=Math.floor(this.alpha);
this.shadow.translate[1]=this.image.translate[1]-this.height/2-3;};
mkt_logo_anim_icon.prototype.free=function(){
if(this.components.length==0)return;
for(var i=0,max=this.components.length;i<max;i++){
if(this.components[i] instanceof gtext||
this.components[i] instanceof gtextbox){
setf_text(this.components[i],"");}else if(this.components[i] instanceof gimage){
this.components[i].src="";}
}
this.components.splice(0,this.components.length);}
mkt_logo_anim_icon.prototype.freeResource=function(bool){
gimageResource(this.image,bool);
gimageResource(this.shadow,bool);};
var Anim=new container({
visible_p:true,
translate:[0,-55,-0.6],
});
Anim.create=function(){
if(this.components.length>0){
this.init();
return;}
var self=this;
this.components.push(
this.anim_icon_list2=new container({})
);
this.anim_icon_list={components:[]};
this.anim_icon_param=[
[0,10,0.5,150,105,0,null,0,255,57,-38.5,62,46,2*Math.PI*30/360,1,-55,230],
[135,5,0.3,125,87,0,null,0,255,40,-27,43,32],[135,5,0.1,80,56,0,null,0,180,32.5,-22,35,26],[-135,5,0.1,80,56,0,function(obj){
self.anim_icon_list.adjust_position(obj,2);
if(self.anim_icon_list.num>4){
var position2_no=self.anim_icon_list.center_img_no+2;
if(position2_no>self.anim_icon_list.num-1){
position2_no-=self.anim_icon_list.num;}
obj.image.src=self.anim_icon_list.cash_img[0].src;
self.anim_icon_list.img_load_cmp&=(~obj.image.load_flg_pos);
self.anim_icon_list.cash_img[0].src=
self.anim_icon_list.cash_img[1].src;
self.anim_icon_list.img_load_cmp&=
(~self.anim_icon_list.cash_img[0].load_flg_pos);
var cash_second_no=self.anim_icon_list.center_img_no+4;
if(cash_second_no>self.anim_icon_list.num-1){
cash_second_no-=self.anim_icon_list.num;}
self.anim_icon_list.cash_img[1].src=
self.anim_icon_list.img_src[cash_second_no];
self.anim_icon_list.img_load_cmp&=
(~self.anim_icon_list.cash_img[1].load_flg_pos);}
},0,180,32.5,-22,35,26],
[-135,5,0.3,125,87,0,null,0,255,40,-27,43,32,2*Math.PI*105/360,1,55,230],
];
this.anim_icon_list.image_onload=function(obj){
self.anim_icon_list.img_load_cmp|=obj.load_flg_pos;
if((self.anim_icon_list.first_img_ready_flg!=true)&&
((self.anim_icon_list.img_load_cmp&self.anim_icon_list.img_cnt)==
self.anim_icon_list.img_cnt)){
self.anim_icon_list.first_img_ready_flg=true;}
};
this.anim_icon_list.get_next_position=function(obj,now_pos){
var ret;
switch(now_pos){
case 0:
ret=4;
break;
case 4:
if(this.num==3){
ret=1;}else{
ret=3;}
break;
default:
ret=now_pos-1;
break;}
return ret;};
this.anim_icon_list.adjust_position=function(obj,pos){
obj.translate=[
self.anim_icon_param[pos][0],
self.anim_icon_param[pos][1],
self.anim_icon_param[pos][2]];
obj.setSize(
self.anim_icon_param[pos][3],
self.anim_icon_param[pos][4],
self.anim_icon_param[pos][5],
self.anim_icon_param[pos][8],
self.anim_icon_param[pos][11],
self.anim_icon_param[pos][12]);
obj.next_pos=this.get_next_position(obj,pos);};
this.anim_icon_list.free=function(){
if(this.num<3)return;
if(this.img_src){
this.img_src.splice(0,this.img_src.length);}
if(this.cash_img){
for(var i=0;i<this.cash_img.length;i++){
this.cash_img[i].src="";}
this.cash_img.splice(0,this.cash_img.length);}
for(var i=0;i<this.components.length;i++){
this.components[i].moveTo_animation=null;
this.components[i].free();}
this.components.splice(0,this.components.length);}
this.anim_icon_list.freeResource=function(bool){
if(this.num<3)return;
if(this.cash_img){
gimageResource(this.cash_img[0],bool);
gimageResource(this.cash_img[1],bool);}
for(var i=0;i<this.components.length;i++){
this.components[i].freeResource(bool);}
}
this.freeResource=function(bool){
this.anim_icon_list.freeResource(bool);}
}
Anim.start=function(data){
this.create();

var self=this;
self.anim_icon_list.num=data.length;
self.anim_icon_list.img_cnt=0;
self.anim_icon_list.img_load_cmp=0;
self.anim_icon_list.first_img_ready_flg=false;
self.anim_icon_list.center_img_no=0;
if(self.anim_icon_list.num<3)return;
var k;
var img_no;
self.anim_icon_list.img_src=new Array();
for(var i=0;i<self.anim_icon_list.num;i++){
self.anim_icon_list.img_src[i]=data[i];}
for(var i=0;(i<self.anim_icon_list.num)&&(i<4);i++){
if((i==self.anim_icon_list.num-1)||(i==3)){
k=4;
img_no=self.anim_icon_list.num-1;}else{
k=i;
img_no=i;}
self.anim_icon_list.components.push(
new mkt_logo_anim_icon(
null,
[self.anim_icon_param[k][0],
self.anim_icon_param[k][1],
self.anim_icon_param[k][2]],
self.anim_icon_param[k][3],
self.anim_icon_param[k][4],
self.anim_icon_param[k][8],
self.anim_icon_list.image_onload,
i));
self.anim_icon_list.img_cnt|=(0x01<<i);
self.anim_icon_list.components[i].image.src=
self.anim_icon_list.img_src[img_no];

self.anim_icon_list.components[i].next_pos=
self.anim_icon_list.get_next_position(
self.anim_icon_list.components[i],k);}
if(self.anim_icon_list.num>4){
self.anim_icon_list.cash_img=new Array(2);
self.anim_icon_list.cash_img[0]=new gimage({
src:self.anim_icon_list.img_src[3],
onload:self.anim_icon_list.image_onload,
onerror:function(obj){
if(obj.src!=load_failure_img)obj.src=load_failure_img;}});
self.anim_icon_list.cash_img[0].load_flg_pos=0x10;
self.anim_icon_list.img_cnt|=0x10;
self.anim_icon_list.cash_img[1]=new gimage({
src:self.anim_icon_list.img_src[4],
onload:self.anim_icon_list.image_onload,
onerror:function(obj){
if(obj.src!=load_failure_img)obj.src=load_failure_img;}});
self.anim_icon_list.cash_img[1].load_flg_pos=0x20;
self.anim_icon_list.img_cnt|=0x20;}
};
Anim.animation_cnt=0;
var MKT_LOGO_ANIMATION_CNT=12;
Anim.animation=function(obj,count){
if(obj.visible_p==false)return;
if(!obj.anim_icon_list)return;
if(obj.anim_icon_list.num<3)return;
obj.animation_cnt++;
for(var i=0,i_max=obj.anim_icon_list.components.length;i<i_max;i++){
if(obj.anim_icon_list.components[i].moveTo_animation){
obj.anim_icon_list.components[i].moveTo_animation(
obj.anim_icon_list.components[i],obj.animation_cnt);}
}
if(obj.animation_cnt<MKT_LOGO_ANIMATION_CNT+1){
return;}else{
obj.animation_cnt=0;
obj.move_icon(obj);}
obj.anim_icon_list2.components=[];
for(var i=0;i<obj.anim_icon_list.components.length;i++)
obj.anim_icon_list2.components[i]=obj.anim_icon_list.components[i];
obj.anim_icon_list2.components.sort(function(a,b){
if(a.translate[2]<b.translate[2])return -1;
return 1;});};
Anim.move_icon=function(obj){
var j;
for(var i=0,i_max=obj.anim_icon_list.components.length;i<i_max;i++){
j=obj.anim_icon_list.components[i].next_pos;
if((obj.anim_icon_list.components.length==3)&&(j==1)){
obj.anim_icon_list.components[i].translate[2]-=0.2;}
obj.anim_icon_list.components[i].next_pos=
obj.anim_icon_list.get_next_position(
obj.anim_icon_list.components[i],j);
obj.anim_icon_list.components[i].moveTo(
obj.anim_icon_param[j][0],
obj.anim_icon_param[j][1],
obj.anim_icon_param[j][2],
obj.anim_icon_param[j][3],
obj.anim_icon_param[j][4],
obj.anim_icon_param[j][5],
obj.anim_icon_param[j][6],
obj.anim_icon_param[j][7],
obj.anim_icon_param[j][8],
(MKT_LOGO_ANIMATION_CNT+1),
obj.anim_icon_param[j][13],
obj.anim_icon_param[j][14],
obj.anim_icon_param[j][15],
obj.anim_icon_param[j][16]
);}
this.anim_icon_list.center_img_no++;
if(this.anim_icon_list.center_img_no>
this.anim_icon_list.num-1){
this.anim_icon_list.center_img_no=0;}
obj.anim_icon_list2.components=[];
for(var i=0;i<obj.anim_icon_list.components.length;i++)
obj.anim_icon_list2.components[i]=obj.anim_icon_list.components[i];
obj.anim_icon_list2.components.sort(function(a,b){
if(a.translate[2]<b.translate[2])return -1;
return 1;});}
Anim.init=function(){
if(this.anim_icon_list)
this.anim_icon_list.first_img_ready_flg=false;
this.animation_cnt=0;}
Anim.stop=function(){
this.init();
this.anim_icon_list.free();
for(var i=0,max=this.components.length;i<max;i++){
if(this.components[i] instanceof gtext||
this.components[i] instanceof gtextbox){
setf_text(this.components[i],"");}else if(this.components[i] instanceof gimage){
this.components[i].src="";}
}
this.components.splice(0,this.components.length);}
Anim.destroy=Anim.stop;
var gadget=new Gadget();
gadget.init=function(){

this.icon_path=[];
this._readyAdImage(false);

var app_list=null;
try{
var ret=apps_nvram_file.read({filename:"apps_list",async:false,
finished:function(){},product_id:"home",});
ret=sysutil.tconv.binary_to_string(ret);
app_list=eval(ret);
var APP_LIST=[];
var index=0;
for(var i=0;i<app_list.length;i++){
if(app_list[i]&&app_list[i].substring(0,2)!="03"){
var restricted=eval(getInfoPlist(app_list[i],"restricted"));
if(restricted!=true){
APP_LIST[index]=app_list[i];
index++;}
}
}
this.app_num=index;}catch(e){
console.log(" nvram_file error :Error = "+e.message);}
for(var i=0;i<this.app_num;i++){
this.icon_path[i]=APPLI_PATH+APP_LIST[i]+"/icon.png";}

this.bg=new gimage({translate:[0,0,-0.6],width:400,height:224,
draw_type:FULL,src:png_path+"vc_bg.png"});
this.image=new gimage({translate:[0,68,0],width:250,height:70,
draw_type:FULL,
src:png_path+(system.locale.language=="fr-CA"?"vc_logo_ca_fr.png":"vc_logo.png")});
this.components.push(this.bg,this.image,Anim);
this._ad_mode=false;
this._ad_hide=false;
this._ad_show=false;};
gadget.setSize=function(width,height){
this.bg.width=width;
this.bg.height=height;};
gadget.activate=function(bool){
if(bool){
if(Anim.components.length==0){
Anim.start(this.icon_path);}
}
};
gadget.animation=function(count){
Anim.animation(Anim,count)

if((FULL_SCREEN==true)&&(FirstTime!=false)){
if(system.get_power_status()==system.POWER_STATUS_ON){
this._readyAdImage(true);
FULL_SCREEN=false;}
}
if(this._ad_hide==true){
this._adHideAnim(count);
return !SU_IS_4K;}
if(this._ad_show==true)this._adShowAnim(count);
return !SU_IS_4K;};
gadget.launchApl=function(){
if(this._getAdMode()==false){
if(system.mdl_cfg.apps_context==system.mdl_cfg.APPS_CONTEXT_SURFER)
{
discard_stage("apps");
add_stage_load_path("apps",PATH+"apps.js");
apputil.on_stage("apps",PRODUCT_ID,arguments[1]);}else {
LogReport.report(LogReport.LAUNCH_APL,PRODUCT_ID,arguments[1]);
system.apps.launch_apps();}
}
};
gadget.getStatus=function(){
return {"movable":false,"removable":false};};
gadget.freeResource=function(bool){
gimageResource(this.bg,bool);
gimageResource(this.image,bool);
if(typeof Anim.freeResource=="function"){
Anim.freeResource(bool);}
};
gadget.voicePlay=function(){
if(system.locale.country=="JP")
VoicePlay("アプリケーション");
else
VoicePlay("Apps");}
gadget.sm_timer={};
gadget.setFullscreen=function (bool){
if(bool==true){
FULL_SCREEN=true;
if(SM_AD_READY==true){
this._setFullscreen(bool);}
}
};
gadget._showVCFace=function (bool){
if(bool==true){
this.bg.visible_p=true;
this.image.visible_p=true;
Anim.visible_p=true;}else {
this.bg.visible_p=false;
this.image.visible_p=false;
Anim.visible_p=false;}
}
}
gadget._setFullscreen=function (bool){
if(bool==true){
gadget._setAdFace(false);
gadget._setAdFace(true);}else {
gadget._setAdFace(false);}
};
gadget._readyAdImage=function (bool){
var self=this;
var _image=new gimage({src:read_file(SM_AD_IMAGE)||SM_AD_IMAGE,
onload:function(){
SM_AD_READY=true;
try{
if(bool==true)self._setFullscreen(true);}catch(e){};},
onerror:function(){
SM_AD_READY=false;},});};
gadget._setAdFace=function (bool){

if(bool==true){
this._showVCFace(false);
this._ad_mode=true;
this._ad_hide=false;
this._ad_show=true;
this.ad_image=new gimage({width:412,height:212,draw_type:INSCRIBED,color:[255,255,255,0],
src:read_file(SM_AD_IMAGE)||SM_AD_IMAGE,translate:[0,10,0.3],});
this.ad_label=new gbox({width:412,height:20,color:[0,0,0,0],translate:[0,-232*0.5+10,0.3],});
this.ad_title=new gtext({width:412-20,font_size:14,align:RIGHT,translate:[0,-232*0.5+10,0.3],
color:[255,255,255,0],text:LANG("LT_APPS_SPONSORED_AD"),});
this.components.push(this.ad_image,this.ad_label,this.ad_title);

this._impressionNotify();

var self=this;
append_timer(self,6000,function(obj){
delete_timer(obj);
self._showVCFace(true);
self._ad_show=false;
self._ad_hide=true;});
if(this.message_1)this.message_1.setAlpha(0);
if(this.message_2)this.message_2.setAlpha(0);}else {
if(this._ad_mode==true){
delete_timer(this);
this.ad_image.src="";
setf_text(this.ad_title,"");
var index=this.components.indexOf(this.ad_image);
this.components.splice(index,3);}
this._showVCFace(true);
this._ad_mode=false;}
};
gadget._adShowAnim=function (count){
if(this.ad_image.color[3]>250){
this.ad_image.color[3]=255;
this.ad_label.color[3]=160;
this.ad_title.color[3]=255;
this._ad_show=false;
return;}
this.ad_image.color[3]+=25;
this.ad_label.color[3]+=16;
this.ad_title.color[3]+=25;};
gadget._adHideAnim=function (count){
if(this.ad_image.color[3]<30){
this.ad_image.visible_p=false;
this.ad_label.visible_p=false;
this.ad_title.visible_p=false;
this._ad_hide=false;
this._setAdFace(false);
return;}
this.ad_image.color[3]-=25;
this.ad_label.color[3]-=16;
this.ad_title.color[3]-=25;};
gadget._getAdMode=function (){
return this._ad_mode;};
gadget._impressionNotify=function (){
var pana_urls=[];
var sm_urls=[];

var server_json=this._getSMFile(SM_SERVER_JSON);
var feed_json=this._getSMFile(SM_FEED_JSON);
if(server_json&&server_json.details&&server_json.details.startup_ui_impression_tracking_url){
pana_urls[0]=server_json.details.startup_ui_impression_tracking_url
+"&lang="+system.locale.language.substr(0,5)+"&country="+system.locale.country
+"&pos=-1";}
if(feed_json&&feed_json.details&&feed_json.details.impressionTrackingUrl){
sm_urls=feed_json.details.impressionTrackingUrl;}
var ad_user_agent="";
if(server_json&&server_json.details){
ad_user_agent=server_json.details.ad_user_agent||"";}
var urls={"urls":sm_urls,
"panasonic_urls":pana_urls,};
if(this._judgeFirstTime()==true){
try{
ebus.sm_advertisement.notify_impression();
this._downPONFlag();}catch(e){};}else {
if(sm_urls&&(sm_urls instanceof Array)){
for(var i=0;i<sm_urls.length;i++){
http_request({
"url":sm_urls[i],
"method":"GET",
"user_agent":ad_user_agent,
"onload":function (status,header,body){},
"sync":false,
});}
}
if(pana_urls&&(pana_urls instanceof Array)){
for(var i=0;i<pana_urls.length;i++){
http_request({
"url":pana_urls[i],
"method":"GET",
"onload":function (status,header,body){},
"sync":false,
});}
}
}
};
gadget._judgeAnimMessage=function (){
if(this._mhs_state==true){
try{
ret=apps_nvram.read("mhs_market","home");
if(ret=="ON"){
this._mhs_state=false;
ret=false;}else{
this._mhs_state=true;
ret=true;}
}catch(e){
ret=true;}
}else {
ret=false;}
return ret;};
gadget._judgeFirstTime=function (){
if(FirstTime==true){
var ret=null;
try{
ret=apps_nvram.read("poweron_check","home");
if(ret==null)return true;
FirstTime=false;
ret=eval(ret);}catch(e){
}
}else {
ret=FirstTime;}
return ret;};
gadget._downPONFlag=function (){
try{
apps_nvram.write("poweron_check","false","home");}catch(e){
}
};
gadget._getSMFile=function (file_name){
var ret=null;
try{
http_request({url:file_name,
sync:true,method:"GET",
onload:function(status,header,body){
if(status==200){
ret=body;}
},});
if(file_name==SM_FEED_JSON){
var start=ret.indexOf("var smCreative =");
var end=ret.indexOf("};");
if((start==-1)||(end==-1)){
return null;}
ret=ret.replace(/^[^\{]+{/,"{");
ret=ret.replace(/;$/,"");}
ret=JSON.parse(ret);}catch(e){
}
return ret;};
return gadget;
