#*
Copyright 2004 The Apache Software Foundation

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*#

#set($table = $jetspeed.columns)
#set($sizes = $jetspeed.columnSizes)

#set($myPage = $jetspeed.page)

#set($myFragment = $jetspeed.currentFragment)

#set($decorator = $myPage.getDefaultDecorator($myFragment.getType()))

#set($actions = $jetspeed.PageDecoratorActions)

  
 #if($myFragment.getDecorator())
        #set($decorator = $myFragment.getDecorator())
  #end

  #if ($decorator)
        #set($decoTop = "${decorator}/decorator-top.vm")
        #set($decoBottom = "${decorator}/decorator-bottom.vm")
  #end

<!-- Decorator  $decorator  ${decoTop} - ${decoBottom}-->


  #if (($decoTop) && ($myFragment == $myPage.getRootFragment()))
      #parse($jetspeed.getDecoration($decoTop, "layout").appRelativePath)
  #end

#set($layoutType =$portletConfig.getInitParameter("layoutType"))
#if($jetspeed.portletMode.toString() == "edit")
  #set($editing = true)    
  #set($lastColumn = $renderRequest.getAttribute("numberOfColumns") - 1)
#end    

#if ($actions.size()>0)
<table  width="100%" cellspacing="0" cellpadding="0" >
  <tr>
    <td class="PContent" style="font-size:1pt;" nowrap="true">&nbsp;</td>

    <td align="left" valign="middle" class="PContent" >
    </td>
    <td align="right" valign="middle" class="PContent" >
      <table border="0" cellpadding="0" cellspacing="0" >
      <tr>
      #foreach ($action in $actions)
      <td align="right" valign="middle" class="PContent" >
      <a href="${action.Action}" title="${action.Name}" ><img src="${action.Link}" alt="${action.Alt}" border="0"></a>
      <td/>
      #end
      </tr>
      </table>
    </td>

    <td class="PContent" style="font-size:1pt;" nowrap="true">&nbsp;</td>
  </tr>
</table>
#end

<div id="portal-layout-$htmlUtil.getSafeElementId($myPage.id)" class="portal-layout">
<table  width="100%" cellspacing="0" cellpadding="0" >
  <tr>
     #set ($sizeIndex = 0)
     #foreach($entry in $table)
        #if ($sizes)
          #if ($sizeIndex < $sizes.size())
             <td valign='top' width='$sizes.get($sizeIndex)'/>
          #else
	       <td valign="top">          
          #end
        #else
       <td  valign="top">
       #end
       #set ($sizeIndex = $sizeIndex + 1)     
       <table width="100%" class="portal-layout-column">
       #foreach($f in $entry)       
        <tr>
         <td width="100%">			
            #set($row = $f.getPropertyValue($layoutType, "row"))
            #set($col = $f.getPropertyValue($layoutType, "column"))
            #set($temp = 0) ##create temp Integer to parse strings
	        #set($row = $temp.parseInt($row))
            #set($col = $temp.parseInt($col))
            #if($editing)<div id="_$f.id">        
            <div style="position:relative; top:10px; left:0; width:100%; height:100%;">
              <div id="_$f.id_toolBox"  >
               <table cellpadding="0" cellspacing="0" >
                 <tr>
                   <td >
                   </td>
                   <td align="center" onMouseover="this.style.backgroundColor='red'" onMouseout="this.style.backgroundColor=''">
                        #if($row > 0)
                         #set($upUrl = $renderResponse.createRenderURL())    
                         $!upUrl.setParameter("moveBy","0,-1")
                         $!upUrl.setParameter("fragmentId","$f.id")
                         <a href="$upUrl"><img src="content/images/movePortletUp.gif" border="0" title="Move Portlet Up"/></a>
                       #end
                   </td>
                   <td>
                   </td>
                 </tr>
                 <tr>
                   <td align="right" onMouseover="this.style.backgroundColor='red'" onMouseout="this.style.backgroundColor=''">
                        #if($lastColumn > 0 && $col > 0)            
                         #set($leftUrl = $renderResponse.createRenderURL())    
                         $!leftUrl.setParameter("moveBy","-1,0")
                         $!leftUrl.setParameter("fragmentId","$f.id")    
                         <a href="$leftUrl"><img src="content/images/movePortletLeft.gif" border="0" title="Move Portlet Left"/></a>
                        #end
                   </td>
                   <td align="center" style="font-size:smaller; font-weight:bold" >
                      &nbsp;  Position &nbsp;
                   </td>
                   <td align="left" onMouseover="this.style.backgroundColor='red'" onMouseout="this.style.backgroundColor=''">
                        #if($lastColumn > 0 && $col < $lastColumn)
                         #set($rightUrl = $renderResponse.createRenderURL())    
                         $!rightUrl.setParameter("moveBy","1,0")
                         $!rightUrl.setParameter("fragmentId","$f.id")
                         <a href="$rightUrl"><img src="content/images/movePortletRight.gif" border="0" title="Move Portlet Right"/></a>
                        #end
                    </td>
                 </tr>
				 <tr>
					<td ></td>
					<td align="center" onMouseover="this.style.backgroundColor='red'" onMouseout="this.style.backgroundColor=''">
					  #set($lastRow = $renderRequest.getAttribute("lastRowForColumn").get($col))
					  #if($row < $lastRow)						
					    #set($downUrl = $renderResponse.createRenderURL())	
			            $!downUrl.setParameter("moveBy","0,1")
			            $!downUrl.setParameter("fragmentId","$f.id")
					    <a href="$downUrl"><img src="content/images/movePortletDown.gif" border="0" title="Move Portlet Down"/></a>
					  #end
					</td>
					<td ></td>
				 </tr>
			  </table>
			</div>
		 #end			
           ## get the decorated Portlet content
		  #if($f.type == "portlet")
   		    #parse($jetspeed.decorateAndInclude($f))
		  #else		
			$jetspeed.setCurrentFragment($f)
			$f.renderedContent			
		  #end
           
          ##$jetspeed.decorateAndInclude($f)

		  #if($editing)
		 </div>
		</div>
       #end		

      </td>
	 </tr>
	   #end

    </table>
   </td>
   #end
  </tr>
</table>
</div>

#if (($decoBottom ) && ($myFragment == $myPage.getRootFragment()))
   #parse($jetspeed.getDecoration($decoBottom, "layout").appRelativePath)
#end
