﻿// JScript File
function CMapGridItem (tmTopoliszMap)
{
	this.iLeft = 0;
	this.iTop  = 0;
	this.pMap = tmTopoliszMap;
	this.iWidth = this.pMap.GetMapGridItemWidth();
	this.iHeight = this.pMap.GetMapGridItemHeight();
	this.iIdxX = 0;
	this.iIdxY = 0;	
	this.iLevel = 0;
	this.strUrl = "";
	this.div = null;
	this.img = null;
	this.div = NewTag('div');
	this.div.className = "gridItem";
	this.div.style.left = this.iLeft + "px";
	this.div.style.top = this.iTop + "px";
	this.div.style.width = this.iWidth + "px";
	this.div.style.height = this.iHeight + "px";
	this.div.style.position = "absolute";
	this.visible = true;
	
	var me = this;
	
	this.SetPos = function(iPosY, iPosX)
	{
		me.div.style.left = (Math.floor(iPosX)) + "px";
		me.div.style.top = (Math.floor(iPosY)) + "px";
	}		
	
	this.GetImgId = function ()
	{
	    return me.pMap.divMap.id + "img" + me.iLevel + ";" + me.iIdxY + ";" + me.iIdxX;
	}		
	
	// új img elemet hoz létre
	// iIdxX,iIdxY : a csempek abszolut indexei
	this.Load = function (iLevel, iIdxY, iIdxX)
	{
	    var bNoImg = (me.img == null) ? true : false;
	    
    	me.iIdxX = iIdxX;
        me.iIdxY = iIdxY;
        me.iLevel = iLevel;
    
        if (bNoImg)
        {
            me.img = document.createElement ('img');                           
            me.img.className = "gridItem";      
            me.img.style.position = "absolute";      
        }
        
        me.div.style.display="none";        
        me.img.style.display="none";        
        
        me.img.onload = function ()
        {
            if (!me.visible)
            {
                if (me.div)
                    me.div.style.display="none";        
                if (me.img)
                    me.img.style.display="none";        
            }
            else
            {
                if (me.div)
                    me.div.style.display=""; 
                    
                if (me.img)       
                    me.img.style.display="";        
            }        
        }
                        
        me.img.setAttribute("id",me.GetImgId());     
                  
        if (bNoImg)
        {  
            me.div.appendChild (me.img);
        }
        
        var FileName = me.pMap.pGridMain.GetImageFileName (iIdxY, iIdxX);               
        SetImage(me.img, FileName, me.iWidth, me.iHeight, me.iDummy);
   	}	
	
	this.Show  = function ()
	{
	    me.visible = true;
	    if (me.div)	    
	        me.div.style.display="";
	    if (me.img)	    
	        me.img.style.display="";
	}
	
	this.Hide  = function ()
	{
	    me.visible = false;
	    if (me.div)
	        me.div.style.display="none";
	    if (me.img)	    
	        me.img.style.display="none";
	        
	}
	
	// törli a tartalmát a GridItemnek, s új képelemet hoz létre a 
	// megadott tartalommal
	this.Set = function (iLevel,iIdxY, iIdxX)
	{
		// me.RemoveImg ();
		me.Load(iLevel, iIdxY, iIdxX);    	
	}
	
	this.RemoveImg = function ()
	{
//		var imgblock = GetBlock (me.GetImgId());          
//		if (imgblock)     
//			imgblock.parentNode.removeChild (imgblock); 
//		delete imgblock;
//		imgblock = null;	
	}
}



