﻿//---------------------------------------------------------------------------------
//  (c) 2007 Guardian Networks, Inc
//---------------------------------------------------------------------------------


GNgui.GNMenuBar = Class.create();
GNgui.GNMenuBar.prototype = 
{
initialize : function ( left, top, id )
	{
		if ( left == null )	{ alert('PleaseWait: left not specified' );	}
		if ( top == null ) { alert('PleaseWait: top not specified' ); }
		if ( id == null ) {	alert('PleaseWait: id not specified' ); }	
    
    GNgui.GNMenuBar.prototype.CreateElement(left,top,id);
    GNgui.GNMenuBar.prototype.CreateLogo(id);

    Event.observe ( window , 'resize' , GNgui.GNMenuBar.prototype.ChangeWidth.bindAsEventListener(this));
   },
   
   CreateElement : function(left, top, id )
   {
		this.newelement = $ce('div');
		$ac(document.body,this.newelement);
		
		this.newelement.setAttribute('id',id);
		this.newelement.style.position = 'absolute';
		this.newelement.style.zindex = 50;
		
		this.LastPosition = 0;


		$el(id,left);
		$et(id,top);
		$ew(id,document.body.clientWidth);
		$eh(id,40);
		this.LeftPosition = $ew(id);
    this.newelement.className = "GNMenuBar";
   },
   
   CreateLogo : function ( id )
   {
    this.logo = $ce('img');
    $ac(id,this.logo);
    
    this.logo.setAttribute('id',id+'logo');
    this.logo.style.position = 'absolute';
    this.logo.menutype=-1;
    $el(id+'logo',0);
    $et(id+'logo',0);
	},
	
	ID : function()
	{
		return this.newelement.id;
	},
	
	Show : function()
	{
		this.newelement.style.visibility = 'inherit';
	},
	
	Hide : function()
	{
		this.newelement.style.visibility = 'hidden';
	
	},
	ChangeWidth : function ()
	{
	  var id = this.newelement.id;
	  $ew(id,document.body.clientWidth);
	  
	  this.LeftPosition = document.body.clientWidth;
	  		
	  		
	l=this.newelement.children.length;
    for ( var i = 0 ; i < l; i++ )
    {
      var element = this.newelement.children[i];
      if ( element.menutype == 1)
      {
		    $el(element.id,this.LeftPosition-$ew(element.id+"img")- 3);
		    this.LeftPosition = this.LeftPosition - $ew(element.id+"img") -3;
		    //this.LeftPosition = this.LeftPosition - $ew(element.id);
      }
    }
	},
	
	SetLogo : function ( fileName )
	{
    this.logo.src = fileName;
    this.LastPosition = $ew(this.logo.id) + 8
	},
	
	AddItem : function ( id , Text, Top, MouseOver )
	{
	  var e = new GNgui.GNMenuItem(id,Text,Top,MouseOver);
		$ac(this.ID(),e.newelement);
		$el(e.IMGID(),this.LastPosition);	
    e.PositionSubContainer();
		this.LastPosition = this.LastPosition + $ew(e.IMGID()) + 2;
		return e;
	},
	
	AddStaticItem : function (  id , Text, Top, MouseOver )
	{
	  var e = new GNgui.GNMenuItem(id,Text,Top, MouseOver);  
		e.newelement.style.zindex = 2;
		$ac(this.ID(),e.newelement);
		
		$el(e.ID(),this.LeftPosition - $ew( e.IMGID() ) - 13 );
		this.LeftPosition = this.LeftPosition - $ew( e.IMGID() ) -3;
		e.newelement.menutype=1;
		e.Selectable ( false );
		$remove(e.SubItemContainer);
		
		return e;
	}
	
}