﻿//---------------------------------------------------------------------------------
//  (c) 2007 Guardian Networks, Inc
//---------------------------------------------------------------------------------


GNgui.GNMenuSubItem = Class.create();
GNgui.GNMenuSubItem.prototype = 
{
	initialize : function (id , containerid, Text)
	{
		if ( id == null ) {	alert('PleaseWait: id not specified' ); }	
		
		var DataTable = $e(id);
		var row = DataTable.insertRow ( DataTable.rows.length );
		row.id='ROW'+Text+id;

	  var Cell = row.insertCell ( 0 );
	  Cell.innerHTML = "<img src='./" + TARGET + "/images/topbar_drop_left.gif' border='0'>";
	  Cell.style.width = '8';
	  Cell.style.align = 'left';
	 
	  Cell = row.insertCell ( 1 );
	  Cell.innerHTML = "<span class='GNMenuSubItem' id='SMItem"+Text+id+"'>" + Text + "&nbsp;&nbsp;</span>"; 
      Cell.className = 'GNMenuSubItem';
Cell.style.width = '25px';
      
	  Cell = row.insertCell ( 2 );
	  Cell.innerHTML = "<img src='./" + TARGET + "/images/topbar_drop_right_noarrow.gif' border='0'>";
	  Cell.style.width = '14';
	  Cell.style.align = 'right';
    
    this.ScreenName = "";
    this.ContainerID = containerid;
    
     Event.observe ( $e('SMItem'+Text+id) , 'click' , GNgui.GNMenuSubItem.prototype.MouseClick.bindAsEventListener(this));
    //Event.observe ( this.newelement , 'mouseover' , GNgui.GNMenuSubItem.prototype.MouseOver.bindAsEventListener(this));    
    //Event.observe ( this.newelement , 'mouseout' ,  GNgui.GNMenuSubItem.prototype.MouseOut.bindAsEventListener(this));    
    //Event.observe ( this.newelement , 'mousedown' , GNgui.GNMenuSubItem.prototype.MouseDown.bindAsEventListener(this));
    //Event.observe ( this.newelement , 'mouseup' ,   GNgui.GNMenuSubItem.prototype.MouseUp.bindAsEventListener(this));
  },

	ID : function()
	{
		return this.newelement.id;
	},
	
	Show : function()
	{
		this.newelement.style.visibility = 'inherit';
	},
	
	Hide : function()
	{
		this.newelement.style.visibility = 'hidden';
	},
	
	MouseOver : function ( event )
	{
	  //this.newelement.className = "GNMenuSubItem GNMenuSubItemMouseOver";

	  Event.stop ( event );
	  return false;
	},
	
	MouseOut : function ( event )
	{
	  //this.newelement.className = "GNMenuSubItem";

	  Event.stop ( event );
	  return false;
	},
	
	MouseDown : function ( event )
	{
	  //this.newelement.className = "GNMenuSubItem GNMenuSubItemMouseDown";

	  Event.stop ( event );
	  return false;
	},
	
	MouseUp : function ( event )
	{
	  //this.newelement.className = "GNMenuSubItem GNMenuSubItemMouseOver";
  
    Event.stop ( event );
	  return false;
	},
	
	MouseClick : function ( event )
	{
      if ( this.ScreenName != "" )
      { 						        
				Gutenberg.PublishNow ( "ShowScreen",this.ScreenName );
				Gutenberg.PublishNow ( "AppendAccordionChild",this.ScreenName );
				currentScreenName = this.ScreenName;
        if ( Permissions.CheckDevicePermissions('Water Optimizer'))
				{
					if (WaterOptimizerGroups != null) 
					{
						WaterOptimizerGroups.CreateGroup();
					}
				}
			}
		  
		  $e(this.ContainerID).className = "GNMenuSubItemContainer NotVisible";
		  
		  Event.stop ( event );
		  return false;
	},
	
	AssociateScreen : function ( ScreenName )
	{
	  this.ScreenName = ScreenName;
	}
	
}