
/* ================= Sections with progressive disclosure =================== */

function updateScrollbars()
{
  setTimeout(function()
    {
      var el = $('.scrollbar-fix-outer');
      if (el.length)
      {
        if (el.css("margin-bottom") == "0.75pt")
        {
          el.css("margin-bottom", "1.5pt");
        }
        else
        {
          el.css("margin-bottom", "0.75pt");
        }
      }
    },
    10
  );
}

function hideSection(sectionid)
{
  document.getElementById("Section"+sectionid).style.display = "none";
  document.getElementById("Link"+sectionid).href = "javascript:showSection("+sectionid+")";
  document.getElementById("NextLink"+sectionid).href = "javascript:showSection("+sectionid+")";
  document.getElementById("Pic"+sectionid).src = "detail_collapsed.png";
  $("#Pic"+sectionid).ifixpng(16, 16);
  updateScrollbars();
}

function showSection(sectionid)
{
  document.getElementById("Section"+sectionid).style.display = "block";
  document.getElementById("Link"+sectionid).href = "javascript:hideSection("+sectionid+")";
  document.getElementById("NextLink"+sectionid).href = "javascript:hideSection("+sectionid+")";
  document.getElementById("Pic"+sectionid).src = "detail_expanded.png";
  $("#Pic"+sectionid).ifixpng(16, 16);
  updateScrollbars();
}


/* ============================== Command links ============================= */

var 
  commandLinkImgDir='';

function getCommandLinkElement(childEl){
    if (childEl == null)
        return null;
    var nofMatches = $('.commandLink', childEl.parentElement).length;
    if (nofMatches> 0){
        return childEl;        
    }        
    else{
        return getCommandLinkElement(childEl.parentElement);
    }
}

function handleCommandLinkMouseEnter(el){
    id = el.id;
       
    aParent = getCommandLinkElement(el);
        
    var fadeInSpeed = 250;
    if (aParent)
        fadeInSpeed = aParent.LayerButton['hover'].fadeIn.speed;
    
    iconSrcHover = el.getAttribute('iconSrcHover');
    iconEl = document.getElementById(id + '.icon');
    iconContEl = document.getElementById(id + '.iconCont');
    iconContEl.filters(0).Duration = fadeInSpeed / 1000;
    iconContEl.filters(0).Apply();
    iconEl.filters(0).src = iconSrcHover;  
    iconContEl.filters(0).Play();
    currForeColor = el.currentStyle.color;    
    el.setAttribute('lastForeColor', currForeColor);
    $('.commandLinkTexts', el).animate({ color: '#2F4AE5'}, 250);
    
      
}

function handleCommandLinkMouseLeave(el){
    id = el.id;
    
    aParent = getCommandLinkElement(el);
    
    var fadeOutSpeed = 450;
    if (aParent)
        fadeOutSpeed = aParent.LayerButton['hover'].fadeOut.speed;
    
    iconSrcNormal = el.getAttribute('iconSrcNormal');  
    iconEl = document.getElementById(id + '.icon');
    iconContEl = document.getElementById(id + '.iconCont');
    iconContEl.filters(0).Duration = fadeOutSpeed / 1000;
    iconContEl.filters(0).Apply();
    iconEl.filters(0).src = iconSrcNormal;  
    iconContEl.filters(0).Play();
    lastForeColor = el.getAttribute('lastForeColor');
    $('.commandLinkTexts', el).animate({ color: lastForeColor}, 450);

}

function BodyLoaded()
{ 	    	    


  $('img').ifixpng(16, 16);

  //convert all <button> elements with css class ".commandLinkButton" into vista's command link style buttons (using LayerButton extension)
  $('.commandLinkButton').each(function(){

        id = $(this).attr('id');
        onclick = $(this).attr('onclick') +  '';
        if (onclick)
            onclick = onclick.replace("function anonymous()", "");
        else
            onclick = "";
   
        iconSrcNormal = $('img', this).attr('src');
        iconSrcHover  = $('img', this).attr('hoverSrc');
        
        if (!iconSrcNormal){
            iconSrcNormal = commandLinkImgDir+'command_link_normal.png';                      
            iconWidth  = '15pt';
            iconHeight = '15pt';
        }else{
          iconWidth   = $('img', this).get(0).offsetWidth + '-0.75pt';
          iconHeight  = $('img', this).get(0).offsetHeight + '-0.75pt';        
        }
        if (!iconSrcHover){
            iconSrcHover  = commandLinkImgDir + 'command_link_hover.png';
        }
        
        hintText = $(this).attr('title');        
        if (!hintText)
            hintText = '';
        
        html = '<a href="javascript:void(0);" class="commandLinkContent" tabindex="0" style="cursor:hand;" onclick= "ShowResult(\'' + $(this).attr('cmd') + '\');">'+
               '<table id="' + id + '" cellspacing="0" cellpadding="0"  style="width:auto;"'+
               '     iconSrcNormal="' + iconSrcNormal + '"'+
               '     iconSrcHover= "' + iconSrcHover  + '"'+
	           '     onmouseenter="handleCommandLinkMouseEnter(this);" '+
	           '     onmouseleave="handleCommandLinkMouseLeave(this);"> '+
	           '   <tr>'+
		       '     <td id="' + id + '.iconCont' + '"  class="image" valign="top" width="' + iconWidth + '" style="padding:3.75pt;  filter: progid:DXImageTransform.Microsoft.Fade(duration=0.450)">'+
		       '         <span class="commandLinkIcon" id="' + id + '.icon' + '" style="display:block; width:' + iconWidth + '; height:' + iconHeight + '; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true,sizingMethod=scale, src=\'' + iconSrcNormal + '\')"/>'+
		       '     </td>'+
		       '     <td valign="top" align="left" class="commandLinkTexts" style="padding-top:5.25pt; padding-bottom:2.25pt; padding-right:15pt;">'+
		       '         <div id="' + id + '.actionText' + '" class="commandLinkAction">' + $(this).text() + '</div>'+
               '         <div class="commandLinkHint"  >' + hintText       + '</div>'+
		       '     </td>'+
	           '   </tr>'+
	           '</table>'+
	           '</a>';
	    //alert(html);
        $(this).replaceWith(html);
        
    }
   );  

   $('.commandLinkContent').LayerButton(
    {
     'hover':
      {
        'imageSource':  { 'prefix': commandLinkImgDir + 'command_link_hover_', 'suffix': '.png' },
        'imageBorders': { 'top': 4, 'right': 4, 'bottom': 4, 'left': 4 },
        'fadeIn':       { 'speed': 250 },
        'fadeOut':      { 'speed': 450 }
      }
    }
  );  


};
