/*
AjaxExplorer Copyright (C) 2007 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=='M51' || (id.indexOf('M')==-1 && id.indexOf('P')==-1)) return;
  if((obj=get(id).style).opacity==0.4 || obj.filter=='alpha(opacity=40)') 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 'M21': case 'P21': fileBrowse(0); break;
    case 'M22': case 'P22': fileSort(); break;
    case 'M31': case 'P31': fileZip(0); break;
    case 'M32': case 'P32': fileZip(1); break;
    case 'M41': case 'P41': fileRestoreAll(); break;
    case 'M42': case 'P42': fileRestore(); break;
    case 'M43': case 'P43': fileEmptyBin(); break;
    case 'M61': case 'P61': fileProperty(); break;
    case 'M71': case 'P71': fileWallpaper(); 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 'M231': case 'P221': fileSortLoad('name'); break;
    case 'M232': case 'P222': fileSortLoad('type'); break;
    case 'M511': case 'P511': fileCreate(0); break;
    case 'M512': case 'P512': fileCreate(1); break;
  }
}

function menuGenerate(what)
{
  var copy=getData('clip_task');
  var exts=over? fileNameExt(over):'';

  display(what+'30', !rdir && (exts=='---' || exts=='zip')? 1:0);
  display(what+'40', rdir? 1:0);
  display(what+'20', !mark? 1:0);
  display(what+'50', !mark && !rdir? 1:0);
  display(what+'60', !rdir || !mark? 1:0);
  display(what+'70', exts=='gif' || exts=='jpg' || exts=='jpeg' || exts=='png'? 1:0);
  display(what+'80', sdir && over? 1:0);

  opacity(what+'02', over && !rdir? 1:0.4);
  opacity(what+'11', mark && !rdir && !sdir? 1:0.4);
  opacity(what+'12', mark && !rdir && !sdir? 1:0.4);
  opacity(what+'13', copy && !rdir && !sdir? 1:0.4);
  opacity(what+'14', mark? 1:0.4);
  opacity(what+'15', mark && !rdir? 1:0.4);
  opacity(what+'31', exts=='zip'? 1:0.4);
  opacity(what+'32', exts=='---'? 1:0.4);
  opacity(what+'42', mark? 1:0.4);

  opacity(what+'011', view!='list'? 1:0.4);
  opacity(what+'012', view!='icon'? 1:0.4);
  opacity(what+'013', view!='tile'? 1:0.4);
  opacity(what+'021', over && !rdir? 1:0.4);
  opacity(what+'022', !rdir && exts!='---'? 1:0.4);
  opacity(what+'023', !rdir && exts!='---'? 1:0.4);
  opacity(what+'221', !fnew && sort!='name'? 1:0.4);
  opacity(what+'222', !fnew && sort!='type'? 1:0.4);
}

function menuHide(id)
{
  display(id? id:'menu', 0);
}

function menuShow(evt)
{
  var tX, tY;
  menuGenerate('M');

  iX=150;
  iY=205;
  obj=get('menu').style;
  obj.left=(oX=(tX=cX+sX)+iX<mX? tX:tX-iX)+'px';
  obj.top=(oY=(tY=cY+sY)+iY<mY? tY:tY-iY)+'px';
  obj.display='block';
}

function menuShowSub(id)
{
  var tY=0;

  switch(id)
  {
    case 'M010': tY=-1;	break;
    case 'M020': tY=12;	break;
    case 'M220': tY=129;break;
    case 'M510': 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';
}
