var product_id="0387878700000062";
var png_path=APPLI_PATH+product_id+"/gadget/";
var BACK_IMG=png_path+"apps_back_gradation.png";
var DEFAULT_IMG=png_path+"gadget_appMarket_noback.png";
var SALE_IMG=png_path+"sale_tag.png";
var NEW_IMG=png_path+"store_btn_new_icon.png";
var MARKET_IMG=png_path+"market_logo.png";
var SHOST=getHostName();
var HOST=getDefaultUrl("testurl").match(new RegExp("(http://[^/]*)/"))[1];
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.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="BACKGROUND";
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");}
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=10";}
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 {
var tmp_data=new Array();
for(var i=0;i<data.length;i++){
if(data[i].sale_type==0){
tmp_data.push(data[i]);}
}
if(self.data_list.length==0){
self.data_list=self.data_list.concat(tmp_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(tmp_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="BACKGROUND";}
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.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.anim_count=0;
if((SU_IS_4K==true)||(SU_IS_SLOW_ANIM==true)){
this.fade_anim_count=1;}else {
this.fade_anim_count=32;}
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();

var icon_p=new Object();
icon_p.width=309;
icon_p.height=174;
icon_p.translate=[90,-10,0];
icon_p.visible_p=true;
icon_p.draw_type=DIRECT;
icon_p.src=DEFAULT_IMG;
this.icon=new gimage(icon_p);
this.icon.color[3]=0;
this.components.push(this.icon);};
gadget.FadeObj.prototype._setDataMain=function(){
var self=this;
return function(data){
if((self.sub.getType()=="BACKGROUND")&&(data.type=="BACKGROUND")){
return;}
self.main.setData(data);}
};
gadget.FadeObj.prototype._setDataSub=function(){
var self=this;
return function(data){
if((self.main.getType()=="BACKGROUND")&&(data.type=="BACKGROUND")){
return;}
self.sub.setData(data);}
};
gadget.FadeObj.prototype.freeResource=function(bool){
this.image_a.freeResource(bool);
this.image_b.freeResource(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()=="BACKGROUND"){
this.icon.color[3]=255;}
}else {
this.main.setAlpha((alpha+this.anim_fade_step));
if(this.sub.getType()=="BACKGROUND"){
this.icon.color[3]=(alpha+this.anim_fade_step);}
}
var alpha=this.sub.getAlpha();
if((alpha-this.anim_fade_step)<=0){
this.sub.setAlpha(0);
if(this.main.getType()=="BACKGROUND"){
this.icon.color[3]=0;}
}else {
this.sub.setAlpha((alpha-this.anim_fade_step));
if(this.main.getType()=="BACKGROUND"){
this.icon.color[3]=(alpha-this.anim_fade_step);}
}
};
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);

var bg_p=new Object();
bg_p.width=412;
bg_p.height=232;
bg_p.translate=[0,0,0];
bg_p.visible_p=false;
bg_p.src=DEFAULT_IMG;
this.bg=new gimage(bg_p);
this.components.push(this.bg);};
gadget.Item.prototype.freeResource=function(bool){
gimageResource(this.image,bool);
gimageResource(this.sale,bool);
gimageResource(this.new_icon,bool);
gimageResource(this.bg,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 "BACKGROUND":
this.image.src="";
this.bg.visible_p=true;
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;
this.bg.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.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});

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.ctl=new gadget.Ctl({width:206,height:116});
this.components.push(this.back_img2,this.back_img,this.ctl,this.title_text);}
gadget.animation=function(count){
var ret;
if(count<this.icon_anim_start_count){
ret=false;}else {
ret=this.ctl.animation();}
return ret;};
gadget.launchApl=function(){
apputil.launch_apl(product_id,null);};
gadget.freeResource=function(bool){
if(this.ctl){
this.ctl.freeResource();}
gimageResource(this.back_img,bool);
gtextResource(this.title_text,bool);};
gadget.voicePlay=function(){
if(system.locale.country=="JP")
VoicePlay("アプリマーケット");
else
VoicePlay("Apps Market");}
return gadget;
