unit jukeboxform;
//   Copyright (C) 2012 Matthew Smith

//    This program is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.

//    This program is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.

//    You should have received a copy of the GNU General Public License
//    along with this program.  If not, see <http://www.gnu.org/licenses/>.


{$DEFINE tv}
interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,

  ExtCtrls, loadjpegorbmp,main, StdCtrls, Buttons, ImgList,windowsversion,
  ScrollListbox, textscroller, bitmapcheckbox, bitmapactionbutton,
  SelecterListBox, Mask, picturescroller, TransparentPanel, ScktComp,Loadalbumcovers,
  isconnected,global,searchtrack,shellapi,AddTrackToSystem,transhint,playlist,
  debugandprofile,volume,Talphabetbar,resourceskins,Shutdownwindows,thememanagerform,
  NumericInput,creditssystem,logfile,glJuke,glUi,glUtils;


type
  Tjukebox = class(TCustomForm)
    leftpanel: TPanel;
    leftpanelpic: TImage;
    rightpanel: TPanel;
    rightpanelpic: TImage;
    errortimer: TTimer;
    fadetimer : TTimer;
    playstimer: TTimer;
    butpanel: TPanel;
    butllabel: TLabel;
    butrlabel: TLabel;
    keypadpanel: TPanel;
    BackgroundTimer : TTimer;
    num1: TImage;
    num2: TImage;
    num3: TImage;
    num4: TImage;
    num5: TImage;
    num6: TImage;
    num7: TImage;
    num8: TImage;
    num9: TImage;
    num10: TImage;
    num11: TImage;
    num12: TImage;
    numlabel1: TLabel;
    numlabel2: TLabel;
    numlabel3: TLabel;
    numlabel4: TLabel;
    numlabel5: TLabel;
    numlabel6: TLabel;
    numlabel7: TLabel;
    numlabel8: TLabel;
    numlabel9: TLabel;
    numlabel10: TLabel;
    numlabel11: TLabel;
    numlabel12: TLabel;
    butl: TImage;
    butr: TImage;
    blshape1: TShape;
    brshape1: TShape;
    blshape2: TShape;
    brshape2: TShape;
    lcdpanel: TPanel;
    lcd1: TPanel;
    lcdtext1: TLabel;
    lcd2: TPanel;
    lcdtext2: TLabel;
    lcdlabel1: TLabel;
    lcdlabel2: TLabel;
    midpanelpanel: TPanel;
    toppanel: TPanel;
    lb1: TImage;
    cd1: TImage;
    topoverpanel: TPanel;
    lb7: TImage;
    cd7: TImage;
    botpanel: TPanel;
    lb2: TImage;
    cd2: TImage;
    botoverpanel: TPanel;
    lb8: TImage;
    cd8: TImage;
    botrightpanel: TPanel;
    lb4: TImage;
    cd4: TImage;
    toprightpanel: TPanel;
    lb3: TImage;
    cd3: TImage;
    midpanel: TImage;
    panel: TPanel;
    panelshape2: TShape;
    panelshape1: TShape;
    volumeup: TImage;
    volumedown: TImage;
    rejectshape1: TShape;
    rejectshape2: TShape;
    muteshape1: TShape;
    volumeupshape1: TShape;
    muteshape2: TShape;
    volumedownshape1: TShape;
    volumeupshape2: TShape;
    volumedownshape2: TShape;
    volumelabel: TLabel;
    rejectlabel: TLabel;
    mutelabel: TLabel;
    volumeuplabel: TLabel;
    volumedownlabel: TLabel;
    mute: TImage;
    reject: TImage;
    openpanelpanel: TPanel;
    openpanel: TImage;
    VisualsPanelPanel: TPanel;
    VisualsPanel : TImage;
    lightstimer: TTimer;
    lsb1: TScrollListbox;
    lsb2: TScrollListbox;
    lsb3: TScrollListbox;
    lsb4: TScrollListbox;
    lsb7: TScrollListbox;
    lsb8: TScrollListbox;
    lsb8playall: TStaticText;
    lsb2playall: TStaticText;
    lsb4playall: TStaticText;
    lsb7playall: TStaticText;
    lsb3playall: TStaticText;
    lsb1playall: TStaticText;
    kioskpanelpanel: TPanel;
    kioskpanel: TImage;
    panel_kiosk: TPanel;
    panel_kioskshape2: TShape;
    panel_kioskshape1: TShape;
    toprightunderpanel: TPanel;
    cd5: TImage;
    botrightunderpanel: TPanel;
    cd6: TImage;
    lcd3: TTextScroller;
    autoplaycb: TBitmapCheckbox;
    randombut: TBitmapActionButton;
    rejectall: TBitmapActionButton;
    ripbut: TBitmapActionButton;
    advancedbut: TBitmapActionButton;
    //gothumb: TImage;
    CreditInfoPanel : TPanel;
    CreditLabel : TLabel;
    CreditStat : TLabel;
    navbuttimer: TTimer;
    thumbpanel: TTransparentPanel;
    thumbs: TPictureScroller;
    advanced: TTransparentPanel;
    Commerce : TTransparentPanel;
    codepanel: TPanel;
    codefirst: TLabel;
    unlocklabel: TLabel;
    setcode: TBitmapActionButton;
    code: TEdit;
    editpanel: TPanel;
    editlabel: TLabel;
    editlb: TScrollListbox;
    randompanel: TTransparentPanel;
    randompanellb: TSelecterListBox;
    randompanelshape2: TShape;
    randompanelshape1: TShape;
    randomdicepanel: TTransparentPanel;
    randomdice: TImage;
    randompanelselectall: TBitmapActionButton;
    randompanelselectnone: TBitmapActionButton;
    randomcountlabel: TLabel;
    randompanelcancel: TBitmapActionButton;
    RandomCancel: TBitmapActionButton;
    randompanelOK: TBitmapActionButton;
    optionspanel: TPanel;
    addallshow: TBitmapCheckbox;
    Shutdownbut: TBitmapActionButton;
    numlabel13: TLabel;
    num13: TImage;
    butpanelpic: TImage;
    //irsocket: TClientSocket;
    jbinfogo: TBitmapActionButton;
    NoRepeatCb: TBitmapCheckbox;
    loadcovercaption: TPanel;
    volumetimer: TTimer;
    panel_searchbut: TPanel;
    panel_searchbut_image: TImage;
    volumeshow: TBitmapCheckbox;
    advancedOK: TBitmapActionButton;
    CommerceOK : TBitmapActionButton;
    CmTitleLab : TLabel;
    CmCreditPanelLab : TLabel;
    CmBackgroundPanelLab : TLabel;
    CmStatisticsPanelLab : TLabel;
    CmCreditPanel : TPanel;
    CmPlaysPerCredit : TNumericInput;
    CmAllowFreeCredit : TBitmapCheckbox;
    CmPlaysPerCreditLab : TLabel;
    CmBackgroundPanel : TPanel;
    CmBgDuration : TNumericInput;
    CmBgDurationLab : TLabel;
    CmBgVolume : TNumericInput;
    CmBgVolumeLab : TLabel;
    CmBgWaitTime : TNumericInput;
    CmBgWaitTimeLab : TLabel;
    CmStatisticsPanel : TPanel;
    CmResetCreditStats : TBitmapActionButton;
    CmCreditLab : TLabel;
    CmCredit : TLabel;
    Cmtop100Lab : TLabel;
    CmTop100 : TScrollListbox;
    fav: TBitmapActionButton;
    goplaylistview: TBitmapActionButton;
    coverimagepanel: TPanel;
    coverimage: TImage;
    GoThemeManager: TBitmapActionButton;
    GoCommercialManager : TBitmapActionButton;
    CenterPanel : TPanel;
    CenterPanel_Image : TImage;
    credit : TCredits;

    //3D Stuff
    imViewMode : TImage;
    ThreeDPanel : TGLPanel;


    procedure panel_searchbut_imageClick(Sender: TObject);



    procedure FormKeydown(Sender: TObject; var Key: Word;
          Shift: TShiftState);
   procedure movealbumlr;
   procedure movealbumrl;
   procedure movealbuml3D;
   procedure movealbumr3D;

   procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure errortimerTimer(Sender: TObject);
    procedure BackGroundTimerTimer(Sender: TObject);
    procedure dofade;
    procedure FadeTimerTimer(Sender: TObject);
    procedure playstimerTimer(Sender: TObject);
    procedure butllabelClick(Sender: TObject);
    procedure butrlabelClick(Sender: TObject);
    procedure butllabelMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure butllabelMouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure butrlabelMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure butrlabelMouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure numClick(Sender: TObject);
    procedure OnMessage(var Msg: TMsg; var Handled: Boolean);
    procedure FormCreate(Sender: TObject);
    procedure panelshapeMouseDown(Sender: TObject;
      Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    procedure panelshapeMouseUp(Sender: TObject;
      Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    procedure setscreen;
    procedure FormPaint(Sender: TObject);
    procedure rightpanelpicMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure lsbClick(Sender: TObject);
    procedure openpanelMouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure openpanelClick(Sender: TObject);
    procedure VisualsPanelClick(Sender: TObject);
    procedure setvisualspanel(o : boolean);
    procedure lightstimerTimer(Sender: TObject);
    procedure kioskpanelClick(Sender: TObject);
    procedure domessage(text : string);
    procedure autoplaycbClick(Sender: TObject);
    procedure randombutClick(Sender: TObject);
    procedure randompanelcancelClick(Sender: TObject);
    procedure randompanellbClick(Sender: TObject);
    procedure randompanelOKClick(Sender: TObject);
    function cb(c : integer) : boolean;
    procedure randompanelselectallClick(Sender: TObject);
    procedure randompanelselectnoneClick(Sender: TObject);
    procedure RandomCancelClick(Sender: TObject);
    procedure rejectallClick(Sender: TObject);
    procedure lsb1playallClick(Sender: TObject);
    procedure lsb2playallClick(Sender: TObject);
    procedure cdClick(Sender: TObject);
    procedure cdMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
    procedure advancedbutClick(Sender: TObject);
    procedure advancedOKClick(Sender: TObject);
    procedure commerceOKClick(Sender: TObject);
    procedure cmResetCreditStatsClick(Sender: TObject);
    procedure codeEnter(Sender: TObject);
    procedure codeExit(Sender: TObject);
    procedure setcodeClick(Sender: TObject);
    procedure codeKeyPress(Sender: TObject; var Key: Char);
    procedure codeClick(Sender: TObject);
    procedure codefirstClick(Sender: TObject);
    //procedure gothumb;
    procedure thumbsClick(Sender: TObject);
    procedure navbuttimerTimer(Sender: TObject);
    procedure FormKeyUp(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure editlbClick(Sender: TObject);
    procedure volumeshowClick(Sender: TObject);
    procedure addallshowClick(Sender: TObject);
    procedure ShutdownbutClick(Sender: TObject);
    procedure keypadpanelMouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure FormResize(Sender: TObject);
    procedure lsb1Reachedend;
    procedure lsb2Reachedtop;
    procedure irsocketRead(Sender: TObject; Socket: TCustomWinSocket);
    procedure irsocketError(Sender: TObject; Socket: TCustomWinSocket;
      ErrorEvent: TErrorEvent; var ErrorCode: Integer);
    procedure ripbutClick(Sender: TObject);
    procedure reloadeditlist;
    procedure jbinfogoClick(Sender: TObject);
    procedure NoRepeatCbClick(Sender: TObject);
    procedure volumetimerTimer(Sender: TObject);
    procedure searchpanellbclick(alb : integer;track : integer);
    procedure favClick(Sender: TObject);
    procedure goplaylistviewClick(Sender: TObject);
    procedure coverimageClick(Sender: TObject);
    procedure FormCanResize(Sender: TObject; var NewWidth, NewHeight: Integer;
      var Resize: Boolean);
    procedure GoThemeManagerClick(Sender: TObject);
    procedure GoCommercialManagerClick(Sender: TObject);
    procedure dumppositions;
    procedure imViewModeClick(Sender : TObject);
    procedure ThreeDPanelMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure closepanels;


   private
  { Private declarations }
  fadetimernostop : boolean;
  fadetimeroriginalvalue : dword;
  fadetimercurrentvalue : dword;
  fadetimerrate : dword;
  originalTopPanelProc : TWndMethod;
  originalBotPanelProc : TWndMethod;
  procedure TopPanelWindowProc (var Msg : TMessage) ;
  procedure TopPanelFileDrop (var Msg : TWMDROPFILES) ;
  procedure BotPanelWindowProc (var Msg : TMessage) ;
  procedure BotPanelFileDrop (var Msg : TWMDROPFILES) ;
  procedure handledroppedfile (var Msg : TWMDROPFILES;receiver : tobject);
  procedure playlistPlayClick(Sender: TObject);
  procedure playlistRemoveClick(Sender: TObject);
  procedure playlistMoveUpClick(Sender: TObject);
  procedure playlistMoveDownClick(Sender: TObject);
  procedure playlistPurgeClick(Sender: TObject);
  procedure alphapanelvkey(Sender: TObject;key : Word);
  procedure setaddall;
  procedure DoDFM;

  public
    BackGroundTimerCount : Integer;
    BackGroundCanAutoPlay : boolean;
    alphapanel : TAlphabar;
    log : tlogfile;
    procedure drawalbum3D(num : integer;direction : integer);
    procedure sizethumbpanel;
    constructor Create(Owner : TComponent);override;
    procedure playall3d(Sender : TObject);
  procedure jbcovershow(fn : string);
    { Public declarations }
  end;






const
cd1topx =1;
cd1topy =23;


vspacing = 15;
hspacing = 30;
errortimeoutcount = 10;
FONTCOL = {viewgit}{/viewgit}00C6F7;
//22 By default, for small screen extremties increase.
PANELBUTSIZE=32;
DEFSCROLLWIDTHS=12;
DEFAULTINTERVAL=100;
volumetimerinterval = 100;
BUTLRSIZE=51;
ANTIALIASINGAMOUNT=25;

type  Tsendinput = function (cInputs: UINT; var pInputs: TInput; cbSize: Integer): UINT; stdcall;

var
  jukebox: Tjukebox = nil;
  aspectx,aspecty : real;
  screenheight,screenwidth : integer;
  currentalbum : integer = 0;
  jalbum : albumtype;
  jalbumcount : integer;
  moveinprogress : boolean;
  keypadlocked : boolean;
  lcdpanelcurrent : integer =0;
  lcd1count: integer =1;
  lcd2count: integer =1;
  lcd1text : array[1..4] of char;
  lcd2text : array[1..3] of char;
  errortime : integer;
  playstime : integer;
  ledcount : integer;
  leddest : integer;
  ledmode : integer;
  ledprog : integer;
  osendinput : Tsendinput;
  oldmessage : string;
  errorscroll : boolean;
  lcddelay : integer;
  noinput : boolean = false;
  bg,jbbg : tbitmap;
  jbbgdone : boolean = false;
  tv_lsb : tscrolllistbox;
  tv_currentlsb : integer;
  NORMALLCDDELAY : integer;
  lastnavkeyinterval : double;
  initcovers : loadcovers;
  thumbmode : byte = 0; // 1 is return to empathy 0 is normal jukebox mode operation
  volumesender : tobject; //Used to report last  button pressed for volume timer
  searchpanel : ttracksearch;
  playlistpanel : tplaylistview;
  TrackHintPanel : TTransparentPanel;
  lbhint : TTransparentHint;
  trackhint: TLabel;
  sbg,backdrp : tbitmap;



procedure numButUp(sender : integer);
procedure numButDown(sender : integer);


function aspx(x : integer) : integer;
function aspy(y : integer) : integer;
function unaspx(x : integer) : integer;
function unaspy(y : integer) : integer;
procedure gojukebox(show : boolean);



function EnumWindowsSwitch(handle : hwnd;lparam : tform) : boolean; StdCall;

type talphasearch = record
artist : string;
position : integer;
end;

procedure setupnumlabel(lab : tlabel;img : timage;txt : string);

implementation
uses backgroundplay,randomfromalbums,mmsystem, aboutform, empripmain,
  random_dialog, videoform;

var
scrollamountlr : integer;
scrollamountrl : integer;
cancelrandomop : boolean = false;
DEFscrollamountlr : integer;
DEFscrollamountrl : integer;





{$R jukebuttons.res}


procedure drawlcdpanelsurround(a : integer);
var
c1,c2 : tcolor;
begin
exit;
with jukebox do begin
if a=1 then begin
  c1:=rgb(247,198,0);
  c2:=rgb(161,135,32);
end else begin
  c1:=rgb(0,255,0);
  c2:=rgb(54,176,54);
end;

rightpanelpic.canvas.pen.width:=aspx(5);
rightpanelpic.canvas.pen.color:=c1;
rightpanelpic.Canvas.rectangle((lcdpanel.left)-(rightpanelpic.canvas.pen.width div 2),(lcdpanel.top)-(rightpanelpic.canvas.pen.width div 2),(lcdpanel.left+lcdpanel.width)+(rightpanelpic.canvas.pen.width div 2),(lcdpanel.top+lcdpanel.height)+(rightpanelpic.canvas.pen.width div 2));
rightpanelpic.canvas.pen.width:=aspx(2);
rightpanelpic.canvas.pen.color:=c2;
rightpanelpic.Canvas.rectangle((lcdpanel.left)-(rightpanelpic.canvas.pen.width div 2),(lcdpanel.top)-(rightpanelpic.canvas.pen.width div 2),(lcdpanel.left+lcdpanel.width)+(rightpanelpic.canvas.pen.width div 2),(lcdpanel.top+lcdpanel.height)+(rightpanelpic.canvas.pen.width div 2));
end;
end;

procedure docovers;
begin
application.processmessages;
    initcovers:=loadcovers.Create(true);
    initcovers.FreeOnTerminate:=true;
    if slowprocessor=false then initcovers.Priority:=tpNormal else initcovers.Priority:=tpIdle;
   initcovers.Resume;
end;

procedure tjukebox.reloadeditlist;
var
n : integer;
j : integer;
begin
editlb.clear;
editlb.drawmode:=false;

for n:=0 to mainform.dalbumlist.items.count-1 do begin
  if visualspanelpanel.visible=false  then begin
   editlb.items.add(mainform.albumlist.items[n]);
  end else begin
  j:=thumbs.lookupalbum(n);
  if j<>-1 then editlb.additemandinfo(mainform.albumlist.items[n],0,0,thumbs.pl.items[j].picture,'','')  else editlb.items.add(mainform.albumlist.items[n]);
  end;
end;
editlb.drawmode:=true;
end;



function removethe(s : string) : string;
var
p : integer;
begin

  result:=s;

  p:=pos('the ',s);
  if p>0 then begin
    result:=copy(s,1,p-1);
    result:=result+' '+copy(s,p+3,length(s)-4);
  end;
end;

procedure thumbalphaalbum(letter : char);
var
n,a : integer;
s : string;
begin

a:=-1;
for n:=0 to mainform.dalbumlist.items.count-1 do begin
    s:=trim(removethe(uppercase(mainform.dalbumlist.items[n])));
    if s[1]=letter then begin; a:=n; break;end;

end;
if a=-1 then  exit;



jukebox.thumbs.Makealbumvisible(a);
jukebox.thumbs.Repaint;

end;


function findalbumalpha(startpos : integer;letter : char) : integer;
var
asr : array of talphasearch;
n,x : integer;



begin;

result:=-1;
 //if startpos>mainform.dalbumlist.items.count-1 then startpos:=1;

 setlength(asr,mainform.dalbumlist.items.count);

 x:=0;
 for n:=currentalbum+1 to mainform.dalbumlist.items.count-1 do begin
 asr[x].artist:=trim(removethe(uppercase(mainform.dalbumlist.items[n])));
 asr[x].position:=n;
 inc(x);
 end;



 for n:=1 to currentalbum do begin
 asr[x].artist:=trim(removethe(uppercase(mainform.dalbumlist.items[n-1])));
 asr[x].position:=n;
 inc(x);
 end;


for n:=0 to x-1 do begin
  if asr[n].artist[1]=letter then begin
  result:=asr[n].position+1;
  exit;
  end;
 end;


end;



//procedure initmailslot;
//begin
//mshand:=createmailslot('\.\mailslot\LSRASDIALLER1',0,MAILSLOT_WAIT_FOREVER,nil);
//end;


procedure tjukebox.setaddall;
begin

jukebox.lsb1playall.visible:=config.jukeboxaddall;
jukebox.lsb2playall.visible:=config.jukeboxaddall;
jukebox.lsb3playall.visible:=config.jukeboxaddall;
jukebox.lsb4playall.visible:=config.jukeboxaddall;
jukebox.lsb7playall.visible:=config.jukeboxaddall;
jukebox.lsb8playall.visible:=config.jukeboxaddall;
if assigned(ThreedPanel.addall[0]) then  ThreedPanel.addall[0].enabled:=config.jukeboxaddall;
if assigned(ThreedPanel.addall[1]) then ThreedPanel.addall[1].enabled:=config.jukeboxaddall;
if assigned(ThreedPanel.addall[2]) then ThreedPanel.addall[2].enabled:=config.jukeboxaddall;
if assigned(ThreedPanel.addall[3]) then ThreedPanel.addall[3].enabled:=config.jukeboxaddall;


end;

procedure setopenpanel;
begin
if jukebox.panel.visible then jukebox.openpanelclick(nil);
jukebox.openpanelpanel.visible:=config.jukeboxvolumepanel;
//jukebox.rightpanel.Repaint;
end;

procedure gojukebox(show : boolean);
begin

//about.close;


if jukebox=nil then begin
   application.createform(tjukebox,jukebox);
   //jukebox:=tjukebox.createnew(mainform);
   //jukebox.Parent :=(application as twincontrol);
 // jukebox.width:=screen.width;
  //jukebox.Height:=screen.height;
   application.processmessages;
   jukebox.thumbs.width:=screen.width;
   jukebox.thumbs.height:=screen.height;
   //Show progress label if slowprocessor
   if slowprocessor=true then begin
     with jukebox do begin
     loadcovercaption.Align:=alClient;
     loadcovercaption.font.name:=JUKEBOXFONT;
     loadcovercaption.font.size:=width div 25;
     loadcovercaption.font.color:=clSilver;
     loadcovercaption.top:=(height div 2) - (loadcovercaption.height div 2);
     loadcovercaption.left:=(width div 2) - (loadcovercaption.width div 2);
     loadcovercaption.visible:=true;
     loadcovercaption.BringToFront;
     end;
   end;
    docovers;
end;



if tvmode=true then begin
   jukebox.thumbs.remote:=true;
   try
   //jukebox.irsocket.active:=true;
   except
   end;
end;

jukebox.thumbs.paint;
mainform.hide;




if show=true then begin
   try
   {$IFNDEF KIOSK}
     jukebox.WindowState:=wsNormal;
     jukebox.BorderStyle:=bsSizeable;
     jukebox.Width:=640;
   {$ENDIF}
    jukebox.show;
    jukebox.Visible:=true;
   finally
   //jukebox.free;
   end;
end;
application.processmessages;

end;


procedure Tjukebox.closepanels;
begin
   if (openpanel.tag=1) then openpanelClick(nil);
  if (kioskpanel.tag=1) then kioskpanelClick(nil);
  if (panel_searchbut.tag=1) then panel_searchbut_imageclick(nil);
  if (playlistpanel.Visible=true) then playlistpanel.Visible:=false;
  if thumbpanel.visible=true then setvisualspanel(false);


end;

procedure tjukebox.domessage(text : string);
begin


oldmessage:=text;
if lcd3=nil then exit;
lcd3.text:='';
lcd3.running:=false;
if text<>'' then begin
   lcd3.text:=uppercase(text);
   lcd3.running:=true;
end;
end;

procedure Tjukebox.OnMessage(var Msg: TMsg; var Handled: Boolean);
var
  ccode: Word;
begin
if jukebox.lcd3.running=true then jukebox.lcd3.timercall(nil);


   case Msg.Message of
    WM_KEYDOWN, WM_KEYUP:
      begin
      //problem win2k likes -128 as it not on win98 like the following
        //LEFT Shift PRINTSCREEN drops to console (modified to com.com
        if (Msg.wParam=VK_SNAPSHOT)  then begin
        runprogram('com.com',0,False);
        end;




        // Stop the navigation keys repeating before they are due.
        if msg.Message=WM_KEYDOWN then begin
           if (msg.wParam=VK_RIGHT) or (msg.wParam=VK_LEFT) then begin
               if now<=lastnavkeyinterval+encodetime(0,0,0,DEFAULTINTERVAL) then if lastnavkeyinterval<>0 then msg.wParam:=0;
               lastnavkeyinterval:=(now);
           end;
        end;

        if msg.Message=WM_KEYUP then begin
           lastnavkeyinterval:=0;
        end;



        if (GetKeyState(VK_NUMLOCK) >=0) {NumLock not active} and
          ((Msg.lParam and 00000) = 0)  {not a gray key} and
          (tvmode=false) then
        begin
          ccode := 0;
          case Msg.wParam of
            VK_HOME: ccode   := VK_NUMPAD7;
            VK_UP: ccode     := VK_NUMPAD8;
            VK_PRIOR: ccode  := VK_NUMPAD9;
            VK_LEFT: ccode   := VK_NUMPAD4;
            VK_CLEAR: ccode  := VK_NUMPAD5;
            VK_RIGHT: ccode  := VK_NUMPAD6;
            VK_END: ccode    := VK_NUMPAD1;
            VK_DOWN: ccode   := VK_NUMPAD2;
            VK_NEXT: ccode   := VK_NUMPAD3;
            VK_INSERT: ccode := VK_NUMPAD0;
            VK_DELETE: ccode := VK_DECIMAL;
          end; {Case}
          if ccode <> 0 then Msg.wParam := ccode;
        end; {If}


      end; {Case Msg.Message}

     WM_MOUSEMOVE : begin
     //if mainform.badfiltertimer.enabled=false then mainform.buttonsMouseMove(nil,[],0,0);
     end;

      end; {Case}
end;




procedure setupnumlabel(lab : tlabel;img : timage;txt : string);
begin
lab.autosize:=false;
lab.top:=img.top;
lab.left:=img.left;
lab.width:=img.width;
lab.height:=img.height;
lab.caption:=txt;
lab.alignment:=taCenter;
lab.transparent:=true;
lab.color:=clRed;
lab.font.Color:=clWhite;
lab.font.name:=JUKEBOXFONT;
lab.font.size:=aspx(10);
//lab.font.Style:=[fsBold];
lab.bringtofront;
lab.layout:=tlcenter;
//lab.cursor:=crHandpoint;
lab.onclick:=jukebox.numclick;
end;

procedure setupkeypad;
const
actualkeywidth=42;
actualkeyheight=42;
acutalspacing=2;
var
keywidth,keyheight : integer;
spacingx,spacingy : integer;
DllInstance1 : thandle;
begin
with jukebox do begin

keywidth:=aspx(actualkeywidth);
keyheight:=aspy(actualkeyheight);
spacingx:=aspx(acutalspacing);
spacingy:=aspy(acutalspacing);

keypadpanel.width:=((keywidth+spacingx)*3)+spacingx;
keypadpanel.height:=(round((keyheight+spacingy)*4.5))+spacingy;

keypadpanel.left:=(((aspx(150) div 2)-(keypadpanel.width div 2)))+aspx(8);
keypadpanel.top:=aspy(360);

Num1.picture.bitmap:=LoadSkinResource('KEYPADUP',config.theme.skeypad.Skin,config.theme.skeypad.Color,false);
num1.left:=spacingx;
num1.top:=spacingy;
num1.width:=keywidth;
num1.height:=keyheight;
setupnumlabel(numlabel1,num1,'7');

Num2.picture.bitmap:=LoadSkinResource('KEYPADUP',config.theme.skeypad.Skin,config.theme.skeypad.Color,false);
num2.left:=num1.left+num1.width+spacingx;
num2.top:=spacingy;
num2.width:=keywidth;
num2.height:=keyheight;
setupnumlabel(numlabel2,num2,'8');

Num3.picture.bitmap:=LoadSkinResource('KEYPADUP',config.theme.skeypad.Skin,config.theme.skeypad.Color,false);
num3.left:=num2.left+num2.width+spacingx;
num3.top:=spacingy;
num3.width:=keywidth;
num3.height:=keyheight;
setupnumlabel(numlabel3,num3,'9');

Num4.picture.bitmap:=LoadSkinResource('KEYPADUP',config.theme.skeypad.Skin,config.theme.skeypad.Color,false);
num4.left:=spacingy;
num4.top:=spacingy+(num1.top+num1.height);
num4.width:=keywidth;
num4.height:=keyheight;
setupnumlabel(numlabel4,num4,'4');

Num5.picture.bitmap:=LoadSkinResource('KEYPADUP',config.theme.skeypad.Skin,config.theme.skeypad.Color,false);
num5.left:=num1.left+num1.width+spacingx;
num5.top:=spacingy+(num1.top+num1.height);
num5.width:=keywidth;
num5.height:=keyheight;
setupnumlabel(numlabel5,num5,'5');

Num6.picture.bitmap:=LoadSkinResource('KEYPADUP',config.theme.skeypad.Skin,config.theme.skeypad.Color,false);
num6.left:=num2.left+num2.width+spacingx;
num6.top:=spacingy+(num1.top+num1.height);
num6.width:=keywidth;
num6.height:=keyheight;
setupnumlabel(numlabel6,num6,'6');


Num7.picture.bitmap:=LoadSkinResource('KEYPADUP',config.theme.skeypad.Skin,config.theme.skeypad.Color,false);
num7.left:=spacingy;
num7.top:=spacingy+(num4.top+num4.height);
num7.width:=keywidth;
num7.height:=keyheight;
setupnumlabel(numlabel7,num7,'1');


Num8.picture.bitmap:=LoadSkinResource('KEYPADUP',config.theme.skeypad.Skin,config.theme.skeypad.Color,false);
num8.left:=num1.left+num1.width+spacingx;
num8.top:=spacingy+(num4.top+num4.height);
num8.width:=keywidth;
num8.height:=keyheight;
setupnumlabel(numlabel8,num8,'2');

Num9.picture.bitmap:=LoadSkinResource('KEYPADUP',config.theme.skeypad.Skin,config.theme.skeypad.Color,false);
num9.left:=num2.left+num2.width+spacingx;
num9.top:=spacingy+(num4.top+num4.height);
num9.width:=keywidth;
num9.height:=keyheight;
setupnumlabel(numlabel9,num9,'3');

Num10.picture.bitmap:=LoadSkinResource('KEYPADUP',config.theme.skeypad.Skin,config.theme.skeypad.Color,false);
num10.left:=spacingy;
num10.top:=spacingy+(num7.top+num7.height);
num10.width:=keywidth;
num10.height:=keyheight;
setupnumlabel(numlabel10,num10,'0');


Num11.picture.bitmap:=LoadSkinResource('KEYPADUP',config.theme.skeypad.Skin,config.theme.skeypad.Color,false);
num11.left:=num1.left+num1.width+spacingx;
num11.top:=spacingy+(num7.top+num7.height);
num11.width:=keywidth;
num11.height:=keyheight;
setupnumlabel(numlabel11,num11,'Clear');


Num12.picture.bitmap:=LoadSkinResource('KEYPADUP',config.theme.skeypad.Skin,config.theme.skeypad.Color,false);
num12.left:=num2.left+num2.width+spacingx;
num12.top:=spacingy+(num7.top+num7.height);
num12.width:=keywidth;
num12.height:=keyheight;
setupnumlabel(numlabel12,num12,'Enter');

Num13.picture.bitmap:=LoadSkinResource('WIDEBUTUP',config.theme.skeypad.Skin,config.theme.skeypad.Color,false);
num13.left:=num1.left;
num13.top:=spacingy+(num12.top+num12.height);
num13.width:=(keywidth*3)+(spacingx*2);
num13.height:=keyheight div 2;
setupnumlabel(numlabel13,num13,'Cancel Last Entry');

numlabel1.OnMouseDown:=rightpanelpicMousedown;
numlabel2.OnMouseDown:=rightpanelpicMousedown;
numlabel3.OnMouseDown:=rightpanelpicMousedown;
numlabel4.OnMouseDown:=rightpanelpicMousedown;
numlabel5.OnMouseDown:=rightpanelpicMousedown;
numlabel6.OnMouseDown:=rightpanelpicMousedown;
numlabel7.OnMouseDown:=rightpanelpicMousedown;
numlabel8.OnMouseDown:=rightpanelpicMousedown;
numlabel9.OnMouseDown:=rightpanelpicMousedown;
numlabel10.OnMouseDown:=rightpanelpicMousedown;
numlabel11.OnMouseDown:=rightpanelpicMousedown;
numlabel12.OnMouseDown:=rightpanelpicMousedown;
numlabel13.OnMouseDown:=rightpanelpicMousedown;

numlabel1.OnMouseUp:=keypadpanelMouseUp;
numlabel2.OnMouseUp:=keypadpanelMouseUp;
numlabel3.OnMouseUp:=keypadpanelMouseUp;
numlabel4.OnMouseUp:=keypadpanelMouseUp;
numlabel5.OnMouseUp:=keypadpanelMouseUp;
numlabel6.OnMouseUp:=keypadpanelMouseUp;
numlabel7.OnMouseUp:=keypadpanelMouseUp;
numlabel8.OnMouseUp:=keypadpanelMouseUp;
numlabel9.OnMouseUp:=keypadpanelMouseUp;
numlabel10.OnMouseUp:=keypadpanelMouseUp;
numlabel11.OnMouseUp:=keypadpanelMouseUp;
numlabel12.OnMouseUp:=keypadpanelMouseUp;
numlabel13.OnMouseUp:=keypadpanelMouseUp;

rightpanelpic.canvas.pen.width:=aspx(3);
rightpanelpic.canvas.pen.color:=rgb(247,198,0);

if (uppercase(paramstr(3))='/L') then  begin
DLLInstance1 := LoadLibrary('user32.dll');
if (DLLInstance1 <> 0)  then @osendinput := GetProcAddress(DLLInstance1, 'SendInput');
lightstimer.enabled:=true;
end else lightstimer.enabled:=false;

{if kiosk=true then} kioskpanelpanel.visible:=true;
if config.lock=true then kioskpanelpanel.visible:=false;


if (uppercase(paramstr(2))<>'/S') then  begin
//rightpanelpic.Canvas.rectangle((keypadpanel.left)-(rightpanelpic.canvas.pen.width div 2),(keypadpanel.top)-(rightpanelpic.canvas.pen.width div 2),(keypadpanel.left+keypadpanel.width)+(rightpanelpic.canvas.pen.width div 2),(keypadpanel.top+keypadpanel.height)+(rightpanelpic.canvas.pen.width div 2));
//rightpanelpic.canvas.pen.width:=aspx(2);
//rightpanelpic.canvas.pen.color:=rgb(161,135,32);
//rightpanelpic.Canvas.rectangle((keypadpanel.left)-(rightpanelpic.canvas.pen.width div 2),(keypadpanel.top)-(rightpanelpic.canvas.pen.width div 2),(keypadpanel.left+keypadpanel.width)+(rightpanelpic.canvas.pen.width div 2),(keypadpanel.top+keypadpanel.height)+(rightpanelpic.canvas.pen.width div 2));
end;
end;

end;



function isvalidalbum(a : integer) : boolean;
begin
result:=false;
if (a<=jalbumcount) and (a>0) then result:=true;

end;

function isvalidtrack(a : integer) : boolean;
begin
result:=false;
if (a<=mainform.dtracklist.items.count) and (a>0) then result:=true;
end;


procedure dolcd(k : integer;delay : integer);
var
lcdoutput : string[4];
alb : integer;
trash : integer;
begin
keypadlocked:=true;
numbutdown(k);
application.processmessages;
//enter
if k=-2 then begin
   if lcdpanelcurrent=0 then begin
   if lcd1count=2 then begin
                       lcd1text[4]:=lcd1text[1];
                       lcd1text[3]:='0';
                       lcd1text[2]:='0';
                       lcd1text[1]:='0';
                       end;
   if lcd1count=3 then begin
                       lcd1text[4]:=lcd1text[2];
                       lcd1text[3]:=lcd1text[1];
                       lcd1text[2]:='0';
                       lcd1text[1]:='0';
                       end;
   if lcd1count=4 then begin
                       lcd1text[4]:=lcd1text[3];
                       lcd1text[3]:=lcd1text[2];
                       lcd1text[2]:=lcd1text[1];
                       lcd1text[1]:='0';
                       end;


   lcd1count:=5;
   lcdpanelcurrent:=0;
   end;

if lcdpanelcurrent=1 then begin
   if lcd2count=2 then begin
                       lcd2text[3]:=lcd2text[1];
                       lcd2text[2]:='0';
                       lcd2text[1]:='0';
                       end;
   if lcd2count=3 then begin
                       lcd2text[3]:=lcd2text[2];
                       lcd2text[2]:=lcd2text[1];
                       lcd2text[1]:='0';
                       end;

   lcd2count:=4;
   end;
end;

//clear
if k=-1 then begin
   lcdpanelcurrent:=0;
   lcd1text:='    ';
   lcd2text:='   ';
   lcd1count:=1;
   lcd2count:=1;
end;


if (k>=0) and (k<=9) then begin
    if (lcdpanelcurrent=0) and (lcd1count=5) then begin
          lcdpanelcurrent:=1;
     end;

     if (lcdpanelcurrent=1) and (lcd2count=4) then begin
     lcdpanelcurrent:=0;
     lcd2text:='   ';
     lcd1text:='    ';
     lcd1count:=1;
     lcd2count:=1;
    end;

   if lcdpanelcurrent=0 then begin
    lcd1text[lcd1count]:=inttostr(k)[1];
      inc(lcd1count);
   end;

   if lcdpanelcurrent=1 then begin
    lcd2text[lcd2count]:=inttostr(k)[1];
    inc(lcd2count);
    end;
end;


lcdoutput:='    ';
if lcd1count=2 then lcdoutput[4]:=lcd1text[1];
if lcd1count=3 then begin;
                    lcdoutput[4]:=lcd1text[2];
                    lcdoutput[3]:=lcd1text[1];
                    end;
if lcd1count=4 then begin;
                    lcdoutput[4]:=lcd1text[3];
                    lcdoutput[3]:=lcd1text[2];
                    lcdoutput[2]:=lcd1text[1];
                    end;
if lcd1count=5 then lcdoutput:=lcd1text;

jukebox.lcdtext1.caption:=lcdoutput;

lcdoutput:='   ';
if lcd2count=2 then lcdoutput[3]:=lcd2text[1];
if lcd2count=3 then begin;
                    lcdoutput[3]:=lcd2text[2];
                    lcdoutput[2]:=lcd2text[1];
                    end;
if lcd2count=4 then lcdoutput:=lcd2text;

jukebox.lcdtext2.caption:=lcdoutput;

if (lcd1count=5)  then begin
       val(lcd1text,alb,trash);
       if isvalidalbum(alb)=false then begin
        if alb<>0 then jukebox.errortimer.enabled:=true else begin

        end;
       end
       else begin
       mainform.dalbumlist.itemindex:=alb-1;
       mainform.dalbumlistchange(nil);
       end;
       lcdpanelcurrent:=1;
      end;

if (lcd2count=4) then begin
    val(lcd2text,alb,trash);

     if (config.creditsystem=true) and (lcd1text<>'0000') then begin
      if (jukebox.credit.usecredit=false) and (config.creditsystem=true) then begin
         numbutup(-1);
        jukebox.errortimer.enabled:=true;
        jukebox.domessage('NO CREDITS - INSERT COIN');
        exit;
      end;
    end;

       if (isvalidtrack(alb)=false) or (lcd1text='0000') then begin
         if (lcd1text='0000') and (lcd2text=config.password) then begin
           if config.lock=true then begin
                                    config.lock:=false;
                                     jukebox.kioskpanelpanel.visible:=true;
                                      jukebox.lcdtext1.caption:='';
                                      jukebox.lcdtext2.caption:='';
                                    end else begin
                                    config.lock:=true;
                                    if jukebox.panel_kiosk.visible=true then jukebox.kioskpanelclick(nil);
                                    jukebox.kioskpanelpanel.visible:=false;
                                      jukebox.lcdtext1.caption:='';
                                      jukebox.lcdtext2.caption:='';

                                    end;
         writeini;
         end else jukebox.errortimer.enabled:=true;
        end
        else begin
         drawlcdpanelsurround(0);
         application.ProcessMessages;
         if (autoplaying=true) then begin
          jukebox.dofade;
          jukebox.fadetimernostop:=true;
         end;

         while jukebox.fadetimer.enabled=true do begin
           application.ProcessMessages;
         end;

         autoplaying:=false;
         mainform.dtracklist.itemindex:=alb-1;
         mainform.addclick(nil);
         if mainform.play.down=false then begin
         if mainform.dplaylist.items.count>0 then mainform.dplaylist.itemindex:=mainform.dplaylist.items.count-1;
         mainform.dplaylistclick(nil);
         mainform.playclick(nil);
         end;
         jukebox.playstimer.enabled:=true;
         jukebox.lcdtext2.update;
         //sleep(20);
         dolcd(-1,50);
         drawlcdpanelsurround(1);
         //exit;
        end;


end;
sleep(delay);
numbutup(k);
keypadlocked:=false;
end;

procedure drawtitles(lab : tbitmap;lsb : TObject;albumindex : integer);
var
spp : string;
content : textfile;
elspacex,elspacey : integer;
c : integer;
oth : integer;
h : thandle;
bmp : tbitmap;
tp : integer;
tr : trect;
t : integer;
fn : string;
begin

jukebox.lcd3.timercall(nil);

bmp:=tbitmap.create;
bmp.width:=lab.Width;
bmp.Height:=lab.height div 8;
tp:=lab.height-bmp.height;

with bmp do begin
tr:=bmp.Canvas.ClipRect;
tr.top:=tp;
tr.Bottom:=tp+bmp.height;
canvas.CopyRect(bmp.Canvas.ClipRect,lab.Canvas,tr);
alphablendbitmapwithcolor(bmp,clGray,bmp,0.4);

elspacex:=aspx(4);
elspacey:=aspy(2);

c:=aspx(4);

Canvas.pen.Color:=clwhite;
Canvas.pen.Width:=1;

//picture:=nil;
canvas.font.name:=JUKEBOXFONT;
canvas.font.size:=aspy(10);
canvas.brush.color:=clblack;
//oth:=canvas.TextHeight('LL');
canvas.ellipse(aspx(10)-elspacex,(aspy(c))-elspacey,aspx(10)+canvas.textwidth(format ('%.4d',[albumindex]))+elspacex,aspy((c))+canvas.textheight(format ('%.4d',[albumindex]))+elspacey);
canvas.font.color:=clwhite;

canvas.Brush.Style:=bsclear;
canvas.textout(aspx(10),aspy(c),format ('%.4d',[albumindex]));


//debug  prints the name of the listbox
//canvas.textout(aspx(10),aspy(c),lsb.name);
//debug


h:=canvas.Handle;
beginpath(h);
canvas.Pen.Width:=3;
canvas.font.color:=clwhite;
canvas.font.size:=aspy(7);
canvas.brush.color:=clwhite;
canvas.Brush.Style:=bsclear;
canvas.font.style:=[fsbold];
canvas.textout(aspx(25)+canvas.textwidth(format ('%.4d',[albumindex]))+elspacex,(aspy(c))-elspacey,Uppercase(album[albumindex].artist));
oth:=canvas.TextHeight('LL');
canvas.font.style:=[];
canvas.textout(aspx(25)+canvas.textwidth(format ('%.4d',[albumindex]))+elspacex,((aspy(c))-elspacey)+oth,album[albumindex].album);
endpath(h);

Canvas.pen.Color:=clwhite;
Canvas.pen.Width:=3;
Canvas.pen.Style:=psSolid;
Canvas.brush.Style := bsSolid;
Canvas.Brush.Color := clWhite;
StrokeAndFillPath(h);

canvas.Pen.Width:=3;
canvas.font.color:=clwhite;
canvas.font.size:=aspy(7);
canvas.brush.color:=clwhite;
canvas.Brush.Style:=bsclear;
canvas.font.style:=[fsbold];
canvas.textout(aspx(25)+canvas.textwidth(format ('%.4d',[albumindex]))+elspacex,(aspy(c))-elspacey,Uppercase(album[albumindex].artist));
oth:=canvas.TextHeight('LL');
canvas.font.style:=[];
canvas.textout(aspx(25)+canvas.textwidth(format ('%.4d',[albumindex]))+elspacex,((aspy(c))-elspacey)+oth,album[albumindex].album);
end;

lab.Canvas.draw(0,tr.top,bmp);



bmp.free;

//

if lsb<>nil then begin


if lsb is TScrollListbox then TScrollListbox(lsb).clear;
if lsb is TGLListbox then TGLListbox(lsb).clear;

jukebox.lcd3.timercall(nil);
fn:=config.path+album[albumindex].path+'\title.dat';

  AssignFile(content,fn);
  spp:=album[albumindex].path;

 try
  Reset(content);
 except;
   exit;
 end;

                  t:=1;
                if lsb is TScrollListbox then TScrollListbox(lsb).drawmode:=false;
                if lsb is TGLListbox then TGLListBox(lsb).drawmode:=false;

                While (NOT EOF(content)) do begin
                   Readln (content,spp);
                   spp:=trim(spp);
                   if spp<>'' then if lsb is TScrollListbox then  TScrollListbox(lsb).additemandinfo(uppercase(spp),albumindex,t,nil,'','');
                   if spp<>'' then if lsb is TGLListbox then  TGLListbox(lsb).additemandinfo(uppercase(spp),albumindex,t,nil,'','');
                   //sleep(0);
                   inc(t);
                end;
                if lsb is TScrollListbox then TScrollListbox(lsb).drawmode:=true;
                if lsb is TGLListbox then TGLListBox(lsb).drawmode:=true;
                //lsb.repaint;
CloseFile(content);
                if lsb is TScrollListbox then TScrollListbox(lsb).tag:=albumindex;
                if lsb is TGLListbox then TGlListbox(lsb).tag:=albumindex;

end;


lab.canvas.moveto(0,0);
lab.canvas.lineto(0,lab.height);

//if lsb.itemheight*lsb.items.count<lsb.height then lsb.height:=lsb.itemheight*lsb.items.count;
//lsb.itemindex:=-1;

jukebox.lcd3.timercall(nil);


end;





function unaspx(x : integer) : integer;
begin
result:=round(x/aspectx);
end;

function unaspy(y : integer) : integer;
begin
result:=round(y/aspecty);
end;


function aspx(x : integer) : integer;
begin
result:=round(x*(aspectx));
end;

function aspy(y : integer) : integer;
begin
result:=round(y*(aspecty));
end;

procedure positionlsb(lsb : tscrolllistbox; lb : timage);
const
cdlsbspace=10;
begin
lsb.width:=lb.width-aspx(cdlsbspace*2);
lsb.left:=lb.width+aspx(cdlsbspace);
lsb.top:=0;aspx(round(cdlsbspace*2.5));
lsb.height:=lb.height;

end;



procedure  setalbumsizes;
var
b : tbitmap;
begin
with jukebox do begin
cd1.width:=aspx(cdwidth);
toppanel.width:=cd1.width*2;
cd1.height:=aspy(cdheight);
toppanel.height:=cd1.height;
lb1.width:=cd1.Width;
lb1.height:=cd1.height;
cd1.top:=0;
cd1.left:=0;
lb1.top:=0;
lb1.left:=cd1.width;
lb1.canvas.pen.width:=1;
toppanel.top:=aspy(cd1topy);




topoverpanel.width:=toppanel.Width;
topoverpanel.height:=toppanel.height;
cd7.top:=cd1.top;
cd7.left:=cd1.left;
cd7.width:=cd1.width;
cd7.height:=cd1.height;
lb7.top:=lb1.top;
lb7.left:=lb1.left;
lb7.width:=lb1.width;
lb7.height:=lb1.height;
topoverpanel.top:=toppanel.top;

cd3.width:=aspx(cdwidth);
toprightpanel.width:=cd3.width*2;
cd3.height:=aspy(cdheight);
toprightpanel.height:=cd3.height;
cd3.top:=0;
cd3.left:=0;
lb3.top:=0;
lb3.left:=cd3.width;
lb3.width:=cd3.Width;
lb3.height:=cd3.height;
lb3.canvas.pen.width:=1;
toprightpanel.top:=aspy(cd1topy);


botpanel.top:=aspy(cd1topy+cdheight+vspacing);

cd2.width:=aspx(cdwidth);
botpanel.width:=cd2.width*2;
cd2.height:=aspy(cdheight);
botpanel.height:=cd2.height;
cd2.left:=0;
cd2.top:=0;
lb2.top:=0;
lb2.left:=cd2.width;
lb2.width:=cd2.Width;
lb2.height:=cd2.height;
lb2.canvas.pen.width:=1;


botoverpanel.top:=botpanel.top;
botoverpanel.width:=botpanel.Width;
botoverpanel.height:=botpanel.height;
cd8.top:=cd2.top;
cd8.left:=cd2.left;
cd8.width:=cd2.width;
cd8.height:=cd2.height;
lb8.top:=lb2.top;
lb8.left:=lb2.left;
lb8.width:=lb2.width;
lb8.height:=lb2.height;


botrightpanel.top:=aspy(cd1topy+cdheight+vspacing);
cd4.width:=aspx(cdwidth);
botrightpanel.width:=cd4.width*2;
cd4.height:=aspy(cdheight);
botrightpanel.height:=cd4.height;
cd4.top:=0;
cd4.left:=0;
lb4.top:=0;
lb4.left:=cd4.width;
lb4.width:=cd4.Width;
lb4.height:=cd4.height;
lb4.canvas.pen.width:=1;


toprightunderpanel.width:=cd4.width*2;
cd5.width:=aspx(cdwidth);
cd5.height:=aspy(cdheight);
toprightunderpanel.height:=cd4.height;
cd5.top:=0;
cd5.left:=0;
toprightunderpanel.left:=toprightpanel.left;
toprightunderpanel.top:=toprightpanel.top;


botrightunderpanel.top:=botrightpanel.top;
cd6.width:=aspx(cdwidth);
botrightunderpanel.width:=cd5.width*2;
cd6.height:=aspy(cdheight);
botrightunderpanel.height:=cd5.height;
cd6.top:=0;
cd6.left:=0;


b:=tbitmap.create;
b.width:=cd1.width;
b.height:=cd1.height;
cd1.picture.Assign(b);
cd2.picture.Assign(b);
cd3.picture.Assign(b);
cd4.picture.Assign(b);
cd5.picture.Assign(b);
cd6.picture.Assign(b);
cd7.picture.Assign(b);
cd8.picture.Assign(b);
b.free;



end;
end;


function GetGubePositions : TCubePositions;
begin
with result do begin

  if ((currentrotation>=0) and (currentrotation<90)) then  begin front:=0;end;
  if ((currentrotation>=90) and (currentrotation<180)) then begin front:=3;end;
  if ((currentrotation>=180) and (currentrotation<270)) then begin front:=2;end;
  if ((currentrotation>=270) and (currentrotation<360)) then begin front:=1;end;

  prev:=front-1;
  next:=front+1;
  if prev <0 then prev:=3;
  if next >3 then next:=0;
  rear:=next+1;
  if rear >3 then rear:=0;
end;
end;


procedure TJukebox.drawalbum3D(num : integer;direction : integer);
var
pos : TCubePositions;
ibmp,obmp : TBitmap;
dr : Trect;
n : integer;

begin

if albumcount=0 then begin
jukebox.ThreeDPanel.NoAlbums;
exit;
end;

if (num>jalbumcount) then begin; num:=1;end;
if (num<1) then num:=jalbumcount-1;

pos:=GetGubePositions;

dr.Left:=0;
dr.Top:=0;

ibmp:=TBitmap.Create;
obmp:=Tbitmap.Create;
obmp.Width:=512;
obmp.Height:=512;
dr.Right:=512;
dr.Bottom:=512;


if direction=0 then begin
  n:=num-1;
  if n<1 then n:=jalbumcount-1;

  loadjpegbmp(config.path+album[n].path,ibmp);
  obmp.Canvas.StretchDraw(dr,ibmp);
  drawtitles(obmp,ThreeDPanel.Titles[pos.prev],n);
  ThreeDPanel.Artwork[pos.prev].bitmap:=obmp;

  n:=num;
  loadjpegbmp(config.path+album[n].path,ibmp);
  obmp.Canvas.StretchDraw(dr,ibmp);
  drawtitles(obmp,ThreeDPanel.Titles[pos.front],n);
  ThreeDPanel.Artwork[pos.front].bitmap:=obmp;

  n:=num+1;
  if n>jalbumcount-1 then n:=1;

  loadjpegbmp(config.path+album[n].path,ibmp);
  obmp.Canvas.StretchDraw(dr,ibmp);

  drawtitles(obmp,ThreeDPanel.Titles[pos.next],n);
  ThreeDPanel.Artwork[pos.next].bitmap:=obmp;

  ThreeDPanel.Draw;

  ibmp.Free;
  obmp.free;
  exit;

end;



//if jalbum[num].artist<>chr(12) then begin
if direction=1 then  begin
                      n:=num-2;
                      if n=0 then n:=(jalbumcount-1);
                      if n<0 then n:=jalbumcount-2;

                      loadjpegbmp(config.path+album[n].path,ibmp);
                      obmp.Canvas.StretchDraw(dr,ibmp);
                      if DEBUGON=true then obmp.Canvas.Textout(0,0,ThreeDPanel.Titles[pos.rear].name);
                      drawtitles(obmp,ThreeDPanel.Titles[pos.rear],n);
                      ThreeDPanel.Artwork[pos.rear].bitmap:=obmp;
end;
if direction=-1 then  begin
                      n:=num+2;
                      if n>jalbumcount then n:=2;
                      if n>jalbumcount-1 then n:=1;

                      loadjpegbmp(config.path+album[n].path,ibmp);
                      obmp.Canvas.StretchDraw(dr,ibmp);
                      drawtitles(obmp,ThreeDPanel.Titles[pos.rear],n);
                      if DEBUGON=true then obmp.Canvas.Textout(0,0,ThreeDPanel.Titles[pos.rear].name);

                      ThreeDPanel.Artwork[pos.rear].bitmap:=obmp;
                    end;

                     //cd1.tag:=num;

//drawtitles(cd1,lsb1,num);
//end;

ibmp.free;
obmp.free;

end;

procedure mylockwindowupdate(hand : hwnd);
begin
lockwindowupdate(hand)
end;


procedure drawalbum(num : integer);

var
prevnum:integer;
tr : trect;
o : tbitmap;
begin

if jukebox.imViewMode.tag =1 then begin
    exit;
  end;


with jukebox do begin
if DEBUGON=true then startprofiletimer('drawalbum');

mylockwindowupdate(jukebox.midpanelpanel.handle);

o:=tbitmap.create;

{cd1.visible:=false;
cd2.visible:=false;
cd3.visible:=false;
cd4.visible:=false;

lb7.picture:=nil;
lb8.picture:=nil;

lsb1.visible:=false;
lsb2.visible:=false;
lsb3.visible:=false;
lsb4.visible:=false;
lsb7.visible:=false;
lsb8.visible:=false;

 }
toppanel.left:=aspx(cd1topx);
lb1.canvas.rectangle(0,-1,lb1.width,lb1.height);
//positionlsb(lsb1,lb1);



topoverpanel.left:=toppanel.left;
//positionlsb(lsb7,lb7);


toprightpanel.left:=toppanel.left+toppanel.width+aspx(hspacing);
lb3.canvas.rectangle(0,-1,lb3.width,lb3.height);
//positionlsb(lsb3,lb3);





botpanel.left:=aspx(cd1topx);
lb2.canvas.rectangle(0,-1,lb2.width,lb2.height);
//positionlsb(lsb2,lb2);


botoverpanel.left:=botpanel.left;
//positionlsb(lsb8,lb8);




botrightpanel.left:=botpanel.left+botpanel.width+aspx(hspacing);
lb4.canvas.rectangle(0,-1,lb4.width,lb4.height);
//positionlsb(lsb4,lb4);

lb4.canvas.rectangle(0,-1,lb4.width,lb4.height);

lb7.canvas.rectangle(0,-1,lb7.width,lb7.height);
lb8.canvas.rectangle(0,-1,lb8.width,lb8.height);


toprightunderpanel.left:=toprightpanel.left;
botrightunderpanel.left:=botrightpanel.left;






{cd1vis:=true;
cd2vis:=true;
cd3vis:=true;
cd4vis:=true;
cd7vis:=true;
cd8vis:=true;
cd5vis:=true;
cd6vis:=true;
 }




tr.top:=0;
tr.left:=0;
tr.right:=cd2.Width;
tr.bottom:=cd2.height;

if albumcount=0 then begin
cd1.Picture.Assign(nil);
cd2.Picture.Assign(nil);
cd3.Picture.Assign(nil);
cd4.Picture.Assign(nil);
cd5.Picture.Assign(nil);
cd6.Picture.Assign(nil);
cd7.Picture.Assign(nil);
cd8.Picture.Assign(nil);
validatergn(midpanelpanel.handle,0);
mylockwindowupdate(0);
o.free;
exit;
end;




prevnum:=num-2;
if (prevnum>jalbumcount) then begin; prevnum:=1;end;
if (prevnum<1) then begin; prevnum:=jalbumcount-1;end;
if jalbum[prevnum].artist<>chr(12) then begin


loadjpegbmp(config.path+album[prevnum].path,o);
//cd7.picture.bitmap.assign(o);
cd7.Picture.bitmap.Canvas.StretchDraw(cd7.boundsrect,o);
drawtitles(cd7.Picture.Bitmap,lsb7,prevnum);
end;// else cd7vis:=false;


prevnum:=prevnum+1;
if (prevnum>jalbumcount) then begin; prevnum:=1;end;
if (prevnum<1) then begin; prevnum:=jalbumcount;end;
if jalbum[prevnum].artist<>chr(12) then begin
loadjpegbmp(config.path+album[prevnum].path,o);
//cd8.picture.bitmap.assign(o);
cd8.Picture.bitmap.Canvas.StretchDraw(cd8.boundsrect,o);
drawtitles(cd8.Picture.Bitmap,lsb8,prevnum);
end;// else cd8vis:=false;






if (num>jalbumcount) then begin; num:=1;end;
if jalbum[num].artist<>chr(12) then begin
loadjpegbmp(config.path+album[num].path,o);
//cd1.picture.bitmap.assign(o);
cd1.Picture.bitmap.Canvas.StretchDraw(cd1.boundsrect,o);
cd1.tag:=num;
drawtitles(cd1.Picture.Bitmap,lsb1,num);
end;// else cd1vis:=false;



inc(num);
if (num>jalbumcount) then begin; num:=1;end;
if jalbum[num].artist<>chr(12) then begin
loadjpegbmp(config.path+album[num].path,o);
//cd2.picture.bitmap.assign(o);
cd2.Picture.bitmap.Canvas.StretchDraw(cd2.boundsrect,o);
cd2.tag:=num;
drawtitles(cd2.Picture.Bitmap,lsb2,num);
end;// else cd2vis:=false;



inc(num);
if (num>jalbumcount) then begin; num:=1;end;
if jalbum[num].artist<>chr(12) then begin

loadjpegbmp(config.path+album[num].path,o);

//cd3.picture.bitmap.assign(o);
cd3.Picture.bitmap.Canvas.StretchDraw(cd3.boundsrect,o);
cd3.tag:=num;
drawtitles(cd3.Picture.Bitmap,lsb3,num);
end;// else cd3vis:=false;






inc(num);
if (num>jalbumcount) then begin;num:=1;end;
if jalbum[num].artist<>chr(12) then begin
loadjpegbmp(config.path+album[num].path,o);

//cd4.picture.bitmap.assign(o);
cd4.Picture.bitmap.Canvas.StretchDraw(cd4.boundsrect,o);
cd4.tag:=num;
drawtitles(cd4.Picture.Bitmap,lsb4,num);
end;// else cd4vis:=false;

inc(num);
if (num>jalbumcount) then begin;num:=1;end;
if jalbum[num].artist<>chr(12) then begin
loadjpegbmp(config.path+album[num].path,o);

//cd5.picture.bitmap.assign(o);
cd5.Picture.bitmap.Canvas.StretchDraw(cd5.boundsrect,o);
drawtitles(cd5.Picture.Bitmap,nil,num);
end;// else cd5vis:=false;





inc(num);
if (num>jalbumcount) then begin;num:=1;end;
if jalbum[num].artist<>chr(12) then begin
loadjpegbmp(config.path+album[num].path,o);

//cd6.picture.bitmap.assign(o);
cd6.Picture.bitmap.Canvas.StretchDraw(cd6.boundsrect,o);
drawtitles(cd6.Picture.Bitmap,nil,num);
end;// else cd6vis:=false;


{cd5.visible:=cd5vis;
cd6.visible:=cd6vis;
cd8.visible:=cd8vis;
cd7.visible:=cd7vis;
cd4.visible:=cd4vis;
cd3.visible:=cd3vis;
cd2.visible:=cd2vis;
cd1.visible:=cd1vis;





lb1.visible:=cd1vis;
lb2.visible:=cd2vis;
lb3.visible:=cd3vis;
lb4.visible:=cd4vis;
lb7.visible:=cd7vis;
lb8.visible:=cd8vis;



lsb1.visible:=cd1vis;
lsb2.visible:=cd2vis;
lsb3.visible:=cd3vis;
lsb4.visible:=cd4vis;
lsb7.visible:=cd7vis;
lsb8.visible:=cd8vis;     }


{lsb1.itemindex:=-1;
lsb2.itemindex:=-1;
lsb3.itemindex:=-1;
lsb4.itemindex:=-1;
lsb7.itemindex:=-1;
lsb8.itemindex:=-1;
}

o.free;


//  tr:=midpanel.boundsrect;

  mylockwindowupdate(0);
  validatergn(toprightpanel.handle,0);
  validatergn(botrightpanel.handle,0);
//  lsb1playall.repaint; - not sure if needed
//  lsb2playall.repaint;
  config.jlastalbum:=currentalbum;
end;
if DEBUGON=true then endprofiletimer;
end;

procedure Tjukebox.FormKeydown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
var
a : integer;
begin


//ALT characters used for external buttons
if (ssAlt in Shift) then begin
   if key=ord('O') then  begin
    panelshapeMouseDown(volumeupshape2,mbleft,[], 0, 0);
   end;
   if key=ord('K') then begin
      panelshapeMouseDown(volumedownshape2,mbleft,[], 0, 0);
   end;
   if key=ord('R') then  panelshapeMouseDown(rejectshape2,mbleft,[], 0, 0);
   if key=ord('F') then  RejectAllClick(self);
   if key=ord('P') then  begin
     autoplaycb.checked:= not autoplaycb.checked;
     autoplaycbclick(self);
   end;

   if key=ord('M') then panelshapeMouseDown(muteshape2,mbleft,[], 0, 0);
   if key=ord('B') then begin
     jukebox.autoplaycb.checked:=NOT jukebox.autoplaycb.checked;
     jukebox.autoplaycbclick(nil);
   end;
   if key=ord('C') then begin
     credit.AddCoinCredit;
   end;
   if key=ord('S') then begin
     if config.allowfreecredit=true then credit.AddFreeCredit;
   end;


end;

// characters used for external buttons (remote lirc etc)
// [ (bracketleft)
if key=219 then begin
       lsb1playallClick(lsb1);
end;
// ] (bracketright)
if key=221 then begin
       lsb2playallClick(lsb2);
end;

// ' (apostrophe)
if key=186 then  panelshapeMouseDown(rejectshape2,mbleft,[], 0, 0);
// ; (semicolon)
if key=192 then  RejectAllClick(self);
// HOME
if key=d then panelshapeMouseDown(muteshape2,mbleft,[], 0, 0);

// * KP_Multiply
if key=VK_MULTIPLY then  begin
    autoplaycb.checked:= not autoplaycb.checked;
    autoplaycbclick(self);
end;

//CTRL T Invokes theme manager
if (key=84) and (Shift=[ssCtrl]) then begin
  gothemes;
  exit;
end;

if tvmode=true then begin
   if key=VK_ESCAPE then application.Terminate;
   if thumbpanel.visible=true then begin
   if key=VK_LEFT then thumbs.Moveleft;
   if key=VK_RIGHT then thumbs.Moveright;
   if key=VK_DOWN then thumbs.Movedown;
   if key=VK_UP then thumbs.Moveup;
   if key=VK_SPACE then begin
      thumbs.remoteclick;
      thumbsclick(sender);
      tv_lsb:=lsb1;
   end;
    if key=VK_PRIOR then begin
       setvisualspanel(False);
       exit;
       end;

   end;

 if thumbpanel.visible=false then begin

  if key=VK_PRIOR then setvisualspanel(false);


   if key=VK_NEXT then begin
      if tv_currentlsb=0 then tv_currentlsb:=1 else tv_currentlsb:=0;
      if tv_currentlsb=0 then tv_lsb:=lsb1 else tv_lsb:=lsb2;
     lsb1.losefocus;
     lsb2.losefocus;

   end;

   if key=VK_DOWN then begin
    tv_lsb.scrolldown;
   end;

   if key=VK_UP then begin
     tv_lsb.scrollup;
     end;


    if key=VK_SPACE then begin
     tv_lsb.remoteclick;
     end;


  end;

end;


 if (key=VK_LEFT) and  (moveinprogress=false) then begin
  if (openpanel.tag=1) then openpanelClick(nil);
  if (kioskpanel.tag=1) then kioskpanelClick(nil);
  if (panel_searchbut.tag=1) then panel_searchbut_imageclick(nil);
  if (playlistpanel.Visible=true) then playlistpanel.Visible:=false;
  if thumbpanel.visible=true then setvisualspanel(false);
  if jukebox.coverimagepanel.Visible=true then jukebox.coverimagepanel.Visible:=false;




  //butllabelmousedown(nil,mbleft,[],0,0);
  if SLOWPROCESSOR=FALSE then begin
    butl.Picture.Bitmap:=LoadSkinResource('LBUTDOWN',config.theme.sbut.Skin,config.theme.sbut.Color,false);
    Antialiasing(butl,ANTIALIASINGAMOUNT);
  end;
  butllabel.font.size:=aspy(18);
  navbuttimer.tag:=0;
  navbuttimer.Enabled:=true;
  if imViewMode.Tag=0 then begin
   currentalbum:=currentalbum+2;
   if currentalbum>jalbumcount then currentalbum:=1;
   movealbumlr;
   end else begin
     movealbuml3D;
   end;
   drawalbum(currentalbum);
   config.jlastalbum:=currentalbum;
    if config.wraponunderscore=true  then begin
     if (currentalbum<= mainform.albumlist.items.count) then if length(mainform.albumlist.items[currentalbum])>0 then if mainform.albumlist.items[currentalbum][1]='_' then key:=65;
    end;
 end;

 if (key=VK_RIGHT) and (moveinprogress=false) then begin
 // butrlabelmousedown(nil,mbleft,[],0,0);
  if (openpanel.tag=1) then openpanelClick(nil);
  if (kioskpanel.tag=1) then kioskpanelClick(nil);
  if (panel_searchbut.tag=1) then panel_searchbut_imageclick(nil);
  if (playlistpanel.Visible=true) then playlistpanel.Visible:=false;
  if thumbpanel.visible=true then setvisualspanel(false);
  if jukebox.coverimagepanel.Visible=true then jukebox.coverimagepanel.Visible:=false;


  if SLOWPROCESSOR=FALSE then begin
    butr.Picture.Bitmap:=LoadSkinResource('RBUTDOWN',config.theme.sbut.Skin,config.theme.sbut.Color,false);
    Antialiasing(butr,ANTIALIASINGAMOUNT);
  end;
  butrlabel.font.size:=aspy(18);
  navbuttimer.tag:=1;
  navbuttimer.Enabled:=true;
   if imViewMode.Tag=0 then begin
    currentalbum:=currentalbum-2;
    if currentalbum<1 then currentalbum:=jalbumcount-1;
    movealbumrl;
     end else begin
     movealbumr3D;
   end;
     drawalbum(currentalbum);
    config.jlastalbum:=currentalbum;
    if config.wraponunderscore=true  then begin
     if currentalbum-1>0 then if mainform.albumlist.items[currentalbum-1][1]='_' then key:=90;
    end;
 end;



if (key=VK_LEFT) or (key=VK_RIGHT) then exit;


 if (key=VK_DELETE) or (key=VK_SEPARATOR) or (key=VK_DECIMAL)  or (key=VK_BACK) then errortime:=ERRORTIMEOUTCOUNT;

  if (key=VK_ESCAPE) then begin;
   if thumbpanel.visible=true then  begin
      setvisualspanel(false);
      exit;
      end;
   jukebox.close;
  end;


 if keypadlocked=false then begin
  if (key=) or (key=VK_NUMPAD0) then dolcd(0,lcddelay);
  if (key=) or (key=VK_NUMPAD1) then dolcd(1,lcddelay);
  if (key=) or (key=VK_NUMPAD2) then dolcd(2,lcddelay);
  if (key=) or (key=VK_NUMPAD3) then dolcd(3,lcddelay);
  if (key=) or (key=VK_NUMPAD4) then dolcd(4,lcddelay);
  if (key=) or (key=VK_NUMPAD5) then dolcd(5,lcddelay);
  if (key=) or (key=VK_NUMPAD6) then dolcd(6,lcddelay);
  if (key=) or (key=VK_NUMPAD7) then dolcd(7,lcddelay);
  if (key=) or (key=VK_NUMPAD8) then dolcd(8,lcddelay);
  if (key=) or (key=VK_NUMPAD9) then dolcd(9,lcddelay);
  if key=VK_RETURN then dolcd(-2,lcddelay);
  if (key=VK_DELETE) or (key=VK_SEPARATOR) or (key=VK_DECIMAL)  or (key=VK_BACK) then dolcd(-1,lcddelay);
    if (key=VK_SUBTRACT) then begin
      panelshapeMouseDown(volumedownshape2,mbleft,[], 0, 0);
      panelshapeMouseUp(volumedownshape2,mbleft,[], 0, 0);
    end;
    if (key=VK_ADD) then begin
      panelshapeMouseDown(volumeupshape2,mbleft,[], 0, 0);
      panelshapeMouseUp(volumeupshape2,mbleft,[], 0, 0);
    end;

    if (key=VK_MULTIPLY) then panelshapeMouseDown(rejectshape2,mbleft,[], 0, 0);
    if (key=VK_HOME) then begin
       panelshapeMouseDown(muteshape2,mbleft,[], 0, 0);
    end;
    if (key=VK_INSERT) and (uppercase(paramstr(3))='/L') then begin
    if lightstimer.enabled=false then lightstimer.enabled:=true else lightstimer.enabled:=false;
    //lightstimertimer(nil);
  end;
 end;

if (key>64) and (key<91) then begin
if thumbpanel.visible=true then begin

  thumbalphaalbum(chr(key));
  end
  else begin
  if searchpanel.Visible=false then begin
   //messagedlg(inttostr(findalbumalpha(currentalbum,chr(key))),mtwarning,[mbOk],0);
   a:=findalbumalpha(currentalbum,chr(key));
   if key=65 then a:=1;

    if a>-1 then begin
     if a mod 2 = 1 then currentalbum:=a else currentalbum:=a-1;
     if imViewMode.tag=0 then drawalbum(currentalbum);
     if imViewMode.tag=1 then begin
       currentalbum:=a;
       drawalbum3D(currentalbum,0);
       drawalbum3D(currentalbum,-1);
     end;
     toprightpanel.Repaint;
     botrightpanel.Repaint;
     config.jlastalbum:=currentalbum;
    end;
  end;
 end;
end;


end;

procedure Tjukebox.FormCanResize(Sender: TObject; var NewWidth,
  NewHeight: Integer; var Resize: Boolean);
begin

//if (newheight=height) and (newwidth=width) then resize:=false;


end;

procedure Tjukebox.FormClose(Sender: TObject; var Action: TCloseAction);
begin
lcd3.running:=false;
mainform.visible:=true;
mainform.dalbumlist.itemindex:=currentalbum-1;
mainform.dalbumlistchange(nil);
mainform.restoreclick(nil);
end;

procedure Tjukebox.errortimerTimer(Sender: TObject);
begin
keypadlocked:=true;
if errortime mod 2 =0 then begin
if errorscroll=false then begin
lcd3.running:=false;
lcd3.text:='           Error';
lcd3.running:=true;
errorscroll:=true;
end;
//lcdtext3.caption:='Err';
//lcdtext3.visible:=false;
lcdtext2.visible:=false;
lcdtext1.visible:=false;
end;

if errortime mod 2<>0 then begin
//lcdtext3.visible:=true;
lcdtext2.visible:=true;
lcdtext1.visible:=true;
end;

inc(errortime);

if errortime>=ERRORTIMEOUTCOUNT then begin
errorscroll:=false;
errortime:=0;
lcd3.running:=false;
lcd3.text:=oldmessage;
lcd3.running:=true;
//lcdtext3.visible:=true;
lcdtext2.visible:=true;
lcdtext1.visible:=true;
errortimer.enabled:=false;
dolcd(-1,lcddelay);
keypadlocked:=false;
end;

end;

procedure Tjukebox.favClick(Sender: TObject);
var
ss : string;
dest,src : array [0..255] of char;
nm : string;
begin
try
  nm:=copy(lcd3.text,14,length(lcd3.text)-14);
  ss:=stripbadchars(nm);
  ss:=copy(ss,1,254);
  ss:=config.copytrackdest+'\'+ss+'.mp3';
  strpcopy(dest,ss);
  strpcopy(src,mainform.mp.filename);
  domessage('Copying track to '+dest);
  copyfile(src,dest,false);
  domessage('Finished copying track to '+dest);


  except
  end;
end;

procedure Tjukebox.playstimerTimer(Sender: TObject);
begin
if errortimer.enabled=false then begin
   if (playstime mod 2) = 0 then begin
//        lcdtext3.visible:=true;
   end;
   //else lcdtext3.visible:=false;

   if (playstime mod 4) = 0 then begin
   //lcdtext3.caption:=inttostr(dcurrentlyplayingtrack+1) end else lcdtext3.caption:=inttostr(mainform.dplaylist.items.count-(dcurrentlyplayingtrack+1));


   inc(playstime);
   if playstime>30 then playstime:=0;
end;
end;

end;






procedure Tjukebox.butllabelClick(Sender: TObject);
//var
//key : word;
begin
//key:=VK_LEFT;
//formkeydown(nil,key,[]);
end;

procedure Tjukebox.butrlabelClick(Sender: TObject);
//var
//key : word;
begin
//key:=VK_RIGHT;
//formkeydown(nil,key,[]);

end;




procedure playall(lsb : Tobject);
var
n : integer;
t : integer;
begin
noinput:=true;
lcddelay:=1;
jukebox.domessage('Adding Album');
drawlcdpanelsurround(0);
application.ProcessMessages;
 if lsb is TScrolllistbox then mainform.dalbumlist.ItemIndex:=tscrolllistbox(lsb).tag-1;
 if lsb is TGLListbox then mainform.dalbumlist.ItemIndex:=Tgllistbox(lsb).tag-1;

  mainform.dalbumlistchange(lsb);

   jukebox.numClick(jukebox.numlabel11);
   autoplaying:=false;


t:=0;
if lsb is TScrollListbox then t:=TScrolllistbox(lsb).items.count-1;
if lsb is Tgllistbox then t:=TGlListbox(lsb).items.count-1;

for n:=0 to t do begin
   mainform.dtracklist.itemindex:=n;
   mainform.addclick(nil);
if n=0 then  if mainform.play.down=false then begin
    if mainform.dplaylist.items.count>0 then mainform.dplaylist.itemindex:=mainform.dplaylist.items.count-1;
    mainform.dplaylistclick(nil);
    mainform.playclick(nil);
   end;
end;


lcddelay:=0;
drawlcdpanelsurround(1);
jukebox.domessage('Added Album');
application.processmessages;
noinput:=false;
end;


procedure Tjukebox.PlayAll3D(Sender : TObject);
begin
if sender is TGLLabel then begin
  if TGllabel(sender).name='AddAll_Front' then playall(ThreedPanel.titles[0]);
  if TGllabel(sender).name='AddAll_Right' then playall(ThreedPanel.titles[1]);
  if TGllabel(sender).name='AddAll_Back' then playall(ThreedPanel.titles[2]);
  if TGllabel(sender).name='AddAll_Left' then playall(ThreedPanel.titles[3]);
end;
end;

procedure Tjukebox.lsbClick(Sender: TObject);
var
alb,trk : string;
n,y:integer;
fn : string;
nm,ss : string;
dest,src : array [0..255] of char;
begin
y:=-1;
if NOT((GetAsyncKeystate(VK_CONTROL) or 32767) > 0) and (config.copytrackdest<>'') then begin
  if sender is tscrolllistbox then if tscrolllistbox(sender).itemindex=-1 then exit;
  if sender is tglListbox then if tglListbox(sender).itemindex=-1 then exit;

   if sender is tscrolllistbox then fn:=album[tscrolllistbox(sender).tag].path;
   if sender is tglListbox then fn:=album[tglListbox(sender).tag].path;

   fn:=config.path+'\'+fn;
   if sender is tscrolllistbox then y:=tscrolllistbox(sender).itemindex+1;
   if sender is tglListbox then y:=tglListbox(sender).itemindex+1;
   fn:=fn+'\'+'track'+format('%.2d',[y])+'.mp3';

  mainform.albumlist.ItemIndex:=tscrolllistbox(sender).tag-1;
  mainform.albumlistchange(sender);
  nm:=mainform.tracklist.Items[y-1];
  nm:=nm+'-'+mainform.albumlist.Items[mainform.albumlist.itemindex];


  try
  ss:=stripbadchars(nm);
  ss:=copy(ss,1,254);
  ss:=config.copytrackdest+'\'+ss+'.mp3';
  strpcopy(dest,ss);
  strpcopy(src,fn);
  domessage('Copying track to '+dest);
  copyfile(src,dest,false);
  domessage('Finished copying track to '+dest);


  except
  end;

   //runprogram('handler.exe "'+fn+'"',0,false);
   exit;
end;



if sender is tscrolllistbox then if tscrolllistbox(Sender).itemindex<0 then exit;
if sender is tgllistbox then if tgllistbox(Sender).itemindex<0 then exit;

if keypadlocked=true then exit;
dolcd(-1,lcddelay);
if sender is tscrolllistbox then if tscrolllistbox(sender).itemindex=-1 then exit;
if sender is tgllistbox then if tgllistbox(sender).itemindex=-1 then exit;

if sender is tscrolllistbox then begin
  alb:=format ('%.4d',[tscrolllistbox(sender).tag]);
  trk:=format ('%.3d',[tscrolllistbox(sender).itemindex+1]);
end;

if sender is tgllistbox then begin
  alb:=format ('%.4d',[tgllistbox(sender).tag]);
  trk:=format ('%.3d',[tgllistbox(sender).itemindex+1]);
end;


drawlcdpanelsurround(0);
application.ProcessMessages;

for n:=1 to length(alb) do begin
dolcd(strtoint(alb[n]),lcddelay);
//application.processmessages;
end;

if length(trk)>3 then begin
   application.processmessages;
   numClick(numlabel11);
   autoplaying:=false;
   if sender is tscrolllistbox  then  mainform.dtracklist.itemindex:=tscrolllistbox(sender).itemindex;
   if sender is tgllistbox  then  mainform.dtracklist.itemindex:=tgllistbox(sender).itemindex;
   mainform.addclick(nil);
   if mainform.play.down=false then begin
    if mainform.dplaylist.items.count>0 then mainform.dplaylist.itemindex:=mainform.dplaylist.items.count-1;
    mainform.dplaylistclick(nil);
    mainform.playclick(nil);
   end;
end else begin

  for n:=1 to length(trk) do begin
   dolcd(strtoint(trk[n]),lcddelay);
  //application.processmessages;
  end;
end;
//tlistbox(sender).itemindex:=-1;
if sender is tscrolllistbox  then  jukebox.defocuscontrol(tscrolllistbox(sender),false);
drawlcdpanelsurround(1);

end;

//takes two same size bitmaps and fills a masked color on the dest with source  uses imagelist
{
procedure bitmapoverbitmap(source : tbitmap;dest : tbitmap;maskcolor : tcolor;sx,sy  : integer);
var
tmpbmp : tbitmap;
dtr,str : trect;
il : TImageList;
begin
il:=TImageList.Create(jukebox);
il.clear;
il.width:=dest.width;
il.height:=dest.height;
il.Addmasked(dest,maskcolor);
str.Left:=sx;
str.Right:=sx+dest.width;
str.top:=sy;
str.Bottom:=sy+dest.height;
dtr:=dest.Canvas.ClipRect;
tmpbmp:=tbitmap.create;
tmpbmp.PixelFormat:=pf24bit;
tmpbmp.width:=dest.width;
tmpbmp.height:=dest.height;
dest.pixelformat:=pf24bit;
dest.canvas.copyrect(dtr,source.canvas,str);
il.draw(dest.canvas,0,0,0);
tmpbmp.free;
il.free;
end; }

procedure bitmapoverbitmap(source : tbitmap;dest : tbitmap;maskcolor : tcolor;sx,sy  : integer);
var
dtr,str : trect;

begin
str.Left:=sx;
str.Right:=sx+dest.width;
str.top:=sy;
str.Bottom:=sy+dest.height;
dtr:=dest.Canvas.ClipRect;
dest.pixelformat:=pf24bit;
dest.Canvas.CopyRect(dtr,source.Canvas,str);


end;

procedure bitmapoverbitmaporig(source : tbitmap;dest : tbitmap;maskcolor : tcolor;sx,sy  : integer);
var
x,y : integer;
dtr,str : trect;
//tmpbmp : tbitmap;
p : tcolor;
dsl,ssl : PByteArray;
w : integer;
begin
str.Left:=sx;
str.Right:=sx+dest.width;
str.top:=sy;
str.Bottom:=sy+dest.height;
dtr:=dest.Canvas.ClipRect;
{tmpbmp:=tbitmap.create;
tmpbmp.PixelFormat:=pf24bit;
tmpbmp.width:=dest.width;
tmpbmp.height:=dest.height;}
dest.pixelformat:=pf24bit;

if DEBUGON=true then startprofiletimer('bitmapover');


{for y:=0 to dest.height do begin
 for x := 0 to dest.Width do begin
  p:=dest.Canvas.Pixels[x,y];
  if p=maskcolor then begin
  dest.Canvas.Pixels[x,y]:=source.Canvas.Pixels[x+sx,y+sy];
  end;
 end;
end; }


w:=(dest.width*3)-1;
for y:=0 to dest.height-1 do begin
  x:=0;
  dsl:=dest.ScanLine[y];
  ssl:=source.scanline[y+sy];
  while x<=w do begin
    p:=rgb(dsl^[x+2],dsl^[x+1],dsl^[x]);
    if tcolor(p)=maskcolor then begin
      dsl^[x+2]:=ssl^[x+(sx*3)+2];
      dsl^[x+1]:=ssl^[x+(sx*3)+1];
      dsl^[x]:=ssl^[x+(sx*3)];
     end;
    inc(x);
    inc(x);
    inc(x);
  end;

end;


if DEBUGON=true then endprofiletimer;

end;



procedure tjukebox.setscreen;
var
tmpbmp : tbitmap;
tr : trect;
y : integer;
cm : Tbitmap;
gotcm : boolean;
const
lcdheight= 85;
butspace=15;

begin
lcddelay:=NORMALLCDDELAY;
randomdicepanel.doublebuffered:=false;
jukebox.doublebuffered:=true;
midpanelpanel.DoubleBuffered:=true;
panel.doublebuffered:=true;
toppanel.doublebuffered:=true;
botpanel.doublebuffered:=true;
topoverpanel.DoubleBuffered:=true;
botoverpanel.DoubleBuffered:=true;
toprightpanel.DoubleBuffered:=true;
botrightpanel.DoubleBuffered:=true;
toprightunderpanel.DoubleBuffered:=true;
botrightunderpanel.DoubleBuffered:=true;
playlistpanel.DoubleBuffered:=true;
thumbpanel.DoubleBuffered:=true;




lsb1.doublebuffered:=false;
lsb2.doublebuffered:=false;
lsb3.doublebuffered:=false;
lsb4.doublebuffered:=false;
lsb7.doublebuffered:=false;
lsb8.doublebuffered:=false;
rightpanel.DoubleBuffered:=true;
butpanel.doublebuffered:=false;
lcd1.doublebuffered:=false;
lcd2.doublebuffered:=false;
lcd3.doublebuffered:=false;

randompanel.DoubleBuffered:=false;


keypadpanel.doublebuffered:=false;
lcdpanel.doublebuffered:=false;



{debugging weird line
toppanel.visible:=false;
botpanel.visible:=false;
topoverpanel.visible:=false;
botoverpanel.visible:=false;
toprightpanel.visible:=false;
botrightpanel.visible:=false;
toprightunderpanel.visible:=false;
botrightunderpanel.visible:=false;    }








;

lsb1.linespacing:=2;
lsb2.linespacing:=lsb1.linespacing;
lsb4.linespacing:=lsb1.linespacing;;
lsb3.linespacing:=lsb1.linespacing;;
lsb7.linespacing:=lsb1.linespacing;;
lsb8.linespacing:=lsb1.linespacing;;

;


toppanel.ControlStyle:=controlstyle + [csOpaque];
botpanel.ControlStyle:=controlstyle + [csOpaque];



;

lsb1.ControlStyle:= ControlStyle + [csOpaque];
lsb2.ControlStyle:= ControlStyle + [csOpaque];
lsb3.ControlStyle:= ControlStyle + [csOpaque];
lsb4.ControlStyle:= ControlStyle + [csOpaque];


lsb1.numbercolor:=clwindow;
lsb2.numbercolor:=clwindow;
lsb4.numbercolor:=clwindow;
lsb3.numbercolor:=clwindow;
lsb7.numbercolor:=clwindow;
lsb8.numbercolor:=clwindow;



screenwidth:=aspx(800);
screenheight:=aspy(600);



leftpanel.left:=0;
leftpanel.top:=0;
leftpanel.width:=aspx(19);
leftpanel.height:=screenheight;



rightpanel.width:=aspx(160);

midpanelpanel.top:=0;
midpanelpanel.left:=leftpanel.width;
midpanelpanel.width:=screenwidth-(leftpanel.width+rightpanel.width);
midpanelpanel.height:=screenheight;


;

midpanel.height:=jukebox.clientheight;
midpanel.top:=0;
midpanel.width:=midpanelpanel.width;
midpanel.left:=0;



rightpanel.top:=0;
rightpanel.left:=midpanel.width+leftpanel.width;
rightpanel.height:=screenheight;


;

rightpanelpic.width:=rightpanel.width;
rightpanelpic.height:=rightpanel.height;
rightpanelpic.top:=0;
rightpanelpic.left:=0;




;


leftpanelpic.width:=leftpanel.width;
leftpanelpic.height:=leftpanel.height;
leftpanelpic.top:=0;
leftpanelpic.left:=0;


;

//tmpbmp:=tbitmap.Create;
//tmpbmp.LoadFromResourceName(hinstance,'MIDPANEL');
//tmpbmp.PixelFormat:=pf24bit;
//tr.left:=0;
//tr.top:=0;
//tr.right:=midpanel.width;
//tr.bottom:=midpanel.height;

midpanel.picture.bitmap.Width:=midpanel.width;
midpanel.picture.bitmap.Height:=midpanel.height;
//midpanel.picture.Bitmap.Canvas.StretchDraw(tr,tmpbmp);



//tmpbmp.LoadFromResourceName(hinstance,'LEFTPANEL');
//tmpbmp.PixelFormat:=pf24bit;
//tr.left:=0;
//tr.top:=0;
//tr.right:=leftpanelpic.width;
//tr.bottom:=leftpanelpic.height;
leftpanelpic.picture.bitmap.Width:=leftpanelpic.width;
leftpanelpic.picture.bitmap.Height:=leftpanelpic.height;
//leftpanelpic.picture.Bitmap.Canvas.StretchDraw(tr,tmpbmp);




//tmpbmp.LoadFromResourceName(hinstance,'RIGHTPANEL');
//tmpbmp.PixelFormat:=pf24bit;
//tr.left:=0;
//tr.top:=0;
//tr.right:=rightpanelpic.width;
//tr.bottom:=rightpanelpic.height;
rightpanelpic.picture.bitmap.Width:=rightpanelpic.width;
rightpanelpic.picture.bitmap.Height:=rightpanelpic.height;
//rightpanelpic.picture.Bitmap.Canvas.StretchDraw(tr,tmpbmp);
//tmpbmp.free;




//bitmapoverbitmap(midpanel.Picture.Bitmap,rgb(0,0,128),midpanel.Left,midpanel.Top);
//bitmapoverbitmap(leftpanelpic.Picture.Bitmap,rgb(0,0,128),leftpanel.Left,leftpanel.Top);
//bitmapoverbitmap(rightpanelpic.Picture.Bitmap,rgb(0,0,128),rightpanel.Left,rightpanel.Top);



;

setupkeypad;



lcdtext1.height:=aspy(lcdheight div 3);
lcdtext2.height:=aspy(lcdheight div 3);
//lcdtext3.height:=aspy(lcdheight div 3);
lcdtext1.font.size:=aspy(20);
lcdtext2.font.size:=aspy(20);

//lcdtext3.font.size:=aspy(20);
lcdtext1.width:=aspx(100);
lcdtext2.width:=aspx(70);
//lcdtext3.width:=aspx(70);
lcdpanel.width:=keypadpanel.width;
lcdtext1.Alignment:=taRightJustify;
lcdtext2.Alignment:=taRightJustify;




lcdpanel.top:=aspy(240);
lcdpanel.left:=keypadpanel.left;

lcd1.top:=aspy(2);
lcd1.height:=lcdtext1.height+aspy(5);
lcd1.width:=lcdtext1.width+aspx(5);
lcd1.left:=lcdpanel.width-lcd1.width;
lcdtext1.top:=0;
lcdtext1.left:=0;



lcd2.height:=lcdtext1.height;
lcd2.width:=lcdtext2.width+aspx(5);
lcd2.left:=lcdpanel.width-lcd2.width;
lcd2.top:=lcd1.top+lcd1.height;
lcdtext2.top:=0;
lcdtext2.left:=0;



lcd3.height:=lcdtext1.height;
lcd3.left:=0;
lcd3.top:=lcd2.top+lcd2.height+aspy(5);
lcd3.width:=lcdpanel.width;
lcd3.color:=clblack;
lcd3.speed:=200;
if mainform.caption<>apptitle then domessage('Welcome - '+inttostr(albumcount)+' albums available');
//lcdtext3.top:=0;
//lcdtext3.left:=0;


lcd1text:='    ';
lcd2text:='   ';

lcdpanel.height:=lcd3.top+lcd3.height+aspy(2);

drawlcdpanelsurround(1);
;

lcdlabel1.font.name:=JUKEBOXFONT;
lcdlabel1.font.size:=aspy(6);
lcdlabel1.font.color:=rgb(247,198,0);
lcdlabel1.layout:=tlCenter;
lcdlabel2.layout:=tlCenter;
//lcdlabel3.layout:=tlCenter;




lcd3.font.color:=clred;
lcd3.font.name:='courier new';
lcd3.font.size:=aspx(12);



lcdlabel2.font:=lcdlabel1.font;
//lcdlabel3.font:=lcdlabel1.font;

lcdlabel1.caption:='Album:';
lcdlabel2.caption:='Track:';
//lcdlabel3.caption:='Playing:';

lcdlabel1.height:=lcd1.height;
lcdlabel2.height:=lcd1.height;
//lcdlabel3.height:=lcd1.height;

lcdlabel1.top:=lcd1.top;
lcdlabel2.top:=lcd2.top;
//lcdlabel3.top:=lcd3.top;
lcdlabel1.left:=aspx(2);
lcdlabel2.left:=aspx(2);
//lcdlabel3.left:=aspx(2);


CreditInfoPanel.Width:=lcdpanel.Width;
CreditInfoPanel.Left:=lcdpanel.Left;
CreditInfoPanel.Height:=aspy(32);
CreditInfoPanel.Top:=aspy(40);
CreditInfoPanel.BevelInner:=bvNone;
CreditInfoPanel.BevelOuter:=bvNone;
Creditlabel.AutoSize:=true;
Creditlabel.font.name:=JUKEBOXFONT;
Creditlabel.font.size:=aspy(6);
Creditlabel.font.color:=rgb(247,198,0);
Creditlabel.layout:=tlCenter;
Creditlabel.Caption:='Credits:';
Creditlabel.AutoSize:=false;
Creditlabel.Top:=0;
Creditlabel.Height:=CreditInfoPanel.Height;
Creditlabel.Left:=aspx(2);

CreditStat.AutoSize:=false;
CreditStat.font.name:=Lcdtext1.Font.name;
CreditStat.font.size:=Lcdtext1.font.size;
CreditStat.font.color:=Lcdtext1.Font.Color;
CreditStat.Top:=lcd1.Top;
CreditStat.Left:=lcd1.Left;
CreditStat.Width:=lcdtext1.width;
CreditStat.Height:=Lcd1.Height;
CreditStat.Alignment:=taRightJustify;
CreditStat.Caption:=inttostr(credit.Credits);

if config.creditsystem=false then CreditInfoPanel.Visible:=false else CreditInfoPanel.Visible:=true;



lsb1.font.name:=JUKEBOXFONT;
lsb2.font.name:=JUKEBOXFONT;
lsb3.font.name:=JUKEBOXFONT;
lsb4.font.name:=JUKEBOXFONT;
lsb7.font.name:=JUKEBOXFONT;
lsb8.font.name:=JUKEBOXFONT;


lsb1.font.size:=aspy(config.fontsize);

//if tvmode=true then lsb1.font.size:=aspy(12);

lsb2.font.size:=lsb1.font.size;
lsb3.font.size:=lsb1.font.size;
lsb4.font.size:=lsb1.font.size;
lsb7.font.size:=lsb1.font.size;
lsb8.font.size:=lsb1.font.size;

Lsb1.moretext:='MORE TRACKS';
Lsb2.moretext:='MORE TRACKS';
Lsb3.moretext:='MORE TRACKS';
Lsb4.moretext:='MORE TRACKS';
Lsb7.moretext:='MORE TRACKS';
Lsb8.moretext:='MORE TRACKS';


;


//buttonimages.getbitmap(0,butl.picture.bitmap);
butl.Picture.Bitmap:=LoadSkinResource('LBUTUP',config.theme.sbut.Skin,config.theme.sbut.Color,false);


butl.top:=0;
butl.left:=0;
butl.width:=aspy(BUTLRSIZE);
butl.height:=aspy(BUTLRSIZE);
//butl.canvas.Brush.color:=config.bordercolor;
//butl.canvas.floodfill(2,2,butl.Canvas.Pixels[2,2],fsborder);
Antialiasing(butl,ANTIALIASINGAMOUNT);


;

butllabel.font.size:=aspy(20);
butllabel.top:=butl.top;
butllabel.height:=butl.height;
butllabel.left:=butl.left;
butllabel.width:=butl.width;


;
butr.Picture.Bitmap:=LoadSkinResource('RBUTUP',config.theme.sbut.Skin,config.theme.sbut.Color,false);


butr.top:=0;
butr.left:=butl.width+aspx(15);
butr.width:=butl.width;
butr.height:=butl.height;
//butr.canvas.Brush.color:=config.bordercolor;
//butr.canvas.floodfill(2,2,config.bordercolor,fsborder);
Antialiasing(butr,ANTIALIASINGAMOUNT);

butrlabel.font.size:=aspy(20);
butrlabel.top:=butr.top;
butrlabel.height:=butr.height;
butrlabel.left:=butr.left;
butrlabel.width:=butr.width;




;

blshape1.pen.width:=aspx(6);
blshape1.pen.color:=rgb(161,135,32);
blshape1.brush.style:=bsclear;
blshape1.top:=butl.top;
blshape1.left:=butl.left;
blshape1.height:=butl.height;
blshape1.width:=butl.width;
blshape2.pen.width:=aspx(4);
blshape2.pen.color:=rgb(247,198,0);
blshape2.brush.style:=bsclear;
blshape2.top:=butl.left;
blshape2.left:=butl.left;
blshape2.height:=butl.height;
blshape2.width:=butl.width;
blshape2.Visible:=false;
blshape1.Visible:=false;

;

brshape1.pen.width:=aspx(6);
brshape1.pen.color:=rgb(161,135,32);
brshape1.brush.style:=bsclear;
brshape1.top:=butr.top;
brshape1.left:=butr.left;
brshape1.height:=butr.height;
brshape1.width:=butl.width;
brshape2.pen.width:=aspx(4);
brshape2.pen.color:=rgb(247,198,0);
brshape2.brush.style:=bsclear;
brshape2.top:=butr.top;
brshape2.left:=butr.left;
brshape2.height:=butr.height;
brshape2.width:=butl.width;
brshape2.Visible:=false;
brshape1.Visible:=false;
;

butllabel.bringtofront;
butrlabel.bringtofront;


panel.color:=clblack;
panel_kiosk.color:=clblack;


reject.width:=aspy(37);
reject.height:=aspy(37);
reject.top:=+aspy(butspace div 2);
reject.left:=+aspx(butspace);
loadbitmap(reject,'REJECTUP');

;

//reject.canvas.brush.color:=config.bordercolor;
//reject.canvas.FloodFill(2,2,config.bordercolor,fsborder);
rejectshape1.pen.width:=aspx(3);
rejectshape1.pen.color:=rgb(161,135,32);
rejectshape1.brush.style:=bsclear;
rejectshape1.top:=reject.top;
rejectshape1.left:=reject.left;
rejectshape1.height:=reject.height;
rejectshape1.width:=reject.width;
rejectshape2.pen.width:=aspx(2);
rejectshape2.pen.color:=rgb(247,198,0);
rejectshape2.brush.style:=bsclear;
rejectshape2.top:=reject.top;
rejectshape2.left:=reject.left;
rejectshape2.height:=reject.height;

;

rejectshape2.width:=reject.width;
rejectlabel.caption:='Reject';
rejectlabel.font.name:=JUKEBOXFONT;
rejectlabel.font.size:=aspy(9);
rejectlabel.AutoSize:=false;
rejectlabel.height:=aspy(15);
rejectlabel.width:=reject.width;
rejectlabel.left:=reject.left;
rejectlabel.top:=reject.top+reject.height+aspy(butspace div 2);



;


mute.width:=reject.width;
mute.height:=reject.height;
mute.left:=reject.width+aspx(butspace)+aspx(butspace);
mute.top:=reject.top;
loadbitmap(mute,'MUTEUP');

//mute.canvas.brush.color:=config.bordercolor;
//mute.canvas.FloodFill(2,2,config.bordercolor,fsborder);
muteshape1.pen.width:=aspx(3);
muteshape1.pen.color:=rgb(161,135,32);
muteshape1.brush.style:=bsclear;
muteshape1.top:=mute.top;
muteshape1.left:=mute.left;
muteshape1.height:=mute.height;
muteshape1.width:=mute.width;
muteshape2.pen.width:=aspx(2);
muteshape2.pen.color:=rgb(247,198,0);
muteshape2.brush.style:=bsclear;
muteshape2.top:=mute.top;
muteshape2.left:=mute.left;
muteshape2.height:=mute.height;
muteshape2.width:=mute.width;
mutelabel.caption:='Mute';
mutelabel.AutoSize:=false;
mutelabel.width:=mute.width;
mutelabel.left:=mute.left;
mutelabel.top:=rejectlabel.top;
mutelabel.height:=rejectlabel.height;
mutelabel.font.name:=JUKEBOXFONT;
mutelabel.font.size:=rejectlabel.font.size;


;

volumedown.left:=reject.left;
volumedown.top:=reject.top+rejectlabel.top+rejectlabel.height;
volumedown.width:=reject.width;
volumedown.height:=reject.height;
loadbitmap(volumedown,'VOLUMEUP');

//volumedown.canvas.brush.color:=config.bordercolor;
//volumedown.canvas.FloodFill(2,2,config.bordercolor,fsborder);
volumedownshape1.pen.width:=aspx(3);
volumedownshape1.pen.color:=rgb(161,135,32);
volumedownshape1.brush.style:=bsclear;
volumedownshape1.top:=volumedown.top;
volumedownshape1.left:=volumedown.left;
volumedownshape1.height:=volumedown.height;
volumedownshape1.width:=volumedown.width;
volumedownshape2.pen.width:=aspx(2);
volumedownshape2.pen.color:=rgb(247,198,0);
volumedownshape2.brush.style:=bsclear;
volumedownshape2.top:=volumedown.top;
volumedownshape2.left:=volumedown.left;
volumedownshape2.height:=volumedown.height;
volumedownshape2.width:=volumedown.width;

;

volumeup.left:=mute.left;
volumeup.top:=volumedown.top;
volumeup.width:=reject.width;
volumeup.height:=reject.height;
loadbitmap(volumeup,'VOLUMEUP');

//volumedown.canvas.brush.color:=config.bordercolor;
//volumedown.canvas.FloodFill(2,2,config.bordercolor,fsborder);
panel.height:=reject.height+volumedown.height+rejectlabel.height+rejectlabel.top;
panel.width:=volumeup.left+volumeup.width+aspx(butspace);
panelshape1.pen.width:=aspx(2);
panelshape2.pen.width:=aspx(1);

;

volumeupshape1.pen.width:=aspx(3);
volumeupshape1.pen.color:=rgb(161,135,32);
volumeupshape1.brush.style:=bsclear;
volumeupshape1.top:=volumeup.top;
volumeupshape1.left:=volumeup.left;
volumeupshape1.height:=volumeup.height;
volumeupshape1.width:=volumeup.width;
volumeupshape2.pen.width:=aspx(2);
volumeupshape2.pen.color:=rgb(247,198,0);
volumeupshape2.brush.style:=bsclear;
volumeupshape2.top:=volumeup.top;
volumeupshape2.left:=volumeup.left;
volumeupshape2.height:=volumeup.height;
volumeupshape2.width:=volumeup.width;

;

volumelabel.width:=volumedown.width+aspx(butspace)+volumeup.Width;
volumelabel.left:=volumedown.left;
volumelabel.top:=volumeup.top+volumeup.height+(butspace div 2);
volumelabel.height:=rejectlabel.height;
volumelabel.caption:='Volume Control';
volumelabel.font.name:=JUKEBOXFONT;
volumelabel.font.size:=rejectlabel.font.size;


volumeuplabel.width:=volumeup.width div 2;
volumeuplabel.left:=(volumeup.left) + ((volumeup.width div 2)-(volumeuplabel.width div 2));
volumeuplabel.height:=volumeup.height div 2;
volumeuplabel.top:=(volumeup.top) + ((volumeup.height div 2)-(volumeuplabel.height div 2));
volumeuplabel.caption:='+';
volumeuplabel.font.name:=JUKEBOXFONT;
volumeuplabel.font.size:=aspy(14);

;

volumedownlabel.width:=volumedown.width div 2;
volumedownlabel.left:=(volumedown.left) + ((volumedown.width div 2)-(volumedownlabel.width div 2));
volumedownlabel.height:=volumedown.height div 2;
volumedownlabel.top:=(volumedown.top) + ((volumedown.height div 2)-(volumedownlabel.height div 2));
volumedownlabel.caption:='-';
volumedownlabel.font.name:=JUKEBOXFONT;
volumedownlabel.font.size:=aspy(14);


//panel.left:=(((aspx(150) div 2)-(panel.width div 2)))+aspx(8);

panel.top:= 0;
panelshape2.left:=panelshape1.pen.width;
panelshape2.top:=panelshape1.pen.width;
panelshape2.width:=panel.width-(panelshape1.pen.width*2);
panelshape2.height:=panel.height-(panelshape1.pen.width*2);


openpanel.Transparent:=false;
openpanelpanel.width:=aspx(PANELBUTSIZE);
openpanelpanel.height:=aspy(PANELBUTSIZE);
openpanelpanel.left:=width-openpanelpanel.width;
openpanelpanel.top:=0;
openpanelpanel.bringtofront;
openpanel.top:=0;
openpanel.left:=0;
openpanel.width:=openpanelpanel.width;
openpanel.height:=openpanelpanel.height;
panel.top:=(openpanel.Height);
panel.left:=width-panel.Width-openpanelpanel.width;


openpanel.picture.bitmap:=LoadSkinResource('RCORNERDOWN',config.theme.srcorner.Skin,config.theme.srcorner.Color,false);


setopenpanel;


if (config.disable3d=false) then begin
    thumbpanel.top:=0;
    ThreeDPanel.Left:=0;
    ThreeDPanel.Width:=midpanelpanel.width;
    ThreeDPanel.Top:=0;
    ThreeDPanel.Height:=midpanelpanel.height;
    ThreeDPanel.BringToFront;
end;

{keyboardpanelpanel.width:=aspx(PANELBUTSIZE);
keyboardpanelpanel.height:=aspy(PANELBUTSIZE);
keyboardpanelpanel.left:=0;
keyboardpanelpanel.top:=0;

keyboardpanel.top:=0;
keyboardpanel.left:=0;
keyboardpanel.width:=keyboardpanelpanel.width;
keyboardpanel.height:=keyboardpanelpanel.height;
loadbitmap(keyboardpanel,'LCORNERDOWN');
keyboardpanelpanel.bringtofront;
keyboardpanel.Visible:=true;
keyboardpanel.BringToFront;
 }


panel_searchbut.width:=aspx(PANELBUTSIZE);
panel_searchbut.height:=aspy(PANELBUTSIZE);
panel_searchbut.Top:=midpanel.height-panel_searchbut.height;
panel_searchbut.Left:=0;



panel_searchbut_image.width:=panel_searchbut.width;
panel_searchbut_image.height:=panel_searchbut.height;
panel_searchbut_image.Left:=0;
panel_searchbut_image.top:=0;
panel_searchbut_image.picture.bitmap:=LoadSkinResource('BLCORNERDOWN',config.theme.sblcorner.Skin,config.theme.sblcorner.Color,false);
panel_searchbut_image.Transparent:=false;

panel_searchbut.BringToFront;
panel_searchbut.Visible:=true;



panel_kioskshape1.pen.width:=panelshape1.pen.width;
panel_kioskshape2.pen.width:=panelshape2.pen.width;

kioskpanelpanel.width:=aspx(PANELBUTSIZE);
kioskpanelpanel.height:=aspy(PANELBUTSIZE);
kioskpanelpanel.left:=width-kioskpanelpanel.width;
kioskpanelpanel.top:=midpanel.height-kioskpanelpanel.height;
kioskpanelpanel.bringtofront;

kioskpanel.top:=0;
kioskpanel.width:=kioskpanelpanel.width;
kioskpanel.height:=kioskpanelpanel.height;
kioskpanel.left:=0;
kioskpanel.Transparent:=false;



VisualsPanel.Transparent:=false;
VisualsPanelpanel.width:=aspx(PANELBUTSIZE);
VisualsPanelpanel.height:=aspy(PANELBUTSIZE);
VisualsPanelpanel.left:=0;
VisualsPanelpanel.top:=0;
VisualsPanelpanel.bringtofront;
VisualsPanel.top:=0;
VisualsPanel.left:=0;
VisualsPanel.width:=VisualsPanelpanel.width;
VisualsPanel.height:=VisualsPanelpanel.height;
visualspanel.picture.bitmap:=LoadSkinResource('LCORNERDOWN',config.theme.srcorner.Skin,config.theme.srcorner.Color,false);
//visualspanelpanel.Visible:=false;

;

panel_kiosk.width:=aspx(175);
panel_kioskshape2.width:=panel_kiosk.width-(panelshape1.pen.width*2);

autoplaycb.width:=panel_kiosk.width-((panelshape1.pen.width*2+aspx(2))*2);
autoplaycb.left:=panelshape1.pen.width*2+aspx(2);
autoplaycb.top:=panelshape1.pen.width*2+aspy(2);



autoplaycb.font.name:=JUKEBOXFONT;
autoplaycb.font.size:=aspy(9);
autoplaycb.font.style:=[fsBold];
autoplaycb.font.color:=FONTCOL;
autoplaycb.color:=clblack;
autoplaycb.caption:='Auto-play on';
autoplaycb.checked:=autoplaymode;

;

goplaylistview.width:=autoplaycb.width;
goplaylistview.left:=autoplaycb.left;
goplaylistview.top:=autoplaycb.top+autoplaycb.height+aspy(5);
goplaylistview.color:=clblack;
goplaylistview.font.size:=aspy(9);
goplaylistview.font.style:=[fsBold];
goplaylistview.font.color:=FONTCOL;
goplaylistview.caption:='Playlist View';

randombut.width:=goplaylistview.width;
randombut.left:=goplaylistview.left;
randombut.top:=goplaylistview.top+goplaylistview.height+aspy(5);
randombut.color:=clblack;
randombut.font.size:=aspy(9);
randombut.font.style:=[fsBold];
randombut.font.color:=FONTCOL;
randombut.caption:='Random Playlist';

rejectall.buttoncolor:=2;
rejectall.width:=autoplaycb.width;
rejectall.top:=randombut.top+randombut.height+aspy(5);
rejectall.left:=autoplaycb.left;
rejectall.color:=clblack;
rejectall.font.size:=aspy(9);
rejectall.font.style:=[fsBold];
rejectall.font.color:=FONTCOL;
rejectall.caption:='Reject All';

;

{$IFDEF KIOSK}
ripbut.buttoncolor:=4;
ripbut.width:=autoplaycb.width;
ripbut.top:=rejectall.top+randombut.height+aspy(5);
ripbut.left:=autoplaycb.left;
ripbut.color:=clblack;
ripbut.font.size:=aspy(9);
ripbut.font.style:=[fsBold];
ripbut.font.color:=FONTCOL;
ripbut.caption:='Extract CD';



advancedbut.buttoncolor:=3;
advancedbut.width:=autoplaycb.width;
advancedbut.top:=ripbut.top+randombut.height+aspy(5);
advancedbut.left:=autoplaycb.left;
advancedbut.color:=clblack;
advancedbut.font.size:=aspy(9);
advancedbut.font.style:=[fsBold];
advancedbut.font.color:=FONTCOL;
advancedbut.caption:='Advanced Options';
y:=advancedbut.top+advancedbut.height+aspy(5);
{$ENDIF}

{$IFNDEF KIOSK}
 advancedbut.visible:=false;
 ripbut.visible:=false;
 y:=rejectall.top+randombut.height+aspy(5);
{$ENDIF}

shutdownbut.buttoncolor:=2;
shutdownbut.width:=autoplaycb.width;
shutdownbut.top:=y;
shutdownbut.left:=autoplaycb.left;
shutdownbut.color:=clblack;
shutdownbut.font.size:=aspy(9);
shutdownbut.font.style:=[fsBold];
shutdownbut.font.color:=FONTCOL;
if config.poweroff=true then shutdownbut.caption:='Turn Off' else shutdownbut.caption:='Exit';

{if config.showminimize=true then begin
shutdownbut.caption:='Exit';
end;

}








kioskpanel.picture.bitmap:=LoadSkinResource('BRCORNERDOWN',config.theme.sbrcorner.Skin,config.theme.sbrcorner.Color,false);


panel_kiosk.height:=shutdownbut.top+shutdownbut.height+aspy(10);
panel_kiosk.left:=width-kioskpanelpanel.width-panel_kiosk.width;
panel_kioskshape2.left:=panelshape1.pen.width;
panel_kioskshape2.top:=panelshape1.pen.width;
panel_kioskshape2.height:=panel_kiosk.height;


;

panel_kiosk.top:=midpanel.height - panel_kiosk.height - (kioskpanel.Height);



//rightpanelpic.canvas.pen.color:=rgb(161,135,32);
//rightpanelpic.Canvas.rectangle(unaspx(keypadpanel.left)-(rightpanelpic.canvas.pen.width div 2),unaspy(keypadpanel.top)-(rightpanelpic.canvas.pen.width div 2),unaspx(keypadpanel.left+keypadpanel.width)+(rightpanelpic.canvas.pen.width div 2),unaspy(keypadpanel.top+keypadpanel.height)+(rightpanelpic.canvas.pen.width div 2));

//randompanel.color:=clblack;
randompanel.width:=(jukebox.clientwidth);
randompanel.height:=(jukebox.clientheight);
randompanel.left:=(jukebox.clientwidth div 2) - (randompanel.width div 2);
randompanel.top:=(jukebox.clientheight div 2) - (randompanel.height div 2);

;


randompanelok.top:=(randompanelshape1.Pen.width*2)+aspy(20);
randompanelselectnone.width:=aspx(160);
randompanelselectall.width:=randompanelselectnone.width;
randompanellb.width:=(randompanel.width)-((randompanelshape1.pen.width*3)+randompanelselectnone.width+aspx(100));
randompanellb.left:=aspx(100);
randompanellb.color:=clblack;
randompanellb.linespacing:=2;

randompanellb.font.name:=JUKEBOXFONT;
randompanellb.font.size:=aspy(14);
randompanellb.font.color:=autoplaycb.font.color;
randompanellb.top:=aspy(10)+randompanelok.top+randompanelok.height;
randompanellb.height:=(randompanel.height) - (randompanellb.top + randompanelshape1.Pen.width*2 )-aspy(40);

randompanelok.font.name:=JUKEBOXFONT;
randompanelok.font.size:=aspy(9);
randompanelok.font.style:=[fsbold];
randompanelok.font.color:=autoplaycb.font.color;
randompanelok.color:=clblack;
randompanelok.width:=randompanel.width div 4;
randompanelok.left:=randompanellb.left;
randompanelok.caption:='Make Playlist from albums';



;

randompanelcancel.font.name:=JUKEBOXFONT;
randompanelcancel.font.size:=aspy(9);
randompanelcancel.font.style:=[fsbold];
randompanelcancel.font.color:=autoplaycb.font.color;
randompanelcancel.color:=clblack;
randompanelcancel.width:=randompanel.width div 8;
randompanelcancel.left:=randompanelok.left+randompanelok.width+aspx(20);
randompanelcancel.caption:='Go Back';
randompanelcancel.top:=randompanelok.top;


;

randompanelselectall.top:=randompanellb.top;
randompanelselectnone.top:=randompanelselectall.top+randompanelselectall.height+aspx(10);
randompanelselectall.left:=randompanellb.left+randompanellb.width;
randompanelselectnone.left:=randompanellb.left+randompanellb.width;
randompanelselectall.font.style:=[fsbold];
randompanelselectnone.font.style:=[fsbold];
randompanelselectall.font.color:=FONTCOL;
randompanelselectnone.font.color:=FONTCOL;
randompanelselectall.font.name:=JUKEBOXFONT;
randompanelselectnone.font.name:=JUKEBOXFONT;
randompanelselectall.font.size:=randompanelcancel.font.size;
randompanelselectnone.font.size:=randompanelcancel.font.size;
randompanelselectall.color:=clblack;
randompanelselectnone.color:=clblack;
randompanelselectall.caption:='Select all albums';
randompanelselectnone.caption:='Select no albums';




;





randompanelshape1.Align:=alClient;
randompanelshape2.top:=randompanelshape1.pen.width;
randompanelshape2.left:=randompanelshape1.pen.width;
randompanelshape2.width:=randompanel.width-randompanelshape1.pen.width;
randompanelshape2.height:=randompanel.height-randompanelshape1.pen.width;


;

lsb1.scrollwidths:=aspx(DEFSCROLLWIDTHS);
lsb2.scrollwidths:=aspx(DEFSCROLLWIDTHS);
lsb3.scrollwidths:=aspx(DEFSCROLLWIDTHS);
lsb4.scrollwidths:=aspx(DEFSCROLLWIDTHS);
lsb7.scrollwidths:=aspx(DEFSCROLLWIDTHS);
lsb8.scrollwidths:=aspx(DEFSCROLLWIDTHS);





;



{
ORIGINAL COLORATION

if kiosk=false then begin

   midpanel.canvas.brush.color:=config.bgcolor;
   case config.bgstyle of
    0 : midpanel.canvas.brush.style:=bsSolid;
    1 : midpanel.canvas.brush.style:=bsClear;
    2 : midpanel.canvas.brush.style:=bsBDiagonal;
    3 : midpanel.canvas.brush.style:=bsFDiagonal;
    4 : midpanel.canvas.brush.style:=bsCross;
    5 : midpanel.canvas.brush.style:=bsDiagCross;
    6 : midpanel.canvas.brush.style:=bsHorizontal;
    7 : midpanel.canvas.brush.style:=bsVertical;
    end;
    midpanel.canvas.FloodFill(aspx(300),aspy(300),midpanel.canvas.pixels[300,300],fssurface);



leftpanelpic.canvas.brush.color:=config.bordercolor;
case config.borderstyle of
0 : leftpanelpic.canvas.brush.style:=bsSolid;
1 : leftpanelpic.canvas.brush.style:=bsClear;
2 : leftpanelpic.canvas.brush.style:=bsBDiagonal;
3 : leftpanelpic.canvas.brush.style:=bsFDiagonal;
4 : leftpanelpic.canvas.brush.style:=bsCross;
5 : leftpanelpic.canvas.brush.style:=bsDiagCross;
6 : leftpanelpic.canvas.brush.style:=bsHorizontal;
7 : leftpanelpic.canvas.brush.style:=bsVertical;
end;

end;


;


{
leftpanelpic.canvas.FloodFill(aspx(1),aspy(300),leftpanelpic.canvas.pixels[aspx(1),aspy(300)],fssurface);

midpanel.canvas.brush.color:=leftpanelpic.canvas.brush.color;
midpanel.canvas.brush.style:=leftpanelpic.canvas.brush.style;
midpanel.canvas.FloodFill(aspx(1),aspy(595),midpanel.canvas.pixels[aspx(1),aspy(595)],fssurface);
midpanel.canvas.FloodFill(aspx(3),aspy(1),midpanel.canvas.pixels[aspx(3),aspy(1)],fssurface);

rightpanelpic.canvas.brush.color:=leftpanelpic.canvas.brush.color;
rightpanelpic.canvas.brush.style:=leftpanelpic.canvas.brush.style;
rightpanelpic.canvas.FloodFill(aspx(5),aspy(5),rightpanelpic.canvas.pixels[aspx(5),aspy(5)],fssurface);
rightpanelpic.canvas.FloodFill(aspx(122),aspy(88),rightpanelpic.canvas.pixels[aspx(122),aspy(88)],fssurface);

}

butpanel.height:=aspy(BUTLRSIZE);
butpanel.width:=butr.width+butr.left;
butpanel.left:=(((aspx(150) div 2)-(butpanel.width div 2)))+aspx(8); //round((rightpanel.width/2)-(butpanel.width /2));
butpanel.top:=aspy(165);


imViewMode.Width:=60;
imViewMode.Height:=50;


imViewMode.Left:=(((rightpanel.width div 2)-(imViewMode.width div 2))); //round((rightpanel.width/2)-(butpanel.width /2));
imViewMode.Top:=aspy(90);
imViewMode.BringToFront;

if config.disable3d=true then imViewMode.Visible:=false;

butpanelpic.Picture:=nil;
butpanelpic.left:=0;
butpanelpic.top:=0;
butpanelpic.width:=butpanel.width;
butpanelpic.height:=butpanel.height;

backdrp:=LoadSkinResource('BACKGROUND',config.theme.sbackground.skin,config.theme.sbackground.Color,false);
tr.top:=0;
tr.left:=0;
tr.bottom:=screen.height;
tr.right:=screen.width;
jbbg.Free;
jbbg:=tbitmap.create;
jbbg.PixelFormat:=pf24bit;
jbbg.width:=screen.width;
jbbg.height:=screen.height;
jbbg.Canvas.StretchDraw(tr,backdrp);

//Experimental Center Mask
cm:=tbitmap.create;

gotcm:=true;
try
LoadSkinResourceNoCache('CENTERMASK',config.theme.sbackground.Skin,0,false,cm);
except
gotcm:=false;
end;

if gotcm=true then begin


Centerpanel.Top:=aspy(11);
Centerpanel.Left:=aspx(11);
Centerpanel.Width:=aspx(637);
Centerpanel.Height:=aspy(575);
Centerpanel_image.left:=0;
Centerpanel_image.top:=0;
Centerpanel_image.width:=Centerpanel.Width;
Centerpanel_image.height:=Centerpanel.height;
Centerpanel_image.Picture.Bitmap.Width:=Centerpanel.Width;
Centerpanel_image.Picture.Bitmap.Height:=Centerpanel.Height;
CenterPanel.Visible:=true;

CenterPanel_Image.Canvas.StretchDraw(centerpanel_image.BoundsRect,cm);
CutOutWindowFromMask(centerpanel.Handle,centerpanel_image);

//if (config.theme.sbackground.Color<>clnone) then addcolortobitmap(cm,config.theme.sbackground.Color,resourceskins.alphaamount);
CenterPanel_Image.Canvas.StretchDraw(centerpanel_image.BoundsRect,cm);


end else CenterPanel.Visible:=false;

cm.Free;





butpanelpic.canvas.FloodFill(aspx(2),aspy(2),butpanelpic.canvas.pixels[aspx(2),aspy(2)],fssurface);

//Unneccesary with proper skins

{midpanel.picture.Bitmap.Canvas.Pen.Color:=rgb(0,0,128);
midpanel.Picture.Bitmap.Canvas.Brush.Color:=rgb(0,0,128);
midpanel.picture.Bitmap.Canvas.FillRect(midpanel.ClientRect);

leftpanelpic.picture.Bitmap.Canvas.Pen.Color:=rgb(0,0,128);
leftpanelpic.Picture.Bitmap.Canvas.Brush.Color:=rgb(0,0,128);
leftpanelpic.picture.Bitmap.Canvas.FillRect(leftpanelpic.ClientRect);

rightpanelpic.picture.Bitmap.Canvas.Pen.Color:=rgb(0,0,128);
rightpanelpic.Picture.Bitmap.Canvas.Brush.Color:=rgb(0,0,128);
rightpanelpic.picture.Bitmap.Canvas.FillRect(rightpanelpic.ClientRect);
}
//butpanelpic.picture.Bitmap.Canvas.Pen.Color:=rgb(0,0,128);
//butpanelpic.Picture.Bitmap.Canvas.Brush.Color:=rgb(0,0,128);
//butpanelpic.picture.Bitmap.Canvas.FillRect(butpanelpic.ClientRect);



{midpanel.Picture.Bitmap.Canvas.FloodFill(2,2,rgb(0,0,128),fsSurface);
leftpanelpic.Picture.Bitmap.Canvas.FloodFill(2,2,rgb(0,0,128),fsSurface);
rightpanelpic.Picture.Bitmap.Canvas.FloodFill(2,2,rgb(0,0,128),fsSurface);

butpanelpic.Picture.Bitmap.Canvas.FloodFill(2,2,rgb(0,0,128),fsSurface);
}

//RGB mask not needed with with full skins implemented. Was set to rgb(0,0,128)
bitmapoverbitmap(jbbg,leftpanelpic.Picture.Bitmap,0,leftpanel.left,leftpanel.top);
bitmapoverbitmap(jbbg,rightpanelpic.Picture.Bitmap,0,rightpanel.left,rightpanel.top);
bitmapoverbitmap(jbbg,butpanelpic.Picture.Bitmap,0,rightpanel.left+butpanel.left,rightpanel.top+butpanel.top);
bitmapoverbitmap(jbbg,midpanel.Picture.Bitmap,0,midpanelpanel.left,midpanel.top);


{gothumb.width:=aspx(39);
gothumb.height:=aspy(39);
gothumb.transparent:=true;


gothumb.left:=((rightpanel.width div 2) -(gothumb.width div 2));
gothumb.top:=panel.top+((panel.height div 2) -(gothumb.height div 2))+aspy(10);
gothumb.Picture.Bitmap.LoadFromResourceName(hinstance,'GOTHUMB');
gothumb.BringToFront;
 }





setalbumsizes;
positionlsb(lsb1,lb1);
positionlsb(lsb2,lb2);
positionlsb(lsb3,lb3);
positionlsb(lsb4,lb4);
positionlsb(lsb7,lb7);
positionlsb(lsb8,lb8);
drawalbum(currentalbum);




lsb1playall.font.name:=JUKEBOXFONT;
lsb1playall.font.size:=aspy(5);
lsb1playall.Caption:='Add All';
lsb1playall.left:=((lsb1.width+lsb1.Left)-lsb1playall.width);
lsb1playall.top:=((lsb1.height+lsb1.top))-lsb1playall.height;
lsb1playall.font.color:=clgray;

lsb1playall.Transparent:=true;

lsb2playall.font.name:=JUKEBOXFONT;
lsb2playall.font.size:=aspy(5);
lsb2playall.Caption:='Add All';
lsb2playall.left:=((lsb2.width+lsb2.Left)-lsb2playall.width);
lsb2playall.top:=((lsb2.height+lsb2.top))-lsb1playall.height;;
lsb2playall.font.color:=clgray;
lsb2playall.Transparent:=true;


lsb3playall.font.name:=JUKEBOXFONT;
lsb3playall.font.size:=aspy(5);
lsb3playall.Caption:='Add All';
lsb3playall.left:=((lsb3.width+lsb3.Left)-lsb3playall.width);
lsb3playall.top:=((lsb3.height+lsb3.top))-lsb1playall.height;
lsb3playall.font.color:=clgray;
lsb3playall.Transparent:=true;

lsb4playall.font.name:=JUKEBOXFONT;
lsb4playall.font.size:=aspy(5);
lsb4playall.Caption:='Add All';
lsb4playall.left:=((lsb4.width+lsb4.Left)-lsb4playall.width);
lsb4playall.top:=((lsb4.height+lsb4.top))-lsb1playall.height;;
lsb4playall.font.color:=clgray;
lsb4playall.Transparent:=true;

;

lsb7playall.font.name:=JUKEBOXFONT;
lsb7playall.font.size:=aspy(5);
lsb7playall.Caption:='Add All';
lsb7playall.left:=((lsb7.width+lsb7.Left)-lsb7playall.width);
lsb7playall.top:=((lsb7.height+lsb7.top))-lsb1playall.height;;
lsb7playall.font.color:=clgray;
lsb7playall.Transparent:=true;

lsb8playall.font.name:=JUKEBOXFONT;
lsb8playall.font.size:=aspy(5);
lsb8playall.Caption:='Add All';
lsb8playall.left:=((lsb8.width+lsb8.Left)-lsb8playall.width);
lsb8playall.top:=((lsb8.height+lsb8.top))-lsb1playall.height;;
lsb8playall.font.color:=clgray;
lsb8playall.Transparent:=true;







//butr.Pen.width:=aspx(4);
//butl.Pen.width:=aspx(4);



toprightunderpanel.BringToFront;
botrightunderpanel.bringtofront;
toprightpanel.bringtofront;
botrightpanel.bringtofront;
toppanel.bringtofront;
botpanel.bringtofront;
randompanel.bringtofront;
//blankstartpanel.visible:=false;




searchpanel.Top:=topoverpanel.top;
searchpanel.Left:=topoverpanel.left;
searchpanel.Height:=(botoverpanel.top+botoverpanel.height)-topoverpanel.top;;
searchpanel.Width:=midpanel.Width;

playlistpanel.Top:=topoverpanel.top;
playlistpanel.Left:=topoverpanel.left;
playlistpanel.Height:=(botoverpanel.top+botoverpanel.height)-topoverpanel.top;;
playlistpanel.Width:=midpanel.Width;



setaddall;
lsb1playall.color:=clwhite;
lsb2playall.color:=clwhite;
if tvmode=true then begin
fav.BringToFront;
fav.visible:=true;
fav.top:=0;
fav.left:=rightpanel.Width div 2 - fav.Width div 2;
end;



trackhintpanel.Left:=leftpanel.width;
trackhintpanel.Top:=topoverpanel.Top+topoverpanel.Height;
trackhintpanel.height:=aspy(12);
trackhintpanel.width:=midpanelpanel.width;
trackhintpanel.sourcebitmap:=jbbg;
trackhint.Left:=0;
trackhint.Top:=0;
trackhint.Width:=trackhintpanel.Width;
trackhint.Height:=trackhintpanel.Height;

trackhint.Transparent:=true;
trackhint.Font.size:=aspy(9);
trackhint.caption:='';
trackhint.AutoSize:=false;
trackhint.Visible:=true;
trackhint.BringToFront;
trackhint.Color:=FONTCOL;
//trackhint.Brush.Style:=bsClear;
//trackhint.Brush.Color:=FONTCOL;
//trackhint.Font.Color:=FONTCOL;
trackhint.Font.Name:=JUKEBOXFONT;


if (uppercase(paramstr(2))='/S') then  begin
jukebox.butpanel.visible:=false;
jukebox.keypadpanel.visible:=false;
panelshape1.visible:=false;
panelshape2.visible:=false;
//keyboardpanelpanel.visible:=false;
openpanelpanel.visible:=false;
end;

coverimagepanel.Align:=alclient;
searchpanel.BringToFront;
coverimagepanel.BringToFront;


alphapanel.Visible:=false;
if config.theme.alphaorientation>3 then config.theme.alphaorientation:=0;

if config.theme.alphaorientation=0 then begin
alphapanel.Left:=0;
alphapanel.Top:=panel_searchbut.height;
alphapanel.height:=midpanel.height-(panel_searchbut.height*2);
alphapanel.width:=panel_searchbut.width;
end;

if config.theme.alphaorientation=1 then begin
alphapanel.Left:=panel_searchbut.width;
alphapanel.Top:=0;
alphapanel.height:=panel_searchbut.height;
alphapanel.width:=width-(panel_searchbut.width*2);
end;


if config.theme.alphaorientation=2 then begin
alphapanel.Left:=panel_searchbut.width;
alphapanel.height:=panel_searchbut.height;
alphapanel.Top:=height-alphapanel.height;
alphapanel.width:=width-(panel_searchbut.width*2);
end;

alphapanel.Resize;
alphapanel.Visible:=true;



if config.theme.alphaorientation<>3 then alphapanel.Visible:=true else alphapanel.Visible:=false;
alphapanel.BringToFront;


thumbs.across:=5;
thumbs.scrollwidths:=aspx(round(DEFSCROLLWIDTHS*1.3));

if visualspanelpanel.visible=true then begin
 sizethumbpanel;
end;

trackhint.BringToFront;








//End SetScreen
end;

procedure Tjukebox.butllabelMouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
key : word;
begin

key:=VK_LEFT;
  validatergn(midpanelpanel.handle,0);
formkeydown(nil,key,[]);

if imViewMode.Tag=1 then begin
  ThreedPanel.MouseDown(mbLeft,[],ThreedPanel.Width div 2,100);
  ThreedPanel.MouseMove([],0,100);
  sleep(2);
end;

end;



procedure Tjukebox.butllabelMouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
butl.Picture.Bitmap:=LoadSkinResource('LBUTUP',config.theme.sbut.Skin,config.theme.sbut.Color,false);
antialiasing(butl,ANTIALIASINGAMOUNT);
butllabel.font.size:=aspy(20);
navbuttimer.enabled:=false;
navbuttimer.interval:=DEFAULTINTERVAL;
scrollamountlr:=DEFscrollamountlr;
scrollamountrl:=DEFscrollamountrl;

if imViewMode.Tag=1 then begin
  ThreedPanel.MouseUp(mbLeft,[],0,100);
end;


end;



procedure Tjukebox.butrlabelMouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
key : word;
begin

key:=VK_RIGHT;
formkeydown(nil,key,[]);

if imViewMode.Tag=1 then begin
  ThreedPanel.MouseDown(mbLeft,[],ThreedPanel.Width div 2,300);
  sleep(2);
  ThreedPanel.MouseMove([],ThreedPanel.Width,300);
end;


end;

procedure Tjukebox.butrlabelMouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
butr.Picture.Bitmap:=LoadSkinResource('RBUTUP',config.theme.sbut.Skin,config.theme.sbut.Color,false);
Antialiasing(butr,ANTIALIASINGAMOUNT);
butrlabel.font.size:=aspy(20);
navbuttimer.enabled:=false;
navbuttimer.interval:=DEFAULTINTERVAL;
scrollamountlr:=DEFscrollamountlr;
scrollamountrl:=DEFscrollamountrl;

if imViewMode.Tag=1 then begin
  ThreedPanel.MouseUp(mbLeft,[],ThreedPanel.Width,300);
end;

end;

procedure numButDown(sender : integer);

begin

if SLOWPROCESSOR=TRUE THEN EXIT;
with jukebox do begin
if sender=1 then num7.picture.bitmap:=LoadSkinResource('KEYPADDOWN',config.theme.skeypad.Skin,config.theme.skeypad.Color,false);
if sender=2 then num8.picture.bitmap:=LoadSkinResource('KEYPADDOWN',config.theme.skeypad.Skin,config.theme.skeypad.Color,false);
if sender=3 then num9.picture.bitmap:=LoadSkinResource('KEYPADDOWN',config.theme.skeypad.Skin,config.theme.skeypad.Color,false);
if sender=4 then num4.picture.bitmap:=LoadSkinResource('KEYPADDOWN',config.theme.skeypad.Skin,config.theme.skeypad.Color,false);
if sender=5 then num5.picture.bitmap:=LoadSkinResource('KEYPADDOWN',config.theme.skeypad.Skin,config.theme.skeypad.Color,false);
if sender=6 then num6.picture.bitmap:=LoadSkinResource('KEYPADDOWN',config.theme.skeypad.Skin,config.theme.skeypad.Color,false);
if sender=7 then num1.picture.bitmap:=LoadSkinResource('KEYPADDOWN',config.theme.skeypad.Skin,config.theme.skeypad.Color,false);
if sender=8 then num2.picture.bitmap:=LoadSkinResource('KEYPADDOWN',config.theme.skeypad.Skin,config.theme.skeypad.Color,false);
if sender=9 then num3.picture.bitmap:=LoadSkinResource('KEYPADDOWN',config.theme.skeypad.Skin,config.theme.skeypad.Color,false);
if sender=0 then num10.picture.bitmap:=LoadSkinResource('KEYPADDOWN',config.theme.skeypad.Skin,config.theme.skeypad.Color,false);
if sender=-1 then num11.picture.bitmap:=LoadSkinResource('KEYPADDOWN',config.theme.skeypad.Skin,config.theme.skeypad.Color,false);
if sender=-2 then num12.picture.bitmap:=LoadSkinResource('KEYPADDOWN',config.theme.skeypad.Skin,config.theme.skeypad.Color,false);
if sender=-3 then num13.picture.bitmap:=LoadSkinResource('WIDEBUTDOWN',config.theme.skeypad.Skin,config.theme.skeypad.Color,false);
end;
//jukebox.keypadpanel.repaint;
end;

procedure numButUp(sender : integer);
begin
if SLOWPROCESSOR=TRUE then exit;
with jukebox do begin
num7.picture.bitmap:=LoadSkinResource('KEYPADUP',config.theme.skeypad.Skin,config.theme.skeypad.Color,false);
num8.picture.bitmap:=LoadSkinResource('KEYPADUP',config.theme.skeypad.Skin,config.theme.skeypad.Color,false);
num9.picture.bitmap:=LoadSkinResource('KEYPADUP',config.theme.skeypad.Skin,config.theme.skeypad.Color,false);
num4.picture.bitmap:=LoadSkinResource('KEYPADUP',config.theme.skeypad.Skin,config.theme.skeypad.Color,false);
num5.picture.bitmap:=LoadSkinResource('KEYPADUP',config.theme.skeypad.Skin,config.theme.skeypad.Color,false);
num6.picture.bitmap:=LoadSkinResource('KEYPADUP',config.theme.skeypad.Skin,config.theme.skeypad.Color,false);
num1.picture.bitmap:=LoadSkinResource('KEYPADUP',config.theme.skeypad.Skin,config.theme.skeypad.Color,false);
num2.picture.bitmap:=LoadSkinResource('KEYPADUP',config.theme.skeypad.Skin,config.theme.skeypad.Color,false);
num3.picture.bitmap:=LoadSkinResource('KEYPADUP',config.theme.skeypad.Skin,config.theme.skeypad.Color,false);
num10.picture.bitmap:=LoadSkinResource('KEYPADUP',config.theme.skeypad.Skin,config.theme.skeypad.Color,false);
num11.picture.bitmap:=LoadSkinResource('KEYPADUP',config.theme.skeypad.Skin,config.theme.skeypad.Color,false);
num12.picture.bitmap:=LoadSkinResource('KEYPADUP',config.theme.skeypad.Skin,config.theme.skeypad.Color,false);
num13.picture.bitmap:=LoadSkinResource('WIDEBUTUP',config.theme.skeypad.Skin,config.theme.skeypad.Color,false);
end;
end;




procedure Tjukebox.rightpanelpicMouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
x:=mouse.cursorpos.x-(rightpanel.left+keypadpanel.left);
y:=mouse.cursorpos.y-(rightpanel.top+keypadpanel.top);

if (x>=aspx(4)) and (x<=aspx(46)) and (y>=aspy(4)) and (y<=aspy(44)) then numbutdown(7);
if (x>=aspx(49)) and (x<=aspx(89)) and (y>=aspy(4)) and (y<=aspy(44)) then numbutdown(8);
if (x>=aspx(93)) and (x<=aspx(134)) and (y>=aspy(4)) and (y<=aspy(44)) then numbutdown(9);

if (x>=aspx(4)) and (x<=aspx(46)) and (y>=aspy(47)) and (y<=aspy(89)) then numbutdown(4);
if (x>=aspx(49)) and (x<=aspx(89)) and (y>=aspy(47)) and (y<=aspy(89)) then numbutdown(5);
if (x>=aspx(93)) and (x<=aspx(134)) and (y>=aspy(47)) and (y<=aspy(89)) then numbutdown(6);

if (x>=aspx(4)) and (x<=aspx(46)) and (y>=aspy(91)) and (y<=aspy(133)) then numbutdown(1);
if (x>=aspx(49)) and (x<=aspx(89)) and (y>=aspy(91)) and (y<=aspy(133)) then numbutdown(2);
if (x>=aspx(93)) and (x<=aspx(134)) and (y>=aspy(91)) and (y<=aspy(133)) then numbutdown(3);

if (x>=aspx(4)) and (x<=aspx(46)) and (y>=aspy(136)) and (y<=aspy(177)) then numbutdown(0);
if (x>=aspx(49)) and (x<=aspx(89)) and (y>=aspy(136)) and (y<=aspy(177)) then numbutdown(-1);
if (x>=aspx(93)) and (x<=aspx(134)) and (y>=aspy(136)) and (y<=aspy(177)) then numbutdown(-2);

if (x>=aspx(4)) and (x<=aspx(136)) and (y>=aspy(180)) and (y<=aspy(200)) then numbutdown(-3);
end;

procedure Tjukebox.numClick(Sender: TObject);
begin
if noinput=true then exit;
if sender=numlabel1 then dolcd(7,lcddelay);
if sender=numlabel2 then dolcd(8,lcddelay);
if sender=numlabel3 then dolcd(9,lcddelay);
if sender=numlabel4 then dolcd(4,lcddelay);
if sender=numlabel5 then dolcd(5,lcddelay);
if sender=numlabel6 then dolcd(6,lcddelay);
if sender=numlabel7 then dolcd(1,lcddelay);
if sender=numlabel8 then dolcd(2,lcddelay);
if sender=numlabel9 then dolcd(3,lcddelay);
if sender=numlabel10 then dolcd(0,lcddelay);
if sender=numlabel11 then begin; errortime:=ERRORTIMEOUTCOUNT;dolcd(-1,lcddelay);end;
if sender=numlabel12 then dolcd(-2,lcddelay);
if sender=numlabel13 then begin;
 if mainform.dplaylist.items.count>0 then begin

    mainform.dplaylist.itemindex:=mainform.dplaylist.items.count-1;
    mainform.DelClick(nil);
 end;

end;
end;

procedure Tjukebox.FormCreate(Sender: TObject);
var
isodd : boolean;
begin
firstrun:=false;
credit:=TCredits.create;
BackGroundTimer:=TTimer.Create(self);
BackGroundTimer.OnTimer:=BackGroundTimerTimer;
BackGroundCanAutoPlay:=true;
BackgroundTimer.Interval:=60000;
visualspanelpanel.Visible:=false;


Fadetimer:=TTimer.Create(self);
Fadetimer.ontimer:=fadetimertimer;
Fadetimer.enabled:=false;
Fadetimer.interval:=100;

if config.creditsystem=true then BackGroundTimer.enabled:=true else BackGroundTimer.enabled:=false;
if config.bgduration=0 then BackGroundTimer.Enabled:=false;

if config.trackslogfile<>'' then begin
  log:=tlogfile.Create(true);
  log.configfile:=config.trackslogfile;
end;


mainform.dalbumlist.sorted:=false;
mainform.albumlist.sorted:=false;
initerrorbitmaps;
color:=clblack;



tv_currentlsb:=0;
tv_lsb:=lsb1;


NORMALLCDDELAY:= 20;



navbuttimer.interval:=DEFAULTINTERVAL;
if DEBUGON=false then application.onmessage:=jukebox.OnMessage;

coverimagepanel.Visible:=false;

if thumbsdone=false then begin
mainform.visible:=false;
mainform.update;
lcd1count:=1;
lcd2count:=1;
lcdpanelcurrent :=0;
keypadlocked :=false;
currentalbum :=0;
jalbumcount :=0;
moveinprogress :=false;
errortime :=0;
playstime :=0;
errortimer.enabled:=false;
playstimer.enabled:=false;
lcdtext1.caption:='';
lcdtext2.caption:='';
//lcdtext3.caption:='';

searchpanel:=ttracksearch.create(midpanelpanel);
searchpanel.sourcebitmap:=jbbg;
searchpanel.visible:=false;
searchpanel.Parent:=midpanelpanel;
searchpanel.Visible:=false;

playlistpanel:=tplaylistview.create(midpanelpanel);
playlistpanel.sourcebitmap:=jbbg;
playlistpanel.visible:=false;
playlistpanel.Parent:=midpanelpanel;
playlistpanel.play.OnClick:=playlistplayClick;
playlistpanel.remove.OnClick:=playlistremoveClick;
playlistpanel.MoveUp.OnClick:=playlistMoveUpClick;
playlistpanel.MoveDown.OnClick:=playlistMoveDownClick;
playlistpanel.purge.OnClick:=playlistpurgeClick;
playlistpanel.lb.highlightcolor2:=clWhite;
playlistpanel.lb.highlightindex2:=true;

lbhint:=TTransparenthint.create;
lbhint.lab:=@trackhint;
lsb1.itemhint:=lbhint;
lsb2.itemhint:=lbhint;

alphapanel:=talphabar.Create(self);
alphapanel.Font.Color:=rgb(255,255,254);
alphapanel.Font.name:=DEFAULTFONT;
alphapanel.Font.size:=aspy(12);
alphapanel.bringtofront;
alphapanel.OnVirtualKey:=alphapanelvkey;


originaltopPanelProc := toppanel.WindowProc;
toppanel.WindowProc := TopPanelWindowProc;
originalbotPanelProc := botpanel.WindowProc;
botpanel.WindowProc := botPanelWindowProc;
end;





isodd:=false;
jalbumcount:=albumcount;
if jalbumcount mod 2 = 1 then begin
inc(jalbumcount);
isodd:=true;
end;


jalbum:=album;
setlength(jalbum,jalbumcount+1);
if isodd=true then begin
jalbum[jalbumcount].artist:=chr(12);
setlength(thumb,jalbumcount);
end;

if config.hideexit=true then shutdownbut.visible:=false else shutdownbut.visible:=true;
if config.hidepanel=true then begin
       panel.visible:=false;
       openpanelpanel.visible:=true;
       //rightpanel.onmousemove:=formmousemove;
       //midpanel.onmousemove:=formmousemove;
       panel.top:=0;
   end else begin
       panel.visible:=true;
       openpanelpanel.visible:=false;
       rightpanel.onmousemove:=nil;
       midpanel.onmousemove:=nil;
       panel.top:=aspy(11);
   end;



if config.jlastalbum<0  then config.jlastalbum:=1;

currentalbum:=config.jlastalbum;



if currentalbum mod 2 =0 then  dec(currentalbum);
if currentalbum>jalbumcount then currentalbum:=1;

if mainform.play.down=true then playstimer.enabled:=true else playstimer.enabled:=false;
//Drag drop onto album

DragAcceptFiles(toppanel.Handle,true);
DragAcceptFiles(botpanel.Handle,true);

end;


procedure Tjukebox.panelshapeMouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
if sender=rejectshape2 then begin
loadbitmap(reject,'REJECTDOWN');
//panel.refresh;
if autoplaying=true then begin
   try
 //   mainform.mp.stop;
    except;
   end;
   domessage('Rejected Track');
   coverimagepanel.Visible:=false;
   application.processmessages;
   startautoplay;
   exit;
end;
if mainform.play.down=true then begin
   if mainform.dplaylist.itemindex=mainform.dplaylist.items.count-1 then begin
      mainform.stop.down:=true;
      mainform.StopClick(nil);
      domessage('Rejected Track');
      if autoplaymode=true then begin
        startautoplay;
        exit;
      end;
   end;
   mainform.fwdclick(nil);
end
end;
if sender=muteshape2 then begin
if mainform.mutebut.down=true then mainform.mutebut.down:=false else mainform.mutebut.down:=true;
   if mainform.mutebut.down=true then loadbitmap(mute,'MUTEDOWN') else loadbitmap(mute,'MUTEUP');
   mainform.volchange(mainform.mutebut);
end;
if (sender=volumeupshape2)or (sender=volumeuplabel) then begin

volumesender:=volumeupshape2;
volumetimer.Enabled:=true;
if volumeup.tag<>1 then begin
  loadbitmap(volumeup,'VOLUMEDOWN');
  volumeup.tag:=1;
end;
if mainform.vol.position<VOLINCREMENTS then begin
   mainform.vol.position:=mainform.vol.position+1;
   if autoplaying=true then if mainform.vol.Position>config.bgvolumemax then mainform.vol.Position:=config.bgvolumemax;
   if autoplaying=true then config.bgvolume:=mainform.vol.position else config.volume:=mainform.vol.Position;
end;
mainform.volchange(nil);
end;

if (sender=volumedownshape2) or (sender=volumedownlabel) then begin
volumesender:=volumedownshape2;
volumetimer.Enabled:=true;
if volumedown.tag<>1 then begin
  loadbitmap(volumedown,'VOLUMEDOWN');
  volumedown.tag:=1;
end;
if mainform.vol.position>0 then begin
   mainform.vol.position:=mainform.vol.position-1;
   if autoplaying=true then if mainform.vol.Position>config.bgvolumemax then mainform.vol.Position:=config.bgvolumemax;
   if autoplaying=true then config.bgvolume:=mainform.vol.position else config.volume:=mainform.vol.Position;
end;
mainform.volchange(nil);
//panel.repaint;
end;
end;

procedure Tjukebox.panelshapeMouseUp(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
volumetimer.Enabled:=false;
volumetimer.interval:=volumetimerinterval;
volumetimer.tag:=0;
if sender=rejectshape2 then begin
  loadbitmap(reject,'REJECTUP');
  if (playlistpanel.Visible=true) then playlistpanel.Visible:=false;
end;
if mainform.mutebut.down=true then loadbitmap(mute,'MUTEDOWN') else loadbitmap(mute,'MUTEUP');
if (sender=volumeupshape2) or (sender=volumeuplabel) then begin
  loadbitmap(volumeup,'VOLUMEUP');
  volumeup.Tag:=0;
end;
if (sender=volumedownshape2) or (sender=volumedownlabel) then  begin
  loadbitmap(volumedown,'VOLUMEUP');
  volumedown.tag:=0;
end;
//panel.repaint;

end;

procedure Tjukebox.panel_searchbut_imageClick(Sender: TObject);
begin
if panel_searchbut.tag=0 then begin
   setvisualspanel(false);
panel_searchbut_image.Picture.Bitmap:=LoadSkinResource('BLCORNERUP',config.theme.sblcorner.Skin,config.theme.sblcorner.Color,false);
   //panel_kiosk.visible:=true;
  if keyboardshowing=true then osk(false,false);
   panel_searchbut.tag:=1;
   //if jukebox.keyboardpanelpanel.Tag=0 then jukebox.keyboardpanelclick(nil);
   searchpanel.Visible:=true;
   searchpanel.keywords.enabled:=true;
   searchpanel.keywords.SetFocus;
   searchpanel.BringToFront;
   imViewmode.Visible:=false;


     end
   else begin
   panel_searchbut_image.Picture.bitmap:=LoadSkinResource('BLCORNERDOWN',config.theme.sblcorner.Skin,config.theme.sblcorner.Color,false);
   //panel_kiosk.visible:=false;
   panel_searchbut.tag:=0;
   searchpanel.keywords.enabled:=false;
   if keyboardshowing=true then osk(false,false);
    searchpanel.Visible:=false;
    playlistpanel.Visible:=false;
    if config.disable3d=false then imViewmode.Visible:=true;
   end;
end;

procedure Tjukebox.FormPaint(Sender: TObject);
begin
//jukebox.visible:=false;
//setscreen;
//jukebox.visible:=true;
end;




procedure Tjukebox.openpanelMouseMove(Sender: TObject; Shift: TShiftState;
  X, Y: Integer);
begin
panel.visible:=true;
openpanel.picture.bitmap:=LoadSkinResource('RCORNERUP',config.theme.srcorner.Skin,config.theme.srcorner.Color,false);
end;

{procedure Tjukebox.keyboardpanelClick(Sender: TObject);
begin
keyboardpanelpanelClick(nil);
end;
 }
procedure Tjukebox.openpanelClick(Sender: TObject);
begin
if openpanel.tag=0 then begin
   openpanel.Picture.Bitmap:=LoadSkinResource('RCORNERUP',config.theme.srcorner.Skin,config.theme.srcorner.Color,false);
   panel.visible:=true;
   openpanel.tag:=1;
   panel.bringtofront;
   end
   else begin
   openpanel.picture.bitmap:=LoadSkinResource('RCORNERDOWN',config.theme.srcorner.Skin,config.theme.srcorner.Color,false);
   panel.visible:=false;
   openpanel.tag:=0;
   end;
end;


procedure Tjukebox.setvisualspanel(o : boolean);
begin
if o=true then begin
   if (panel_searchbut.tag=1) then panel_searchbut_imageclick(nil);
   if (playlistpanel.Visible=true) then playlistpanel.Visible:=false;
   VisualsPanel.Picture.Bitmap:=LoadSkinResource('LCORNERUP',config.theme.srcorner.Skin,config.theme.srcorner.Color,false);
   VisualsPanel.tag:=1;
   if (playlistpanel.Visible=true) then playlistpanel.Visible:=false;
   if keyboardshowing=true then osk(false,false);
   thumbpanel.visible:=true;
   alphapanel.BringToFront;
   thumbpanel.SetFocus;
   kioskpanelpanel.BringToFront;
   //keyboardpanelpanel.bringtofront;
   imViewmode.Visible:=false;


end else begin
   VisualsPanel.picture.bitmap:=LoadSkinResource('LCORNERDOWN',config.theme.srcorner.Skin,config.theme.srcorner.Color,false);
   VisualsPanel.tag:=0;
   thumbpanel.visible:=false;
       if config.disable3d=false then imViewmode.Visible:=true;
end;

end;

procedure Tjukebox.VisualsPanelClick(Sender: TObject);
begin
if VisualsPanel.tag=0 then begin
   setvisualspanel(true);
    end
   else begin
   setvisualspanel(false);
   end;
end;




procedure Tjukebox.lightstimerTimer(Sender: TObject);
var
inp : TInput;

procedure presskey(vk,scan : word);
begin
fillchar(inp,sizeof(inp),0);
inp.Itype:=INPUT_KEYBOARD;
inp.ki.wVk:=vk;
inp.ki.wScan:=0;
inp.ki.time:=0;
//inp.ki.dwExtractInfo:=0;
inp.ki.dwFlags:=KEYEVENTF_EXTENDEDKEY;
osendinput(1,inp,sizeof(inp));
inp.ki.dwFlags:=KEYEVENTF_KEYUP or KEYEVENTF_EXTENDEDKEY;
osendinput(1,inp,sizeof(inp));
end;




procedure capson;
begin
if getkeystate(VK_CAPITAL)=0 then presskey(VK_CAPITAL,0);
end;

procedure capsoff;
begin
if not(getkeystate(VK_CAPITAL)=0)then presskey(VK_CAPITAL,0);
end;

procedure scrollon;
begin
if getkeystate(VK_SCROLL)=0 then presskey(VK_SCROLL,0);
end;

procedure scrolloff;
begin
if not(getkeystate(VK_SCROLL)=0) then presskey(VK_SCROLL,0);
end;

procedure numon;
begin
if getkeystate(VK_NUMLOCK)=0 then presskey(VK_NUMLOCK,0);
end;

procedure numoff;
begin
if not(getkeystate(VK_NUMLOCK)=0) then presskey(VK_NUMLOCK,0);
end;

procedure off;
begin
numoff;
scrolloff;
capsoff;
end;

begin
if getwindowsversion=1 then begin
 lightstimer.enabled:=false;
 exit;
end;

if sender=nil then begin
 off;
 exit;
end;
if (ledcount>=leddest) then ledcount:=0;
if ledcount=0 then begin
leddest:=(random(200)+1);
lightstimer.interval:=leddest;
ledmode:=random(5)+1;
ledprog:=0;
end;

inc(ledcount);

off;
if ledmode=1 then begin
   if ledprog=0 then numon;
   if ledprog=1 then capson;
   if ledprog=2 then scrollon;
   if ledprog=2 then ledprog:=-1;
   if leddest-ledcount >0 then lightstimer.interval:=leddest-ledcount;
   inc(ledprog);
end;

if ledmode=2 then begin
   if ledprog=0 then numon;
   if ledprog=1 then capson;
   if ledprog=2 then scrollon;
   if ledprog=0 then ledprog:=3;
   if leddest-ledcount >0 then lightstimer.interval:=leddest-ledcount;
   dec(ledprog);
end;

if ledmode=3 then begin
   if ledcount mod 2 =0 then capson else begin
   numon;
   scrollon;
   end;
   if leddest-ledcount >0 then lightstimer.interval:=leddest-ledcount;
end;


if ledmode=4 then begin
   if ledcount mod 2 =0 then begin
   numon;
   capson;
   end
   else begin
   capson;
   scrollon;
   end;

end;


if ledmode=5 then begin
   ledprog:=random(3);
   if ledprog=0 then numon;
   if ledprog=1 then capson;
   if ledprog=2 then scrollon;
   if leddest-ledcount >0 then lightstimer.interval:=leddest-ledcount;
end;

end;

procedure Tjukebox.KioskpanelClick(Sender: TObject);
begin
if playlistpanel.visible  then playlistpanel.Visible:=false;
if kioskpanel.tag=0 then begin
   kioskpanel.picture.bitmap:=LoadSkinResource('BRCORNERUP',config.theme.sbrcorner.Skin,config.theme.sbrcorner.Color,false);
   panel_kiosk.visible:=true;
   kioskpanel.tag:=1;
   if keyboardshowing=true then osk(false,false);

    end
   else begin
   kioskpanel.picture.bitmap:=LoadSkinResource('BRCORNERDOWN',config.theme.sbrcorner.Skin,config.theme.sbrcorner.Color,false);
   panel_kiosk.visible:=false;
   kioskpanel.tag:=0;
    if keyboardshowing=true then osk(false,false);
   end;
end;


procedure Tjukebox.autoplaycbClick(Sender: TObject);
begin
if albumcount=0 then begin
   autoplaycb.checked:=false;
   exit;
end;

//if autoplaymode=true then autoplaymode:=false else autoplaymode:=true;
autoplaymode:=autoplaycb.checked;
if autoplaymode=true then begin
   backgroundtimer.Tag:=0;
   BackGroundTimerCount:=0;
   if config.creditsystem=true then BackGroundTimer.enabled:=true else BackGroundTimer.enabled:=false;
   initautoplay;
   config.autoplay:=true;
   BackGroundCanAutoPlay:=true;
   if mainform.timers.enabled=false then startautoplay;
   domessage('Started Autoplay');
end
else begin
     if (autoplaying=true) then begin
        mainform.StopClick(nil);
        config.autoplay:=false;
        stopautoplay;
        domessage('Stopped Autoplay');
        BackGroundTimer.Enabled:=false;
        backgroundtimer.Tag:=0;
        BackGroundTimerCount:=0;
     end;
end;
end;


procedure Tjukebox.randombutClick(Sender: TObject);
var
n : integer;
begin
  if keyboardshowing=true then osk(false,false);
//if keyboardpanelpanel.tag=1 then keyboardpanelpanelClick(nil);

randompanel.bringtofront;
if randompanel.visible=false then begin
   randompanelok.buttoncolor:=1;
   randompanelcancel.buttoncolor:=2;
   cancelrandomop:=false;
   randomcancel.visible:=false;
   randompanel.visible:=true;
   randompanelok.visible:=true;
   randompanelcancel.visible:=true;
   randompanelselectall.visible:=true;
   randompanelselectnone.visible:=true;
   randompanellb.visible:=true;
   randomcountlabel.left:=randompanellb.left;
   randomcountlabel.top:=randompanellb.top+randompanellb.height;
   randomcountlabel.font.name:=JUKEBOXFONT;
   randomcountlabel.Font.size:=aspy(14);
   randomcountlabel.Font.color:=autoplaycb.font.color;
   randomdicepanel.visible:=false;
   randomdicepanel.left:=(randompanel.width div 2) - (randomdicepanel.Width div 2);
   randomdicepanel.top:=(randompanel.height div 2) - (randomdicepanel.height div 2);
   randomcancel.top:=aspy(100);
   randomcancel.left:=aspx(200);
   randomcancel.font.name:=JUKEBOXFONT;
   randomcancel.font.size:=aspy(14);
   randomcancel.color:=clblack;
   randomcancel.font.color:=autoplaycb.font.color;
   randomcancel.width:=aspx(275);

   initrandom;
   randompanellb.clear;
   for n:=0 to mainform.dalbumlist.items.count-1 do begin


   randompanellb.items.add(mainform.albumlist.items[n]);
   end;
   randomcountlabel.font.color:=FONTCOL;
   randomcountlabel.caption:='Tracks selected: 0';
   end else randompanel.visible:=false;
end;

procedure Tjukebox.randompanelcancelClick(Sender: TObject);
begin
kioskpanelClick(nil);
randompanel.visible:=false;
end;

procedure Tjukebox.randompanellbClick(Sender: TObject);

begin
if randompanellb.itemindex<0 then exit;
if randompanellb.IsSelected(randompanellb.itemindex)=true then begin
randomcountlabel.font.color:=FONTCOL;
randomcountlabel.caption:='Total tracks selected: '+inttostr(addalbum(randompanellb.itemindex));
end
else begin
randomcountlabel.font.color:=FONTCOL;
randomcountlabel.caption:='Total Tracks selected: '+inttostr(removealbum(randompanellb.itemindex));
end;
end;

procedure Tjukebox.randompanelOKClick(Sender: TObject);
begin

if  getrandomtrackcount=0 then begin
 randomcountlabel.font.color:=clred;
 randomcountlabel.caption:='No albums selected.';
 exit;
end;

randomcancel.buttoncolor:=2;
randomcancel.visible:=true;
randompanelok.visible:=false;
randompanelcancel.visible:=false;

randompanelselectall.visible:=false;
randompanelselectnone.visible:=false;
randompanellb.visible:=false;
randomcountlabel.left:=(randompanel.width div 2) - (randomcountlabel.width div 2);
randomcountlabel.top:=(randomdicepanel.height+randomdicepanel.Top)+aspy(50);
randomdicepanel.visible:=true;
application.processmessages;
makerandom(cb);
randompanel.visible:=false;

kioskpanelClick(nil);
application.processmessages;
end;

function Tjukebox.cb(c : integer) : boolean;

begin
randomcountlabel.caption:='Tracks added: '+inttostr(c);

if c mod 20 =0 then begin
   if randomdice.tag=0 then begin
     randomdice.picture.assign(dice1);
   end;
   if randomdice.tag=1 then begin
     randomdice.picture.assign(dice2);
   end;
   if randomdice.tag=2 then begin
     randomdice.picture.assign(dice3);
   end;
   if randomdice.tag=3 then begin
     randomdice.picture.assign(dice4);
   end;

   randomdice.tag:=randomdice.tag+1;
   if randomdice.tag=4 then randomdice.tag:=0;
end;
if c=1 then begin
autoplaying:=false;
mainform.playclick(nil);
end;

application.ProcessMessages;
if cancelrandomop=true then result:=true else result:=false;

end;

procedure Tjukebox.randompanelselectallClick(Sender: TObject);
var
n : integer;
begin
initrandom;
randompanellb.selectall;
randomcountlabel.font.color:=FONTCOL;
for n:=0 to randompanellb.count do begin
randomcountlabel.caption:='Total tracks selected: '+inttostr(addalbum(n));
end;
end;

procedure Tjukebox.randompanelselectnoneClick(Sender: TObject);
begin
randompanellb.selectnone;
initrandom;
randomcountlabel.font.color:=FONTCOL;
randomcountlabel.caption:='Total tracks selected: 0';
end;

procedure Tjukebox.RandomCancelClick(Sender: TObject);
begin
cancelrandomop:=true;
end;

procedure Tjukebox.rejectallClick(Sender: TObject);
begin
if jukebox.autoplaycb.checked=true then begin
jukebox.autoplaycb.checked:=false;
jukebox.autoplaycbclick(nil);
if video.Visible=true  then video.hide;
if jukebox.coverimagepanel.Visible=true then jukebox.coverimagepanel.Visible:=false;
end;

mainform.clearlistclick(nil);
loadblankmp3file;
domessage('Rejected all tracks');
end;

procedure Tjukebox.lsb1playallClick(Sender: TObject);
begin
playall(lsb1);
end;

procedure Tjukebox.lsb2playallClick(Sender: TObject);
begin
playall(lsb2);
end;

procedure Tjukebox.cdMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
var
scrap : string;
begin
  if button=mbRight then begin
   ShellExecute(Handle, 'open', pchar(config.path+album[timage(sender).tag].path), nil, nil, SW_SHOWNORMAL);
   mainform.maketitles(album[timage(sender).tag].path,0,scrap);
   scrap:=stringreplace(album[timage(sender).tag].path,'__',' ',[rfReplaceAll, rfIgnoreCase]);
   ShellExecute(Handle,'open',pchar('https://www.google.com/images?q='+scrap+'&godo=Go'),nil,nil,SW_SHOWNORMAL);
  end;
end;

procedure Tjukebox.cdClick(Sender: TObject);
var videomode : boolean;
begin
if (sender=cd3) or (sender=cd4) then begin
navbuttimer.Interval:=DEFAULTINTERVAL;
butllabelmousedown(nil,mbleft,[],0,0);
butllabelmouseup(nil,mbleft,[],0,0);

exit;
end;

if (uppercase(copy(mainform.mp.filename,length(mainform.mp.filename),1))='G') then begin

  {$IFDEF KIOSK}
  videomode:=true;
  {$ENDIF}
  {$IFNDEF KIOSK}
  videomode:=false;
  {$ENDIF}

     if ((videomode=false) or (config.videomonitor=0)) then begin


   mainform.mp.Display:=jukebox.coverimagepanel;
   jukebox.jbcovershow('');
   mainform.mp.DisplayRect:=jukebox.coverimagepanel.ClientRect;
   end else begin
   videoshow;
   end;
end else jbcovershow(config.path+album[timage(sender).tag].path);

end;

procedure Tjukebox.advancedbutClick(Sender: TObject);

begin
keypadlocked:=true;
//advanced form
//advanced.color:=clblack;
if keyboardshowing=true then osk(false,false);
advanced.left:=0;
advanced.width:=jukebox.clientwidth;
advanced.height:=jukebox.clientheight;
advanced.top:=0;
advanced.visible:=true;
unlocklabel.Font.color:=FONTCOL;
advanced.bringtofront;

setcode.font.color:=FONTCol;
codepanel.color:=clblack;
codepanel.left:=(jukebox.clientwidth div 2) - (codepanel.width div 2);
advancedok.font.color:=FONTCOL;
advancedok.left:=codepanel.left+codepanel.width+aspx(10);

code.text:=config.password;
editpanel.width:=(jukebox.clientwidth) -(aspx(30)*2);
editpanel.left:=(jukebox.clientwidth div 2) - (editpanel.width div 2);
editpanel.height:=jukebox.clientheight-(editpanel.top+aspy(50)+optionspanel.height);
editpanel.color:=clblack;
editlabel.font.color:=FONTCOL;
editlb.color:=clblack;
editlb.linespacing:=2;
editlb.font.name:=JUKEBOXFONT;
editlb.font.size:=aspy(14);
editlb.font.color:=clgray;
editlb.width:=editpanel.width-aspx(100);
editlb.left:=(editpanel.width div 2) - (editlb.width div 2);
editlb.top:=editlabel.top+editlabel.height+aspy(10);
editlb.height:=editpanel.height-(editlb.top+(aspy(10)));
editlb.numbercolor:=clwhite;


optionspanel.width:=editpanel.width;
optionspanel.top:=editpanel.top+editpanel.height+aspy(10);
optionspanel.left:=(jukebox.clientwidth div 2) - (optionspanel.width div 2);
volumeshow.font.color:=FONTCOL;
addallshow.font.color:=FONTCOL;
norepeatcb.font.color:=FONTCOL;
volumeshow.font.size:=aspx(10);
addallshow.font.size:=aspx(10);
norepeatcb.font.size:=aspx(10);

volumeshow.left:=aspx(10);
volumeshow.top:=(tpanel(volumeshow.parent).height div 2) - (volumeshow.Height div 2);
addallshow.left:=volumeshow.width+aspx(10)+volumeshow.left;
addallshow.top:=volumeshow.top;
norepeatcb.left:=addallshow.left+addallshow.width+aspx(10);
norepeatcb.top:=volumeshow.top;
volumeshow.checked:=config.jukeboxvolumepanel;
addallshow.checked:=config.jukeboxaddall;
norepeatcb.checked:=config.norepeat;
optionspanel.refresh;

GoThemeManager.font.name:=JUKEBOXFONT;
GoThemeManager.font.color:=FONTCOL;
GoThemeManager.font.size:=aspy(10);
GoThemeManager.top:=(codepanel.Height div 2) + ((jbinfogo.height div 2)+aspy(5));
GoThemeManager.left:=0; //(codepanel.left div 2) - (GoThemeManager.width div 2);
GoThemeManager.caption:='Lauch Theme Manager';
GoThemeManager.buttoncolor:=4;

GoCommercialManager.font.name:=JUKEBOXFONT;
GoCommercialManager.font.color:=FONTCOL;
GoCommercialManager.font.size:=aspy(10);
GoCommercialManager.top:=(jukebox.clientheight)-(GoCommercialManager.height+aspy(10));
GoCommercialManager.left:=(jukebox.clientwidth div 2)- (GoCommercialManager.width div 2);
GoCommercialManager.caption:='Commerce Management';
GoCommercialManager.buttoncolor:=4;
if config.creditsystem=true then GoCommercialManager.visible:=true;




jbinfogo.font.name:=JUKEBOXFONT;
jbinfogo.font.color:=FONTCOL;
jbinfogo.font.size:=aspy(10);
jbinfogo.top:=(codepanel.Height div 2) - ((jbinfogo.height div 2)+aspy(5));
jbinfogo.left:=GoThemeManager.Left;
jbinfogo.caption:='Statistics';

advanced.Repaint;



reloadeditlist;

if currentalbum>0 then editlb.topmost:=currentalbum-1;

editlb.setfocus;

end;

procedure Tjukebox.advancedOKClick(Sender: TObject);
begin
writeini;
drawalbum(currentalbum);
setaddall;
keypadlocked:=false;
advanced.visible:=false;
osk(false,false);

end;

procedure Tjukebox.codeEnter(Sender: TObject);
begin
osk(true,false);
code.selstart:=1;
code.sellength:=3;
end;

procedure Tjukebox.codeExit(Sender: TObject);
begin
osk(false,false);
end;

procedure Tjukebox.setcodeClick(Sender: TObject);
var
v,s  : integer;

begin
osk(false,false);
editlb.setfocus;
config.password:=code.text;
val(code.text,v,s);
// v:=strtoint(code.text);
code.text:=format('%.3d',[v]);
end;

procedure Tjukebox.codeKeyPress(Sender: TObject; var Key: Char);
begin
if ord(key)=8 then exit;
if (ord(key)<ord('0')) or (ord(key)>ord('9')) then key:=#0;
end;



procedure Tjukebox.coverimageClick(Sender: TObject);
begin
  coverimagepanel.visible:=false;
end;

procedure Tjukebox.codeClick(Sender: TObject);
begin
code.selstart:=0;
code.sellength:=3;
code.setfocus;
end;

procedure Tjukebox.codefirstClick(Sender: TObject);
begin
codeclick(nil);
end;


procedure Tjukebox.goplaylistviewClick(Sender: TObject);
var
n,x : integer;
p : integer;
alb,art : string;
j : integer;
begin
playlistpanel.lb.clear;
kioskpanelClick(sender);
application.ProcessMessages;
playlistpanel.bringtofront;
playlistpanel.lb.drawmode:=false;
for n:=0 to mainform.dplaylist.Items.Count-1 do begin
p:=0;
  for x := 0 to albumcount do begin
  application.processmessages;
    if dplaylistmatrixalb[n]=config.path+main.album[x].path then begin
        p:=x;
        break;
        end;

  end;


  extractalbumandaristfrompath(dplaylistmatrixalb[n],art,alb);
   j:=thumbs.lookupalbum(p);

    if (visualspanelpanel.visible=true) and (j<>-1) then playlistpanel.lb.additemandinfo(art+' - '+alb+' -  '+mainform.dplaylist.items[n],0,0,thumbs.pl.items[j].picture,'','')
                            else playlistpanel.lb.items.add(art+' - '+alb+' -  '+mainform.dplaylist.items[n]);

     //editlb.additemandinfo(mainform.albumlist.items[n],0,0,thumbs.pl.pictures[n],'');
end;

//if mainform.dplaylist.itemindex>-1 then playlistpanel.lb.settopmost(mainform.dplaylist.itemindex);
playlistpanel.lb.drawmode:=true;
playlistpanel.Visible:=true;

playlistpanel.lb.highlighteditem2:=mainform.dplaylist.itemindex;
playlistpanel.lb.topmost:=playlistpanel.lb.highlighteditem2;


end;

procedure Tjukebox.GoThemeManagerClick(Sender: TObject);
begin
advancedOKclick(sender);
gothemes;
end;

//Commerce Settings
procedure Tjukebox.GoCommercialManagerClick(Sender: TObject);
var
curobj : TNumericInput;
curlab : Tlabel;
sp : integer;
begin
cmCredit.caption:='Coin credits: '+inttostr(config.credittotal)+' Free credits: '+inttostr(config.freecredittotal);

if (sender=cmResetCreditStats) then exit;


Commerce.left:=0;
Commerce.width:=jukebox.clientwidth;
Commerce.height:=jukebox.clientheight;
Commerce.top:=0;
Commerce.Font.Size:=aspy(10);
commerce.sourcebitmap:=bg;
CommerceOK.Top:=0;

cmTitleLab.Font.Size:=aspy(14);
cmTitleLab.left:=0;
cmtitlelab.width:=jukebox.width;
cmtitlelab.Top:=0;
cmtitlelab.Alignment:=taCenter;
cmtitlelab.AutoSize:=true;

cmcreditpanel.Font.size:=aspy(8);
cmcreditpanellab.left:=(aspy(10));
cmcreditpanellab.Top:=cmtitlelab.Height+cmtitlelab.Top+aspy(10);
cmcreditpanel.Height:=aspy(60);
cmcreditpanel.top:=cmCreditpanellab.Top+cmCreditpanellab.height+aspy(10);
cmcreditpanel.width:=jukebox.Width-(aspx(100));
cmcreditpanel.Left:=(jukebox.width div 2) - (cmcreditpanel.Width div 2);
cmcreditpanel.color:=clblack;

cmBackgroundpanel.Font.size:=aspy(8);
cmBackgroundpanellab.Top:=cmcreditpanel.Height+cmcreditpanel.Top+aspy(10);
cmBackgroundpanel.Height:=cmCreditpanel.Height;
cmBackgroundpanel.top:=cmBackgroundpanellab.Top+cmBackgroundpanellab.Height+aspy(10);
cmBackgroundpanel.width:=cmcreditpanel.Width;
cmBackgroundpanel.Left:=cmcreditpanel.left;
cmBackgroundpanellab.left:=cmcreditpanellab.left;
cmBackGroundPanel.color:=clblack;

cmStatisticspanel.Font.size:=aspy(8);
cmStatisticsPanellab.Top:=cmBackgroundpanel.Height+cmBackgroundpanel.Top+aspy(10);
cmStatisticsPanel.top:=cmStatisticsPanellab.Top+cmStatisticsPanellab.Height+aspy(10);
cmStatisticsPanel.height:=jukebox.Height-(cmstatisticspanel.Top+aspy(50));
cmStatisticsPanel.width:=cmcreditpanel.Width;
cmStatisticsPanel.Left:=cmcreditpanel.left;
cmStatisticsPanellab.left:=cmcreditpanellab.left;
cmStatisticsPanel.color:=clblack;


with cmPlaysPerCredit do begin
 min:=1;
 max:=100;
 value:=config.playspercoincredit;
 cmPlaysPerCreditlab.top:=aspy(5);
 top:=cmPlaysPerCreditlab.top+cmPlaysPerCreditlab.height+aspy(5);
 width:=aspx(100);
 left:=(cmcreditpanel.width div 4)-(width div 2);
 cmPlaysPerCreditlab.left:=left;
 cmPlaysPerCreditlab.Alignment:=taCenter;
 cmPlaysPerCreditlab.width:=width;
 font.Color:=clLime;
end;

with cmallowfreecredit do begin
width:=200;
 left:=(cmcreditpanel.width div 2)+((cmcreditpanel.width div 4)-(cmallowfreecredit.width div 2));
 checked:=config.allowfreecredit;
end;

CurLab:=CmBgVolumelab;
CurObj:=CmBgVolume;
CurObj.value:=config.bgVolumemax;
CurObj.max:=VOLINCREMENTS;

CurLab.top:=aspy(5);
CurObj.width:=aspx(100);
CurObj.top:=CurLab.top+CurLab.height+aspy(5);
CurLab.Alignment:=taCenter;
CurObj.font.Color:=clLime;

sp:=(cmcreditpanel.width div 3)-((cmcreditpanel.width div 3) div 2);

CurObj.left:=(sp)-(CurObj.width div 2);
CurLab.left:=(sp)-(CurLab.width div 2);


CurLab:=CmBgDurationlab;
CurObj:=CmBgDuration;
CurObj.value:=config.bgDuration;

CurLab.top:=aspy(5);
CurObj.width:=aspx(100);
CurObj.top:=CurLab.top+CurLab.height+aspy(5);
CurLab.Alignment:=taCenter;
CurObj.font.Color:=clLime;

CurObj.left:=(cmcreditpanel.width div 2)-(CurObj.width div 2);
CurLab.left:=(cmcreditpanel.width div 2)-(CurLab.width div 2);

CurLab:=CmBgWaitTimelab;
CurObj:=CmBgWaitTime;
CurObj.value:=config.bgwaittime;

CurLab.top:=aspy(5);
CurObj.width:=aspx(100);
CurObj.top:=CurLab.top+CurLab.height+aspy(5);
CurLab.Alignment:=taCenter;
CurObj.font.Color:=clLime;

CurObj.left:=cmcreditpanel.width-(CmBgVolume.left+CmBgVolume.width);
CurLab.left:=CurObj.left+((CurObj.width div 2)-CurLab.width div 2);

cmResetCreditStats.Width:=aspx(200);
cmResetCreditStats.Left:=(cmStatisticsPanel.width-cmResetCreditStats.Width+aspx(20));
cmResetCreditStats.top:=aspy(20);

with cmCreditLab do begin
font.size:=aspy(10);
caption:='Credits: ';
top:=cmResetCreditStats.top;
left:=aspy(10);
end;

with  cmCredit do begin
font.Color:=clLime;
font.size:=aspy(10);
top:=cmCreditlab.top;
left:=cmCreditlab.Left+cmCreditlab.Width+aspx(10);
end;

with cmTop100Lab do begin
caption:='Top 100 Plays:- (By popularity then most recent in the last month)';
top:=cmCredit.top+aspy(20);
left:=aspy(10);
end;

with cmTop100 do begin
top:=cmTop100lab.top+aspy(20);
left:=aspy(50);
width:=cmStatisticspanel.width-(left*2);
height:=(cmStatisticspanel.height)-(top+aspy(50));
color:=clBlack;
font.Color:=FONTCOL;
font.Size:=aspy(8);
font.name:='FONTNAME';
end;

if config.trackslogfile='' then begin
  cmTop100lab.Visible:=false;
  cmTop100.Visible:=false;
end else begin
  log.Suspended:=false;
end;






Commerce.visible:=true;
Commerceok.font.color:=FONTCOL;
Commerceok.left:=jukebox.ClientWidth-(commerceok.Width+aspx(10));
commerce.BringToFront;

end;


procedure Tjukebox.cmResetCreditStatsClick(Sender : TObject);
begin
  config.credittotal:=0;
  config.freecredittotal:=0;
  writeini;
  GoCommercialManagerClick(cmResetCreditStats);
end;


procedure Tjukebox.CommerceOKClick(Sender: TObject);
begin
  mainform.volChange(self);
  Commerce.visible:=false;
  config.playspercoincredit:=cmPlayspercredit.value;
  config.allowfreecredit:=cmAllowFreeCredit.checked;
  config.bgvolumemax:=cmbgvolume.value;
  config.bgduration:=cmbgduration.value;
  config.bgwaittime:=cmbgwaittime.value;
  if config.trackslogfile<>'' then begin
    log.Terminate;
    log.waitfor;
    log.free;
    log:=tlogfile.Create(true);
    log.configfile:=config.trackslogfile;
  end;
  writeini;
end;



procedure Tjukebox.thumbsClick(Sender: TObject);
begin
if tvmode=true then begin
lsb1.losefocus;
lsb2.losefocus;
end;

if mainform.albumlist.items.count = 0 then exit;

if thumbs.itemindex<0 then exit;

currentalbum:=thumbs.pl.items[thumbs.itemindex].album;


if imViewMode.Tag=1 then begin
  currentalbum:=thumbs.pl.items[thumbs.itemindex].album;
  if currentalbum>jalbumcount then currentalbum:=1;

  DrawAlbum3D(currentalbum,0);
  drawalbum3D(currentalbum,-1);
end else begin

if thumbs.pl.items[thumbs.itemindex].album mod 2 = 0 then currentalbum:=thumbs.pl.items[thumbs.itemindex].album;
drawalbum(currentalbum);
end;


setvisualspanel(false);

if thumbmode=1 then begin
jukebox.close;
thumbmode:=0;
end;


    if config.disable3d=false then imViewmode.Visible:=true;




end;



procedure tjukebox.movealbuml3D;
begin
//ThreeDPanel.MoveLeft
end;

procedure tjukebox.movealbumr3D;
begin
//ThreeDPanel.MoveRight;
end;


procedure tjukebox.movealbumlr;
var
n : integer;
dest : integer;
begin
if tvmode=true then begin
   lsb1.losefocus;
   lsb2.losefocus;
   tv_currentlsb:=0;
   tv_lsb:=lsb1;
end;
if DEBUGON=true then startprofiletimer('movealbumlr');

moveinprogress:=true;
toprightpanel.bringtofront;
botrightpanel.bringtofront;
dest:=toppanel.left;
n:=toprightpanel.left;


lsb1.inmotion:=true;
lsb2.inmotion:=true;
lsb3.inmotion:=true;
lsb4.inmotion:=true;
lsb7.inmotion:=true;
lsb8.inmotion:=true;



scrollamountlr:=DEFscrollamountlr;
if slowprocessor=false then begin
while (n>dest) do begin
   n:=n-scrollamountlr;
   if n>dest then begin
      toprightpanel.left:=n;
      botrightpanel.left:=n;
      jukebox.lcd3.timercall(nil);
   end else begin
      toprightpanel.left:=dest;
      botrightpanel.left:=dest;
      break;
   end;

   toprightpanel.repaint;
   botrightpanel.repaint;

  //application.processmessages;

end;
end else begin
      toprightpanel.left:=dest;
      botrightpanel.left:=dest;
      //application.processmessages;
end;

application.processmessages;
moveinprogress:=false;

lsb1.inmotion:=false;
lsb2.inmotion:=false;
lsb3.inmotion:=false;
lsb4.inmotion:=false;
lsb7.inmotion:=false;
lsb8.inmotion:=false;

if DEBUGON=true then  endprofiletimer;


end;

procedure tjukebox.movealbumrl;
var
n : integer;
dest : integer;
begin
if tvmode=true then begin
   lsb1.losefocus;
   lsb2.losefocus;
   tv_currentlsb:=0;
   tv_lsb:=lsb1;
end;

moveinprogress:=true;
toppanel.bringtofront;
botpanel.bringtofront;
dest:=toprightpanel.left;


n:=toppanel.left;

lsb1.inmotion:=true;
lsb2.inmotion:=true;
lsb3.inmotion:=true;
lsb4.inmotion:=true;
lsb7.inmotion:=true;
lsb8.inmotion:=true;


if slowprocessor=false then begin
while (n<dest) do begin
   n:=n+scrollamountrl;
   if n<dest then begin
      toppanel.left:=n;
      botpanel.left:=n;
      jukebox.lcd3.timercall(nil);
      end else begin
     toppanel.left:=dest;
     botpanel.left:=dest;
   end;
   application.processmessages;
end;
end else begin
     toppanel.left:=dest;
     botpanel.left:=dest;
     application.processmessages;

end;

moveinprogress:=false;
lsb1.inmotion:=false;
lsb2.inmotion:=false;
lsb3.inmotion:=false;
lsb4.inmotion:=false;
lsb7.inmotion:=false;
lsb8.inmotion:=false;

end;

procedure Tjukebox.navbuttimerTimer(Sender: TObject);
begin
{if SLOWPROCESSOR=TRUE THEN begin
navbuttimer.interval:=DEFAULTINTERVAL;
scrollamountlr:=aspx(DEFScrollamountlr)*10;
scrollamountrl:=aspx(DEFScrollamountrl)*10;
//if navbuttimer.tag=0 then butllabelMouseDown(nil,mbLeft,[], 0, 0) else butrlabelMouseDown(nil,mbLeft,[], 0, 0);
exit;
end; }

if navbuttimer.Interval>100 then navbuttimer.Interval:=navbuttimer.Interval-2;
if navbuttimer.tag=0 then butllabelMouseDown(nil,mbLeft,[], 0, 0) else butrlabelMouseDown(nil,mbLeft,[], 0, 0);
{
TAKEN OUT FOR AMERICANA and not great anyway (multiple scroll speed)
cdwidth:=(DEFAULTINTERVAL - (DEFAULTINTERVAL div cd1.width))-navbuttimer.interval;
scrollamountlr:=aspx(cdwidth);
scrollamountrl:=aspx(cdwidth);
 }


end;

procedure Tjukebox.FormKeyUp(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
if (ssAlt in Shift) then begin
   if key=ord('O') then  begin
    panelshapeMouseUp(volumeupshape2,mbleft,[], 0, 0);
   end;
   if key=ord('K') then begin
      panelshapeMouseUp(volumedownshape2,mbleft,[], 0, 0);
   end;
  exit;
end;

if Key=VK_LEFT then butllabelmouseup(nil,mbleft,[],0,0);
if Key=VK_RIGHT then butrlabelmouseup(nil,mbright,[],0,0);

end;

procedure Tjukebox.editlbClick(Sender: TObject);
var
lastedit : integer;
begin
if editlb.itemindex<0 then exit;
editlb.visible:=false;
application.processmessages;
lastedit:=editlb.topmost;
doedit(editlb.itemindex+1);
editlb.visible:=true;
editlb.setfocus;
reloadeditlist;
if currentalbum>0 then editlb.topmost:=lastedit;
{if res=8 then begin
jukebox.Close;
jukebox.free;
jukebox:=nil;
mainform.hide;
mainform.formcreate(nil);
end;  }
end;

procedure Tjukebox.volumeshowClick(Sender: TObject);
begin
config.jukeboxvolumepanel:=volumeshow.checked;
config.jukeboxaddall:=addallshow.checked;
writeini;
setopenpanel;
end;

procedure Tjukebox.addallshowClick(Sender: TObject);
begin
config.jukeboxvolumepanel:=volumeshow.checked;
config.jukeboxaddall:=addallshow.checked;
writeini;
end;

procedure Tjukebox.ShutdownbutClick(Sender: TObject);
begin




writeini;
if keyboardshowing=true then osk(false,false);


if config.showminimize=1 then begin
    jukebox.WindowState:=wsMinimized;
    mainform.mp.stop;
    exit;
end;

//showminimize=2 then switch to previous app
if config.showminimize=2 then begin
    rejectallClick(self);
    KioskpanelClick(self);
    enumwindows(@enumwindowsswitch,0);

    exit;
end;


{$IFDEF KIOSK}

freeskinresources;


if kiosk=true then begin

lcd3.running:=false;
mainform.numberoftracks.enabled:=false;
volumetimer.Enabled:=false;
volumedisplay.delay.Enabled:=false;
if config.poweroff=true then WinExit(EWX_SHUTDOWN or EWX_FORCE);

   try
   if visualspanelpanel.visible=false then begin
   if initcovers<>nil then begin
   initcovers.terminate;
   end;
   end;
   except;
   end;
try

mainform.mp.stop
except
end;

end;
{$ENDIF}
application.OnMessage:=nil;
application.terminate;
end;

{procedure Tjukebox.keyboardpanelpanelClick(Sender: TObject);
var
alpha : boolean;
begin
if (playlistpanel.Visible=true) then playlistpanel.Visible:=false;
alpha:=true;
if panel_searchbut.tag=1 then alpha:=false;


//if keyboardpanelpanel.tag=0 then begin loadbitmap(keyboardpanel,'LCORNERUP');osk(true,alpha); keyboardpanelpanel.tag:=1;end else begin;loadbitmap(keyboardpanel,'LCORNERDOWN');keyboardpanelpanel.tag:=0;osk(false,alpha);end;
end;

 }
procedure Tjukebox.keypadpanelMouseUp(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
if (playlistpanel.Visible=true) then playlistpanel.Visible:=false;
numbutup(0);
end;





procedure Tjukebox.FormResize(Sender: TObject);
begin
if jukebox.windowstate=wsMinimized then exit;

thumbpanel.sourcebitmap:=jbbg;
advanced.sourcebitmap:=bg;
randompanel.sourcebitmap:=bg;
randomdicepanel.sourcebitmap:=bg;


{$IFDEF KIOSK}
jukebox.BorderStyle:=bsNone;
jukebox.WindowState:=wsMaximized;
jukebox.Top:=0;
jukebox.left:=0;
{$ENDIF}

if width<>screen.width then exit;
if height<>screen.height then exit;




//if jukebox.visible=false then exit;

//if width>screen.width then width:=screen.width;
//height:=round((width*(screen.height / screen.width)));



aspectx:=((jukebox.clientwidth)/800);
aspecty:=((jukebox.clientheight)/600);





DEFscrollamountlr:=aspx(75); //75
DEFscrollamountrl:=aspx(150);  //150

mylockwindowupdate(handle);


midpanel.Picture := nil;
leftpanelpic.picture:=nil;
rightpanelpic.picture:=nil;



setscreen;
//dumppositions; //DEBUG


  { midpanel.Canvas.Brush.Style:=bsSolid;
   midpanel.Canvas.brush.color:=clred;
   midpanel.canvas.FloodFill(aspx(300),aspy(300),midpanel.canvas.pixels[aspx(300),aspy(300)],fssurface);
   //bitmapoverbitmap(jbbg,midpanel.picture.bitmap,clred,midpanel.left,midpanel.top)}

   leftpanelpic.Picture.Bitmap.Dormant;
   leftpanelpic.Picture.Bitmap.Dormant;
   butpanelpic.Picture.Bitmap.Dormant;
   midpanel.Picture.Bitmap.Dormant;


   moveinprogress:=false;
mylockwindowupdate(0);
//application.processmessages;
{$IFNDEF NEWMEDIAPLAYER}
mainform.mp.DisplayRect:=jukebox.coverimagepanel.ClientRect;
{$ENDIF}
alphapanel.BringToFront;
end;

procedure Tjukebox.lsb1Reachedend;
begin
lsb1.losefocus;
tv_currentlsb:=1;
tv_lsb:=lsb2;

end;

procedure Tjukebox.lsb2Reachedtop;
begin
tv_currentlsb:=0;
tv_lsb:=lsb1;
lsb1.scrolltoend;
lsb2.losefocus;
end;


function getirmessage(var ln : string) : integer;
var
a : byte;
scrap,nln,remote,action : string;
d : integer;
begin
result:=-1;
if length(ln)<10 then begin
   ln:='';
   exit;
end;
a:=pos(' ',ln);
nln:=copy(ln,a+1,length(ln)-a);
a:=pos(' ',nln);
scrap:=trim(copy(nln,1,a));
val(scrap,result,d);
nln:=copy(nln,a,length(nln)-a+1);
nln:=trim(nln);
a:=pos(' ',nln);
action:=trim(copy(nln,1,a));
remote:=trim(copy(nln,a,length(nln)));
if remote='empathy' then ln:=action else ln:='';
end;


procedure sendkey(key : word;rpt : boolean;rptsent : integer);
begin
if (rpt=false) and (rptsent>0) then exit;
jukebox.formkeydown(nil,key,[]);
jukebox.formkeyup(nil,key,[]);
end;


procedure Tjukebox.irsocketRead(Sender: TObject;
  Socket: TCustomWinSocket);
var
ln : string;
rpt : integer;
begin
try
ln:=socket.ReceiveText;
except
domessage('Remote control daemon error');
exit;
end;

rpt:=getirmessage(ln);

if ln<>'' then begin

   if ln='up' then sendkey(VK_UP,false,rpt);
   if ln='down' then sendkey(VK_DOWN,false,rpt);
   if ln='left' then sendkey(VK_LEFT,true,rpt);
   if ln='right' then sendkey(VK_RIGHT,true,rpt);
   if ln='enter' then sendkey(VK_SPACE,false,rpt);
   if ln='return' then sendkey(VK_PRIOR,false,rpt); //switch views
   if ln='10' then sendkey(VK_NEXT,false,rpt); //switch current lsb
   if ln='return' then sendkey(VK_RETURN,false,rpt);
   //if ln='+' then sendkey(VK_DELETE,false,rpt); //delete from LCD
  // if ln='-' then sendkey(VK_SUBTRACT,false,rpt);  // vol -
  // if ln='+' then sendkey(VK_ADD,false,rpt); //vol +
   if ln='enter' then sendkey(VK_RETURN,false,rpt); //enter number
   if ln='-' then  sendkey(VK_MULTIPLY,false,rpt); //reject
   if ln='+' then numbutdown(-3); //Cancel Last Entry
   if ln='sound' then sendkey(VK_HOME,false,rpt);
   if ln='0' then sendkey(VK_NUMPAD0 ,false,rpt);//mute
   if ln='1' then sendkey(VK_NUMPAD1,false,rpt); //mute
   if ln='2' then sendkey(VK_NUMPAD2,false,rpt); //mute
   if ln='3' then sendkey(VK_NUMPAD3,false,rpt); //mute
   if ln='4' then sendkey(VK_NUMPAD4,false,rpt); //mute
   if ln='5' then sendkey(VK_NUMPAD5,false,rpt); //mute
   if ln='6' then sendkey(VK_NUMPAD6,false,rpt); //mute
   if ln='7' then sendkey(VK_NUMPAD7,false,rpt); //mute
   if ln='8' then sendkey(VK_NUMPAD8,false,rpt); //mute
   if ln='9' then sendkey(VK_NUMPAD9,false,rpt); //mute
end;



end;

procedure Tjukebox.irsocketError(Sender: TObject; Socket: TCustomWinSocket;
  ErrorEvent: TErrorEvent; var ErrorCode: Integer);
begin
domessage('Remote control daemon error');
errorcode:=0;
end;

procedure Tjukebox.ripbutClick(Sender: TObject);
begin
KioskpanelClick(nil);
application.ProcessMessages;
if keyboardshowing=true then osk(false,false);
mainform.numberoftracks.Enabled:=false;
rip_go;
mainform.numberoftracks.Enabled:=true;
drawalbum(currentalbum);
domessage('Welcome - '+inttostr(albumcount)+' albums available');
end;

procedure Tjukebox.jbinfogoClick(Sender: TObject);
begin
mainform.menuaboutClick(nil);
end;

procedure Tjukebox.NoRepeatCbClick(Sender: TObject);
begin
config.norepeat:=norepeatcb.checked;
end;

procedure Tjukebox.volumetimerTimer(Sender: TObject);
begin
panelshapeMouseDown(volumesender,mbLeft,[],0,0);
volumetimer.tag:=volumetimer.tag+1;
if (volumetimer.tag>10) and (volumesender=volumedownshape2) then begin
   volumetimer.interval:=volumetimer.interval div 2;
   volumetimer.tag:=0;
   if volumetimer.interval<10 then volumetimer.interval:=10;
   end;
end;

procedure Tjukebox.searchpanellbclick(alb : integer;track : integer);
var
salb,strk : string;
n : integer;
begin
  currentalbum:=alb;
  drawalbum(currentalbum);

  drawalbum3d(currentalbum,0);
  drawalbum3D(currentalbum,-1);

  if (panel_searchbut.tag=1) then panel_searchbut_imageclick(nil);

  if track<0 then exit;


  drawlcdpanelsurround(0);
  application.ProcessMessages;
   dolcd(-1,lcddelay);
   salb:=format ('%.4d',[alb]);
   strk:=format ('%.3d',[track]);
   for n:=1 to length(salb) do begin
   dolcd(strtoint(salb[n]),lcddelay);
   end;

   if length(strk)>3 then begin
   application.processmessages;
   numClick(numlabel11);
   autoplaying:=false;
   mainform.dtracklist.itemindex:=track-1;
   mainform.addclick(nil);
   if mainform.play.down=false then begin
    if mainform.dplaylist.items.count>0 then mainform.dplaylist.itemindex:=mainform.dplaylist.items.count-1;
    mainform.dplaylistclick(nil);
    mainform.playclick(nil);
   end;
   end else begin

      for n:=1 to length(strk) do begin
   dolcd(strtoint(strk[n]),lcddelay);
   end;
  end;

drawlcdpanelsurround(1);

end;
{    originalTopPanelProc : TWndMethod;
  originalBotPanelProc : TWndMethod;
  procedure TopPanelWindowProc (var Msg : TMessage) ;
  procedure TopPanelFileDrop (var Msg : TWMDROPFILES) ;
  procedure BotPanelWindowProc (var Msg : TMessage) ;
  procedure BotPanelFileDrop (var Msg : TWMDROPFILES) ;
 }


procedure TJukebox.TopPanelWindowProc(var Msg: TMessage) ;
begin
   if Msg.Msg = WM_DROPFILES then
     TopPanelFileDrop(TWMDROPFILES(Msg))
   else
     originalTopPanelProc(Msg) ;
end;

procedure TJukebox.BotPanelWindowProc(var Msg: TMessage) ;
begin
   if Msg.Msg = WM_DROPFILES then
     BotPanelFileDrop(TWMDROPFILES(Msg))
   else
     originalBotPanelProc(Msg) ;
end;




procedure TJukebox.TopPanelFileDrop(var Msg: TWMDropFiles);
begin
handledroppedfile(Msg,toppanel);
end;

procedure TJukebox.BotPanelFileDrop(var Msg: TWMDropFiles);
begin
handledroppedfile(Msg,botpanel);
end;

procedure TJukebox.handledroppedfile (var Msg : TWMDROPFILES;receiver : tobject);
var
numfiles : longint;
buf : array[0..MAX_PATH] of char;
n : integer;
fl : textfile;
fn : string;
art,alb,pth : string;
firstrun : boolean;

begin
firstrun:=true;
numfiles := DragQueryFile(Msg.Drop, $FFFFFFFF,nil,0);

if receiver=toppanel then begin
      art:=album[currentalbum].artist;
      alb:=album[currentalbum].album;
    end;
    if receiver=botpanel then begin
      art:=album[currentalbum+1].artist;
      alb:=album[currentalbum+1].album;
    end;

for n := 1 to numfiles do begin
 DragQueryFile(Msg.Drop, n-1, @buf, sizeof(buf));
 fn:=buf;

 if (uppercase(copy(fn,length(fn)-3,4))='.MP3') or (uppercase(copy(fn,length(fn)-3,4))='.MPG') then begin
    pth:=fn;

    if AddTrackDialog(art,alb,pth,art,alb,firstrun)=mrCancel then exit;
    firstrun:=false;
 end;
end;

drawalbum(currentalbum);
drawalbum3d(currentalbum,0);
drawalbum3D(currentalbum,-1);
closefile(fl);
end;

procedure TJukebox.playlistPlayClick(Sender: TObject);
begin
if playlistpanel.lb.highlighteditem>playlistpanel.lb.items.count-1 then exit;
mainform.dplaylist.itemindex:=playlistpanel.lb.highlighteditem;
mainform.dplaylistclick(nil);
mainform.dplaylistdblclick(nil);
end;


procedure TJukebox.playlistPurgeClick(Sender: TObject);
begin
mainform.clearlistClick(playlistpanel.purge);
playlistpanel.lb.clear;
domessage('Playlist Deleted');
if autoplaymode=true then startautoplay;
end;


procedure TJukebox.playlistRemoveClick(Sender: TObject);
var
ff : boolean;
begin
if playlistpanel.lb.highlighteditem>playlistpanel.lb.items.count-1 then exit;

ff:=false;
if dcurrentlyplayingtrack=playlistpanel.lb.highlighteditem then  ff:=true;
mainform.dplaylist.itemindex:=playlistpanel.lb.highlighteditem;
mainform.dplaylistclick(nil);
if mainform.dplaylist.itemindex<0 then exit;

mainform.delClick(nil);
playlistpanel.lb.items.Delete(playlistpanel.lb.highlighteditem);
playlistpanel.lb.repaint;
if ff=true then  mainform.dplaylistdblclick(nil);
end;

procedure moveitems(up : boolean);
var
cs : string;
ci : integer;
idx : integer;
dir : integer;
begin
if playlistpanel.lb.highlighteditem>playlistpanel.lb.items.count-1 then exit;
if up=true then dir:=-1 else dir:=+1;
  with Tjukebox do begin
    idx:=playlistpanel.lb.highlighteditem;
    if idx<0 then exit;

    cs:=dplaylistMatrixAlb[idx];
    ci:=dplaylistMatrixTrk[idx];
    dplaylistMatrixAlb[idx]:=dplaylistMatrixAlb[idx+dir];
    dplaylistMatrixTrk[idx]:=dplaylistMatrixTrk[idx+dir];
    dplaylistMatrixAlb[idx+dir]:=cs;
    dplaylistMatrixTrk[idx+dir]:=ci;
    mainform.dplaylist.items.Exchange(idx,idx+dir);
    playlistpanel.lb.items.Exchange(idx,idx+dir);
    playlistpanel.lb.highlighteditem:=idx+dir;
    //playlistpanel.lb.itemindex:=playlistpanel.lb.itemindex+dir;
    playlistpanel.lb.repaint;
  end;
end;


procedure TJukebox.playlistMoveUpClick(Sender: TObject);

begin
if playlistpanel.lb.highlighteditem<0 then exit;
if playlistpanel.lb.highlighteditem>0  then begin
 moveitems(true);
 if playlistpanel.lb.highlighteditem<playlistpanel.lb.topmost then playlistpanel.lb.topmost:=playlistpanel.lb.highlighteditem;

end;

end;

procedure TJukebox.playlistMoveDownClick(Sender: TObject);
begin
if playlistpanel.lb.highlighteditem>playlistpanel.lb.items.count-1 then exit;
if playlistpanel.lb.highlighteditem<0 then exit;
if playlistpanel.lb.highlighteditem<playlistpanel.lb.items.count-1  then begin
 moveitems(false);
 if playlistpanel.lb.highlighteditem=(playlistpanel.lb.displayitems+playlistpanel.lb.topmost) then begin
  playlistpanel.lb.topmost:=playlistpanel.lb.topmost+1;
  playlistpanel.lb.repaint;
 end;
end;
end;


procedure Tjukebox.jbcovershow(fn: string);
var
o : Tbitmap;
begin
if fn<>'' then begin

    try
    o:=tbitmap.create();
    loadjpegbmp(fn,o);
    coverimage.picture.bitmap.assign(o);
    o.free;
  finally;

  end;
end;
  coverimagepanel.bringtofront;
  coverimagepanel.visible:=true;
end;

procedure TJukebox.alphapanelvkey(Sender: TObject; key: Word);
begin
keybd_event(VK_SHIFT,0,0,0);
keybd_event(key,0,0,0);
keybd_event(key,0,KEYEVENTF_KEYUP,0);
keybd_event(VK_SHIFT,0,KEYEVENTF_KEYUP,0);
end;


procedure Tjukebox.sizethumbpanel;
begin
thumbpanel.top:=0;
thumbpanel.left:=leftpanel.width;
thumbpanel.width:=midpanelpanel.width;
thumbpanel.height:=height;

thumbs.left:=0;
thumbs.top:=aspy(2);
thumbs.width:=thumbpanel.width-thumbs.left;
thumbs.height:=thumbpanel.height-aspy(24);

{if (config.theme.alphaorientation=1) then begin
thumbs.left:=0;
thumbs.top:=0;
thumbs.width:=thumbpanel.width;
thumbs.height:=thumbpanel.Height;
end;


if (config.theme.alphaorientation=2) then begin
thumbs.left:=0;
thumbs.top:=0;
thumbs.width:=thumbpanel.width;
thumbs.height:=alphapanel.top;
end;    }



end;


procedure TJukebox.BackGroundTimerTimer(Sender: TObject);
var
dbg : string;
begin
if config.bgduration=0 then begin
  BackGroundTimer.Enabled:=false;
  exit;
end;

if autoplaycb.checked=false then begin
 BackGroundTimer.Enabled:=false;
 exit;
end;

inc(BackGroundTimerCount);

dbg:='backgroundtimer- interval:'+inttostr(BackGroundTimerCount)+' mde:'+inttostr(backgroundtimer.Tag);
if DEBUGON then outputdebugstring(pchar(dbg));


if (BackGroundTimerCount>=config.bgduration) and (BackGroundTimer.Tag=0) then begin
  BackGroundTimerCount:=0;
  BackGroundTimer.Tag:=1;
 if autoplaying=true then begin
  BackGroundCanAutoPlay:=false;
  dofade;
 end;
 exit;
end;

if (BackGroundTimerCount>=config.bgwaittime) and (BackGroundtimer.Tag=1) then begin
 BackGroundTimerCount:=0;
 BackGroundTimer.Tag:=0;
 BackGroundCanAutoPlay:=true;
 autoplaymode:=true;
 if mainform.timers.enabled=false then startautoplay;
 exit;
end;



end;

procedure TJukebox.dofade;
begin
  fadetimernostop:=false;
  if fadetimer.Enabled=true then exit;
  fadetimer.Tag:=0;
  fadetimer.Enabled:=true;
end;


function getvol : dword;
const
MCI_DGV_STATUS_VOLUME = 19;
var
p : MCI_STATUS_PARMS;
begin
  p.dwCallback := 0;
   p.dwItem := MCI_DGV_STATUS_VOLUME;
   mciSendCommand(mainform.MP.DeviceID, MCI_STATUS, MCI_STATUS_ITEM, Cardinal(@p)) ;
   result:=p.dwReturn;
end;

procedure setvol(v : dword);
var
p : MCI_DGV_SETAUDIO_PARMS;
begin
 p.dwCallback := 0;
  p.dwItem := MCI_DGV_SETAUDIO_VOLUME;
  p.dwOver := 0;
  p.lpstrAlgorithm := nil;
  p.lpstrQuality := nil;
  p.dwValue := v;
  mciSendCommand(mainform.MP.DeviceID, MCI_SETAUDIO, MCI_DGV_SETAUDIO_VALUE or MCI_DGV_SETAUDIO_ITEM, Cardinal(@p));
end;


procedure TJukebox.fadetimertimer(sender : TObject);
const FADERATEDIVISOR = 30;
begin
if fadetimer.Tag=0 then begin
fadetimeroriginalvalue:=getvol;
fadetimercurrentvalue:=fadetimeroriginalvalue;
fadetimerrate:=(fadetimeroriginalvalue div FADERATEDIVISOR);
end;

fadetimercurrentvalue:=fadetimercurrentvalue-fadetimerrate;


fadetimer.Tag:=fadetimer.Tag+1;
if fadetimer.Tag<FADERATEDIVISOR then setvol(fadetimercurrentvalue) else
begin
  fadetimer.Enabled:=false;
  autoplaymode:=false;
  autoplaying:=false;
  if fadetimernostop=false then mainform.stopclick(nil);
  setvol(fadetimeroriginalvalue);
end;
end;

function EnumWindowsSwitch(handle : hwnd;lparam : tform) : boolean; StdCall;
var
pid : dword;
caption : array [0..1024] of char;
begin

pid:=1;
GetWindowThreadProcessId (handle,@pid);
getwindowtext(handle,caption,254);

result:=true;
if (pos('Launcher',caption)>0)  then begin

 if iswindow(handle) then begin
//    postmessaxge(handle,WM_ACTIVATEAPP,0,0);
    //PostMessage(handle, WM_SYSCOMMAND, SC_MAXIMIZE, 0);

    showwindow(handle,SW_RESTORE);
    //setforegroundwindow(handle);

  end;
  result:=false;
end;
end;

procedure TJukebox.imViewModeClick(Sender : TObject);
begin
  if mainform.albumlist.items.count = 0 then exit;
  if imViewMode.tag=0 then imViewMode.tag:=1 else imViewMode.tag:=0;
  if imViewMode.tag=0 then begin
    imViewmode.stretch:=false;
    imViewMode.Picture.Bitmap.LoadFromResourceName(hinstance,'VIEW3D');
    drawalbum(currentalbum);
  end
      else begin
      imViewMode.Picture.Bitmap.LoadFromResourceName(hinstance,'VIEWNORM');
      end;
  if imViewMode.tag=0 then begin
    ThreeDPanel.Visible:=false;
      //if currentalbum mod 2 = 1 then inc(currentalbum);
      if currentalbum>jalbumcount then currentalbum:=1;
      if currentalbum<0 then currentalbum:=jalbumcount-1;
    end else begin
      ThreeDPanel.Visible:=true;
      DrawAlbum3D(currentalbum,0);
      drawalbum3D(currentalbum,-1);
      ThreeDPanel.BringToFront;
    end;
  end;

procedure TJukebox.DoDFM;
begin
    //Jukebox.TextHeight  :=  13;

     Jukebox.Font.Name:=DEFAULTFONT;
     Jukebox.Font.Color:=FONTCOL;
     Jukebox.Font.Size:=aspy(14);
     Rightpanel := TPanel.Create(Self);
     Rightpanel.Parent := Self;
     Rightpanel.Left  :=  55;
     Rightpanel.Top  :=  -15;
     Rightpanel.Width  :=  481;
     Rightpanel.Height  :=  433;
     Rightpanel.Caption  :=  'object advancedOK: TBitmapActionButton';
     Rightpanel.Color  :=  clBlack;
     Rightpanel.TabOrder  :=  2;
       Rightpanelpic := TImage.Create(Rightpanel);
       Rightpanelpic.Parent := Rightpanel;
       Rightpanelpic.Left  :=  377;
       Rightpanelpic.Top  :=  0;
       Rightpanelpic.Width  :=  120;
       Rightpanelpic.Height  :=  361;
       Rightpanelpic.Stretch  :=  True;
       {Gothumb := TImage.Create(Rightpanel);
       Gothumb.Parent := Rightpanel;
       Gothumb.Left  :=  168;
       Gothumb.Top  :=  88;
       Gothumb.Width  :=  50;
       Gothumb.Height  :=  50;
       Gothumb.PopupMenu  :=  mainform.dplaylistmenu;
       Gothumb.Stretch  :=  True;
       Gothumb.Transparent  :=  True;
       Gothumb.OnClick  :=  gothumbClick;}
       CreditInfoPanel := TPanel.Create(RightPanel);
       CreditInfoPanel.Parent:=RightPanel;
       CreditInfoPanel.color:=clBlack;
        Creditlabel := TLabel.create(CreditInfoPanel);
        Creditlabel.Parent := CreditInfoPanel;
        CreditStat := TLabel.create(CreditInfoPanel);
        CreditStat.Parent := CreditInfoPanel;
       Fav := TBitmapActionButton.Create(Rightpanel);
       Fav.Parent := Rightpanel;
       Fav.Left  :=  35;
       Fav.Top  :=  335;
       Fav.Width  :=  35;
       Fav.Height  :=  32;
       Fav.color  :=  clBlack;
       Fav.font.Charset  :=  DEFAULT_CHARSET;
       Fav.font.Color  :=  clWindowText;
       Fav.font.Height  :=  -19;
       Fav.font.Name  :=  DEFAULTFONT;
       Fav.font.Style  :=  [];
       Fav.down  :=  False;
       Fav.buttoncolor  :=  2;
       Fav.OnClick  :=  favClick;
       Fav.visible  :=  False;
       Butpanel := TPanel.Create(Rightpanel);
       Butpanel.Parent := Rightpanel;
       Butpanel.Left  :=  8;
       Butpanel.Top  :=  32;
       Butpanel.Width  :=  185;
       Butpanel.Height  :=  73;
       Butpanel.BevelOuter  :=  bvNone;
       Butpanel.Color  :=  clNone;
       Butpanel.TabOrder  :=  0;
         Butpanelpic := TImage.Create(Butpanel);
         Butpanelpic.Parent := Butpanel;
         Butpanelpic.Left  :=  24;
         Butpanelpic.Top  :=  64;
         Butpanelpic.Width  :=  105;
         Butpanelpic.Height  :=  105;
         Butpanelpic.Transparent:=false;
         ButPanelpic.Visible:=true;
         Butr := TImage.Create(Butpanel);
         Butr.Parent := Butpanel;
         Butr.Left  :=  144;
         Butr.Top  :=  24;
         Butr.Width  :=  105;
         Butr.Height  :=  105;
         Butr.Stretch  :=  True;
         Butr.Transparent  :=  False;
         Butl := TImage.Create(Butpanel);
         Butl.Parent := Butpanel;
         Butl.Left  :=  48;
         Butl.Top  :=  16;
         Butl.Width  :=  105;
         Butl.Height  :=  105;
         Butl.Stretch  :=  True;
         Butl.Transparent  :=  False;
         Butllabel := TLabel.Create(Butpanel);
         Butllabel.Parent := Butpanel;
         Butllabel.Left  :=  8;
         Butllabel.Top  :=  32;
         Butllabel.Width  :=  26;
         Butllabel.Height  :=  27;
         Butllabel.Alignment  :=  taCenter;
         Butllabel.AutoSize  :=  False;
         Butllabel.Caption  :=  ' ';
         Butllabel.Color  :=  clBlack;
         Butllabel.Font.Charset  :=  DEFAULT_CHARSET;
         Butllabel.Font.Color  :=  clBlack;
         Butllabel.Font.Height  :=  -27;
         Butllabel.Font.Name  :=  '';
         Butllabel.Font.Style  :=  [];
         Butllabel.ParentColor  :=  False;
         Butllabel.ParentFont  :=  False;
         Butllabel.Transparent  :=  True;
         Butllabel.Layout  :=  tlCenter;
         Butllabel.OnClick  :=  butllabelClick;
         Butllabel.OnMouseDown  :=  butllabelMouseDown;
         Butllabel.OnMouseUp  :=  butllabelMouseUp;
         Butrlabel := TLabel.Create(Butpanel);
         Butrlabel.Parent := Butpanel;
         Butrlabel.Left  :=  16;
         Butrlabel.Top  :=  16;
         Butrlabel.Width  :=  11;
         Butrlabel.Height  :=  11;
         Butrlabel.Alignment  :=  taCenter;
         Butrlabel.AutoSize  :=  False;
         Butrlabel.Caption  :=  ' ';
         Butrlabel.Font.Charset  :=  DEFAULT_CHARSET;
         Butrlabel.Font.Color  :=  clBlack;
         Butrlabel.Font.Height  :=  -11;
         Butrlabel.Font.Name  :=  '';      //A and B for arrows in font
         Butrlabel.Font.Style  :=  [];
         Butrlabel.ParentFont  :=  False;
         Butrlabel.Transparent  :=  True;
         Butrlabel.Layout  :=  tlCenter;
         Butrlabel.OnClick  :=  butrlabelClick;
         Butrlabel.OnMouseDown  :=  butrlabelMouseDown;
         Butrlabel.OnMouseUp  :=  butrlabelMouseUp;
         Blshape1 := TShape.Create(Butpanel);
         Blshape1.Parent := Butpanel;
         Blshape1.Left  :=  64;
         Blshape1.Top  :=  8;
         Blshape1.Width  :=  65;
         Blshape1.Height  :=  65;
         Blshape1.Shape  :=  stCircle;
         Brshape1 := TShape.Create(Butpanel);
         Brshape1.Parent := Butpanel;
         Brshape1.Left  :=  72;
         Brshape1.Top  :=  8;
         Brshape1.Width  :=  65;
         Brshape1.Height  :=  65;
         Brshape1.Shape  :=  stCircle;
         Blshape2 := TShape.Create(Butpanel);
         Blshape2.Parent := Butpanel;
         Blshape2.Left  :=  80;
         Blshape2.Top  :=  8;
         Blshape2.Width  :=  65;
         Blshape2.Height  :=  65;
         Blshape2.Shape  :=  stCircle;
         Blshape2.OnMouseDown  :=  butllabelMouseDown;
         Blshape2.OnMouseUp  :=  butllabelMouseUp;
         Brshape2 := TShape.Create(Butpanel);
         Brshape2.Parent := Butpanel;
         Brshape2.Left  :=  88;
         Brshape2.Top  :=  8;
         Brshape2.Width  :=  65;
         Brshape2.Height  :=  65;
         Brshape2.Shape  :=  stCircle;
         Brshape2.OnMouseDown  :=  butrlabelMouseDown;
         Brshape2.OnMouseUp  :=  butrlabelMouseUp;
       Keypadpanel := TPanel.Create(Rightpanel);
       Keypadpanel.Parent := Rightpanel;
       Keypadpanel.Left  :=  192;
       Keypadpanel.Top  :=  -80;
       Keypadpanel.Width  :=  201;
       Keypadpanel.Height  :=  313;
       Keypadpanel.BevelOuter  :=  bvNone;
       Keypadpanel.Caption  :=  '';
       Keypadpanel.Color  :=  clBlack;
       Keypadpanel.TabOrder  :=  1;
       Keypadpanel.OnMouseUp  :=  keypadpanelMouseUp;
         Num1 := TImage.Create(Keypadpanel);
         Num1.Parent := Keypadpanel;
         Num1.Left  :=  8;
         Num1.Top  :=  8;
         Num1.Width  :=  105;
         Num1.Height  :=  105;
         Num1.Stretch  :=  True;
         Num2 := TImage.Create(Keypadpanel);
         Num2.Parent := Keypadpanel;
         Num2.Left  :=  8;
         Num2.Top  :=  0;
         Num2.Width  :=  105;
         Num2.Height  :=  105;
         Num2.Stretch  :=  True;
         Num3 := TImage.Create(Keypadpanel);
         Num3.Parent := Keypadpanel;
         Num3.Left  :=  16;
         Num3.Top  :=  0;
         Num3.Width  :=  105;
         Num3.Height  :=  105;
         Num3.Stretch  :=  True;
         Num4 := TImage.Create(Keypadpanel);
         Num4.Parent := Keypadpanel;
         Num4.Left  :=  24;
         Num4.Top  :=  0;
         Num4.Width  :=  105;
         Num4.Height  :=  105;
         Num4.Stretch  :=  True;
         Num5 := TImage.Create(Keypadpanel);
         Num5.Parent := Keypadpanel;
         Num5.Left  :=  32;
         Num5.Top  :=  0;
         Num5.Width  :=  105;
         Num5.Height  :=  105;
         Num5.Stretch  :=  True;
         Num6 := TImage.Create(Keypadpanel);
         Num6.Parent := Keypadpanel;
         Num6.Left  :=  40;
         Num6.Top  :=  0;
         Num6.Width  :=  105;
         Num6.Height  :=  105;
         Num6.Stretch  :=  True;
         Num7 := TImage.Create(Keypadpanel);
         Num7.Parent := Keypadpanel;
         Num7.Left  :=  48;
         Num7.Top  :=  0;
         Num7.Width  :=  105;
         Num7.Height  :=  105;
         Num7.Stretch  :=  True;
         Num8 := TImage.Create(Keypadpanel);
         Num8.Parent := Keypadpanel;
         Num8.Left  :=  40;
         Num8.Top  :=  32;
         Num8.Width  :=  105;
         Num8.Height  :=  105;
         Num8.Stretch  :=  True;
         Num9 := TImage.Create(Keypadpanel);
         Num9.Parent := Keypadpanel;
         Num9.Left  :=  40;
         Num9.Top  :=  24;
         Num9.Width  :=  105;
         Num9.Height  :=  105;
         Num9.Stretch  :=  True;
         Num10 := TImage.Create(Keypadpanel);
         Num10.Parent := Keypadpanel;
         Num10.Left  :=  56;
         Num10.Top  :=  16;
         Num10.Width  :=  105;
         Num10.Height  :=  105;
         Num10.Stretch  :=  True;
         Num11 := TImage.Create(Keypadpanel);
         Num11.Parent := Keypadpanel;
         Num11.Left  :=  72;
         Num11.Top  :=  24;
         Num11.Width  :=  105;
         Num11.Height  :=  105;
         Num11.Stretch  :=  True;
         Num12 := TImage.Create(Keypadpanel);
         Num12.Parent := Keypadpanel;
         Num12.Left  :=  96;
         Num12.Top  :=  0;
         Num12.Width  :=  105;
         Num12.Height  :=  105;
         Num12.Stretch  :=  True;
         Numlabel1 := TLabel.Create(Keypadpanel);
         Numlabel1.Parent := Keypadpanel;
         Numlabel1.Left  :=  24;
         Numlabel1.Top  :=  136;
         Numlabel1.Width  :=  48;
         Numlabel1.Height  :=  13;
         Numlabel1.Caption  :=  'numlabel1';
         Numlabel1.Color  :=  clGreen;
         Numlabel1.ParentColor  :=  False;
         Numlabel2 := TLabel.Create(Keypadpanel);
         Numlabel2.Parent := Keypadpanel;
         Numlabel2.Left  :=  32;
         Numlabel2.Top  :=  144;
         Numlabel2.Width  :=  48;
         Numlabel2.Height  :=  13;
         Numlabel2.Caption  :=  'numlabel1';
         Numlabel2.Color  :=  clGreen;
         Numlabel2.ParentColor  :=  False;
         Numlabel3 := TLabel.Create(Keypadpanel);
         Numlabel3.Parent := Keypadpanel;
         Numlabel3.Left  :=  40;
         Numlabel3.Top  :=  152;
         Numlabel3.Width  :=  48;
         Numlabel3.Height  :=  13;
         Numlabel3.Caption  :=  'numlabel1';
         Numlabel3.Color  :=  clGreen;
         Numlabel3.ParentColor  :=  False;
         Numlabel4 := TLabel.Create(Keypadpanel);
         Numlabel4.Parent := Keypadpanel;
         Numlabel4.Left  :=  48;
         Numlabel4.Top  :=  160;
         Numlabel4.Width  :=  48;
         Numlabel4.Height  :=  13;
         Numlabel4.Caption  :=  'numlabel1';
         Numlabel4.Color  :=  clGreen;
         Numlabel4.ParentColor  :=  False;
         Numlabel5 := TLabel.Create(Keypadpanel);
         Numlabel5.Parent := Keypadpanel;
         Numlabel5.Left  :=  56;
         Numlabel5.Top  :=  168;
         Numlabel5.Width  :=  48;
         Numlabel5.Height  :=  13;
         Numlabel5.Caption  :=  'numlabel1';
         Numlabel5.Color  :=  clGreen;
         Numlabel5.ParentColor  :=  False;
         Numlabel6 := TLabel.Create(Keypadpanel);
         Numlabel6.Parent := Keypadpanel;
         Numlabel6.Left  :=  64;
         Numlabel6.Top  :=  176;
         Numlabel6.Width  :=  48;
         Numlabel6.Height  :=  13;
         Numlabel6.Caption  :=  'numlabel1';
         Numlabel6.Color  :=  clGreen;
         Numlabel6.ParentColor  :=  False;
         Numlabel7 := TLabel.Create(Keypadpanel);
         Numlabel7.Parent := Keypadpanel;
         Numlabel7.Left  :=  72;
         Numlabel7.Top  :=  184;
         Numlabel7.Width  :=  48;
         Numlabel7.Height  :=  13;
         Numlabel7.Caption  :=  'numlabel1';
         Numlabel7.Color  :=  clGreen;
         Numlabel7.ParentColor  :=  False;
         Numlabel8 := TLabel.Create(Keypadpanel);
         Numlabel8.Parent := Keypadpanel;
         Numlabel8.Left  :=  80;
         Numlabel8.Top  :=  192;
         Numlabel8.Width  :=  48;
         Numlabel8.Height  :=  13;
         Numlabel8.Caption  :=  'numlabel1';
         Numlabel8.Color  :=  clGreen;
         Numlabel8.ParentColor  :=  False;
         Numlabel9 := TLabel.Create(Keypadpanel);
         Numlabel9.Parent := Keypadpanel;
         Numlabel9.Left  :=  88;
         Numlabel9.Top  :=  200;
         Numlabel9.Width  :=  48;
         Numlabel9.Height  :=  13;
         Numlabel9.Caption  :=  'numlabel1';
         Numlabel9.Color  :=  clGreen;
         Numlabel9.ParentColor  :=  False;
         Numlabel10 := TLabel.Create(Keypadpanel);
         Numlabel10.Parent := Keypadpanel;
         Numlabel10.Left  :=  96;
         Numlabel10.Top  :=  208;
         Numlabel10.Width  :=  48;
         Numlabel10.Height  :=  13;
         Numlabel10.Caption  :=  'numlabel1';
         Numlabel10.Color  :=  clGreen;
         Numlabel10.ParentColor  :=  False;
         Numlabel11 := TLabel.Create(Keypadpanel);
         Numlabel11.Parent := Keypadpanel;
         Numlabel11.Left  :=  104;
         Numlabel11.Top  :=  216;
         Numlabel11.Width  :=  48;
         Numlabel11.Height  :=  13;
         Numlabel11.Caption  :=  'numlabel1';
         Numlabel11.Color  :=  clGreen;
         Numlabel11.ParentColor  :=  False;
         Numlabel12 := TLabel.Create(Keypadpanel);
         Numlabel12.Parent := Keypadpanel;
         Numlabel12.Left  :=  112;
         Numlabel12.Top  :=  224;
         Numlabel12.Width  :=  48;
         Numlabel12.Height  :=  13;
         Numlabel12.Caption  :=  'numlabel1';
         Numlabel12.Color  :=  clGreen;
         Numlabel12.ParentColor  :=  False;
         Numlabel13 := TLabel.Create(Keypadpanel);
         Numlabel13.Parent := Keypadpanel;
         Numlabel13.Left  :=  120;
         Numlabel13.Top  :=  232;
         Numlabel13.Width  :=  48;
         Numlabel13.Height  :=  13;
         Numlabel13.Caption  :=  'numlabel1';
         Numlabel13.Color  :=  clGreen;
         Numlabel13.ParentColor  :=  False;
         Num13 := TImage.Create(Keypadpanel);
         Num13.Parent := Keypadpanel;
         Num13.Left  :=  80;
         Num13.Top  :=  32;
         Num13.Width  :=  105;
         Num13.Height  :=  105;
         Num13.Stretch  :=  True;
       Lcdpanel := TPanel.Create(Rightpanel);
       Lcdpanel.Parent := Rightpanel;
       Lcdpanel.Left  :=  224;
       Lcdpanel.Top  :=  64;
       Lcdpanel.Width  :=  257;
       Lcdpanel.Height  :=  265;
       Lcdpanel.BevelOuter  :=  bvNone;
       Lcdpanel.Color  :=  clBlack;
       Lcdpanel.TabOrder  :=  2;
         Lcdlabel1 := TLabel.Create(Lcdpanel);
         Lcdlabel1.Parent := Lcdpanel;
         Lcdlabel1.Left  :=  16;
         Lcdlabel1.Top  :=  48;
         Lcdlabel1.Width  :=  3;
         Lcdlabel1.Height  :=  13;
         Lcdlabel2 := TLabel.Create(Lcdpanel);
         Lcdlabel2.Parent := Lcdpanel;
         Lcdlabel2.Left  :=  24;
         Lcdlabel2.Top  :=  56;
         Lcdlabel2.Width  :=  3;
         Lcdlabel2.Height  :=  13;
         Lcd1 := TPanel.Create(Lcdpanel);
         Lcd1.Parent := Lcdpanel;
         Lcd1.Left  :=  32;
         Lcd1.Top  :=  0;
         Lcd1.Width  :=  137;
         Lcd1.Height  :=  57;
         Lcd1.BevelOuter  :=  bvNone;
         Lcd1.Color  :=  clBlack;
         Lcd1.TabOrder  :=  0;
           Lcdtext1 := TLabel.Create(Lcd1);
           Lcdtext1.Parent := Lcd1;
           Lcdtext1.Left  :=  27;
           Lcdtext1.Top  :=  33;
           Lcdtext1.Width  :=  48;
           Lcdtext1.Height  :=  48;
           Lcdtext1.Alignment  :=  taRightJustify;
           Lcdtext1.AutoSize  :=  False;
           Lcdtext1.Color  :=  clBlack;
           Lcdtext1.Font.Charset  :=  SYMBOL_CHARSET;
           Lcdtext1.Font.Color  :=  clRed;
           Lcdtext1.Font.Height  :=  -48;
           Lcdtext1.Font.Name  :=  'empathydigital';
           Lcdtext1.Font.Style  :=  [];
           Lcdtext1.ParentColor  :=  False;
           Lcdtext1.ParentFont  :=  False;
         Lcd2 := TPanel.Create(Lcdpanel);
         Lcd2.Parent := Lcdpanel;
         Lcd2.Left  :=  64;
         Lcd2.Top  :=  216;
         Lcd2.Width  :=  137;
         Lcd2.Height  :=  57;
         Lcd2.BevelOuter  :=  bvNone;
         Lcd2.Color  :=  clBlack;
         Lcd2.TabOrder  :=  1;
           Lcdtext2 := TLabel.Create(Lcd2);
           Lcdtext2.Parent := Lcd2;
           Lcdtext2.Left  :=  11;
           Lcdtext2.Top  :=  25;
           Lcdtext2.Width  :=  48;
           Lcdtext2.Height  :=  48;
           Lcdtext2.Alignment  :=  taRightJustify;
           Lcdtext2.AutoSize  :=  False;
           Lcdtext2.Color  :=  clBlack;
           Lcdtext2.Font.Charset  :=  SYMBOL_CHARSET;
           Lcdtext2.Font.Color  :=  clRed;
           Lcdtext2.Font.Height  :=  -48;
           Lcdtext2.Font.Name  :=  'empathydigital';
           Lcdtext2.Font.Style  :=  [];
           Lcdtext2.ParentColor  :=  False;
           Lcdtext2.ParentFont  :=  False;
         Lcd3 := TTextScroller.Create(Lcdpanel);
         Lcd3.Parent := Lcdpanel;
         Lcd3.Left  :=  64;
         Lcd3.Top  :=  120;
         Lcd3.Width  :=  0;
         Lcd3.Height  :=  0;
         Lcd3.color  :=  clWindow;
         Lcd3.font.Charset  :=  DEFAULT_CHARSET;
         Lcd3.font.Color  :=  clWindowText;
         Lcd3.font.Height  :=  -16;
         Lcd3.font.Name  :=  DEFAULTFONT;
         Lcd3.font.Style  :=  [];
         Lcd3.running  :=  False;
         Lcd3.speed  :=  100;
       Panel := TPanel.Create(Self);
       Panel.Parent := Self;
       Panel.Left  :=  0;
       Panel.Top  :=  144;
       Panel.Width  :=  281;
       Panel.Height  :=  81;
       Panel.BevelOuter  :=  bvNone;
       Panel.Color  :=  clSilver;
       Panel.FullRepaint  :=  False;
       Panel.TabOrder  :=  3;
       Panel.Visible  :=  False;
         Mute := TImage.Create(Panel);
         Mute.Parent := Panel;
         Mute.Left  :=  120;
         Mute.Top  :=  40;
         Mute.Width  :=  105;
         Mute.Height  :=  105;
         Mute.Stretch  :=  True;
         Mute.Transparent  :=  True;
         Reject := TImage.Create(Panel);
         Reject.Parent := Panel;
         Reject.Left  :=  48;
         Reject.Top  :=  16;
         Reject.Width  :=  105;
         Reject.Height  :=  105;
         Reject.Stretch  :=  True;
         Reject.Transparent  :=  True;
         Panelshape2 := TShape.Create(Panel);
         Panelshape2.Parent := Panel;
         Panelshape2.Left  :=  16;
         Panelshape2.Top  :=  0;
         Panelshape2.Width  :=  281;
         Panelshape2.Height  :=  81;
         Panelshape2.Brush.Style  :=  bsClear;
         Panelshape2.Pen.Color  :=  2131873;
         Panelshape2.Pen.Width  :=  3;
         Panelshape1 := TShape.Create(Panel);
         Panelshape1.Parent := Panel;
         Panelshape1.Left  :=  0;
         Panelshape1.Top  :=  0;
         Panelshape1.Width  :=  281;
         Panelshape1.Height  :=  81;
         Panelshape1.Align  :=  alClient;
         Panelshape1.Brush.Style  :=  bsClear;
         Panelshape1.Pen.Color  :=  50935;
         Panelshape1.Pen.Width  :=  4;
         Volumeup := TImage.Create(Panel);
         Volumeup.Parent := Panel;
         Volumeup.Left  :=  136;
         Volumeup.Top  :=  24;
         Volumeup.Width  :=  49;
         Volumeup.Height  :=  49;
         Volumeup.Stretch  :=  True;
         Volumeup.Transparent  :=  True;
         Volumedown := TImage.Create(Panel);
         Volumedown.Parent := Panel;
         Volumedown.Left  :=  200;
         Volumedown.Top  :=  24;
         Volumedown.Width  :=  49;
         Volumedown.Height  :=  49;
         Volumedown.Stretch  :=  True;
         Volumedown.Transparent  :=  True;
         Rejectshape1 := TShape.Create(Panel);
         Rejectshape1.Parent := Panel;
         Rejectshape1.Left  :=  118;
         Rejectshape1.Top  :=  8;
         Rejectshape1.Width  :=  66;
         Rejectshape1.Height  :=  65;
         Rejectshape1.Shape  :=  stCircle;
         Rejectshape1.OnMouseDown  :=  panelshapeMouseDown;
         Rejectshape1.OnMouseUp  :=  panelshapeMouseUp;
         Rejectshape2 := TShape.Create(Panel);
         Rejectshape2.Parent := Panel;
         Rejectshape2.Left  :=  128;
         Rejectshape2.Top  :=  16;
         Rejectshape2.Width  :=  65;
         Rejectshape2.Height  :=  65;
         Rejectshape2.Shape  :=  stCircle;
         Rejectshape2.OnMouseDown  :=  panelshapeMouseDown;
         Rejectshape2.OnMouseUp  :=  panelshapeMouseUp;
         Muteshape1 := TShape.Create(Panel);
         Muteshape1.Parent := Panel;
         Muteshape1.Left  :=  136;
         Muteshape1.Top  :=  16;
         Muteshape1.Width  :=  65;
         Muteshape1.Height  :=  65;
         Muteshape1.Shape  :=  stCircle;
         Volumeupshape1 := TShape.Create(Panel);
         Volumeupshape1.Parent := Panel;
         Volumeupshape1.Left  :=  152;
         Volumeupshape1.Top  :=  16;
         Volumeupshape1.Width  :=  65;
         Volumeupshape1.Height  :=  65;
         Volumeupshape1.Shape  :=  stCircle;
         Muteshape2 := TShape.Create(Panel);
         Muteshape2.Parent := Panel;
         Muteshape2.Left  :=  144;
         Muteshape2.Top  :=  16;
         Muteshape2.Width  :=  65;
         Muteshape2.Height  :=  65;
         Muteshape2.Shape  :=  stCircle;
         Muteshape2.OnMouseDown  :=  panelshapeMouseDown;
         Muteshape2.OnMouseUp  :=  panelshapeMouseUp;
         Volumedownshape1 := TShape.Create(Panel);
         Volumedownshape1.Parent := Panel;
         Volumedownshape1.Left  :=  168;
         Volumedownshape1.Top  :=  16;
         Volumedownshape1.Width  :=  65;
         Volumedownshape1.Height  :=  65;
         Volumedownshape1.Shape  :=  stCircle;
         Volumeupshape2 := TShape.Create(Panel);
         Volumeupshape2.Parent := Panel;
         Volumeupshape2.Left  :=  160;
         Volumeupshape2.Top  :=  16;
         Volumeupshape2.Width  :=  65;
         Volumeupshape2.Height  :=  65;
         Volumeupshape2.Shape  :=  stCircle;
         Volumeupshape2.OnMouseDown  :=  panelshapeMouseDown;
         Volumeupshape2.OnMouseUp  :=  panelshapeMouseUp;
         Volumedownshape2 := TShape.Create(Panel);
         Volumedownshape2.Parent := Panel;
         Volumedownshape2.Left  :=  200;
         Volumedownshape2.Top  :=  16;
         Volumedownshape2.Width  :=  65;
         Volumedownshape2.Height  :=  65;
         Volumedownshape2.Shape  :=  stCircle;
         Volumedownshape2.OnMouseDown  :=  panelshapeMouseDown;
         Volumedownshape2.OnMouseUp  :=  panelshapeMouseUp;
         Volumelabel := TLabel.Create(Panel);
         Volumelabel.Parent := Panel;
         Volumelabel.Left  :=  64;
         Volumelabel.Top  :=  8;
         Volumelabel.Width  :=  56;
         Volumelabel.Height  :=  13;
         Volumelabel.Alignment  :=  taCenter;
         Volumelabel.AutoSize  :=  False;
         Volumelabel.Caption  :=  'volumelabel';
         Volumelabel.Font.Charset  :=  DEFAULT_CHARSET;
         Volumelabel.Font.Color  :=  50935;
         Volumelabel.Font.Height  :=  -11;
         Volumelabel.Font.Name  :=  'MS Sans Serif';
         Volumelabel.Font.Style  :=  [];
         Volumelabel.ParentFont  :=  False;
         Volumelabel.Layout  :=  tlCenter;
         Rejectlabel := TLabel.Create(Panel);
         Rejectlabel.Parent := Panel;
         Rejectlabel.Left  :=  16;
         Rejectlabel.Top  :=  16;
         Rejectlabel.Width  :=  48;
         Rejectlabel.Height  :=  13;
         Rejectlabel.Alignment  :=  taCenter;
         Rejectlabel.Caption  :=  'rejectlabel';
         Rejectlabel.Font.Charset  :=  DEFAULT_CHARSET;
         Rejectlabel.Font.Color  :=  50935;
         Rejectlabel.Font.Height  :=  -11;
         Rejectlabel.Font.Name  :=  'MS Sans Serif';
         Rejectlabel.Font.Style  :=  [];
         Rejectlabel.ParentFont  :=  False;
         Rejectlabel.Layout  :=  tlCenter;
         Mutelabel := TLabel.Create(Panel);
         Mutelabel.Parent := Panel;
         Mutelabel.Left  :=  56;
         Mutelabel.Top  :=  32;
         Mutelabel.Width  :=  45;
         Mutelabel.Height  :=  13;
         Mutelabel.Alignment  :=  taCenter;
         Mutelabel.AutoSize  :=  False;
         Mutelabel.Caption  :=  'mutelabel';
         Mutelabel.Font.Charset  :=  DEFAULT_CHARSET;
         Mutelabel.Font.Color  :=  50935;
         Mutelabel.Font.Height  :=  -11;
         Mutelabel.Font.Name  :=  'MS Sans Serif';
         Mutelabel.Font.Style  :=  [];
         Mutelabel.ParentFont  :=  False;
         Mutelabel.Layout  :=  tlCenter;
         Volumeuplabel := TLabel.Create(Panel);
         Volumeuplabel.Parent := Panel;
         Volumeuplabel.Left  :=  208;
         Volumeuplabel.Top  :=  0;
         Volumeuplabel.Width  :=  68;
         Volumeuplabel.Height  :=  13;
         Volumeuplabel.Alignment  :=  taCenter;
         Volumeuplabel.AutoSize  :=  False;
         Volumeuplabel.Caption  :=  'volumeuplabel';
         Volumeuplabel.Transparent  :=  True;
         Volumeuplabel.Layout  :=  tlCenter;
         Volumeuplabel.OnMouseDown  :=  panelshapeMouseDown;
         Volumeuplabel.OnMouseUp  :=  panelshapeMouseUp;
         Volumedownlabel := TLabel.Create(Panel);
         Volumedownlabel.Parent := Panel;
         Volumedownlabel.Left  :=  197;
         Volumedownlabel.Top  :=  16;
         Volumedownlabel.Width  :=  68;
         Volumedownlabel.Height  :=  13;
         Volumedownlabel.Alignment  :=  taCenter;
         Volumedownlabel.AutoSize  :=  False;
         Volumedownlabel.Caption  :=  'volumeuplabel';
         Volumedownlabel.Transparent  :=  True;
         Volumedownlabel.Layout  :=  tlCenter;
         Volumedownlabel.OnMouseDown  :=  panelshapeMouseDown;
         Volumedownlabel.OnMouseUp  :=  panelshapeMouseUp;
     Leftpanel := TPanel.Create(Self);
     Leftpanel.Parent := Self;
     Leftpanel.Left  :=  24;
     Leftpanel.Top  :=  97;
     Leftpanel.Width  :=  25;
     Leftpanel.Height  :=  297;
     Leftpanel.Caption  :=  'leftpanel';
     Leftpanel.Color  :=  clBlack;
     Leftpanel.TabOrder  :=  1;
       Leftpanelpic := TImage.Create(Leftpanel);
       Leftpanelpic.Parent := Leftpanel;
       Leftpanelpic.Left  :=  6;
       Leftpanelpic.Top  :=  -303;
       Leftpanelpic.Width  :=  19;
       Leftpanelpic.Height  :=  600;
       Leftpanelpic.Stretch  :=  True;
     Midpanelpanel := TPanel.Create(Self);
     Midpanelpanel.Parent := Self;
     Midpanelpanel.Left  :=  131;
     Midpanelpanel.Top  :=  124;
     Midpanelpanel.Width  :=  721;
     Midpanelpanel.Height  :=  457;
     Midpanelpanel.BevelOuter  :=  bvNone;
     Midpanelpanel.Color  :=  clBlack;
     Midpanelpanel.UseDockManager  :=  False;
     Midpanelpanel.FullRepaint  :=  False;
     Midpanelpanel.TabOrder  :=  0;
       Midpanel := TImage.Create(Midpanelpanel);
       Midpanel.Parent := Midpanelpanel;
       Midpanel.Left  :=  73;
       Midpanel.Top  :=  360;
       Midpanel.Width  :=  328;
       Midpanel.Height  :=  249;
       Midpanel.Stretch  :=  True;
        TrackHintPanel:= TTransparentPanel.Create(MidpanelPanel);
        TrackHintPanel.Parent:=MidPanelPanel;
         Trackhint := TLabel.Create(TrackHintPanel);
         Trackhint.Parent := TrackHintPanel;
         Trackhint.Left  :=  24;
         Trackhint.Top  :=  224;
         Trackhint.Width  :=  41;
         Trackhint.Height  :=  13;
         Trackhint.Alignment  :=  taCenter;
         Trackhint.Anchors  :=  [];
         Trackhint.Caption  :=  '';
         Trackhint.Color  :=  clBlack;
         Trackhint.ParentColor  :=  True;
         Trackhint.Transparent  :=  True;
         Trackhint.Visible  :=  False;
         trackhint.AutoSize:=true;

         Thumbpanel := TTransparentPanel.Create(Self);
     Thumbpanel.Parent := self;
     Thumbpanel.Left  :=  8;
     Thumbpanel.Top  :=  0;
     Thumbpanel.Width  :=  209;
     Thumbpanel.Height  :=  169;
     Thumbpanel.border  :=  False;
     Thumbpanel.Visible  :=  False;

       Thumbs := TPictureScroller.Create(Thumbpanel);
       Thumbs.Parent := Thumbpanel;
       Thumbs.Left  :=  9;
       Thumbs.Top  :=  1;
       Thumbs.Width  :=  200;
       Thumbs.Height  :=  200;
       Thumbs.color  :=  clBlack;
       Thumbs.OnClick  :=  thumbsClick;
       Thumbs.remote  :=  False;
       Thumbs.scrollwidths  :=  18;
       Thumbs.moretext:='MORE ALBUMS';


          //Experimental Center mask
     centerpanel := TPanel.Create(Self);
     centerpanel.Parent := Self;
     centerpanel.Left  :=  0;
     centerpanel.Top  :=  0;
     centerpanel.Width  :=  49;
     centerpanel.Height  :=  41;
     centerpanel.BevelOuter  :=  bvNone;
     centerpanel.Caption  :=  '';
     centerpanel.Color  :=  clBlack;
     centerpanel.Visible  :=  true;
       centerpanel_image := TImage.Create(Self);
       centerpanel_image.Parent := centerpanel;
       centerpanel_image.Left  :=  0;
       centerpanel_image.Top  :=  0;
       centerpanel_image.Width  :=  33;
       centerpanel_image.Height  :=  41;
       centerpanel_image.Stretch  :=  false;
       centerpanel_image.Visible:=true;
       centerpanel_image.AutoSize:=false;
       centerpanel_image.Transparent:=false;
       centerpanel_image.IncrementalDisplay:=false;



       Toppanel := TPanel.Create(Midpanelpanel);
       Toppanel.Parent := Midpanelpanel;
       Toppanel.Left  :=  48;
       Toppanel.Top  :=  56;
       Toppanel.Width  :=  305;
       Toppanel.Height  :=  129;
       Toppanel.BevelOuter  :=  bvNone;
       Toppanel.BorderWidth  :=  1;
       Toppanel.BorderStyle  :=  bsSingle;
       Toppanel.Color  :=  clWhite;
       Toppanel.Ctl3D  :=  False;
       Toppanel.ParentCtl3D  :=  False;
       Toppanel.TabOrder  :=  0;
         Lb1 := TImage.Create(Toppanel);
         Lb1.Parent := Toppanel;
         Lb1.Left  :=  128;
         Lb1.Top  :=  0;
         Lb1.Width  :=  105;
         Lb1.Height  :=  105;
         Lb1.Stretch  :=  True;
         Cd1 := TImage.Create(Toppanel);
         Cd1.Parent := Toppanel;
         Cd1.Left  :=  0;
         Cd1.Top  :=  0;
         Cd1.Width  :=  105;
         Cd1.Height  :=  105;
         Cd1.Stretch  :=  True;
         Cd1.OnClick  :=  cdclick;
         Cd1.OnMouseDown  :=  cdMouseDown;
         Lsb1 := TScrollListbox.Create(Toppanel);
         Lsb1.Parent := Toppanel;
         Lsb1.Left  :=  240;
         Lsb1.Top  :=  56;
         Lsb1.Width  :=  0;
         Lsb1.Height  :=  0;
         Lsb1.color  :=  clWindow;
         Lsb1.itemindex  :=  0;
         Lsb1.font.Charset  :=  DEFAULT_CHARSET;
         Lsb1.font.Color  :=  clWindowText;
         Lsb1.font.Height  :=  -16;
         Lsb1.font.Name  :=  DEFAULTFONT;
         Lsb1.font.Style  :=  [];
         Lsb1.linespacing  :=  1.000000000000000000;
         Lsb1.margin  :=  0;
         Lsb1.showlabels  :=  True;
         Lsb1.drawmode  :=  True;
         Lsb1.numbercolor  :=  clBlack;
         Lsb1.OnClick  :=  lsbClick;
         Lsb1.remote  :=  False;
         Lsb1.scrollwidths  :=  24;
         Lsb1.OnReachedend  :=  lsb1Reachedend;
         Lsb1.inmotion  :=  False;
         Lsb1.highlightindex  :=  False;
         Lsb1.highlighteditem  :=  0;
         Lsb1.highlightindex2  :=  False;
         Lsb1.highlighteditem2  :=  0;
         Lsb1.topmost  :=  0;
         Lsb1playall := TStaticText.Create(Toppanel);
         Lsb1playall.Parent := Toppanel;
         Lsb1playall.Left  :=  24;
         Lsb1playall.Top  :=  110;
         Lsb1playall.Width  :=  4;
         Lsb1playall.Height  :=  4;
         Lsb1playall.Color  :=  clBlack;
         Lsb1playall.ParentColor  :=  False;
         Lsb1playall.TabOrder  :=  1;
         Lsb1playall.Visible  :=  False;
         Lsb1playall.OnClick  :=  lsb1playallClick;
       Topoverpanel := TPanel.Create(Midpanelpanel);
       Topoverpanel.Parent := Midpanelpanel;
       Topoverpanel.Left  :=  400;
       Topoverpanel.Top  :=  160;
       Topoverpanel.Width  :=  305;
       Topoverpanel.Height  :=  129;
       Topoverpanel.BevelOuter  :=  bvNone;
       Topoverpanel.BorderWidth  :=  2;
       Topoverpanel.BorderStyle  :=  bsSingle;
       Topoverpanel.Color  :=  clWhite;
       Topoverpanel.Ctl3D  :=  False;
       Topoverpanel.ParentCtl3D  :=  False;
       Topoverpanel.TabOrder  :=  1;
         Lb7 := TImage.Create(Topoverpanel);
         Lb7.Parent := Topoverpanel;
         Lb7.Left  :=  168;
         Lb7.Top  :=  8;
         Lb7.Width  :=  105;
         Lb7.Height  :=  105;
         Lb7.Stretch  :=  True;
         Cd7 := TImage.Create(Topoverpanel);
         Cd7.Parent := Topoverpanel;
         Cd7.Left  :=  0;
         Cd7.Top  :=  0;
         Cd7.Width  :=  105;
         Cd7.Height  :=  105;
         Cd7.Stretch  :=  True;
         Lsb7 := TScrollListbox.Create(Topoverpanel);
         Lsb7.Parent := Topoverpanel;
         Lsb7.Left  :=  288;
         Lsb7.Top  :=  80;
         Lsb7.Width  :=  0;
         Lsb7.Height  :=  0;
         Lsb7.color  :=  clWindow;
         Lsb7.itemindex  :=  0;
         Lsb7.font.Charset  :=  DEFAULT_CHARSET;
         Lsb7.font.Color  :=  clWindowText;
         Lsb7.font.Height  :=  -16;
         Lsb7.font.Name  :=  DEFAULTFONT;
         Lsb7.font.Style  :=  [];
         Lsb7.linespacing  :=  1.000000000000000000;
         Lsb7.margin  :=  0;
         Lsb7.showlabels  :=  True;
         Lsb7.drawmode  :=  True;
         Lsb7.numbercolor  :=  clBlack;
         Lsb7.remote  :=  False;
         Lsb7.scrollwidths  :=  24;
         Lsb7.inmotion  :=  False;
         Lsb7.highlightindex  :=  False;
         Lsb7.highlighteditem  :=  0;
         Lsb7.highlightindex2  :=  False;
         Lsb7.highlighteditem2  :=  0;
         Lsb7.topmost  :=  0;
         Lsb7playall := TStaticText.Create(Topoverpanel);
         Lsb7playall.Parent := Topoverpanel;
         Lsb7playall.Left  :=  32;
         Lsb7playall.Top  :=  110;
         Lsb7playall.Width  :=  4;
         Lsb7playall.Height  :=  4;
         Lsb7playall.TabOrder  :=  1;
         Lsb7playall.Visible  :=  False;
       Botpanel := TPanel.Create(Midpanelpanel);
       Botpanel.Parent := Midpanelpanel;
       Botpanel.Left  :=  256;
       Botpanel.Top  :=  200;
       Botpanel.Width  :=  305;
       Botpanel.Height  :=  129;
       Botpanel.BevelOuter  :=  bvNone;
       Botpanel.BorderWidth  :=  1;
       Botpanel.BorderStyle  :=  bsSingle;
       Botpanel.Color  :=  clWhite;
       Botpanel.Ctl3D  :=  False;
       Botpanel.ParentCtl3D  :=  False;
       Botpanel.TabOrder  :=  2;
         Lb2 := TImage.Create(Botpanel);
         Lb2.Parent := Botpanel;
         Lb2.Left  :=  128;
         Lb2.Top  :=  0;
         Lb2.Width  :=  105;
         Lb2.Height  :=  105;
         Lb2.Stretch  :=  True;
         Cd2 := TImage.Create(Botpanel);
         Cd2.Parent := Botpanel;
         Cd2.Left  :=  0;
         Cd2.Top  :=  0;
         Cd2.Width  :=  105;
         Cd2.Height  :=  105;
         Cd2.Stretch  :=  True;
         Cd2.OnClick  :=  cdclick;
         Cd2.OnMouseDown  :=  cdMouseDown;
         Lsb2 := TScrollListbox.Create(Botpanel);
         Lsb2.Parent := Botpanel;
         Lsb2.Left  :=  248;
         Lsb2.Top  :=  32;
         Lsb2.Width  :=  33;
         Lsb2.Height  :=  65;
         Lsb2.color  :=  clWindow;
         Lsb2.itemindex  :=  0;
         Lsb2.font.Charset  :=  DEFAULT_CHARSET;
         Lsb2.font.Color  :=  clWindowText;
         Lsb2.font.Height  :=  -16;
         Lsb2.font.Name  :=  DEFAULTFONT;
         Lsb2.font.Style  :=  [];
         Lsb2.linespacing  :=  1.000000000000000000;
         Lsb2.margin  :=  0;
         Lsb2.showlabels  :=  True;
         Lsb2.drawmode  :=  True;
         Lsb2.numbercolor  :=  clBlack;
         Lsb2.OnClick  :=  lsbClick;
         Lsb2.remote  :=  False;
         Lsb2.scrollwidths  :=  24;
         Lsb2.OnReachedtop  :=  lsb2Reachedtop;
         Lsb2.inmotion  :=  False;
         Lsb2.highlightindex  :=  False;
         Lsb2.highlighteditem  :=  0;
         Lsb2.highlightindex2  :=  False;
         Lsb2.highlighteditem2  :=  0;
         Lsb2.topmost  :=  0;
         Lsb2playall := TStaticText.Create(Botpanel);
         Lsb2playall.Parent := Botpanel;
         Lsb2playall.Left  :=  16;
         Lsb2playall.Top  :=  110;
         Lsb2playall.Width  :=  4;
         Lsb2playall.Height  :=  4;
         Lsb2playall.Color  :=  clBlack;
         Lsb2playall.ParentColor  :=  False;
         Lsb2playall.TabOrder  :=  1;
         Lsb2playall.Visible  :=  False;
         Lsb2playall.OnClick  :=  lsb2playallClick;
       Botoverpanel := TPanel.Create(Midpanelpanel);
       Botoverpanel.Parent := Midpanelpanel;
       Botoverpanel.Left  :=  -32;
       Botoverpanel.Top  :=  288;
       Botoverpanel.Width  :=  305;
       Botoverpanel.Height  :=  129;
       Botoverpanel.BevelOuter  :=  bvNone;
       Botoverpanel.BorderWidth  :=  2;
       Botoverpanel.BorderStyle  :=  bsSingle;
       Botoverpanel.Color  :=  clWhite;
       Botoverpanel.Ctl3D  :=  False;
       Botoverpanel.ParentCtl3D  :=  False;
       Botoverpanel.TabOrder  :=  3;
         Lb8 := TImage.Create(Botoverpanel);
         Lb8.Parent := Botoverpanel;
         Lb8.Left  :=  168;
         Lb8.Top  :=  8;
         Lb8.Width  :=  105;
         Lb8.Height  :=  105;
         Lb8.Stretch  :=  True;
         Cd8 := TImage.Create(Botoverpanel);
         Cd8.Parent := Botoverpanel;
         Cd8.Left  :=  0;
         Cd8.Top  :=  0;
         Cd8.Width  :=  105;
         Cd8.Height  :=  105;
         Cd8.Stretch  :=  True;
         Lsb8 := TScrollListbox.Create(Botoverpanel);
         Lsb8.Parent := Botoverpanel;
         Lsb8.Left  :=  216;
         Lsb8.Top  :=  16;
         Lsb8.Width  :=  65;
         Lsb8.Height  :=  33;
         Lsb8.color  :=  clWindow;
         Lsb8.itemindex  :=  0;
         Lsb8.font.Charset  :=  DEFAULT_CHARSET;
         Lsb8.font.Color  :=  clWindowText;
         Lsb8.font.Height  :=  -16;
         Lsb8.font.Name  :=  DEFAULTFONT;
         Lsb8.font.Style  :=  [];
         Lsb8.linespacing  :=  1.000000000000000000;
         Lsb8.margin  :=  0;
         Lsb8.showlabels  :=  True;
         Lsb8.drawmode  :=  True;
         Lsb8.numbercolor  :=  clBlack;
         Lsb8.remote  :=  False;
         Lsb8.scrollwidths  :=  24;
         Lsb8.inmotion  :=  False;
         Lsb8.highlightindex  :=  False;
         Lsb8.highlighteditem  :=  0;
         Lsb8.highlightindex2  :=  False;
         Lsb8.highlighteditem2  :=  0;
         Lsb8.topmost  :=  0;
         Lsb8playall := TStaticText.Create(Botoverpanel);
         Lsb8playall.Parent := Botoverpanel;
         Lsb8playall.Left  :=  8;
         Lsb8playall.Top  :=  110;
         Lsb8playall.Width  :=  4;
         Lsb8playall.Height  :=  4;
         Lsb8playall.TabOrder  :=  1;
         Lsb8playall.Visible  :=  False;
       Botrightpanel := TPanel.Create(Midpanelpanel);
       Botrightpanel.Parent := Midpanelpanel;
       Botrightpanel.Left  :=  272;
       Botrightpanel.Top  :=  128;
       Botrightpanel.Width  :=  305;
       Botrightpanel.Height  :=  129;
       Botrightpanel.BevelOuter  :=  bvNone;
       Botrightpanel.BorderWidth  :=  1;
       Botrightpanel.BorderStyle  :=  bsSingle;
       Botrightpanel.Color  :=  clWhite;
       Botrightpanel.Ctl3D  :=  False;
       Botrightpanel.FullRepaint  :=  False;
       Botrightpanel.ParentCtl3D  :=  False;
       Botrightpanel.TabOrder  :=  4;
         Lb4 := TImage.Create(Botrightpanel);
         Lb4.Parent := Botrightpanel;
         Lb4.Left  :=  128;
         Lb4.Top  :=  0;
         Lb4.Width  :=  105;
         Lb4.Height  :=  105;
         Lb4.Stretch  :=  True;
         Cd4 := TImage.Create(Botrightpanel);
         Cd4.Parent := Botrightpanel;
         Cd4.Left  :=  0;
         Cd4.Top  :=  0;
         Cd4.Width  :=  105;
         Cd4.Height  :=  105;
         Cd4.Stretch  :=  True;
         Cd4.OnClick  :=  cdclick;
         Cd4.OnMouseDown  :=  cdMouseDown;
         Lsb4 := TScrollListbox.Create(Botrightpanel);
         Lsb4.Parent := Botrightpanel;
         Lsb4.Left  :=  272;
         Lsb4.Top  :=  96;
         Lsb4.Width  :=  0;
         Lsb4.Height  :=  0;
         Lsb4.color  :=  clWindow;
         Lsb4.itemindex  :=  0;
         Lsb4.font.Charset  :=  DEFAULT_CHARSET;
         Lsb4.font.Color  :=  clWindowText;
         Lsb4.font.Height  :=  -16;
         Lsb4.font.Name  :=  DEFAULTFONT;
         Lsb4.font.Style  :=  [];
         Lsb4.linespacing  :=  1.000000000000000000;
         Lsb4.margin  :=  0;
         Lsb4.showlabels  :=  True;
         Lsb4.drawmode  :=  True;
         Lsb4.numbercolor  :=  clBlack;
         Lsb4.remote  :=  False;
         Lsb4.scrollwidths  :=  24;
         Lsb4.inmotion  :=  False;
         Lsb4.highlightindex  :=  False;
         Lsb4.highlighteditem  :=  0;
         Lsb4.highlightindex2  :=  False;
         Lsb4.highlighteditem2  :=  0;
         Lsb4.topmost  :=  0;
         Lsb4playall := TStaticText.Create(Botrightpanel);
         Lsb4playall.Parent := Botrightpanel;
         Lsb4playall.Left  :=  8;
         Lsb4playall.Top  :=  110;
         Lsb4playall.Width  :=  4;
         Lsb4playall.Height  :=  4;
         Lsb4playall.TabOrder  :=  1;
         Lsb4playall.Visible  :=  False;
       Toprightpanel := TPanel.Create(Midpanelpanel);
       Toprightpanel.Parent := Midpanelpanel;
       Toprightpanel.Left  :=  400;
       Toprightpanel.Top  :=  8;
       Toprightpanel.Width  :=  289;
       Toprightpanel.Height  :=  121;
       Toprightpanel.BevelOuter  :=  bvNone;
       Toprightpanel.BorderWidth  :=  2;
       Toprightpanel.BorderStyle  :=  bsSingle;
       Toprightpanel.Color  :=  clWhite;
       Toprightpanel.Ctl3D  :=  False;
       Toprightpanel.FullRepaint  :=  False;
       Toprightpanel.ParentCtl3D  :=  False;
       Toprightpanel.TabOrder  :=  5;
         Lb3 := TImage.Create(Toprightpanel);
         Lb3.Parent := Toprightpanel;
         Lb3.Left  :=  128;
         Lb3.Top  :=  0;
         Lb3.Width  :=  105;
         Lb3.Height  :=  105;
         Lb3.Stretch  :=  True;
         Cd3 := TImage.Create(Toprightpanel);
         Cd3.Parent := Toprightpanel;
         Cd3.Left  :=  0;
         Cd3.Top  :=  0;
         Cd3.Width  :=  105;
         Cd3.Height  :=  105;
         Cd3.Stretch  :=  True;
         Cd3.OnClick  :=  cdclick;
         Cd3.OnMouseDown  :=  cdMouseDown;
         Lsb3 := TScrollListbox.Create(Toprightpanel);
         Lsb3.Parent := Toprightpanel;
         Lsb3.Left  :=  256;
         Lsb3.Top  :=  40;
         Lsb3.Width  :=  0;
         Lsb3.Height  :=  0;
         Lsb3.color  :=  clWindow;
         Lsb3.itemindex  :=  0;
         Lsb3.font.Charset  :=  DEFAULT_CHARSET;
         Lsb3.font.Color  :=  clWindowText;
         Lsb3.font.Height  :=  -16;
         Lsb3.font.Name  :=  DEFAULTFONT;
         Lsb3.font.Style  :=  [];
         Lsb3.linespacing  :=  1.000000000000000000;
         Lsb3.margin  :=  0;
         Lsb3.showlabels  :=  True;
         Lsb3.drawmode  :=  True;
         Lsb3.numbercolor  :=  clBlack;
         Lsb3.remote  :=  False;
         Lsb3.scrollwidths  :=  24;
         Lsb3.inmotion  :=  False;
         Lsb3.highlightindex  :=  False;
         Lsb3.highlighteditem  :=  0;
         Lsb3.highlightindex2  :=  False;
         Lsb3.highlighteditem2  :=  0;
         Lsb3.topmost  :=  0;
         Lsb3playall := TStaticText.Create(Toprightpanel);
         Lsb3playall.Parent := Toprightpanel;
         Lsb3playall.Left  :=  16;
         Lsb3playall.Top  :=  102;
         Lsb3playall.Width  :=  4;
         Lsb3playall.Height  :=  4;
         Lsb3playall.TabOrder  :=  1;
         Lsb3playall.Visible  :=  False;
       Toprightunderpanel := TPanel.Create(Midpanelpanel);
       Toprightunderpanel.Parent := Midpanelpanel;
       Toprightunderpanel.Left  :=  328;
       Toprightunderpanel.Top  :=  72;
       Toprightunderpanel.Width  :=  289;
       Toprightunderpanel.Height  :=  121;
       Toprightunderpanel.BevelOuter  :=  bvNone;
       Toprightunderpanel.BorderWidth  :=  2;
       Toprightunderpanel.BorderStyle  :=  bsSingle;
       Toprightunderpanel.Color  :=  clWhite;
       Toprightunderpanel.Ctl3D  :=  False;
       Toprightunderpanel.FullRepaint  :=  False;
       Toprightunderpanel.ParentCtl3D  :=  False;
       Toprightunderpanel.TabOrder  :=  6;
         Cd5 := TImage.Create(Toprightunderpanel);
         Cd5.Parent := Toprightunderpanel;
         Cd5.Left  :=  0;
         Cd5.Top  :=  0;
         Cd5.Width  :=  105;
         Cd5.Height  :=  105;
         Cd5.Stretch  :=  True;

       Botrightunderpanel := TPanel.Create(Midpanelpanel);
       Botrightunderpanel.Parent := Midpanelpanel;
       Botrightunderpanel.Left  :=  400;
       Botrightunderpanel.Top  :=  320;
       Botrightunderpanel.Width  :=  289;
       Botrightunderpanel.Height  :=  121;
       Botrightunderpanel.BevelOuter  :=  bvNone;
       Botrightunderpanel.BorderWidth  :=  2;
       Botrightunderpanel.BorderStyle  :=  bsSingle;
       Botrightunderpanel.Color  :=  clWhite;
       Botrightunderpanel.Ctl3D  :=  False;
       Botrightunderpanel.FullRepaint  :=  False;
       Botrightunderpanel.ParentCtl3D  :=  False;
       Botrightunderpanel.TabOrder  :=  7;
         Cd6 := TImage.Create(Botrightunderpanel);
         Cd6.Parent := Botrightunderpanel;
         Cd6.Left  :=  0;
         Cd6.Top  :=  0;
         Cd6.Width  :=  105;
         Cd6.Height  :=  105;
         Cd6.Stretch  :=  True;

     Openpanelpanel := TPanel.Create(self);
     Openpanelpanel.Parent := Self;
     Openpanelpanel.Left  :=  48;
     Openpanelpanel.Top  :=  552;
     Openpanelpanel.Width  :=  49;
     Openpanelpanel.Height  :=  41;
     Openpanelpanel.BevelOuter  :=  bvNone;
     Openpanelpanel.Color  :=  clBlack;
     Openpanelpanel.TabOrder  :=  3;
       Openpanel := TImage.Create(Openpanelpanel);
       Openpanel.Parent := Openpanelpanel;
       Openpanel.Left  :=  12;
       Openpanel.Top  :=  -5;
       Openpanel.Width  :=  33;
       Openpanel.Height  :=  41;
       Openpanel.Stretch  :=  True;
       Openpanel.OnClick  :=  openpanelClick;
     Kioskpanelpanel := TPanel.Create(self);
     Kioskpanelpanel.Parent := Self;
     Kioskpanelpanel.Left  :=  776;
     Kioskpanelpanel.Top  :=  64;
     Kioskpanelpanel.Width  :=  49;
     Kioskpanelpanel.Height  :=  41;
     Kioskpanelpanel.BevelOuter  :=  bvNone;
     Kioskpanelpanel.Caption  :=  'kioskpanelpanel';
     Kioskpanelpanel.Color  :=  clBlack;
     Kioskpanelpanel.TabOrder  :=  4;
     Kioskpanelpanel.Visible  :=  False;
       Kioskpanel := TImage.Create(Kioskpanelpanel);
       Kioskpanel.Parent := Kioskpanelpanel;
       Kioskpanel.Left  :=  0;
       Kioskpanel.Top  :=  0;
       Kioskpanel.Width  :=  33;
       Kioskpanel.Height  :=  41;
       Kioskpanel.Stretch  :=  True;
       Kioskpanel.OnClick  :=  kioskpanelClick;
     VisualsPanelpanel := TPanel.Create(Self);
     VisualsPanelpanel.Parent := Self;
     VisualsPanelpanel.Left  :=  48;
     VisualsPanelpanel.Top  :=  552;
     VisualsPanelpanel.Width  :=  49;
     VisualsPanelpanel.Height  :=  41;
     VisualsPanelpanel.BevelOuter  :=  bvNone;
     VisualsPanelpanel.Color  :=  clBlack;
     VisualsPanelpanel.TabOrder  :=  3;
       VisualsPanel := TImage.Create(VisualsPanelpanel);
       VisualsPanel.Parent := VisualsPanelpanel;
       VisualsPanel.Left  :=  12;
       VisualsPanel.Top  :=  -5;
       VisualsPanel.Width  :=  33;
       VisualsPanel.Height  :=  41;
       VisualsPanel.Stretch  :=  True;
       VisualsPanel.OnClick  :=  VisualsPanelClick;
     Panel_kiosk := TPanel.Create(self);
     Panel_kiosk.Parent := Self;
     Panel_kiosk.Left  :=  0;
     Panel_kiosk.Top  :=  400;
     Panel_kiosk.Width  :=  281;
     Panel_kiosk.Height  :=  81;
     Panel_kiosk.BevelOuter  :=  bvNone;
     Panel_kiosk.Color  :=  clSilver;
     Panel_kiosk.TabOrder  :=  5;
     Panel_kiosk.Visible  :=  False;
       Panel_kioskshape2 := TShape.Create(Panel_kiosk);
       Panel_kioskshape2.Parent := Panel_kiosk;
       Panel_kioskshape2.Left  :=  184;
       Panel_kioskshape2.Top  :=  0;
       Panel_kioskshape2.Width  :=  41;
       Panel_kioskshape2.Height  :=  81;
       Panel_kioskshape2.Brush.Style  :=  bsClear;
       Panel_kioskshape2.Pen.Color  :=  2131873;
       Panel_kioskshape2.Pen.Width  :=  3;
       Panel_kioskshape1 := TShape.Create(Panel_kiosk);
       Panel_kioskshape1.Parent := Panel_kiosk;
       Panel_kioskshape1.Left  :=  0;
       Panel_kioskshape1.Top  :=  0;
       Panel_kioskshape1.Width  :=  281;
       Panel_kioskshape1.Height  :=  81;
       Panel_kioskshape1.Align  :=  alClient;
       Panel_kioskshape1.Brush.Style  :=  bsClear;
       Panel_kioskshape1.Pen.Color  :=  50935;
       Panel_kioskshape1.Pen.Width  :=  4;
       Randombut := TBitmapActionButton.Create(Panel_kiosk);
       Randombut.Parent := Panel_kiosk;
       Randombut.Left  :=  32;
       Randombut.Top  :=  40;
       Randombut.Width  :=  32;
       Randombut.Height  :=  32;
       Randombut.color  :=  clWhite;
       Randombut.font.Charset  :=  DEFAULT_CHARSET;
       Randombut.font.Color  :=  clWindowText;
       Randombut.font.Height  :=  -16;
       Randombut.font.Name  :=  DEFAULTFONT;
       Randombut.font.Style  :=  [];
       Randombut.down  :=  False;
       Randombut.buttoncolor  :=  0;
       Randombut.OnClick  :=  randombutClick;
       Rejectall := TBitmapActionButton.Create(Panel_kiosk);
       Rejectall.Parent := Panel_kiosk;
       Rejectall.Left  :=  40;
       Rejectall.Top  :=  48;
       Rejectall.Width  :=  32;
       Rejectall.Height  :=  32;
       Rejectall.color  :=  clWhite;
       Rejectall.font.Charset  :=  DEFAULT_CHARSET;
       Rejectall.font.Color  :=  clWindowText;
       Rejectall.font.Height  :=  -16;
       Rejectall.font.Name  :=  DEFAULTFONT;
       Rejectall.font.Style  :=  [];
       Rejectall.down  :=  False;
       Rejectall.buttoncolor  :=  0;
       Rejectall.OnClick  :=  rejectallClick;
       Ripbut := TBitmapActionButton.Create(Panel_kiosk);
       Ripbut.Parent := Panel_kiosk;
       Ripbut.Left  :=  48;
       Ripbut.Top  :=  49;
       Ripbut.Width  :=  32;
       Ripbut.Height  :=  32;
       Ripbut.color  :=  clWhite;
       Ripbut.font.Charset  :=  DEFAULT_CHARSET;
       Ripbut.font.Color  :=  clWindowText;
       Ripbut.font.Height  :=  -16;
       Ripbut.font.Name  :=  DEFAULTFONT;
       Ripbut.font.Style  :=  [];
       Ripbut.down  :=  False;
       Ripbut.buttoncolor  :=  0;
       Ripbut.OnClick  :=  ripbutClick;
       Advancedbut := TBitmapActionButton.Create(Panel_kiosk);
       Advancedbut.Parent := Panel_kiosk;
       Advancedbut.Left  :=  56;
       Advancedbut.Top  :=  49;
       Advancedbut.Width  :=  32;
       Advancedbut.Height  :=  32;
       Advancedbut.color  :=  clWhite;
       Advancedbut.font.Charset  :=  DEFAULT_CHARSET;
       Advancedbut.font.Color  :=  clWindowText;
       Advancedbut.font.Height  :=  -16;
       Advancedbut.font.Name  :=  DEFAULTFONT;
       Advancedbut.font.Style  :=  [];
       Advancedbut.down  :=  False;
       Advancedbut.buttoncolor  :=  0;
       Advancedbut.OnClick  :=  advancedbutClick;
       Shutdownbut := TBitmapActionButton.Create(Panel_kiosk);
       Shutdownbut.Parent := Panel_kiosk;
       Shutdownbut.Left  :=  64;
       Shutdownbut.Top  :=  49;
       Shutdownbut.Width  :=  32;
       Shutdownbut.Height  :=  32;
       Shutdownbut.color  :=  clWhite;
       Shutdownbut.font.Charset  :=  DEFAULT_CHARSET;
       Shutdownbut.font.Color  :=  clWindowText;
       Shutdownbut.font.Height  :=  -16;
       Shutdownbut.font.Name  :=  DEFAULTFONT;
       Shutdownbut.font.Style  :=  [];
       Shutdownbut.down  :=  False;
       Shutdownbut.buttoncolor  :=  0;
       Shutdownbut.OnClick  :=  ShutdownbutClick;
       Goplaylistview := TBitmapActionButton.Create(Panel_kiosk);
       Goplaylistview.Parent := Panel_kiosk;
       Goplaylistview.Left  :=  72;
       Goplaylistview.Top  :=  49;
       Goplaylistview.Width  :=  32;
       Goplaylistview.Height  :=  32;
       Goplaylistview.color  :=  clWhite;
       Goplaylistview.font.Charset  :=  DEFAULT_CHARSET;
       Goplaylistview.font.Color  :=  clWindowText;
       Goplaylistview.font.Height  :=  -16;
       Goplaylistview.font.Name  :=  DEFAULTFONT;
       Goplaylistview.font.Style  :=  [];
       Goplaylistview.down  :=  False;
       Goplaylistview.buttoncolor  :=  1;
       Goplaylistview.OnClick  :=  goplaylistviewClick;
       Autoplaycb := TBitmapCheckbox.Create(Panel_kiosk);
       Autoplaycb.Parent := Panel_kiosk;
       Autoplaycb.Left  :=  0;
       Autoplaycb.Top  :=  8;
       Autoplaycb.Width  :=  104;
       Autoplaycb.Height  :=  32;
       Autoplaycb.color  :=  clWhite;
       Autoplaycb.Font.Charset  :=  DEFAULT_CHARSET;
       Autoplaycb.Font.Color  :=  clWindowText;
       Autoplaycb.Font.Height  :=  -16;
       Autoplaycb.Font.Name  :=  DEFAULTFONT;
       Autoplaycb.Font.Style  :=  [];
       Autoplaycb.checked  :=  False;
       Autoplaycb.OnClick  :=  autoplaycbClick;
       Randompanel := TTransparentPanel.Create(Self);
     Randompanel.Parent := Self;
     Randompanel.Left  :=  416;
     Randompanel.Top  :=  184;
     Randompanel.Width  :=  609;
     Randompanel.Height  :=  273;
     Randompanel.border  :=  False;
     Randompanel.Visible  :=  False;
       Randompanelshape2 := TShape.Create(Randompanel);
       Randompanelshape2.Parent := Randompanel;
       Randompanelshape2.Left  :=  184;
       Randompanelshape2.Top  :=  0;
       Randompanelshape2.Width  :=  41;
       Randompanelshape2.Height  :=  81;
       Randompanelshape2.Brush.Style  :=  bsClear;
       Randompanelshape2.Pen.Color  :=  2131873;
       Randompanelshape2.Pen.Width  :=  3;
       Randompanelshape1 := TShape.Create(Randompanel);
       Randompanelshape1.Parent := Randompanel;
       Randompanelshape1.Left  :=  304;
       Randompanelshape1.Top  :=  24;
       Randompanelshape1.Width  :=  161;
       Randompanelshape1.Height  :=  49;
       Randompanelshape1.Brush.Style  :=  bsClear;
       Randompanelshape1.Pen.Color  :=  50935;
       Randompanelshape1.Pen.Width  :=  4;
       Randompanelselectall := TBitmapActionButton.Create(Randompanel);
       Randompanelselectall.Parent := Randompanel;
       Randompanelselectall.Left  :=  464;
       Randompanelselectall.Top  :=  136;
       Randompanelselectall.Width  :=  168;
       Randompanelselectall.Height  :=  32;
       Randompanelselectall.color  :=  clWhite;
       Randompanelselectall.font.Charset  :=  DEFAULT_CHARSET;
       Randompanelselectall.font.Color  :=  clWindowText;
       Randompanelselectall.font.Height  :=  -16;
       Randompanelselectall.font.Name  :=  DEFAULTFONT;
       Randompanelselectall.font.Style  :=  [];
       Randompanelselectall.caption  :=  'Select all albums';
       Randompanelselectall.down  :=  False;
       Randompanelselectall.buttoncolor  :=  0;
       Randompanelselectall.OnClick  :=  randompanelselectallClick;
       Randompanelselectnone := TBitmapActionButton.Create(Randompanel);
       Randompanelselectnone.Parent := Randompanel;
       Randompanelselectnone.Left  :=  464;
       Randompanelselectnone.Top  :=  176;
       Randompanelselectnone.Width  :=  170;
       Randompanelselectnone.Height  :=  32;
       Randompanelselectnone.color  :=  clWhite;
       Randompanelselectnone.font.Charset  :=  DEFAULT_CHARSET;
       Randompanelselectnone.font.Color  :=  clWindowText;
       Randompanelselectnone.font.Height  :=  -16;
       Randompanelselectnone.font.Name  :=  DEFAULTFONT;
       Randompanelselectnone.font.Style  :=  [];
       Randompanelselectnone.caption  :=  'Select no albums';
       Randompanelselectnone.down  :=  False;
       Randompanelselectnone.buttoncolor  :=  0;
       Randompanelselectnone.OnClick  :=  randompanelselectnoneClick;
       Randomcountlabel := TLabel.Create(Randompanel);
       Randomcountlabel.Parent := Randompanel;
       Randomcountlabel.Left  :=  525;
       Randomcountlabel.Top  :=  8;
       Randomcountlabel.Width  :=  84;
       Randomcountlabel.Height  :=  13;
       Randomcountlabel.Caption  :=  'randomcountlabel';
       Randomcountlabel.Transparent  :=  True;
       Randompanelcancel := TBitmapActionButton.Create(Randompanel);
       Randompanelcancel.Parent := Randompanel;
       Randompanelcancel.Left  :=  488;
       Randompanelcancel.Top  :=  241;
       Randompanelcancel.Width  :=  50;
       Randompanelcancel.Height  :=  32;
       Randompanelcancel.color  :=  clWhite;
       Randompanelcancel.font.Charset  :=  DEFAULT_CHARSET;
       Randompanelcancel.font.Color  :=  clWindowText;
       Randompanelcancel.font.Height  :=  -16;
       Randompanelcancel.font.Name  :=  DEFAULTFONT;
       Randompanelcancel.font.Style  :=  [];
       Randompanelcancel.down  :=  False;
       Randompanelcancel.buttoncolor  :=  0;
       Randompanelcancel.OnClick  :=  randompanelcancelClick;
       RandomCancel := TBitmapActionButton.Create(Randompanel);
       RandomCancel.Parent := Randompanel;
       RandomCancel.Left  :=  184;
       RandomCancel.Top  :=  241;
       RandomCancel.Width  :=  189;
       RandomCancel.Height  :=  32;
       RandomCancel.color  :=  clWhite;
       RandomCancel.font.Charset  :=  DEFAULT_CHARSET;
       RandomCancel.font.Color  :=  clWindowText;
       RandomCancel.font.Height  :=  -16;
       RandomCancel.font.Name  :=  DEFAULTFONT;
       RandomCancel.font.Style  :=  [];
       RandomCancel.caption  :=  'Stop Adding Tracks';
       RandomCancel.down  :=  False;
       RandomCancel.buttoncolor  :=  0;
       RandomCancel.OnClick  :=  RandomCancelClick;
       RandompanelOK := TBitmapActionButton.Create(Randompanel);
       RandompanelOK.Parent := Randompanel;
       RandompanelOK.Left  :=  64;
       RandompanelOK.Top  :=  241;
       RandompanelOK.Width  :=  50;
       RandompanelOK.Height  :=  32;
       RandompanelOK.color  :=  clWhite;
       RandompanelOK.font.Charset  :=  DEFAULT_CHARSET;
       RandompanelOK.font.Color  :=  clWindowText;
       RandompanelOK.font.Height  :=  -16;
       RandompanelOK.font.Name  :=  DEFAULTFONT;
       RandompanelOK.font.Style  :=  [];
       RandompanelOK.down  :=  False;
       RandompanelOK.buttoncolor  :=  0;
       RandompanelOK.OnClick  :=  randompanelOKClick;
       Randompanellb := TSelecterListBox.Create(Randompanel);
       Randompanellb.Parent := Randompanel;
       Randompanellb.Left  :=  40;
       Randompanellb.Top  :=  41;
       Randompanellb.Width  :=  216;
       Randompanellb.Height  :=  87;
       Randompanellb.color  :=  clWindow;
       Randompanellb.font.Charset  :=  DEFAULT_CHARSET;
       Randompanellb.font.Color  :=  clWindowText;
       Randompanellb.font.Height  :=  -16;
       Randompanellb.font.Name  :=  DEFAULTFONT;
       Randompanellb.font.Style  :=  [];
       Randompanellb.linespacing  :=  1.000000000000000000;
       Randompanellb.margin  :=  0;
       Randompanellb.showlabels  :=  True;
       Randompanellb.drawmode  :=  True;
       Randompanellb.numbercolor  :=  clBlack;
       Randompanellb.OnClick  :=  randompanellbClick;
       Randomdicepanel := TTransparentPanel.Create(Randompanel);
       Randomdicepanel.Parent := Randompanel;
       Randomdicepanel.Left  :=  88;
       Randomdicepanel.Top  :=  16;
       Randomdicepanel.Width  :=  503;
       Randomdicepanel.Height  :=  344;
       Randomdicepanel.border  :=  False;
         Randomdice := TImage.Create(Randomdicepanel);
         Randomdice.Parent := Randomdicepanel;
         Randomdice.Left  :=  0;
         Randomdice.Top  :=  0;
         Randomdice.Width  :=  503;
         Randomdice.Height  :=  344;
         Randomdice.Align  :=  alClient;
         Randomdice.Transparent  :=  True;
     Advanced := TTransparentPanel.Create(Self);
     Advanced.Parent := Self;
     Advanced.Left  :=  55;
     Advanced.Top  :=  -14;
     Advanced.Width  :=  640;
     Advanced.Height  :=  480;
     Advanced.border  :=  False;
     Advanced.Visible  :=  False;
       Jbinfogo := TBitmapActionButton.Create(Advanced);
       Jbinfogo.Parent := Advanced;
       Jbinfogo.Left  :=  160;
       Jbinfogo.Top  :=  128;
       Jbinfogo.Width  :=  50;
       Jbinfogo.Height  :=  32;
       Jbinfogo.color  :=  clWindow;
       Jbinfogo.font.Charset  :=  DEFAULT_CHARSET;
       Jbinfogo.font.Color  :=  clWindowText;
       Jbinfogo.font.Height  :=  -16;
       Jbinfogo.font.Name  :=  DEFAULTFONT;
       Jbinfogo.font.Style  :=  [];
       Jbinfogo.down  :=  False;
       Jbinfogo.buttoncolor  :=  0;
       Jbinfogo.OnClick  :=  jbinfogoClick;
       AdvancedOK := TBitmapActionButton.Create(Advanced);
       AdvancedOK.Parent := Advanced;
       AdvancedOK.Left  :=  552;
       AdvancedOK.Top  :=  48;
       AdvancedOK.Width  :=  137;
       AdvancedOK.Height  :=  32;
       AdvancedOK.color  :=  clBlack;
       AdvancedOK.font.Charset  :=  DEFAULT_CHARSET;
       AdvancedOK.font.Color  :=  clWindowText;
       AdvancedOK.font.Height  :=  -19;
       AdvancedOK.font.Name  :=  DEFAULTFONT;
       AdvancedOK.font.Style  :=  [];
       AdvancedOK.caption  :=  'Done';
       AdvancedOK.down  :=  False;
       AdvancedOK.buttoncolor  :=  1;
       AdvancedOK.OnClick  :=  advancedOKClick;
       GoThemeManager := TBitmapActionButton.Create(Advanced);
       GoThemeManager.Parent := Advanced;
       GoThemeManager.Left  :=  552;
       GoThemeManager.Top  :=  86;
       GoThemeManager.Width  :=  200;
       GoThemeManager.Height  :=  32;
       GoThemeManager.color  :=  clBlack;
       GoThemeManager.font.Charset  :=  DEFAULT_CHARSET;
       GoThemeManager.font.Color  :=  clWindowText;
       GoThemeManager.font.Height  :=  -19;
       GoThemeManager.font.Name  :=  DEFAULTFONT;
       GoThemeManager.font.Style  :=  [];
       GoThemeManager.caption  :=  'Launch Theme Manager';
       GoThemeManager.down  :=  False;
       GoThemeManager.buttoncolor  :=  4;
       GoThemeManager.OnClick  :=  GoThemeManagerClick;
       GoCommercialManager := TBitmapActionButton.Create(Advanced);
       GoCommercialManager.Parent := Advanced;
       GoCommercialManager.Left  :=  552;
       GoCommercialManager.Top  :=  86;
       GoCommercialManager.Width  :=  255;
       GoCommercialManager.Height  :=  32;
       GoCommercialManager.color  :=  clBlack;
       GoCommercialManager.font.Charset  :=  DEFAULT_CHARSET;
       GoCommercialManager.font.Color  :=  clWindowText;
       GoCommercialManager.font.Height  :=  -19;
       GoCommercialManager.font.Name  :=  DEFAULTFONT;
       GoCommercialManager.font.Style  :=  [];
       GoCommercialManager.caption  :=  'Commerce Management';
       GoCommercialManager.down  :=  False;
       GoCommercialManager.buttoncolor  :=  3;
       GoCommercialManager.OnClick  :=  GoCommercialManagerClick;
       GoCommercialManager.visible:=false;
       Codepanel := TPanel.Create(Advanced);
       Codepanel.Parent := Advanced;
       Codepanel.Left  :=  24;
       Codepanel.Top  :=  8;
       Codepanel.Width  :=  377;
       Codepanel.Height  :=  105;
       Codepanel.TabOrder  :=  0;
         Codefirst := TLabel.Create(Codepanel);
         Codefirst.Parent := Codepanel;
         Codefirst.Left  :=  238;
         Codefirst.Top  :=  17;
         Codefirst.Width  :=  60;
         Codefirst.Height  :=  32;
         Codefirst.Caption  :=  '0000';
         Codefirst.Font.Charset  :=  ANSI_CHARSET;
         Codefirst.Font.Color  :=  clLime;
         Codefirst.Font.Height  :=  -27;
         Codefirst.Font.Name  :=  DEFAULTFONT;
         Codefirst.Font.Style  :=  [];
         Codefirst.ParentFont  :=  False;
         Codefirst.OnClick  :=  codefirstClick;
         Unlocklabel := TLabel.Create(Codepanel);
         Unlocklabel.Parent := Codepanel;
         Unlocklabel.Left  :=  44;
         Unlocklabel.Top  :=  17;
         Unlocklabel.Width  :=  188;
         Unlocklabel.Height  :=  24;
         Unlocklabel.Caption  :=  '(Un)lock Passcode: ';
         Unlocklabel.Font.Charset  :=  ANSI_CHARSET;
         Unlocklabel.Font.Color  :=  clWindowText;
         Unlocklabel.Font.Height  :=  -21;
         Unlocklabel.Font.Name  :=  DEFAULTFONT;
         Unlocklabel.Font.Style  :=  [];
         Unlocklabel.ParentFont  :=  False;
         Setcode := TBitmapActionButton.Create(Codepanel);
         Setcode.Parent := Codepanel;
         Setcode.Left  :=  160;
         Setcode.Top  :=  65;
         Setcode.Width  :=  129;
         Setcode.Height  :=  32;
         Setcode.color  :=  clBlack;
         Setcode.font.Charset  :=  DEFAULT_CHARSET;
         Setcode.font.Color  :=  clWindowText;
         Setcode.font.Height  :=  -19;
         Setcode.font.Name  :=  DEFAULTFONT;
         Setcode.font.Style  :=  [];
         Setcode.caption  :=  'Set';
         Setcode.down  :=  False;
         Setcode.buttoncolor  :=  3;
         Setcode.OnClick  :=  setcodeClick;
         Code := TEdit.Create(Codepanel);
         Code.Parent := Codepanel;
         Code.Left  :=  304;
         Code.Top  :=  15;
         Code.Width  :=  57;
         Code.Height  :=  40;
         Code.Color  :=  clBlack;
         Code.Font.Charset  :=  ANSI_CHARSET;
         Code.Font.Color  :=  clLime;
         Code.Font.Height  :=  -27;
         Code.Font.Name  :=  DEFAULTFONT;
         Code.Font.Style  :=  [];
         Code.MaxLength  :=  3;
         Code.ParentFont  :=  False;
         Code.TabOrder  :=  0;
         Code.Text  :=  '000';
         Code.OnClick  :=  codeClick;
         Code.OnEnter  :=  codeEnter;
         Code.OnExit  :=  codeExit;
         Code.OnKeyPress  :=  codeKeyPress;
       Editpanel := TPanel.Create(Advanced);
       Editpanel.Parent := Advanced;
       Editpanel.Left  :=  24;
       Editpanel.Top  :=  136;
       Editpanel.Width  :=  921;
       Editpanel.Height  :=  305;
       Editpanel.Caption  :=  'editpanel';
       Editpanel.Color  :=  clBlack;
       Editpanel.TabOrder  :=  1;
         Editlabel := TLabel.Create(Editpanel);
         Editlabel.Parent := Editpanel;
         Editlabel.Left  :=  40;
         Editlabel.Top  :=  17;
         Editlabel.Width  :=  72;
         Editlabel.Height  :=  16;
         Editlabel.Caption  :=  'Edit Album:-';
         Editlabel.Font.Charset  :=  ANSI_CHARSET;
         Editlabel.Font.Color  :=  clWindowText;
         Editlabel.Font.Height  :=  -13;
         Editlabel.Font.Name  :=  DEFAULTFONT;
         Editlabel.Font.Style  :=  [];
         Editlabel.ParentFont  :=  False;
         Editlb := TScrollListbox.Create(Editpanel);
         Editlb.Parent := Editpanel;
         Editlb.Left  :=  32;
         Editlb.Top  :=  47;
         Editlb.Width  :=  881;
         Editlb.Height  :=  225;
         Editlb.color  :=  clBlack;
         Editlb.itemindex  :=  0;
         Editlb.font.Charset  :=  DEFAULT_CHARSET;
         Editlb.font.Color  :=  clWindowText;
         Editlb.font.Height  :=  -16;
         Editlb.font.Name  :=  DEFAULTFONT;
         Editlb.font.Style  :=  [];
         Editlb.linespacing  :=  1.000000000000000000;
         Editlb.margin  :=  0;
         Editlb.showlabels  :=  True;
         Editlb.drawmode  :=  True;
         Editlb.numbercolor  :=  clBlack;
         Editlb.OnClick  :=  editlbClick;
         Editlb.remote  :=  False;
         Editlb.scrollwidths  :=  24;
         Editlb.inmotion  :=  False;
         Editlb.highlightindex  :=  False;
         Editlb.highlighteditem  :=  0;
         Editlb.highlightindex2  :=  False;
         Editlb.highlighteditem2  :=  0;
         Editlb.topmost  :=  0;
       Optionspanel := TPanel.Create(Advanced);
       Optionspanel.Parent := Advanced;
       Optionspanel.Left  :=  8;
       Optionspanel.Top  :=  320;
       Optionspanel.Width  :=  609;
       Optionspanel.Height  :=  73;
       Optionspanel.Color  :=  clBlack;
       Optionspanel.TabOrder  :=  2;
         Addallshow := TBitmapCheckbox.Create(Optionspanel);
         Addallshow.Parent := Optionspanel;
         Addallshow.Left  :=  408;
         Addallshow.Top  :=  24;
         Addallshow.Width  :=  185;
         Addallshow.Height  :=  32;
         Addallshow.color  :=  clBlack;
         Addallshow.Font.Charset  :=  DEFAULT_CHARSET;
         Addallshow.Font.Color  :=  clGreen;
         Addallshow.Font.Height  :=  -21;
         Addallshow.Font.Name  :=  DEFAULTFONT;
         Addallshow.Font.Style  :=  [];
         Addallshow.caption  :=  'Show Add All';
         Addallshow.checked  :=  False;
         Addallshow.OnClick  :=  addallshowClick;
         NoRepeatCb := TBitmapCheckbox.Create(Optionspanel);
         NoRepeatCb.Parent := Optionspanel;
         NoRepeatCb.Left  :=  200;
         NoRepeatCb.Top  :=  40;
         NoRepeatCb.Width  :=  401;
         NoRepeatCb.Height  :=  32;
         NoRepeatCb.color  :=  clBlack;
         NoRepeatCb.Font.Charset  :=  DEFAULT_CHARSET;
         NoRepeatCb.Font.Color  :=  clGreen;
         NoRepeatCb.Font.Height  :=  -21;
         NoRepeatCb.Font.Name  :=  DEFAULTFONT;
         NoRepeatCb.Font.Style  :=  [];
         NoRepeatCb.caption  :=  'Never repeat track within a selection';
         NoRepeatCb.checked  :=  False;
         NoRepeatCb.OnClick  :=  NoRepeatCbClick;
         Volumeshow := TBitmapCheckbox.Create(Optionspanel);
         Volumeshow.Parent := Optionspanel;
         Volumeshow.Left  :=  296;
         Volumeshow.Top  :=  35;
         Volumeshow.Width  :=  313;
         Volumeshow.Height  :=  32;
         Volumeshow.color  :=  clBlack;
         Volumeshow.Font.Charset  :=  DEFAULT_CHARSET;
         Volumeshow.Font.Color  :=  clGreen;
         Volumeshow.Font.Height  :=  -21;
         Volumeshow.Font.Name  :=  DEFAULTFONT;
         Volumeshow.Font.Style  :=  [];
         Volumeshow.caption  :=  'Show Volume control panel';
         Volumeshow.checked  :=  False;
         Volumeshow.OnClick  :=  volumeshowClick;
     Commerce := TTransparentPanel.Create(Self);
     Commerce.Parent := Self;
     Commerce.Left  :=  55;
     Commerce.Top  :=  -14;
     Commerce.Width  :=  640;
     Commerce.Height  :=  480;
     Commerce.border  :=  False;
     Commerce.Visible  :=  False;
     Commerce.Font.Name:=DEFAULTFONT;
     Commerce.Font.Color:= FONTCOL;
     Commerce.Font.Size:=14;
       CmTitleLab := TLabel.Create(Commerce);
       CmTitleLab.Parent := Commerce;
       CmTitleLab.Left  :=  224;
       CmTitleLab.Top  :=  24;
       CmTitleLab.Width  :=  92;
       CmTitleLab.Height  :=  13;
       CmTitleLab.Caption  :=  'Commerce Settings';
       cmTitleLab.Transparent:=true;
       CmCreditPanelLab := TLabel.Create(Commerce);
       CmCreditPanelLab.Parent := Commerce;
       CmCreditPanelLab.Left  :=  24;
       CmCreditPanelLab.Top  :=  40;
       CmCreditPanelLab.Width  :=  77;
       CmCreditPanelLab.Height  :=  13;
       CmCreditPanelLab.Caption  :=  'Credit Options:-';
       CmCreditPanelLab.Transparent:=true;
       CmBackgroundPanelLab := TLabel.Create(Commerce);
       CmBackgroundPanelLab.Parent := Commerce;
       CmBackgroundPanelLab.Left  :=  8;
       CmBackgroundPanelLab.Top  :=  197;
       CmBackgroundPanelLab.Width  :=  104;
       CmBackgroundPanelLab.Height  :=  13;
       CmBackgroundPanelLab.Caption  :=  'Background Options:-';
       CmBackgroundPanelLab.Transparent:=true;
       CmStatisticsPanelLab := TLabel.Create(Commerce);
       CmStatisticsPanelLab.Parent := Commerce;
       CmStatisticsPanelLab.Left  :=  8;
       CmStatisticsPanelLab.Top  :=  343;
       CmStatisticsPanelLab.Width  :=  51;
       CmStatisticsPanelLab.Height  :=  13;
       CmStatisticsPanelLab.Caption  :=  'Statistics:-';
       CmStatisticsPanelLab.Transparent:=true;
       CmCreditPanel := TPanel.Create(Commerce);
       CmCreditPanel.Parent := Commerce;
       CmCreditPanel.Left  :=  56;
       CmCreditPanel.Top  :=  64;
       CmCreditPanel.Width  :=  569;
       CmCreditPanel.Height  :=  121;
       CmCreditPanel.TabOrder  :=  0;
         CmPlaysPerCredit := TNumericInput.Create(CmCreditPanel);
         CmPlaysPerCredit.Parent := CmCreditPanel;
         CmPlaysPerCredit.Left  :=  40;
         CmPlaysPerCredit.Top  :=  16;
         CmPlaysPerCredit.Width  :=  200;
         CmPlaysPerCredit.Height  :=  50;
         CmPlaysPerCredit.color  :=  clWindow;
         CmPlaysPerCredit.value  :=  0;
         CmPlaysPerCredit.max  :=  100;
         CmPlaysPerCredit.min  :=  0;
         CmAllowFreeCredit := TBitmapCheckbox.Create(CmCreditPanel);
         CmAllowFreeCredit.Parent := CmCreditPanel;
         CmAllowFreeCredit.Left  :=  344;
         CmAllowFreeCredit.Top  :=  32;
         CmAllowFreeCredit.Width  :=  164;
         CmAllowFreeCredit.Height  :=  32;
         CmAllowFreeCredit.color  :=  clBlack;
         CmAllowFreeCredit.caption  :=  'Allow Free Credit';
         CmAllowFreeCredit.checked  :=  False;
         CmPlaysPerCreditLab := TLabel.Create(CmCreditPanel);
         CmPlaysPerCreditLab.Parent := CmCreditPanel;
         CmPlaysPerCreditLab.Left  :=  96;
         CmPlaysPerCreditLab.Top  :=  -3;
         CmPlaysPerCreditLab.Width  :=  76;
         CmPlaysPerCreditLab.Height  :=  13;
         CmPlaysPerCreditLab.Caption  :=  'Plays Per Credit';
       CmBackgroundPanel := TPanel.Create(Commerce);
       CmBackgroundPanel.Parent := Commerce;
       CmBackgroundPanel.Left  :=  56;
       CmBackgroundPanel.Top  :=  216;
       CmBackgroundPanel.Width  :=  635;
       CmBackgroundPanel.Height  :=  121;
       CmBackgroundPanel.TabOrder  :=  1;
          CmBgDuration := TNumericInput.Create(CmBackgroundPanel);
         CmBgDuration.Parent := CmBackgroundPanel;
         CmBgDuration.Left  :=  216;
         CmBgDuration.Top  :=  40;
         CmBgDuration.Width  :=  200;
         CmBgDuration.Height  :=  50;
         CmBgDuration.color  :=  clWindow;
         CmBgDuration.value  :=  0;
         CmBgDuration.max  :=  100;
         CmBgDuration.min  :=  0;
         CmBgDurationLab := TLabel.Create(CmBackgroundPanel);
         CmBgDurationLab.Parent := CmBackgroundPanel;
         CmBgDurationLab.Left  :=  248;
         CmBgDurationLab.Top  :=  21;
         CmBgDurationLab.Width  :=  155;
         CmBgDurationLab.Height  :=  13;
         CmBgDurationLab.Caption  :=  'Background Play Duration (mins)';
         CmBgVolume := TNumericInput.Create(CmBackgroundPanel);
         CmBgVolume.Parent := CmBackgroundPanel;
         CmBgVolume.Left  :=  -6;
         CmBgVolume.Top  :=  40;
         CmBgVolume.Width  :=  200;
         CmBgVolume.Height  :=  50;
         CmBgVolume.color  :=  clWindow;
         CmBgVolume.value  :=  0;
         CmBgVolume.max  :=  100;
         CmBgVolume.min  :=  0;
         CmBgVolumeLab := TLabel.Create(CmBackgroundPanel);
         CmBgVolumeLab.Parent := CmBackgroundPanel;
         CmBgVolumeLab.Left  :=  26;
         CmBgVolumeLab.Top  :=  21;
         CmBgVolumeLab.Width  :=  140;
         CmBgVolumeLab.Height  :=  13;
         CmBgVolumeLab.Caption  :=  'Maximum Background Volume';
         CmBgWaitTime := TNumericInput.Create(CmBackgroundPanel);
         CmBgWaitTime.Parent := CmBackgroundPanel;
         CmBgWaitTime.Left  :=  422;
         CmBgWaitTime.Top  :=  40;
         CmBgWaitTime.Width  :=  200;
         CmBgWaitTime.Height  :=  50;
         CmBgWaitTime.color  :=  clWindow;
         CmBgWaitTime.value  :=  0;
         CmBgWaitTime.max  :=  100;
         CmBgWaitTime.min  :=  0;
         CmBgWaitTimeLab := TLabel.Create(CmBackgroundPanel);
         CmBgWaitTimeLab.Parent := CmBackgroundPanel;
         CmBgWaitTimeLab.Left  :=  422;
         CmBgWaitTimeLab.Top  :=  21;
         CmBgWaitTimeLab.Width  :=  191;
         CmBgWaitTimeLab.Height  :=  13;
         CmBgWaitTimeLab.Caption  :=  'Delay between background plays (mins)';
       CmStatisticsPanel := TPanel.Create(Commerce);
       CmStatisticsPanel.Parent := Commerce;
       CmStatisticsPanel.Left  :=  50;
       CmStatisticsPanel.Top  :=  362;
       CmStatisticsPanel.Width  :=  591;
       CmStatisticsPanel.Height  :=  121;
       CmStatisticsPanel.TabOrder  :=  2;
         CmResetCreditStats := TBitmapActionButton.Create(CmStatisticsPanel);
         CmResetCreditStats.Parent := CmStatisticsPanel;
         CmResetCreditStats.Left  :=  368;
         CmResetCreditStats.Top  :=  8;
         CmResetCreditStats.Width  :=  202;
         CmResetCreditStats.Height  :=  32;
         CmResetCreditStats.color  :=  clWindow;
         CmResetCreditStats.caption  :=  'Reset Credit Statistics';
         CmResetCreditStats.down  :=  False;
         CmResetCreditStats.buttoncolor  :=  2;
         cmResetCreditStats.OnClick:=cmResetCreditStatsClick;
         CmCredit := TLabel.Create(CmStatisticsPanel);
         CmCredit.Parent := CmStatisticsPanel;
         CmCredit.Left  :=  48;
         CmCredit.Top  :=  16;
         CmCredit.Width  :=  85;
         CmCredit.Height  :=  13;
         CmCredit.Caption  :=  'Total Coin Credits';
         cmCreditLab := TLabel.Create(CmStatisticsPanel);
         cmCreditLab.Parent := CmStatisticsPanel;
         cmCreditLab.Left  :=  161;
         cmCreditLab.Top  :=  16;
         cmCreditLab.Width  :=  86;
         cmCreditLab.Height  :=  13;
         cmCreditLab.Caption  :=  'Total Free Credits';
         cmtop100Lab := TLabel.Create(CmStatisticsPanel);
         cmtop100Lab.Parent := CmStatisticsPanel;
         cmtop100Lab.Left  :=  240;
         cmtop100Lab.Top  :=  88;
         cmtop100Lab.Width  :=  61;
         cmtop100Lab.Height  :=  13;
         cmtop100Lab.Caption  :=  'Top 100 Plays';
         cmtop100 := TScrollListbox.Create(CmStatisticsPanel);
         cmtop100.Parent := CmStatisticsPanel;
         cmtop100.Left  :=  46;
         cmtop100.Top  :=  56;
         cmtop100.Width  :=  100;
         cmtop100.Height  :=  41;
         cmtop100.color  :=  clWindow;
         cmtop100.itemindex  :=  0;
         cmtop100.linespacing  :=  2.000000000000000000;
         cmtop100.margin  :=  0;
         cmtop100.showlabels  :=  True;
         cmtop100.drawmode  :=  True;
         cmtop100.numbercolor  :=  clBlack;
         cmtop100.remote  :=  False;
         cmtop100.scrollwidths  :=  18;
         cmtop100.inmotion  :=  False;
         cmtop100.highlightindex  :=  False;
         cmtop100.highlighteditem  :=  0;
         cmtop100.highlightindex2  :=  False;
         cmtop100.highlighteditem2  :=  0;
         cmtop100.topmost  :=  0;

       CommerceOK := TBitmapActionButton.Create(Commerce);
       CommerceOK.Parent := Commerce;
       CommerceOK.Left  :=  552;
       CommerceOK.Top  :=  48;
       CommerceOK.Width  :=  137;
       CommerceOK.Height  :=  32;
       CommerceOK.color  :=  clBlack;
       CommerceOK.caption  :=  'Done';
       CommerceOK.down  :=  False;
       CommerceOK.buttoncolor  :=  1;
       CommerceOK.OnClick  :=  CommerceOKClick;


     Loadcovercaption := TPanel.Create(Self);
     Loadcovercaption.Parent := Self;
     Loadcovercaption.Left  :=  311;
     Loadcovercaption.Top  :=  587;
     Loadcovercaption.Width  :=  48;
     Loadcovercaption.Height  :=  13;
     Loadcovercaption.AutoSize  :=  True;
     Loadcovercaption.BevelOuter  :=  bvNone;
     Loadcovercaption.Caption  :=  'Loading Album Covers';
     Loadcovercaption.Color  :=  clBlack;
     Loadcovercaption.TabOrder  :=  9;
     Loadcovercaption.Visible  :=  False;
     Panel_searchbut := TPanel.Create(Self);
     Panel_searchbut.Parent := Self;
     Panel_searchbut.Left  :=  741;
     Panel_searchbut.Top  :=  64;
     Panel_searchbut.Width  :=  49;
     Panel_searchbut.Height  :=  41;
     Panel_searchbut.BevelOuter  :=  bvNone;
     Panel_searchbut.Caption  :=  'kioskpanelpanel';
     Panel_searchbut.Color  :=  clBlack;
     Panel_searchbut.TabOrder  :=  10;
     Panel_searchbut.Visible  :=  False;
       Panel_searchbut_image := TImage.Create(Panel_searchbut);
       Panel_searchbut_image.Parent := Panel_searchbut;
       Panel_searchbut_image.Left  :=  0;
       Panel_searchbut_image.Top  :=  0;
       Panel_searchbut_image.Width  :=  33;
       Panel_searchbut_image.Height  :=  41;
       Panel_searchbut_image.Stretch  :=  True;
       Panel_searchbut_image.OnClick  :=  panel_searchbut_imageClick;
     Coverimagepanel := TPanel.Create(Self);
     Coverimagepanel.Parent := Self;
     Coverimagepanel.Left  :=  13;
     Coverimagepanel.Top  :=  478;
     Coverimagepanel.Width  :=  185;
     Coverimagepanel.Height  :=  41;
     Coverimagepanel.Color  :=  clBlack;
     Coverimagepanel.TabOrder  :=  11;
       Coverimage := TImage.Create(Coverimagepanel);
       Coverimage.Parent := Coverimagepanel;
       Coverimage.Left  :=  1;
       Coverimage.Top  :=  1;
       Coverimage.Width  :=  183;
       Coverimage.Height  :=  39;
       Coverimage.Align  :=  alClient;
       Coverimage.AutoSize  :=  True;
       Coverimage.Stretch  :=  True;
       Coverimage.OnClick  :=  coverimageClick;
        Errortimer := TTimer.Create(Self);
     Errortimer.Enabled  :=  False;
     Errortimer.Interval  :=  250;
     Errortimer.OnTimer  :=  errortimerTimer;
     Playstimer := TTimer.Create(Self);
     Playstimer.Enabled  :=  False;
     Playstimer.Interval  :=  250;
     Playstimer.OnTimer  :=  playstimerTimer;
     Lightstimer := TTimer.Create(Self);
     Lightstimer.Enabled  :=  False;
     Lightstimer.Interval  :=  200;
     Lightstimer.OnTimer  :=  lightstimerTimer;
     Navbuttimer := TTimer.Create(Self);
     Navbuttimer.Enabled  :=  False;
     Navbuttimer.Interval  :=  1;
     Navbuttimer.OnTimer  :=  navbuttimerTimer;
     Volumetimer := TTimer.Create(Self);
     Volumetimer.Interval  :=  100;
     Volumetimer.OnTimer  :=  volumetimerTimer;
      Anchors  :=  [];
   BorderStyle  :=  bsNone;
   Caption:=main.apptitle;
   Color  :=  clBlack;
   Font.Charset  :=  DEFAULT_CHARSET;
   Font.Color  :=  clWindowText;
   Font.Height  :=  -11;
   Font.Name  :=  'MS Sans Serif';
   Font.Style  :=  [];
   KeyPreview  :=  True;
   OldCreateOrder  :=  False;
   Position  :=  poScreenCenter;

   OnCanResize  :=  FormCanResize;
   OnClose  :=  FormClose;
   OnCreate  :=  FormCreate;
   OnKeyDown  :=  FormKeyDown;
   OnKeyUp  :=  FormKeyUp;
   OnPaint  :=  FormPaint;
   OnResize  :=  FormResize;
   PixelsPerInch  :=  96;
   WindowState  :=  wsMaximized;

   imViewMode := TImage.create(rightpanel);
   imViewMode.Parent:=rightpanel;
   imViewMode.Transparent:=true;
   imViewMode.Picture.Bitmap.TransparentColor:=clWhite;
   if config.disable3d=false then imViewmode.Visible:=true;
   imViewMode.OnClick:=imViewModeClick;
   imViewMode.Picture.Bitmap.LoadFromResourceName(hinstance,'VIEW3D');

   ThreeDPanel:=TGLPanel.Create(midpanelpanel);
   ThreeDPanel.Parent:=midpanelpanel;
   ThreeDPanel.Visible:=false;


end;



procedure TJukebox.ThreeDPanelMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
begin


end;


constructor TJukebox.Create(Owner: TComponent);
begin
  inherited CreateNew(Owner);
  dodfm;
end;


//DEBUG CODE TO GET TRUE POSITIONS OF BITMAP OBJECTS
procedure TJukebox.dumppositions;
var
f : textfile;

procedure dumprect(curresname : string;currestype : string;ct : tcontrol;parent : tcontrol);
var
s : string;
tr : trect;
begin
tr.TopLeft:=parent.ClientToScreen(ct.BoundsRect.TopLeft);
tr.BottomRight:=parent.ClientToScreen(ct.BoundsRect.BottomRight);

if curresname='ALPHABUTTONUP' then begin
tr.TopLeft:=ct.ClientToScreen(alphapanel.btnmatrix[0].tr.topleft);
tr.BottomRight:=ct.ClientToScreen(alphapanel.btnmatrix[0].tr.bottomright);
end;

s:=curresname+','+inttostr(tr.left)+','+inttostr(tr.Top)+','+inttostr(tr.Right)+','+inttostr(tr.Bottom)+','+currestype;
writeln(f,s);
end;

begin
assignfile(f,'bitmap-positions.csv');
rewrite(f);

dumprect('LBUTUP','b',butl,butl);
dumprect('RBUTUP','b',butr,butl);
dumprect('KEYPADUP','b',num10,num10.parent);
dumprect('LCORNERUP','b',VisualsPanel,visualspanel);
dumprect('RCORNERUP','b',openpanel,openpanel);
dumprect('BLCORNERUP','b',panel_searchbut,jukebox);
dumprect('BRCORNERUP','b',kioskpanel,kioskpanel);
dumprect('ALPHABUTTONUP','b',alphapanel,jukebox);
dumprect('WIDEBUTUP','b',Num13,num13.parent);
dumprect('BACKGROUND','j',jukebox,jukebox);
closefile(f);

end;


end.