
var Menu = {

  lastDiv:'',

  load: function()
  {
    this._expandables();
	this._contactList();		
  },
  
  
	

  _contactList: function()
  {
    //Li expandables
//		alert('joe');
//    $$('label[for~=ContactContact]').each(function(el){
		$('label[for^=ContactContact]').each(function(index){
			//alert('fred');							
			//alert(el.readAttribute('for'));						
			$(this).style.textDecoration = 'underline';																		
			Event.live($(this), "mouseover", function(e) { Event.stop(e); $(this).style.cursor='pointer'; });  
																					
			Event.live($(this), "click", function(e) { Event.stop(e); Menu.labelClick($(this)); return false;});  
    });
	},
  
	
  
  /**
   * Click label
   * 
   * @access public
   */
  labelClick: function(el)
  {
 
		//alert(el.readAttribute('for'));
		//alert(el.htmlFor);
		//forAttr =el.readAttribute('for'); // works with ff but not ie
		forAttr =el.htmlFor;
		userId = forAttr.substring(14);
//		alert('joe'+ userId);
//		window.location.href('/users/view/'+userId);
//		return false;
		if (Prototype.Browser.IE) {
			window.location.href('/users/view/'+userId);
			
		}else{
			window.location.replace('/users/view/'+userId);
			//window.location.hash('/users/view/'+userId);
			
		}
		
/*		
		if(window.location.href){
			alert('href');
			window.location.replace('/users/view/'+userId);
		}else{
			alert('else');
			window.location.hash('/users/view/'+userId);
		}
*/	
	},	
		
	
	
	
	
  _expandables: function()
  {	
    //input radio expandables
    $('input[rel~=radio_Other]').each(function(index){
      //Find target
      var target = $(this).attr('reltarget');
      if(target)
      {
        $(this).click( function(index) {
          //Menu.inputClick(el);

					$('#'+target).show();

        });  
      }
    });
		// and hide the other on Home
    $('input[rel~=radio_Home]').each(function(index){
      //Find target
      var target = $(this).attr('reltarget');
      if(target)
      {
        $(this).click( function(index) {
          //Menu.inputClick(el);

					$('#'+target).hide();

        });  
      }
    });



	},
	
	
	
	
  _expandablesOLD: function()
  {
    //Li expandables
    $('li[rel~=expandable]').each(function(index){
      //Find first link
      var link = this.select('a');
      Event.observe(link[0], "click", function(e) { Event.stop(e); Menu.liClick(el); });  
    });
    
    //Div expandables
    $('div[rel~=expandable]').each(function(el){
      //Find target
      var target = this.readAttribute('reltarget');
      var ident = this.readAttribute('relident');
																		
      if(target)
      {
        Event.observe(el, "click", function(e) {
					Event.stop(e);			//cpo I wanted to pass the click through to the adress form
          Menu.divClick(el);
          if(ident) { 
											//window.location.hash = "#"+ident;		//cpo adds to browser history
							///////				window.location.replace("#"+ident);		//cpo does not effect browser history so back buttin functions
										}
        });  
      }
    });
		
    //input radio expandables
    $$('input[rel~=radio_Other]').each(function(el){
      //Find target
      var target = el.readAttribute('reltarget');
      if(target)
      {
        Event.observe(el, "click", function(e) {
        //  Event.stop(e);			//cpo I wanted to pass the click through to the adress form
          Menu.inputClick(el);
        });  
      }
    });
		
		
		
		
		
		
		
  },
  
  /**
   * Click input
   *
   * @access public
   */
  inputClick: function(el)
  {
    var targetId = el.readAttribute('reltarget');
    var target = $(targetId);
    
    if(!target) { return; }
    
    var collapsed = 0;
    if(target.hasClassName('collapsed')) { collapsed = 1; }
    
    if(collapsed)
    {
      target.show();
      target.addClassName('selected');
      target.removeClassName('collapsed');
    }
		
  },
  
  /**
   * Click div
   *
   * @access public
   */
  divClick: function(el)
  {
    var targetId = el.readAttribute('reltarget');
    var target = $(targetId);
    
    if(!target) { return; }
    
    var collapsed = 0;
    if(target.hasClassName('collapsed')) { collapsed = 1; }
    
    if(this.lastDiv && this.lastDiv != targetId)
    {
      var lastDiv = $(this.lastDiv);
      lastDiv.addClassName('collapsed');
      lastDiv.removeClassName('selected');
      lastDiv.hide();
      this.lastDiv = '';
    }
    
    if(collapsed)
    {
      target.show();
      target.addClassName('selected');
      target.removeClassName('collapsed');
      this.lastDiv = targetId;
    }
    else
    {
      target.hide();
      target.addClassName('collapsed');
      target.removeClassName('selected');
      this.lastDiv = '';
    }
		
		
		// new for search channles/ services bar
		$$('.divsrchbar').each(function(obj) {
				 obj.src = "/img/menu_arrow_temp_closed.gif";
  	 });		
    if(collapsed){
		el.select('.divsrchbar').each(function(obj) {
	      obj.src = "/img/menu_arrow_temp_open.gif";
	    });		
		}else{
		el.select('.divsrchbar').each(function(obj) {
	      obj.src = "/img/menu_arrow_temp_closed.gif";
	    });		
			
			
		}
  },
  
  
  /**
   * Click LI
   * 
   * @access public
   */
  liClick: function(el)
  {
    this.liCollapseAll(el);
  
    var collapsed = 0;
    if(el.hasClassName('collapsed')) { collapsed = 1; }
    
    var sub = $(el).select('ul');
    	

    if(sub && sub[0])
    {
      if(collapsed)
      {
        //show
        sub[0].show();
        el.addClassName('selected');
        el.removeClassName('collapsed');
      }
      else
      {
        //hide
        sub[0].hide();
        el.addClassName('collapsed');
        el.removeClassName('selected');
      }
    }
  },
  
  
  /**
   * Collapse all LI's
   * 
   * @access public
   */
  liCollapseAll: function(main)
  {
    main.siblings().each(function(el){
      var rel = el.readAttribute('rel');
      
      if(rel && rel.indexOf('expandable') !== -1)
      {
        var sub = el.select('ul')
        if(sub && sub[0])
        {
          sub[0].hide();
          el.addClassName('collapsed');
          el.removeClassName('selected');
        }
      }
    });
  },
	
	
show: function(targetId){
//	alert('id'+targetId);
	var target = $(targetId);
//	alert(target);
	target.show();
	return false;
},
hide: function(targetId){
	var target = $(targetId);
	target.hide();
	return false;
	
}
	

}


$(document).ready(function()
{
	Menu.load();
}
);

