//High level functions that use the functions in layers.js
//to perform tasks specific to the puzzle.

//Gives a layer in the Layers array the top Z index.
function PickUp(layer)
         {
         var CurrentZ = GetZ(Layers[layer].id);
         SetZ(Layers.length - 1, Layers[layer].id);
         var currentZ;
         for(var index = 0; index < Layers.length; index++)
            {
            currentZ = GetZ(Layers[index].id);
            if(currentZ >= CurrentZ && index != layer)
              {
              SetZ(currentZ - 1, Layers[index].id);
              }
            }
         }
                                          
function Layer(layer, x, y, w, h)
         {
		 this.id = GetLayer(layer);
         SetW(w, this.id);
         SetH(h, this.id);
         Move(x, y, this.id);         
		 this.ClickedX = 0;
		 this.ClickedY = 0;
         this.Word = -1;
         this.Letter = -1;
         this.OverlappedWord = -1;
         this.OverlappedLetter = -1;
		 }
         
function Word()
         {
         this.x = 0;
         this.y = 0;
         this.Solved = false;
         //0 is horisontal, 1 is vertical.
         this.Direction = 0;
         this.Letters = new Array(arguments.length);
         for(var index = 0; index < arguments.length; index++)
		    {
			this.Letters[index] = arguments[index];
			}
         }
         
function Colors()
         {
         this.values = new Array(arguments.length);
         for(var index = 0; index < arguments.length; index++)
		    {
			this.values[index] = arguments[index];
			}
         this.index = 0;
         }
         
function NextColor(Colors) 
         {        
         if(Colors.index < Colors.values.length)
           {           
           document.bgColor = Colors.values[Colors.index];
           Colors.index++;
           }
         }
         
function Flicker(Colors)
         {
         eval('var length = ' + Colors + '.values.length;');
         eval('var index = ' + Colors + '.index;');
         if(index < length)
           {           
           eval('document.bgColor = ' + Colors + '.values[' + Colors + '.index];');
           eval(Colors + '.index++;');
           setTimeout('Flicker(\'' + Colors + '\');', 100);
           }
         else
           {
           eval(Colors + '.index = 0;');
           }
         }                                 
                                     
function ShowAll()
         {
         for(var layer = 0; layer < Layers.length; layer++)
            {                
            Show(Layers[layer].id);  
            }
         }         
                      
