var myScroll;
;(function(){
	window.appdetail={
		mod:'',
		init:function(){
			this.mod=util.getUrlParam('module');
			document.addEventListener('DOMContentLoaded', appdetail.loaded, false);
			CONFIG.appid=util.getUrlParam('appid');
			appdetail.getdata();
			var url=$('#btnback').attr('href');
			$('#btnback').attr('href',url+this.mod);
		},
		getdata:function(){
			$.ajax({
                type: "GET",
                url: util.getapi(CONFIG.api+CONFIG.appid),
                dataType:'json',
                success: function(msg){
                    CONFIG.data=msg.data.result;
                    appdetail.layout();                
                }
            });
		},
		layout:function(){
			var app=CONFIG.data;
			$('a[node-type="applink"]').attr('href',app.downUrl);
			$('#applogo').attr('src',CONFIG.imghost+app.appIcon);
			$('#appname').text(app.appName);
			$('#appusers').text(app.downNum);
			$('#appsize').text(app.packageSize);
			$('#appdetail').text(app.info);
			var tpl=$('#scroller').html();
			var html='';
			for (var i = 0; i < app.picUrl.length; i++) {
				var item=app.picUrl[i];
				html+=util.sprintf(tpl,item);
			};
			$('#scroller').html(html).show();

			if(app.recommendList==''||app.recommendList==undefined || app.recommendList.length==0)
				return;
			var recommetarea=$('#recommendList');
			var tpl=recommetarea.html();
			var html='';
			for (var i = 0; i < app.recommendList.length; i++) {
				var item=app.recommendList[i];
				html+=util.sprintf(tpl,
					'?module=recomment&appid='+item.appId,
					CONFIG.imghost+item.appIcon,
					item.appName);
			};

			recommetarea.html(html).show();
			recommetarea.prev().show();
		},
		loaded:function(){
			myScroll = new iScroll('detailsTab', {
				snap: true,
				momentum: false,
				hScrollbar: false,
				onScrollEnd: function () {
					document.querySelector('#indicator > li.num_on').className = '';
					document.querySelector('#indicator > li:nth-child(' + (this.currPageX + 1) + ')').className = 'num_on';
				}
			});
		}
	};
})();