if(!Array.prototype.forEach){Array.prototype.forEach=function(fun){var len=this.length;if(typeof fun!="function")
throw new TypeError();var thisp=arguments[1];for(var i=0;i<len;i++){if(i in this)
fun.call(thisp,this[i],i,this);}};}
if(!StoreWidget||typeof(StoreWidget)=='undefined'){var StoreWidget=function(name,config){this._widgetName=name;this._config=config;this.render();}
StoreWidget.WIDGET_NUMBER=0;StoreWidget.WIDGET_STYLE_LOADED=false;StoreWidget.prototype={_widgetId:null,_widgetName:'',_config:null,_urlapi:'http://widget.365.co.th/',render:function(){this.loadStyle();this._widgetId="swidget_365_"+this._config.widgetid;document.write('<div id="'+this._widgetId+'" class="WG365Storebox" ></div>');var widget=document.getElementById(this._widgetId);this.renderStyle.call(this,widget);var div=document.createElement('div');div.className="innerWG365Storebox";div.innerHTML='Products loading ... ';widget.appendChild(div);var url=this._urlapi+'handler/storewidget.ashx';url+='?wid='+this._config.widgetid+'&pid='+this._config.partnerid+'&jsoncallback='+this._widgetName+'.aR';this.jsonp(url);},loadStyle:function(){if(!StoreWidget.WIDGET_STYLE_LOADED){StoreWidget.WIDGET_STYLE_LOADED=true;var b=document.createElement("link");b.href=this._urlapi+"core/stwgv1.css";b.rel="stylesheet";b.type="text/css";document.getElementsByTagName("head")[0].appendChild(b);}},renderStyle:function(b){b.style.bgColor=this._config.widgetstyle.backgroundColor;b.style.width=this._config.widgetstyle.width;b.style.height=this._config.widgetstyle.height;},jsonp:function(url,callback){var b=document.createElement("script");b.type="text/javascript";b.src=url;document.getElementsByTagName("head")[0].appendChild(b);},aR:function(jsonRespObj){if(jsonRespObj.length>0){var html=[];html.push("<ul  class=\"WG365productlist\" >");if(typeof(this._config.headerstyle)=='undefined')
html.push("<li class=\"Hfirst\"  >");else
html.push("<li class=\"Hfirst\"  style='background:"+this._config.headerstyle.backgroundColor+"' > ");html.push("<div id=\"h365\" >");html.push("<a href=\"http://www.365.co.th/\"><img title=\"365 Store Widget\" src=\""+this._urlapi+"core/images/365_store_grey.png\" alt=\"365 Store Widget\" ></a>");html.push("</div>");html.push("</li>");var size=(typeof(this._config.size)=='undefined')?null:this._config.size;var color=(typeof(this._config.widgetstyle.color)=='undefined')?"#000000":this._config.widgetstyle.color;jsonRespObj.forEach(function(e,i,array){switch(size){case"small":html.push("<li class=\"Item\" ><div class=\"Item-Small-Box\" >");html.push("<div class=\"Item-Small-Box-Left\" >");html.push("<a href=\""+e.ProductUrl+"\" title=\""+e.Description+"\" ><img src=\""+e.ImageUrl+"\"   alt=\""+e.Description+"\"  style=\"border:0;\"  /></a>");html.push("</div>");html.push("<div class=\"Item-Small-Box-Right\" >  <a href=\""+e.ProductUrl+"\" title=\""+e.Description+"\"  style=\"color:"+color+";\" >"+e.Name+"</a> </div> ");html.push("<div style=\"clear:both;\" ></div>");html.push("</div></a></li>");break;case"middle":html.push("<li class=\"Item\" ><a href=\""+e.ProductUrl+"\" title=\""+e.Description+"\" ><img src=\""+e.ImageUrl+"\"   alt=\""+e.Description+"\"  style=\"border:0;width:140px;height:auto;\"  /></a></li>");break;default:html.push("<li class=\"Item\" ><a href=\""+e.ProductUrl+"\" title=\""+e.Description+"\" ><img src=\""+e.ImageUrl+"\"   alt=\""+e.Description+"\"  style=\"border:0;\"  /></a></li>");break;}});html.push("</ul><br style=\"clear:both;\" >");document.getElementById(this._widgetId).firstChild.innerHTML=html.join("");}}};}
