/**
 * 首页的遮罩层，及菜单的渲染
 */
function SystemClassIndexRender()
{
	_Me=this;
	this.Parent=null;
	this.Data=new Array();
	this.Formation=new Array();
	this.DivCreates=false;
	this.DataIndex=new Array();
	/**
	 * 渲染div的队列
	 */
	this.RenderDivs=new Array();
	this.NowMbDivId=null;
	this.NowMbDivMenuImgUrl=null;
	this.UpInterval=null;
	this.DownInterval=null;
	
	/**
	 * 执行动作
	 */
	this.Go=function(EventObj,ObjId,AreaObj,AreaId)
	{
		_Me.Parent.Debug(ObjId+"Go");
		var MbDiv=_Me.CreateDiv(EventObj,ObjId,AreaObj,AreaId);
		_Me.InitDataIndex();
		_Me.RenderDivContent(MbDiv,AreaId);
	}
	this.InitDataIndex=function()
	{
		_Me.DataIndex['HouseOrnamental_Div']=1;
		_Me.DataIndex['OfficeOrnamental_Div']=1;
		_Me.DataIndex['HotelOrnamental_Div']=1;
	}
	this.RenderDivContent=function(MbDiv,AreaId)
	{
			//取得数据
		    var NowData= _Me.PassData(7,_Me.DataIndex[AreaId],_Me.Data[AreaId],AreaId);

			var HTML= '<dl class="navdl"><dt><img src="'+ _Me.NowMbDivMenuImgUrl+ '" />';
			if (NowData!=null&&NowData!=false)
			{
				for (var i=0; i<NowData.length;i++)
				{
					HTML= HTML+"<dd style=\"cursor:pointer\" onclick=\"window.location='/Cases/piclist.php?Type="+ NowData[i].DictionalyTypeCode +"&Menu="+NowData[i].DictionalyValueCode+"'\">"+NowData[i].DictionalyValueName+"</dd>";
				}
				HTML= HTML+'<span class="spanleftp"><img id="'+AreaId+'_DownButton" src="/Resources/Cases/down.gif" style="cursor:pointer"  /></span><span><img id="'+AreaId+'_UpButton" src="/Resources/Cases/up.gif" style="cursor:pointer"  /></span>';
			}
			HTML = HTML+"</dt>";
			MbDiv.innerHTML=HTML;
			if ($("#"+AreaId+"_UpButton")[0])
			{
				$("#"+AreaId+"_UpButton")[0].onclick=function()
				{
					_Me.UpRows(5,_Me.DataIndex[AreaId],_Me.Data[AreaId],AreaId,MbDiv);
				}
			}
			if($("#"+AreaId+"_DownButton")[0])
			{
				$("#"+AreaId+"_DownButton")[0].onclick=function()
				{
					_Me.NextRows(5,_Me.DataIndex[AreaId],_Me.Data[AreaId],AreaId,MbDiv);
				}
			}
	}
	/**
	 * 下一条
	 */
	this.NextRows=function(Rows,Index,SourceData,AreaId,MbDiv)
	{
		var NextNum=_Me.DataIndex[AreaId]+1;
		var MaxNum=_Me.DataIndex[AreaId]+Rows;
		if (MaxNum>= SourceData.length-1)
		{
			return;
		}
		_Me.DataIndex[AreaId]=_Me.DataIndex[AreaId]+1;
		_Me.RenderDivContent(MbDiv,AreaId);
	}
	/**
	 * 上一条
	 */
	this.UpRows=function(Rows,Index,SourceData,AreaId,MbDiv)
	{
		var UpNum= _Me.DataIndex[AreaId]-1;
		if (UpNum==0)
		{
			return ;
		}
		_Me.DataIndex[AreaId]=_Me.DataIndex[AreaId]-1;
		_Me.RenderDivContent(MbDiv,AreaId);
	}
	/**
	 * 处理数据，构建javascript array 的模拟分页
	 */
	this.PassData=function(Rows,Index,SourceData,AreaId)
	{
		var Index=Index-1;
		var TempData=new Array();
		var Max= Index + Rows;
		var TempDataIndex=0;
		if (!SourceData)
		{
			return TempData;
		}
		for (var i=Index; i<Max; i++)
		{
			TempData[TempDataIndex]= SourceData[i];
			
			if (TempDataIndex== SourceData.length-1)
			{
				return TempData;
			}
			TempDataIndex++
		}
		return TempData;
	}
	/**
	 * 撤销动作
	 */
	this.Cancel=function(EventObj,ObjId,AreaObj,AreaId)
	{
		_Me.Parent.Debug(ObjId+"Cancel");
		_Me.DelDiv(EventObj,ObjId,AreaObj,AreaId);
	}
	/**
	 * 建立蒙板div
	 */
	this.CreateDiv=function(EventObj,ObjId,AreaObj,AreaId)
	{
		if (_Me.RenderDivs[AreaId] == false) {
			_Me.IninMbId(AreaId);
			_Me.Parent.Debug(EventObj + "创建层");
			_Me.CheckUnCloseDiv(EventObj, ObjId, AreaObj, AreaId);
			EventObj.innerHTML = '<div id="' + this.NowMbDivId + '" style=\"height:240px;\"></div>' + EventObj.innerHTML;
			this.ZoomDiv(this.NowMbDivId,"Up");
			Mdiv = $("#" + this.NowMbDivId)[0];
	/**
	 * 蒙罩层离开事件
	 */
			Mdiv.onmouseout = function(e)
			{
			  var e = e || event;
			   if (isMouseLeaveOrEnter(e,Mdiv))
			   {
			   		_Me.Parent.OnMenuMouseOut(EventObj, ObjId, AreaObj, AreaId);
			   } 
			}
			_Me.RenderDivs[AreaId]=true;
			return Mdiv;
		}
	}
	/**
	 * 缩放div
	 * @param {Object} DivIds
	 */
	this.ZoomDiv=function(DivIds,Action)
	{
		var Objs=$("#"+ DivIds)[0];
		if (!Objs)
		{
			return false;
		}
		if (Action=="")
		{
			Action="Up";
		}
		Start=240;
		End=380;
		if (Action=="Up")
		{
			if ( _Me.GetStyleHeight(Objs)!=End)
			{
				_Me.DoAction(Objs,End,"Up")
			}
		}
		if (Action=="Down")
		{
			if (_Me.GetStyleHeight(Objs)!=Start)
			{
				_Me.DoAction(Objs,Start,"Down")
			}
		}
	}
	this.GetStyleHeight=function(Obj)
	{
		var StyleString= Obj.style.height;
		var StyleString= StyleString. replaceAll("px","");
		return parseInt(StyleString);
	}
	this.DoAction=function(Objs,End,Action)
	{
		if (Action=="Up")
		{
			if (_Me.UpInterval!=null)
			{
				_Me.UpInterval=null;
				
			}
			window.setInterval(function(){
			if (_Me.GetStyleHeight(Objs)==380)
			{
						window.clearInterval(_Me.UpInterval);
						return false;
			}
			Objs.style.height= _Me.GetStyleHeight(Objs)+10+"px";
				},1)
		}
		if (Action=="Up")
		{
			if (_Me.DownInterval!=null)
			{
				_Me.DownInterval=null;
			}
		}
	}
	this.CheckUnCloseDiv=function(EventObj,ObjId,AreaObj,AreaId)
	{
		if ($("#mainbav")[0])
		{
			_Me.DelDiv(EventObj,ObjId,AreaObj,AreaId,"mainbav");
		}
		if ($("#mainbavc")[0])
		{
			_Me.DelDiv(EventObj,ObjId,AreaObj,AreaId,"mainbavc")
		}
		if ($("#mainbavr")[0])
		{
			_Me.DelDiv(EventObj,ObjId,AreaObj,AreaId,"mainbavr")
		}
	}
	this.CheckUnEvent=function(EventObj,ObjId,AreaObj,AreaId,Ids)
	{
		for(var i=0; i< _Me.Parent.Types.length; i++)
		{
			$("#"+_Me.Parent.Types[i]+"_Menu_Div")[0].onmouseover=null;
			_Me.Parent.SetMenuMouseOver($("#"+_Me.Parent.Types[i]+"_Menu_Div")[0],_Me.Parent.Types[i]+"_Menu_Div",$("#"+_Me.Parent.Types[i]+"_Div")[0],_Me.Parent.Types[i]+"_Div")
		}
	}
	this.SetDefDivCreates=function(AreaId)
	{
		this.RenderDivs[AreaId]=false;
	}
	this.IninMbId=function(AreaId)
	{
		this.RenderDivs[AreaId]=false;
		if (AreaId=="HouseOrnamental_Div")
		{
			this.NowMbDivId="mainbav";
			this.NowMbDivMenuImgUrl="/Resources/Cases/hometitle.gif";
		}
		if (AreaId=="OfficeOrnamental_Div")
		{
			this.NowMbDivId="mainbavc";
			this.NowMbDivMenuImgUrl="/Resources/Cases/officetitle.gif"
		}
		if (AreaId =="HotelOrnamental_Div")
		{
			this.NowMbDivId="mainbavr";
			this.NowMbDivMenuImgUrl="/Resources/Cases/hoteltitle.gif";
		}
	}
	this.DelDiv=function(EventObj,ObjId,AreaObj,AreaId,Ids)
	{
		if (Ids)
		{
			Elem.Del(Ids);
			_Me.CheckUnEvent(EventObj,ObjId,AreaObj,AreaId,Ids)
			return true;
		}
		_Me.Parent.Debug(EventObj+"删除层");
		Elem.Del(this.NowMbDivId);
		_Me.CheckUnEvent(EventObj,ObjId,AreaObj,AreaId,Ids)
	}
}
