list ActionChoices = ["Stay Off", "Stay On", "Automatic"];
 string msg = "\nGlow controller \nPlease select an option:";
 
 key TouchedByKey;           
 integer channel_dialog;     
 integer listen_id;          
 
                                 
 
 float glow = 0.7;                       
 vector color_off = <1.00,1.00,1.00>;    
 vector color_on = <1.0,0.7,0.5>;        

 
 float alpha_on = 1.0; 
 float alpha_off = 1.0; 
 
 
 
 integer texture_change = 0;             
 
 
 
 
 
 string texture_on = "00000000-0000-2222-3333-100000001035";
 string texture_off = "00000000-0000-2222-3333-100000001035";               
 
 
 
 
 turn_on()
 {
            
            llSetLinkPrimitiveParams
            (LINK_SET,[
            PRIM_COLOR, ALL_SIDES, color_on , alpha_on,
            PRIM_FULLBRIGHT,ALL_SIDES,TRUE,PRIM_POINT_LIGHT,TRUE,<1,0.7,0.5>,2.0,20.0,0.00,
            PRIM_GLOW, ALL_SIDES, glow
            ]);
 
            
            if (texture_change)
            {
                llSetTexture(texture_on, 1);
            }
 }
  
 
  
 
 turn_off()
 {
            
            llSetLinkPrimitiveParams
            (LINK_SET,[
             PRIM_COLOR, ALL_SIDES, color_off , alpha_off,
            PRIM_FULLBRIGHT,ALL_SIDES,FALSE,PRIM_POINT_LIGHT,FALSE,<1,0.7,0.5>,2.0,20.0,0.00,
            PRIM_GLOW, ALL_SIDES, 0.0
            ]);
 
            
            if (texture_change)
            {
                llSetTexture(texture_off, 1);
            }
 }

 

 
 default
 {
    state_entry()
    {
        
        channel_dialog = ( -1 * (integer)("0x"+llGetSubString((string)llGetKey(),-5,-1)) );
       
        
        llSetTimerEvent(0);
    }
 
 

    
    touch_start(integer num_detected)
    {
            TouchedByKey = llDetectedKey(0);
            if ( TouchedByKey == llGetOwner() )
            {
                
                llDialog(TouchedByKey, msg, ActionChoices, channel_dialog);
                
                listen_id = llListen( channel_dialog, "", TouchedByKey, "");
            }
            else
            {
                
              
            }
    }
 
 
 
    
    listen(integer channel, string name, key id, string choice)
    {
        if (choice == "Stay Off")
        {
            
            llSetTimerEvent(0);
  
            
            turn_off();
           
            
            llListenRemove(listen_id);
        }
        else if (choice == "Stay On")
        {
            
            llSetTimerEvent(0);
  
            
            turn_on();
           
            
            llListenRemove(listen_id);
        }
        else if (choice == "Automatic")
        {
            
            llSetTimerEvent(1);
  
            
           
            
            llListenRemove(listen_id);
        }
  
    }

 

   
   on_rez(integer num)
    {
        list TimeStamp = llParseString2List(llGetTimestamp(),["-",":"],["T"]); 
        integer Hour = llList2Integer(TimeStamp,4);
        if(Hour<=6)        
            turn_on();

                
        else if(Hour>=17)
           turn_on();
 
        else
            turn_off();
 
 }
   
   
   timer()
   {
       float ts = osGetApparentTime();
       if (ts > 3600 * 6  && ts < 3600 * 17)
       {
           // Day
          turn_off();
       }
       else 
       {
           //Night
           turn_on();
       }
       
       llSetTimerEvent(60);
   }
 

 }