var utamalayanan=(function(){
	var datalayanan=[];
	var posisi=0;
	var jumlahbaris=0;
	return{
		init:function(a){
			datalayanan=a;
			jumlahbaris=Math.ceil(parseFloat(datalayanan.length)/3);
			
			var htmmain="";
			var posisidata=0;
			for(var i=0;i<jumlahbaris;i++){
				htmmain+="<div id='box_layanan_main_"+i+"' class='box_layanan_main_baris'>";
				for(var n=0;n<3;n++){
					if(posisidata<datalayanan.length){
						htmmain+="<div class='layanan_main_baris'>";
						htmmain+="<a href=\""+lokal+"layanan?id="+datalayanan[posisidata]['id']+"\">";
						htmmain+="<div class='layanan_main_baris_boxgb'><img src='"+lokal+datalayanan[posisidata]['foldergambar']+datalayanan[posisidata]['namagambar']+"' /></div>";
						
						htmmain+="<div class='layanan_main_boxisi_main'>";
						htmmain+="<div class='layanan_main_boxicon'><img src='"+lokal+datalayanan[posisidata]['foldericon']+datalayanan[posisidata]['namaicon']+"'/></div>";
						htmmain+="<div class='layanan_main_boxdata'>";
						htmmain+="<div class='layanan_main_boxdata_judul'>"+datalayanan[posisidata]['nama']+"</div>";
						htmmain+="<div class='layanan_main_boxdata_des'>"+datalayanan[posisidata]['sortdeskripsi']+"</div>";
						htmmain+="</div>";
						htmmain+="</a>";
						htmmain+="<div style='clear:both;'></div>";
						htmmain+="</div>";
						htmmain+="</div>";
						
					}
					posisidata++;
				}
				htmmain+="<div style='clear:both;'></div>";
				htmmain+="</div>";
			}
			htmmain+="<div style='clear:both;'></div>";
			$("#box_layanan_main").html(htmmain);
			
			$("#box_layanan_main_"+posisi).addClass('box_layanan_main_baris_show');
			
		},
		next:function(){
			if(posisi>=jumlahbaris) posisi=0;
			if(posisi<0) posisi=jumlahbaris-1;
			
			var posnext=posisi+1;
			if(posnext>=jumlahbaris) posnext=0;
			if(posnext<0) posnext=jumlahbaris-1;
			
			$("#box_layanan_main_"+posnext).show();
			$("#box_layanan_main_"+posisi).addClass('box_layanan_main_baris_hide');
			$("#box_layanan_main_"+posnext).removeClass('box_layanan_main_baris_rhide');
			$("#box_layanan_main_"+posnext).addClass('box_layanan_main_baris_show');
			
			var posantri=posnext+1;
			if(posantri>=jumlahbaris) posantri=0;
			if(posantri<0) posantri=jumlahbaris-1;
			
			console.log(posisi+" "+posnext+" "+posantri);
			document.getElementById("box_layanan_main_"+posantri).className="box_layanan_main_baris";
			posisi=posisi+1;
			
		},
		back:function(){
			if(posisi<0) posisi=jumlahbaris-1;
			if(posisi>=jumlahbaris) posisi=0;
			
			var posback=posisi-1;
			if(posback<0) posback=jumlahbaris-1;
			if(posback>=jumlahbaris) posback=0;
			
			$("#box_layanan_main_"+posback).show();
			$("#box_layanan_main_"+posback).removeClass('box_layanan_main_baris_hide');
			$("#box_layanan_main_"+posback).addClass('box_layanan_main_baris_show');
			$("#box_layanan_main_"+posisi).addClass('box_layanan_main_baris_rhide');
			
			var posantri=posback-1;
			if(posantri<0) posantri=jumlahbaris-1;
			if(posantri>=jumlahbaris) posantri=0;
			
			console.log(posisi+" "+posback+" "+posantri);
			document.getElementById("box_layanan_main_"+posantri).className="box_layanan_main_baris_r";
			
			posisi=posisi-1;
		},
	};
})();
