// JavaScript Document
var global = {
  isJaxing : false,
  activeLink : {
    keyLinks : '',
    headerLinks : ''
  },
  params : {contentTitle:'', fileName:'', linkId:0, parentId:0},
  linkHierarchy : [],
  activeLinkId : 0,
  jScript : '',
  
  jx : {
    content : '',
    subLinks : ''
  },
  
  port : {
    content : '',
    subLinks : '',
    subLinksTR : '',
    linkHierarchy : ''
  },
  
  load : {
    script : function(td, _contentTitle, _fileName, _linkId, _parentId){
      with(global){
        if(activeLink.keyLinks)misc.removeClass(activeLink.keyLinks);
        td.className = 'hover';
        activeLink.keyLinks = td;
        port.subLinksTR.style.display = 'none';
        params = {contentTitle:_contentTitle, fileName:_fileName, linkId:_linkId, parentId:_parentId};
        
        if(jScript)jScript.Unload();
        
        jScript = new JScript();
        jScript.Load('scripts/'+ _fileName +'.js');
      };
    }
  },
  
  setLinkHierarchy : function(obj){
    var str = '', separator = '';
    with(global){
      for(var i=0, l=linkHierarchy.length; i<l; i++){
        if(linkHierarchy[i].parentId == obj.parentId){
          if(linkHierarchy[i])linkHierarchy.splice(i, linkHierarchy.length);
          break;
        };
      };
      
      if(obj)linkHierarchy.push(obj);
      
      linkHierarchy.Each(function(lnk, i){
        str += separator +'<span style="cursor:pointer" onmouseover="this.style.textDecoration=\'underline\'" onmouseout="this.style.textDecoration=\'none\'" onclick="global.linkHierarchy['+i+'].onAfterClick()">'+lnk.contentTitle+'</span>';
        separator = ' &#8250; ';
      });
      
      port.linkHierarchy.innerHTML = str;
    }    
  },
  
  subLinkEffect : {
    onmouseover : function(){
      var tr = this;
      if(!tr.cells[1])return false;
      
      tr.className = "subLinkHover";
      
      var alpha = 20;
      
      with(tr.cells[1].style){
        filter = 'progid:DXImageTransform.Microsoft.alpha(opacity=\''+ alpha +'\')';
        opacity = alpha/100;
      };
      
      var timer = setInterval(function(){
        /*if(!tr.cells[1].style){
          clearInterval(timer);
          return;
        };*/
        if(!tr.cells[1])return;
        with(tr.cells[1].style){
          filter = 'progid:DXImageTransform.Microsoft.alpha(opacity=\''+ alpha +'\')';
          opacity = alpha/100;
          alpha+=10;
          if(alpha>100)clearInterval(timer);
        };
      }, 50);
    },
    
    onmouseout : function(){
      var tr = this;
      
      tr.className = 'sublinkTitle';
    }
  },
  
  collapsibles : function(){
    var els = [];
    var tds = document.getElementsByTagName("TD");
    for(var i=0, l=tds.length; i<l; i++){
      if(tds[i].className=="collapsible"){
        var _td1 = tds[i];
        var tr = _td1.parentNode;
        var _td2 = tr.parentNode.rows[tr.rowIndex+1].cells[0];
        
        els.push({td1:_td1,td2:_td2});
      };
    };
    
    els.Each(function(obj, i){
      var div = new Div();
      with(div){
        //style.display = 'none';
        innerHTML = obj.td2.innerHTML;
      };
      
      var tbl = new Table(1,2);
        with(tbl){
          with(rows[0]){
          with(cells[0]){
            width = 25;
            align = "center";
		    className = 'cursorHand';
          };
          
          cells[0].onclick = function(){
            if(div.style.display){
              div.removeAttribute('style');
              animation.SlideDown(div, div.offsetHeight, 6, function(){
                div.removeAttribute('style');
				with(tbl.rows[0].cells[0]){
					className = 'cursorHand';
				};
              }
			  );
            }else{
              animation.SlideUp(div, 1, 10, function(){
                div.style.display = 'none';
				with(tbl.rows[0].cells[0]){
					className = 'cursorHand2';
				};
				
              });
            }
          };
          
          with(cells[1]){
            style.cursor = 'default';
            innerHTML = obj.td1.innerHTML;
          };
        };
      };
      
      with(obj.td1){
        innerHTML = '';
        appendChild(tbl);
      };
      
      with(obj.td2){
        innerHTML = '';
        appendChild(div);
      };
    });
  }
};

window.onload = function(){
  with(global.port){
    content = $('contentArea');
    subLinks = $('subLinksArea');
    subLinksTR = $('subLinksTr');
    linkHierarchy = $('linkHierarchyArea');
  };
  
  var i=0, el=$('_key_link_'+i);
  while(el){
    /*el.onmouseover = function(){
      this.style.backgroundImage = 'url(images/gifs/btn_bw_mouseover_bg.gif?t='+ new Date().getTime() +')';
      this.style.color = "#f0f0f0";
    };
    
    el.onmouseout = function(){
      this.removeAttribute('style');
      //this.style.background = 'transparent url(images/gifs/buttonBg.gif)';
    };
    
    //global.keyLinks.push(el);*/
    el.onmouseover = function(){
      if(global.activeLink.keyLinks==this)return;
      this.className = 'hover';
    };
    
    el.onmouseout = function(){
      if(global.activeLink.keyLinks==this)return;
      misc.removeClass(this);
    };
    
    i++;
    el = $('_key_link_'+i);
  };
  
  $('_key_link_0').onclick();
  misc.noTextSelection();
};