var product_id="0387878700000105";
var png_path=APPLI_PATH+product_id+"/gadget/";
var BACK_IMG=png_path+"apps_back_gradation.png";
var DEFAULT_IMG=png_path+"gadget_market_noback.png";
var SALE_IMG=png_path+"sale_tag.png";
var NEW_IMG=png_path+"store_btn_new_icon.png";
var MY_LANG=system.locale.language.substr(0,5);
var APPSMARKET_IMG=png_path+"gadget_appMarket_noback.png";
var SHOST=getHostName();
var HOST=getDefaultUrl("testurl").match(new RegExp("(http://[^/]*)/"))[1];
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;
var ANIM_ENABLE=false;
if(system.mdl_cfg.with_vc_market==true){
var gadget=new Gadget();
gadget.Ctl=function(param){
this.superClass=container;
this.superClass({});
this.translate=param.translate?param.translate:[0,0,0];
this.width=param.width?param.width:400;
this.height=param.height?param.height:40;

this.data_list=null;
this.alert_data=null;
this.getDataIndex=this._getDataIndex();
this.cacheImage=this._cacheImage();

this.image_default=new gimage({translate:[0,0,0],width:412,height:232,draw_type:DIRECT,src:DEFAULT_IMG});
this.components.push(this.image_default);
this.fade_list_index=0;
this.fade_list=new Array();
var self=this;
var onerror=function(){
self.setDataOfIndex(self.fade_list[self.fade_list_index].setDataMain,self.getDataIndex());};
this.fade_list.push(
new gadget.FadeObj({translate:[0,0,0],onerror:onerror,child_class:gadget.Item})
);
this.components=this.components.concat(this.fade_list);
var p=new Object();
p.type="TITLE";
this.fade_list[this.fade_list_index].setDataSub(p);
};
gadget.Ctl.prototype.freeResource=function(bool){
if(this.cacheImage){
this.cacheImage.free(bool);}
if(this.fade_list.length>0){
for(var i=0;i<this.fade_list.length;i++){
this.fade_list[i].freeResource(bool);}
}
if(this.image_default){
gimageResource(this.image_default,bool);}
};
gadget.Ctl.prototype.animation=function(count){
if(this.data_list!=null){
if(this.data_list.length>0){
var isError=false;
for(var i=0;i<this.fade_list.length;i++){
if(this.fade_list[i].isError()==true){
isError=true;
break;}
}
if(isError==false){
if(this.fade_list[this.fade_list_index].animation()==0){
this.setDataOfIndex(this.fade_list[this.fade_list_index].setDataMain,this.getDataIndex());}
}
return true;}else {
return false;}
}else if(this.alert_data==null){
if(system.get_power_status()==system.POWER_STATUS_ON){
this.getHsAlertItem("APP");
this.getHsAlertItem("PHY");
this.getHsAlertItem("SCREEN");}
return true;}else {
return false;}
};
gadget.Ctl.prototype.getHsPromotion=function(sale_type,alert_data){
var lang=system.locale.language.substr(0,5);
var type;
if((alert_data.alert_total>2)&&(alert_data.alert_item>0)){
type="&type=0";}else {
type="&type=1&limit=4";}
switch(sale_type){
case "APP":
var url=SHOST+"/market/hs-promotion?"+"&country="+system.locale.country
+"&language="+lang+type+"&sale_type=0";
break;
case "PHY":
var url=SHOST+"/market/hs-promotion?"+"&country="+system.locale.country
+"&language="+lang+type+"&sale_type=1";
break;
case "SCREEN":
var url=SHOST+"/mhs_market/hs-promotion?"+"&country="+system.locale.country
+"&language="+lang+type;
break;
default:
return;}
var self=this;
if(self.data_list==null){
self.data_list=new Array();}
var onload=function(status,header,body){
if(status==200){
var data=eval("("+body+")");
if(data.error&&(data.error.substring(0,3)=="901")){
return;}else if(data.error&&(data.error!="0")){
return;}else {
if(self.data_list.length==0){
self.data_list=self.data_list.concat(data);
for(var i=0;i<self.fade_list.length;i++){
self.setDataOfIndex(self.fade_list[i].setDataMain,self.getDataIndex());}
}else {
self.data_list=self.data_list.concat(data);}
}
}else {
console.log("error in hs-promotion : status = "+status);}
};
http_request({
url:url,
method:"GET",
onload:onload,
sync:false,
});};
gadget.Ctl.prototype.getHsAlertItem=function(sale_type){
var lang=system.locale.language.substr(0,5);
switch(sale_type){
case "APP":
var url=SHOST+"/market/hs-alert-item?"+"&country="+system.locale.country+"&sale_type=0";
break;
case "PHY":
var url=SHOST+"/market/hs-alert-item?"+"&country="+system.locale.country+"&sale_type=1";
break;
case "SCREEN":
var url=SHOST+"/mhs_market/hs-alert-item?"+"&country="+system.locale.country;
break;
default:
return;}
var self=this;
if(self.alert_data==null){
self.alert_data=new Array();}
var onload=function(status,header,body){
if(status==200){
try{
data=eval("("+body+")");
if(data.error&&(data.error.substring(0,3)=="901")){
self.getHsPromotion(sale_type,{alert_total:0,alert_item:0});
self.alert_data.push({alert_total:0,alert_item:0});}else if(data.error&&(data.error!="0")){
self.alert_data.push({alert_total:0,alert_item:0});
}else {
self.getHsPromotion(sale_type,data);
self.alert_data.push(data);}
}catch(e){
self.alert_data.push({alert_total:0,alert_item:0});
console.log("Error = "+e.message);}
}else {
self.alert_data.push({alert_total:0,alert_item:0});
console.log("error in hs-alert-item : status = "+status);}
if(self.alert_data.length==3){
};}
http_request({
url:url,
method:"GET",
onload:onload,
sync:false,
});};
gadget.Ctl.prototype._getDataIndex=function(){
var index=0;
return function(){
var ret=index;
if(index<=this.data_list.length){
}else {
index=0;}
return index++;};};
gadget.Ctl.prototype.setDataOfIndex=function(func,index){
var data=new Object();
if(index<this.data_list.length){
var data=this.data_list[index];
if(data.sale_type==0){
data.type="APP";}else if(data.sale_type==1){
data.type="PHY";}else {
data.type="SCREEN";}
data.src=this.cacheImage.set(index,data.type);}else {
data.type="TITLE";}
func(data);
force_redraw();};
gadget.Ctl.prototype._cacheImage=function(){
var cache_list=new Array();
var self=this;
return {
set:function(index,type){
var src="";
if(self.data_list){
if(type=="APP"){
src=HOST+"/data/"+self.data_list[index].id+"/catalog/"+self.data_list[index].icon;}else if(type=="PHY"){
src=HOST+"/catalog/"+self.data_list[index].id+"/"+self.data_list[index].icon;}else if(type=="SCREEN"){
src=SHOST+"/mhs_market/screen-image/"+self.data_list[index].id+"/"+self.data_list[index].icon;}
if(!cache_list[index]){
cache_list[index]=new gimage({src:src});}
}
return src;},
free:function(bool){
var max=cache_list.length;
for(var i=0;i<max;i++){
var obj=cache_list[i];
if(obj){
gimageResource(obj,bool);}
}
}
};};
gadget.Badge=function(param){
this.superClass=container;
this.superClass({});
this.translate=param.translate?param.translate:[0,0,0];
this.visible_p=false;
this.icon_img=new gimage({translate:[0,0,0],width:42,height:42,draw_type:DIRECT,
src:BADGE_IMG});
this.icon_num=new gtext({translate:[-1,3,0],width:40,font_size:22,align:CENTER,
font_name:"F015T-bold",text:""});
this.components.push(this.icon_img,this.icon_num);};
gadget.Badge.prototype.setShow=function(bool,alert_data){
this.visible_p=bool;
if(bool){
var num=0;
for(var i=0;i<alert_data.length;i++){
num+=alert_data[i].alert_item;}
setf_text(this.icon_num,""+num);}else {
}
};
gadget.Badge.prototype.freeResource=function(){
this.icon_img.freeResource(bool);
gtextResource(this.icon_num,bool);};
gadget.FadeObj=function(param){
this.superClass=container;
this.superClass({});
this.translate=[0,0,0];
this.child_class=param.child_class;
var onerror=param.onerror?param.onerror:null;
this.title_text1=new gtextbox({width:412,height:40,translate:[50,0,0],text:"",
font_size:32,align:LEFT,visible_p:true,color:fdp_color_p.TEXT_ONBASE});
var title_h=get_text_font_height(this.title_text1,"A");
this.title_text1.height=title_h;
this.title_text1.translate[1]=Math.ceil(title_h/2);
setf_text(this.title_text1,"VIERA");

this.title_text2=new gtextbox({width:412,height:40,translate:[50,0,0],text:"",
font_size:60,align:LEFT,visible_p:true,color:fdp_color_p.TEXT_ONBASE});
var title_h=get_text_font_height(this.title_text2,"A");
this.title_text2.height=title_h;
this.title_text2.translate[1]=-Math.ceil(title_h/2)+10;
setf_text(this.title_text2,"Market");
this.components.push(this.title_text1,this.title_text2);

this.anim_count=0;
if((SU_IS_4K==true)||(SU_IS_SLOW_ANIM==true)){
this.fade_anim_count=1;}else {
this.fade_anim_count=1;}
this.display_anim_count=this.fade_anim_count+64;
this.anim_fade_step=Math.ceil(255/this.fade_anim_count);
this.image_a=new this.child_class({translate:param.translate,onerror:onerror});
this.image_a.setAlpha(0);
this.image_b=new this.child_class({translate:param.translate,onerror:onerror});
this.image_b.setAlpha(255);
this.components.push(this.image_a,this.image_b);
this.main=this.image_a;
this.sub=this.image_b;
this.setDataMain=this._setDataMain();
this.setDataSub=this._setDataSub();};
gadget.FadeObj.prototype._setDataMain=function(){
var self=this;
return function(data){
self.main.setData(data);}
};
gadget.FadeObj.prototype._setDataSub=function(){
var self=this;
return function(data){
self.sub.setData(data);}
};
gadget.FadeObj.prototype.freeResource=function(bool){
this.image_a.freeResource(bool);
this.image_b.freeResource(bool);
gtextResource(this.title_text1,bool);
gtextResource(this.title_text2,bool);};
gadget.FadeObj.prototype.animation=function(){
if(this.anim_count<=this.fade_anim_count){
this.animFade();
this.anim_count++;}else if(this.anim_count<=this.display_anim_count){
this.anim_count++;}else if(this.anim_count>this.display_anim_count){
this.exchange_main_sub();
this.anim_count=0;}else {
this.anim_count++;}
return this.anim_count;};
gadget.FadeObj.prototype.animFade=function(){
var alpha=this.main.getAlpha();
if((alpha+this.anim_fade_step)>=255){
this.main.setAlpha(255);
if(this.sub.getType()=="TITLE"){
this.title_text1.visible_p=false;
this.title_text2.visible_p=false;}
}else {
this.main.setAlpha((alpha+this.anim_fade_step));
if(this.sub.getType()=="TITLE"){
if((alpha+this.anim_fade_step)>=130){
this.title_text1.visible_p=false;
this.title_text2.visible_p=false;}
}
}
var alpha=this.sub.getAlpha();
if((alpha-this.anim_fade_step)<=0){
this.sub.setAlpha(0);
if(this.main.getType()=="TITLE"){
this.title_text1.visible_p=true;
this.title_text2.visible_p=true;}
}else {
this.sub.setAlpha((alpha-this.anim_fade_step));
if(this.main.getType()=="TITLE"){
if((alpha-this.anim_fade_step)<=130){
this.title_text1.visible_p=true;
this.title_text2.visible_p=true;}
}
}
};
gadget.FadeObj.prototype.exchange_main_sub=function(){
if(this.main===this.image_a){
this.main=this.image_b;
this.sub=this.image_a;}else {
this.main=this.image_a;
this.sub=this.image_b;}
};
gadget.FadeObj.prototype.isError=function(){
var ret=false;
if((this.image_a.isError()==true)||(this.image_b.isError()==true)){
ret=true;}
return ret;};
gadget.FadeObj.prototype.isShow=function(){
return this.visible_p;};
gadget.FadeObj.prototype.setShow=function(bool){
this.visible_p=bool;};
gadget.Item=function(param){
this.superClass=container;
this.superClass({});
this.translate=param.translate?param.translate:[0,0,0];
this.width=param.width?param.width:412;
this.height=param.height?param.height:232;
this.onerror=param.onerror?param.onerror:null;
this.onerror_flg=true;
this.type=null;
this.image=new gimage({width:160,height:112,visible_p:false,
draw_type:DIRECT,translate:[0,0,0]});
var self=this;
this.image.onerror=function(obj){
self.onerror_flg=true;
self.sale.visible_p=false;
self.new_icon.visible_p=false;
obj.src="";
if(self.onerror){
self.onerror();}
};
this.image.onload=function(obj){
self.onerror_flg=false;};

var sale_p=new Object();
sale_p.width=62;
sale_p.height=46;
sale_p.draw_type=DIRECT;
sale_p.src=SALE_IMG;
sale_p.visible_p=false;
sale_p.translate=[this.image.width/2-sale_p.width/2,-this.image.height/2+sale_p.height/2,0];
this.sale=new gimage(sale_p);

var new_p=new Object();
new_p.width=66;
new_p.height=33;
new_p.draw_type=DIRECT;
new_p.src=NEW_IMG;
new_p.visible_p=false;
new_p.translate=[this.image.width/2-new_p.width/2-10,-this.image.height/2+new_p.height/2+10,0];
this.new_icon=new gimage(new_p);
this.image_item=new container({translate:[-80,0,0]});
this.image_item.components.push(this.image,this.sale,this.new_icon);
this.components.push(this.image_item);};
gadget.Item.prototype.freeResource=function(bool){
gimageResource(this.image,bool);
gimageResource(this.sale,bool);
gimageResource(this.new_icon,bool);};
gadget.Item.prototype.setData=function(data){
for(var i=0;i<this.components.length;i++){
this.components[i].visible_p=false;}
this.sale.visible_p=false;
this.new_icon.visible_p=false;
this.onerror_flg=true;
this.type=data.type;
switch(data.type){
case "APP":
this.image.width=160;
this.image.height=112;
this.image.translate=[0,0,0];
this.image_item.visible_p=true;
if(this.image.src!=data.src){
this.image.src=data.src;
this.image.visible_p=true;}else {
this.onerror_flg=false;}
if(data.alert_type==2){
this.sale.translate[0]=this.image.width/2-this.sale.width/2;
this.sale.translate[1]=-this.image.height/2+this.sale.height/2;
this.sale.visible_p=true;}else {
this.sale.visible_p=false;}
if(data.alert_type==1){
this.new_icon.translate[0]=this.image.width/2-this.new_icon.width/2-10;
this.new_icon.translate[1]=-this.image.height/2+this.new_icon.height/2+10;
this.new_icon.visible_p=true;}else {
this.new_icon.visible_p=false;}
break;
case "PHY":
this.image.width=120;
this.image.height=120;
this.image.translate=[0,0,0];
this.image_item.visible_p=true;
if(this.image.src!=data.src){
this.image.src=data.src;
this.image.visible_p=true;}else {
this.onerror_flg=false;}
if(data.alert_type==2){
this.sale.translate[0]=this.image.width/2-this.sale.width/2;
this.sale.translate[1]=-this.image.height/2+this.sale.height/2;
this.sale.visible_p=true;}else {
this.sale.visible_p=false;}
if(data.alert_type==1){
this.new_icon.translate[0]=this.image.width/2-this.new_icon.width/2-10;
this.new_icon.translate[1]=-this.image.height/2+this.new_icon.height/2+10;
this.new_icon.visible_p=true;}else {
this.new_icon.visible_p=false;}
break;
case "SCREEN":
this.image.width=220;
this.image.height=Math.floor(this.image.width*9/16);
this.image.translate=[-5,0,0];
this.image_item.visible_p=true;
if(this.image.src!=data.src){
this.image.src=data.src;
this.image.visible_p=true;}else {
this.onerror_flg=false;}
if(data.alert_type==2){
this.sale.translate[0]=this.image.width/2-this.sale.width/2;
this.sale.translate[1]=-this.image.height/2+this.sale.height/2;
this.sale.visible_p=true;}else {
this.sale.visible_p=false;}
if(data.alert_type==1){
this.new_icon.translate[0]=this.image.width/2-this.new_icon.width/2-10;
this.new_icon.translate[1]=-this.image.height/2+this.new_icon.height/2+10;
this.new_icon.visible_p=true;}else {
this.new_icon.visible_p=false;}
break;
case "TITLE":
this.image.src="";
this.onerror_flg=false;
break;
default:
break;}
};
gadget.Item.prototype.getType=function(){
return this.type;};
gadget.Item.prototype.setAlpha=function(alpha){
this.image.color[3]=alpha;
this.sale.color[3]=alpha;
this.new_icon.color[3]=alpha;};
gadget.Item.prototype.getAlpha=function(){
return this.image.color[3];};
gadget.Item.prototype.isError=function(){
return this.onerror_flg;};
gadget.init=function(){
this._readyAdImage(false);

this.icon_anim_start_count=32;
this.back_img=new gimage({width:412,height:232,draw_type:DIRECT,src:BACK_IMG,
color:fdp_color_p.TEXT_SUB_ONBASE});
this.back_img2=new gbox({width:412,height:232,color:fdp_color_p.BASE});
if(ANIM_ENABLE){
this.ctl=new gadget.Ctl({width:206,height:116});
this.components.push(this.back_img2,this.back_img,this.ctl);}else {
this.title_text=new gtextbox({width:412,height:40,translate:[0,0,0],text:"",
font_size:32,align:CENTER,color:fdp_color_p.TEXT_ONBASE});
var title_h=get_text_font_height(this.title_text,"A");
this.title_text.height=title_h;
this.title_text.translate[1]=-232/2+Math.ceil(title_h/2)+15;
var lang=system.locale.language.substr(0,5);
if(lang=="fr-CA"){
setf_text(this.title_text,"Marché pour applications");}else if(lang=="ja-JP"){
setf_text(this.title_text,"アプリ・マーケット");}else {
setf_text(this.title_text,"Apps Market");}
this.icon=new gimage({width:412,height:232,draw_type:DIRECT,src:APPSMARKET_IMG});
this.components.push(this.back_img2,this.back_img,this.icon,this.title_text);}
this._ad_mode=false;
this._ad_hide=false;
this._ad_show=false;
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(/;$/,"");
this.sm_meta=JSON.parse(body);
if(this.sm_meta&&this.sm_meta.details&&this.sm_meta.details.clickThroughUrl)
this.smad_clickable=true;}
ret=read_file(SM_SERVER_JSON);
if(ret!=null){
this.pana_meta=eval("("+ret+")");}
}catch(e){
console.log(e.fileName+":"+e.lineNumber,e.name,e.message);}
}
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){
if(ANIM_ENABLE){
var ret;
if(count<this.icon_anim_start_count){
ret=false;}else {
ret=this.ctl.animation();}
return ret;}
}
return !SU_IS_4K;};
gadget.launchApl=function(locked_panel,report){
if(this._getAdMode()==false){
apputil.launch_apl(product_id);}else if(this._getAdMode()==true){
try{
if(!this.smad_clickable)return true;
sm_store_meta(this.sm_meta,this.pana_meta);
var args="-T -s -R -l "+"from_startup_ui"+
" -d "+"/usr/local/apps_nv/data/home/sm_ad_url";
var me=this;
this._networkCheckObj={};
var finished=function(){
return apputil.launch_apl("0070001200000001",args,locked_panel,report);};
wait_ip_available(function(mode){
if(mode==IP_AVAIL_STAT_NG||mode==IP_AVAIL_STAT_CANCEL){
return;}
judgeNetworkAvailable("net");
append_timer(me._networkCheckObj,1000,function(obj,cnt){
judgeNetworkAvailable("clock");
if(cnt>30){
delete_timer(obj);}else if(isNetworkAvailable()){
delete_timer(obj);
finished();}
});});
return apputil.CODE.WAIT_IP_AVAILABLE;}catch(e){
console.log(e.toSource());}
}
};
gadget.freeResource=function(bool){
if(this.ctl){
this.ctl.freeResource();}
if(this.icon){
gimageResource(this.icon,bool);}
if(this.back_img){
gimageResource(this.back_img,bool);}
};
gadget.voicePlay=function(){
if(system.locale.country=="JP")
VoicePlay("アプリマーケット");
else
VoicePlay("Apps Market");}
gadget.getStatus=function(){
return {"movable":false,"removable":false};};
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){
if(this.ctl){
this.ctl.visible_p=true;}
if(this.icon){
this.icon.visible_p=true;}
}else {
if(this.ctl){
this.ctl.visible_p=false;}
if(this.icon){
this.icon.visible_p=false;}
}
}
}else {
var gadget=new Gadget();
gadget.init=function(){
this._readyAdImage(false);

var title=system.locale.language.match(/^zh/)?"应用程序":"Apps";this.image=new gimage({translate:[0,0,0],width:412,height:232,
draw_type:FULL,src:png_path+"Gadget_apps.png"});
this.title=new gtext({translate:[0,-232/2+25,0],width:400,font_size:32,
text:title,align:CENTER,
color:[255,255,255,255]});
this.components.push(this.image,this.title);
this._ad_mode=false;
this._ad_hide=false;
this._ad_show=false;};
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 !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.image,bool);
gtextResource(this.title,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.image.visible_p=true;
this.title.visible_p=true;}else {
this.image.visible_p=false;
this.title.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;});}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._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;
