/*
	File:         move-element.js
	Author:       Tero Laakso
	Date:         10.8.2008
	Modified:     10.8.2008

	Description:  This file contains functions for moving html element on the screen
	using 8 invisible mask divs.


*/

function moveComponent(componentId,stepX,stepY,minX,maxX,minY,maxY)
{
	var component     = document.getElementById(componentId);
	var moveBoolX = false;
	var moveBoolY = false;
	
	if( (stepX != 0) && ((component.offsetLeft+stepX) > minX) && ((component.offsetLeft+stepX) < maxX) )
	{		
		component.style.left = component.offsetLeft + stepX + 'px';
		moveBoolX = true;
	}
	
	if( (stepY != 0) && ((component.offsetTop+stepY) > minY) && ((component.offsetTop+stepY) < maxY) )
	{
		component.style.top = component.offsetTop + stepY + 'px';
		moveBoolY = true;
	}
	
	return [moveBoolX,moveBoolY];	
}


function moveElement(componentId,stepX,stepY,minX,maxX,minY,maxY,maskInt)
{
	var moveBool = false;
    
	if(	maskInt == 1 )
	{	
		moveBool = moveComponent(componentId,stepX,stepY,minX,maxX,minY,maxY);
		
		if(moveBool[0] == true)
      	{
        	moveComponent(componentId + '-mask-1',stepX,0,minX,maxX,minY,maxY);
        	moveComponent(componentId + '-mask-2',stepX,0,minX,maxX+gridWidth,minY,maxY);
         	moveComponent(componentId + '-mask-3',stepX,0,minX,maxX+gridWidth+gridWidth,minY,maxY);
         	moveComponent(componentId + '-mask-4',stepX,0,minX,maxX,minY,maxY+gridHeight);
			moveComponent(componentId + '-mask-6',stepX,0,minX,maxX+gridWidth+gridWidth,minY,maxY+gridHeight);
         	moveComponent(componentId + '-mask-7',stepX,0,minX,maxX+gridWidth,minY,maxY+gridHeight+gridHeight);
			moveComponent(componentId + '-mask-8',stepX,0,minX,maxX+gridWidth,minY,maxY+gridHeight+gridHeight);
			moveComponent(componentId + '-mask-9',stepX,0,minX,maxX+gridWidth+gridWidth,minY,maxY+gridHeight+gridHeight);
    	}
      	if(moveBool[1] == true)
      	{
        	moveComponent(componentId + '-mask-1',0,stepY,minX,maxX,minY,maxY);
        	moveComponent(componentId + '-mask-2',0,stepY,minX,maxX+gridWidth,minY,maxY+gridHeight);
        	moveComponent(componentId + '-mask-3',0,stepY,minX,maxX+gridWidth+gridWidth,minY,maxY+gridHeight+gridHeight);
          	moveComponent(componentId + '-mask-4',0,stepY,minX,maxX,minY,maxY+gridHeight);
			moveComponent(componentId + '-mask-6',0,stepY,minX,maxX+gridWidth+gridWidth,minY,maxY+gridHeight);
         	moveComponent(componentId + '-mask-7',0,stepY,minX,maxX,minY,maxY+gridHeight+gridHeight);
			moveComponent(componentId + '-mask-8',0,stepY,minX,maxX+gridWidth,minY,maxY+gridHeight+gridHeight);
			moveComponent(componentId + '-mask-9',0,stepY,minX,maxX+gridWidth+gridWidth,minY,maxY+gridHeight+gridHeight);
     	}
	}
	else if( maskInt == 2 )
	{
		moveBool = moveComponent(componentId,0,stepY,minX,maxX,minY,maxY);
              
     	if(moveBool[1] == true)
       	{
      		moveComponent(componentId + '-mask-1',0,stepY,minX,maxX,minY,maxY);
         	moveComponent(componentId + '-mask-2',0,stepY,minX,maxX+gridWidth,minY,maxY);
          	moveComponent(componentId + '-mask-3',0,stepY,minX,maxX+gridWidth+gridWidth,minY,maxY);
        	moveComponent(componentId + '-mask-4',0,stepY,minX,maxX,minY,maxY+gridHeight);
			moveComponent(componentId + '-mask-6',0,stepY,minX,maxX+gridWidth+gridWidth,minY,maxY+gridHeight);
         	moveComponent(componentId + '-mask-7',0,stepY,minX,maxX,minY,maxY+gridHeight+gridHeight);
			moveComponent(componentId + '-mask-8',0,stepY,minX,maxX+gridWidth,minY,maxY+gridHeight+gridHeight);
			moveComponent(componentId + '-mask-9',0,stepY,minX,maxX+gridWidth+gridWidth,minY,maxY+gridHeight+gridHeight);
    	}
	}
	else if( maskInt == 3 )
	{
		moveBool = moveComponent(componentId,-stepX,stepY,minX,maxX,minY,maxY);
    	
		if(moveBool[0] == true)
     	{
       		moveComponent(componentId + '-mask-1',-stepX,0,minX,maxX,minY,maxY);
         	moveComponent(componentId + '-mask-2',-stepX,0,minX,maxX+gridWidth,minY,maxY);
        	moveComponent(componentId + '-mask-3',-stepX,0,minX,maxX+gridWidth+gridWidth,minY,maxY);
        	moveComponent(componentId + '-mask-4',-stepX,0,minX,maxX,minY,maxY+gridHeight);
			moveComponent(componentId + '-mask-6',-stepX,0,minX,maxX+gridWidth+gridWidth,minY,maxY+gridHeight);
         	moveComponent(componentId + '-mask-7',-stepX,0,minX,maxX+gridWidth,minY,maxY+gridHeight+gridHeight);
			moveComponent(componentId + '-mask-8',-stepX,0,minX,maxX+gridWidth,minY,maxY+gridHeight+gridHeight);
			moveComponent(componentId + '-mask-9',-stepX,0,minX,maxX+gridWidth+gridWidth,minY,maxY+gridHeight+gridHeight);
      	}
                
    	if(moveBool[1] == true)
      	{
       		moveComponent(componentId + '-mask-1',0,stepY,minX,maxX,minY,maxY);
        	moveComponent(componentId + '-mask-2',0,stepY,minX,maxX+gridWidth,minY,maxY);
          	moveComponent(componentId + '-mask-3',0,stepY,minX,maxX+gridWidth+gridWidth,minY,maxY);
        	moveComponent(componentId + '-mask-4',0,stepY,minX,maxX,minY,maxY+gridHeight);
			moveComponent(componentId + '-mask-6',0,stepY,minX,maxX+gridWidth+gridWidth,minY,maxY+gridHeight);
         	moveComponent(componentId + '-mask-7',0,stepY,minX,maxX,minY,maxY+gridHeight+gridHeight);
			moveComponent(componentId + '-mask-8',0,stepY,minX,maxX+gridWidth,minY,maxY+gridHeight+gridHeight);
			moveComponent(componentId + '-mask-9',0,stepY,minX,maxX+gridWidth+gridWidth,minY,maxY+gridHeight+gridHeight);
     	}
	}
	else if( maskInt == 4 )
	{
		moveBool = moveComponent(componentId,stepX,0,minX,maxX,minY,maxY);
     	
		if(moveBool[0] == true)
     	{
      		moveComponent(componentId + '-mask-1',stepX,0,minX,maxX,minY,maxY);
        	moveComponent(componentId + '-mask-2',stepX,0,minX,maxX+gridWidth,minY,maxY);
        	moveComponent(componentId + '-mask-3',stepX,0,minX,maxX+gridWidth+gridWidth,minY,maxY);
         	moveComponent(componentId + '-mask-4',stepX,0,minX,maxX,minY,maxY+gridHeight);
			moveComponent(componentId + '-mask-6',stepX,0,minX,maxX+gridWidth+gridWidth,minY,maxY+gridHeight);
        	moveComponent(componentId + '-mask-7',stepX,0,minX,maxX+gridWidth,minY,maxY+gridHeight+gridHeight);
			moveComponent(componentId + '-mask-8',stepX,0,minX,maxX+gridWidth,minY,maxY+gridHeight+gridHeight);
			moveComponent(componentId + '-mask-9',stepX,0,minX,maxX+gridWidth+gridWidth,minY,maxY+gridHeight+gridHeight);
     	}	
	}
	else if( maskInt == 6 )
	{
		moveBool = moveComponent(componentId,-stepX,0,minX,maxX,minY,maxY);
     	
		if(moveBool[0] == true)
     	{
      		moveComponent(componentId + '-mask-1',-stepX,0,minX,maxX,minY,maxY);
        	moveComponent(componentId + '-mask-2',-stepX,0,minX,maxX+gridWidth,minY,maxY);
        	moveComponent(componentId + '-mask-3',-stepX,0,minX,maxX+gridWidth+gridWidth,minY,maxY);
         	moveComponent(componentId + '-mask-4',-stepX,0,minX,maxX,minY,maxY+gridHeight);
			moveComponent(componentId + '-mask-6',-stepX,0,minX,maxX+gridWidth+gridWidth,minY,maxY+gridHeight);
        	moveComponent(componentId + '-mask-7',-stepX,0,minX,maxX+gridWidth,minY,maxY+gridHeight+gridHeight);
			moveComponent(componentId + '-mask-8',-stepX,0,minX,maxX+gridWidth,minY,maxY+gridHeight+gridHeight);
			moveComponent(componentId + '-mask-9',-stepX,0,minX,maxX+gridWidth+gridWidth,minY,maxY+gridHeight+gridHeight);
     	}	
	}
	else if( maskInt == 7)
	{
		moveBool = moveComponent(componentId,stepX,-stepY,minX,maxX,minY,maxY);
                
		if(moveBool[0] == true)
      	{
        	moveComponent(componentId + '-mask-1',stepX,0,minX,maxX,minY,maxY);
         	moveComponent(componentId + '-mask-2',stepX,0,minX,maxX+gridWidth,minY,maxY);
         	moveComponent(componentId + '-mask-3',stepX,0,minX,maxX+gridWidth+gridWidth,minY,maxY);
         	moveComponent(componentId + '-mask-4',stepX,0,minX,maxX,minY,maxY+gridHeight);
			moveComponent(componentId + '-mask-6',stepX,0,minX,maxX+gridWidth+gridWidth,minY,maxY+gridHeight);
         	moveComponent(componentId + '-mask-7',stepX,0,minX,maxX+gridWidth,minY,maxY+gridHeight+gridHeight);
			moveComponent(componentId + '-mask-8',stepX,0,minX,maxX+gridWidth,minY,maxY+gridHeight+gridHeight);
			moveComponent(componentId + '-mask-9',stepX,0,minX,maxX+gridWidth+gridWidth,minY,maxY+gridHeight+gridHeight);
      	}
                
     	if(moveBool[1] == true)
      	{
       		moveComponent(componentId + '-mask-1',0,-stepY,minX,maxX,minY,maxY);
        	moveComponent(componentId + '-mask-2',0,-stepY,minX,maxX+gridWidth,minY,maxY);
        	moveComponent(componentId + '-mask-3',0,-stepY,minX,maxX+gridWidth+gridWidth,minY,maxY);
          	moveComponent(componentId + '-mask-4',0,-stepY,minX,maxX,minY,maxY+gridHeight);
			moveComponent(componentId + '-mask-6',0,-stepY,minX,maxX+gridWidth+gridWidth,minY,maxY+gridHeight);
        	moveComponent(componentId + '-mask-7',0,-stepY,minX,maxX,minY,maxY+gridHeight+gridHeight);
			moveComponent(componentId + '-mask-8',0,-stepY,minX,maxX+gridWidth,minY,maxY+gridHeight+gridHeight);
			moveComponent(componentId + '-mask-9',0,-stepY,minX,maxX+gridWidth+gridWidth,minY,maxY+gridHeight+gridHeight);
       	}
	}
	else if( maskInt == 8 )
	{
		moveBool = moveComponent(componentId,0,-stepY,minX,maxX,minY,maxY);
              
     	if(moveBool[1] == true)
       	{
      		moveComponent(componentId + '-mask-1',0,-stepY,minX,maxX,minY,maxY);
         	moveComponent(componentId + '-mask-2',0,-stepY,minX,maxX+gridWidth,minY,maxY);
          	moveComponent(componentId + '-mask-3',0,-stepY,minX,maxX+gridWidth+gridWidth,minY,maxY);
        	moveComponent(componentId + '-mask-4',0,-stepY,minX,maxX,minY,maxY+gridHeight);
			moveComponent(componentId + '-mask-6',0,-stepY,minX,maxX+gridWidth+gridWidth,minY,maxY+gridHeight);
         	moveComponent(componentId + '-mask-7',0,-stepY,minX,maxX,minY,maxY+gridHeight+gridHeight);
			moveComponent(componentId + '-mask-8',0,-stepY,minX,maxX+gridWidth,minY,maxY+gridHeight+gridHeight);
			moveComponent(componentId + '-mask-9',0,-stepY,minX,maxX+gridWidth+gridWidth,minY,maxY+gridHeight+gridHeight);
    	}
	}
	else if( maskInt == 9)
	{
		moveBool = moveComponent(componentId,-stepX,-stepY,minX,maxX,minY,maxY);
                
		if(moveBool[0] == true)
      	{
        	moveComponent(componentId + '-mask-1',-stepX,0,minX,maxX,minY,maxY);
         	moveComponent(componentId + '-mask-2',-stepX,0,minX,maxX+gridWidth,minY,maxY);
         	moveComponent(componentId + '-mask-3',-stepX,0,minX,maxX+gridWidth+gridWidth,minY,maxY);
         	moveComponent(componentId + '-mask-4',-stepX,0,minX,maxX,minY,maxY+gridHeight);
			moveComponent(componentId + '-mask-6',-stepX,0,minX,maxX+gridWidth+gridWidth,minY,maxY+gridHeight);
         	moveComponent(componentId + '-mask-7',-stepX,0,minX,maxX+gridWidth,minY,maxY+gridHeight+gridHeight);
			moveComponent(componentId + '-mask-8',-stepX,0,minX,maxX+gridWidth,minY,maxY+gridHeight+gridHeight);
			moveComponent(componentId + '-mask-9',-stepX,0,minX,maxX+gridWidth+gridWidth,minY,maxY+gridHeight+gridHeight);
      	}
                
     	if(moveBool[1] == true)
      	{
       		moveComponent(componentId + '-mask-1',0,-stepY,minX,maxX,minY,maxY);
        	moveComponent(componentId + '-mask-2',0,-stepY,minX,maxX+gridWidth,minY,maxY);
        	moveComponent(componentId + '-mask-3',0,-stepY,minX,maxX+gridWidth+gridWidth,minY,maxY);
          	moveComponent(componentId + '-mask-4',0,-stepY,minX,maxX,minY,maxY+gridHeight);
			moveComponent(componentId + '-mask-6',0,-stepY,minX,maxX+gridWidth+gridWidth,minY,maxY+gridHeight);
        	moveComponent(componentId + '-mask-7',0,-stepY,minX,maxX,minY,maxY+gridHeight+gridHeight);
			moveComponent(componentId + '-mask-8',0,-stepY,minX,maxX+gridWidth,minY,maxY+gridHeight+gridHeight);
			moveComponent(componentId + '-mask-9',0,-stepY,minX,maxX+gridWidth+gridWidth,minY,maxY+gridHeight+gridHeight);
       	}
	}	
}


