/*
AjaxExplorer Copyright (C) 2007-2008 Syed Mohammad Sidque Tahir Al-Habshi

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. Head to
GNU site http://www.gnu.org/licenses/ for license copy.
*/

function menuExecute(id)
{
  if(!done || id=='M01' || id=='M61' || (id.indexOf('M')==-1 && id.indexOf('P')==-1)) return;
  if(get(id).style.color=='rgb(153, 153, 153)') return;

  userSystemHide();
  menuHide();
  hX=hY=0;

  switch(id)
  {
    case 'M02': case 'P02': fileOpen(); break;
    case 'M11': case 'P11': fileCopy(0); break;
    case 'M12': case 'P12': fileCopy(1); break;
    case 'M13': case 'P13': filePaste(); break;
    case 'M14': case 'P14': fileDelete(); break;
    case 'M15': case 'P15': fileRename(1); break;
    case 'M31': case 'P31': fileBrowse(0); break;
    case 'M32': case 'P32': fileSort(); break;
    case 'M51': case 'P51': fileProperty(); break;
    case 'M61': case 'P61': fileWallpaper(); break;
    case 'M71': case 'P71': fileRestoreAll(); break;
    case 'M72': case 'P72': fileRestore(); break;
    case 'M73': case 'P73': fileEmptyBin(); break;
    case 'M81': case 'P81': fileOpenResult(); break;

    case 'M011': case 'P011': fileViewLoad('list'); break;
    case 'M012': case 'P012': fileViewLoad('icon'); break;
    case 'M013': case 'P013': fileViewLoad('tile'); break;
    case 'M021': case 'P021': fileOpen('newtab'); break;
    case 'M022': case 'P022': fileOpen('download'); break;
    case 'M023': case 'P023': fileOpen('editor'); break;
    case 'M211': case 'P211': fileSent(0); break;
    case 'M212': case 'P212': fileShare(); break;
    case 'M213': case 'P213': fileZip(0); break;
    case 'M214': case 'P214': fileZip(1); break;
    case 'M321': case 'P321': fileSortLoad('date'); break;
    case 'M322': case 'P322': fileSortLoad('name'); break;
    case 'M323': case 'P323': fileSortLoad('size'); break;
    case 'M324': case 'P324': fileSortLoad('type'); break;
    case 'M411': case 'P411': fileCreate(0); break;
    case 'M412': case 'P412': fileCreate(1); break;
  }
}


function menuGenerate(what)
{
  var copy=getData('clip_task');
  var exts=over? fileList[over][3]:'';

  display(what+'20', !rdir && !sdir && !tdir && mark? 1:0);
  display(what+'30', !mark? 1:0);
  display(what+'40', !mark && !rdir? 1:0);
  display(what+'60', !rdir && (exts=='gif' || exts=='jpg' || exts=='jpeg' || exts=='png')? 1:0);
  display(what+'70', rdir? 1:0);
  display(what+'80', sdir && over? 1:0);

  colorIt(what+'02', over && !rdir? 1:0);
  colorIt(what+'11', mark && !rdir && !sdir && !tdir? 1:0);
  colorIt(what+'12', mark && !rdir && !sdir && !tdir? 1:0);
  colorIt(what+'13', copy && !rdir && !sdir && !tdir? 1:0);
  colorIt(what+'14', mark? 1:0);
  colorIt(what+'15', mark && !rdir && !sdir && !tdir? 1:0);
  colorIt(what+'72', mark? 1:0);

  colorIt(what+'011', view!='list'? 1:0);
  colorIt(what+'012', view!='icon'? 1:0);
  colorIt(what+'013', view!='tile'? 1:0);
  colorIt(what+'021', over && !rdir && !tdir? 1:0);
  colorIt(what+'022', over && !rdir && exts!='dir'? 1:0);
  colorIt(what+'023', over && !rdir && exts!='dir'? 1:0);
  colorIt(what+'211', exts!='dir' && over? 1:0);
  colorIt(what+'212', exts=='dir' && dvrt==path? 1:0);
  colorIt(what+'213', exts=='dir'? 1:0);
  colorIt(what+'214', exts=='zip'? 1:0);
  colorIt(what+'321', sort!='date'? 1:0);
  colorIt(what+'322', sort!='name'? 1:0);
  colorIt(what+'323', sort!='size'? 1:0);
  colorIt(what+'324', sort!='type'? 1:0);
}

function menuHide(id)
{
  display(id? id:'menu', 0);
}

function menuShow(evt)
{
  var tX, tY;
  menuGenerate('M');

  obj=get('menu');
  obj.style.display='block';

  iX=obj.offsetWidth;
  iY=obj.offsetHeight;
  obj.style.left=(oX=(tX=cX+sX)+iX<mX? tX:tX-iX)+'px';
  obj.style.top=(oY=(tY=cY+sY)+iY<mY? tY:tY-iY)+'px';
}

function menuShowSub(id)
{
  var tY=0;

  switch(id)
  {
    case 'M010': tY=-1;	break;
    case 'M020': tY=12;	break;
    case 'M210': tY=116;break;
    case 'M320': tY=129;break;
    case 'M410': tY=155;break;
  }

  if(tY)
  {
    obj=get(id).style;
    obj.top=tY+'px';
    obj.left=(oX>mX-230? -106:120)+'px';
    obj.display='block';
  }
  else display(id, 1);
}

function menuToogle(id, flag)
{
  obj=get(id).style;

  switch(flag)
  {
    case 1: flag=0; break;
    case 2: flag=getData(id)=='0'? 0:1; break;
    default:
	flag=obj.display!='none'? 0:1;
	setData(id, flag);
  }

  get(id+'i').src='images/'+(flag? 'hide':'show')+'.png';
  obj.display=flag? 'block':'none';
}