var table;
$(function() {
	initTable();
	$("#query_btn").click(function() {
		table.fnDraw();
	});
});

function initTable() {
	if (table == undefined) {
		table = $("#tableList").myDataTable({
					"sAjaxSource" : ctx + '/carousel/queryCarousels1',
					"paramSelector" : '#name',
					"iDisplayLength" : 10,
					"bSort" : false,
					"aoColumns" : [
							{
								"sTitle" : "序列",
								"bSortable" : true,
								sWidth : 100
							},
							{
								"sTitle" : "标题",
								sWidth : 150
							},
	                        {
	                        	"sTitle" : "预览",
                        		"fnRender" : function(obj){
                        			var id = obj.aData[6];
	                        		var img = obj.aData[2];
	                        		return "<a href='#' onmouseover='showPic(this,"+id+")' onmouseout='hiddenPic("+id+")'>查看</a>"
	                        		       +"<div id='Layer"+id+"' style='display:none;position:absolute;z-index:1;'><img width='190' height='280' src='"+res+"/upload/"+img+"'></div>";
	                        	}
	                        },
							{
								"sTitle" : "创建时间",
							},
							{
								"sTitle" : "更新时间",
							},
							{
								"sTitle" : "排序",
							},
							{
								"sTitle" : "操作",
								fnRender : function(obj) {
									var id = obj.aData[6];
									return "<a href='"+ctx+"/carousel/queryCarouselsById?id={0}'>编辑</a>&nbsp|&nbsp".format(id)
											+ "<a href='javascript:deletes({0})'>删除</a>".format(id);
								}
							} ]
				});
	} else {
		table.fnPageChange("first", true);
	}
}
function showPic(obj,id){
	var x=$(obj).offset.top;
	var y=$(obj).offset.left;
	document.getElementById("Layer"+id+"").style.left = x; 
	document.getElementById("Layer"+id+"").style.top = y; 
	document.getElementById("Layer"+id+"").style.display = "block"; 
	} 


function hiddenPic(id){ 
	document.getElementById("Layer"+id+"").style.display = "none"; 
	}

function deletes(id){
	
	if(confirm('确定删除吗？')){
	      window.location.href=ctx+'/carousel/deleteCarouselInfo?id='+id;
	 }
}

