doc=document;

function DrawMainGallery(gallery){
  DrawGallery(gallery,6,89,63);
};

function ShowImage(picture,win_width,win_height){
  newWindow=open('','VJO_Viewer','width='+win_width+',height='+win_height+',resizable=no,status=no,toolbar=no,menubar=no,location=no,directories=no');
  doc2=newWindow.document;
  doc2.open();
  doc2.writeln('<BODY LEFTMARGIN="0" TOPMARGIN="0" MARGINHEIGHT="0" MARGINWIDTH="0" bgcolor="#ffffef">');
  doc2.writeln('<center><img src="gallery/'+picture+'"></center>');
  doc2.writeln('</body>');
};

function DrawGallery(gallery,count,_width,_height){
  doc.write('<TABLE CELLSPACING="10" CELLPADDING="0" BORDER="0" BGCOLOR="#e1e1d3">');

  if (gallery[0]!="") doc.write('<TR><TD class=gallery colspan="'+count+'"><center><b>'+gallery[0]+'</b>  (Click an image to view)</center></TD></TR>');
  col_count=0;

  for (k=1;k<gallery.length;k=k+4){
    command=gallery[k];
    file=gallery[k+1];
    ext=gallery[k+2];
    txt=gallery[k+3];
    if (col_count==0) doc.write('<TR>');
    doc.write('<TD class=gallery valign=top><CENTER>');
    if (command==""){
      DrawCImage("",file,ext,"",_width,_height);
//      doc.write('<IMG SRC="gallery/'+file+'-t.'+ext+'" WIDTH="'+_width+'" HEIGHT="'+_height+'" BORDER="1" ALT="VJO Thumbnail Image"></A>');
      if (txt!="") doc.write('<BR>'+txt);
    }else if (command=="a"){
      DrawCImage("a",file,ext,"",_width,_height);
      if (txt!="") doc.write('<BR>'+txt);
    }else if (command=="t"){
      doc.write(txt);
    };
    doc.write('</CENTER></TD>');
    col_count++;
    if (col_count==count){
      doc.write('</TR>');
      col_count=0;
    }
  };
  if (col_count>0) doc.write('</TR>');
  doc.write('</table>');
};

function DrawCImage(com,file,ext,txt,_width,_height){
  if (txt!="") doc.write('<table><tr><td>');
  if (com=="a"){
    doc.write('<A href=javascript:ShowImage("'+file+'.'+ext+'",640,480); border=0>');
    doc.write('<IMG SRC="gallery/'+file+'-t.'+ext+'" WIDTH="'+_width+'" HEIGHT="'+_height+'" BORDER="3" ALT="VJO Thumbnail Image - Click to Load"></A>');
  } else {
    doc.write('<IMG SRC="gallery/'+file+'-t.'+ext+'" WIDTH="'+_width+'" HEIGHT="'+_height+'" BORDER="3" ALT="VJO Thumbnail Image">');
  }
  if (txt!="") doc.write('<BR><CENTER>'+txt+'</CENTER></td></tr></table>');
};

function DrawMenu(MENU,SUBMENU){
  doc.write('<TABLE CELLSPACING="0" CELLPADDING="0" BORDER="0"><TR><TD>');
  doc.write('<TABLE CELLSPACING="0" CELLPADDING="0" width=100% BORDER="0" BACKGROUND="images/top-bg.gif"><TR>');
  doc.write('<TD width=9><IMG SRC="images/top-left.gif" WIDTH="9" HEIGHT="36" BORDER="0"></TD>');
  doc.write('<TD valign=top align=left>');

  doc.write('<TABLE CELLSPACING="0" CELLPADDING="0" BORDER="0" height=30><TR height=20>');

  //get the selected menu item
  menuselect=-1;
  for(k=0;k<top.vjomenu.length;k=k+5){
    if(k/5 == MENU){
      if(top.vjomenu[k+2]==-1){
        menuselect=k/5;
      }else{
        menuselect=top.vjomenu[k+2];
      }
    }
  }

  for(k=0;k<top.vjomenu.length;k=k+5){
    if(top.vjomenu[k+2]==-1){
      doc.write('<TD valign=bottom class=tb-menu');
      if(menuselect == k/5){
        doc.write('sel>&nbsp;'+top.vjomenu[k]+'&nbsp;</TD>');
      }else{
        doc.write('>&nbsp;<A HREF="'+top.vjomenu[k+4][1]+'">'+top.vjomenu[k]+'</A>&nbsp;</TD>');
      }
    }
  }
  doc.write('</TR><TR height=10>');

  for(k=0;k<top.vjomenu.length;k=k+5){
    if(top.vjomenu[k+2]==-1){
    if(menuselect == k/5){
      doc.write('<TD><CENTER><IMG SRC="images/top-select.gif" WIDTH="29" HEIGHT="10" BORDER="0"></CENTER></TD>');
    }else{
      doc.write('<TD></TD>');
    }
    }
  }
  doc.write('</TR></TABLE>');

  doc.write('</TD>');
  doc.write('<TD align=right><IMG SRC="images/top-right.gif" WIDTH="157" HEIGHT="36" BORDER="0"></TD>');
  doc.write('</TR></TABLE>');

  doc.write('<TABLE CELLSPACING="0" CELLPADDING="0" BORDER="0" width=100%><TR BGCOLOR="#4f7e0e">');
  doc.write('<TD BACKGROUND="images/title-bg.gif"><IMG SRC="images/left-title.gif" WIDTH="345" HEIGHT="91" BORDER="0" ALT="title"></TD>');
  doc.write('<TD BACKGROUND="images/title-bg.gif" align=right><IMG SRC="images/right-title.jpg" WIDTH="524" HEIGHT="91" BORDER="0" ALT="title"></TD>');
  doc.write('</TR></TABLE>');

  doc.write('<TABLE CELLSPACING="0" CELLPADDING="0" BORDER="0" width=100%><TR BGCOLOR="#79ab3b">');
  doc.write('<TD><IMG SRC="images/left-location.gif" WIDTH="168" HEIGHT="22" BORDER="0" ALT="location block"></TD>');
  doc.write('<TD BGCOLOR="#79ab3b" VALIGN="middle" ALIGN="right" class=location>');

  DrawLocation(MENU,SUBMENU,menuselect);

  doc.write('</TD>');
  doc.write('</TR></TABLE>');
  doc.write('<TABLE CELLSPACING="0" CELLPADDING="0" BORDER="0" width=100%><TR>');

  DrawSubMenu(MENU,SUBMENU,menuselect);

  doc.write('<TD BGCOLOR="#d2d6bb" valign=top>');

  if(top.vjomenu[(MENU*5)+4][(SUBMENU*3)+2] != ""){
    doc.write('<IMG SRC="images/'+top.vjomenu[(MENU*5)+4][(SUBMENU*3)+2]+'.jpg"><BR>');
  }else{
    randomnum = Math.round(Math.random()*top.imagepool.length)-1;
    if(randomnum<0)randomnum=0;
//    alert(randomnum);
    doc.write('<IMG SRC="images/'+top.imagepool[randomnum]+'.jpg"><BR>');
  }
}

function DrawSubMenu(MENU, SUBMENU, MENU2){
  doc.write('<TD BACKGROUND="images/submenu-bg.gif" width=168 valign=top>');
  doc.write('<TABLE CELLSPACING="0" CELLPADDING="0" BORDER="0">');
  for(k=0;k<top.vjomenu.length;k=k+5){
    if(k/5 == MENU2 || k/5 == MENU || top.vjomenu[k+2]==MENU || top.vjomenu[k+2]==MENU2){
      if(k/5 == MENU){
        doc.write('<TR><TD CLASS=leftmainmenusel><IMG SRC="images/sub-open.gif">'+top.vjomenu[k+1]+'</TD></TR>');
        sbmenu=top.vjomenu[k+4];
        for(l=0;l<sbmenu.length;l=l+3){
          doc.write('<TR><TD CLASS=leftmenu');
          if(SUBMENU == l/3){
            doc.write('sel><IMG SRC="images/sub-sub.gif">'+sbmenu[l]+'</TD></TR>');
          }else{
            doc.write('><IMG SRC="images/sub-sub.gif"><A HREF="'+sbmenu[l+1]+'">'+sbmenu[l]+'</A></TD></TR>');
          }
        }
      }else{
        doc.write('<TR><TD CLASS=leftmainmenu><IMG SRC="images/sub-closed.gif"><A HREF="'+top.vjomenu[k+4][1]+'">'+top.vjomenu[k+1]+'</A></TD></TR>');
      }
    }
  }
  doc.write('</TR></TABLE>');
  doc.write('</TD>');
}

function DrawLocation(MENU, SUBMENU, MENU2){
  doc.write('<A HREF="index.html">VisualJockey</A>&nbsp;');
  if(SUBMENU == 0){
    doc.write('>&nbsp;'+top.vjomenu[MENU*5]);
  }else{
    doc.write('>&nbsp;'+top.vjomenu[(MENU*5)]);
    doc.write('>&nbsp;'+top.vjomenu[(MENU*5)+4][SUBMENU*3]);
  }
    doc.write('&nbsp;&nbsp;');
}

function DrawFooter(){
  doc.write('</td></TR></TABLE>');
  doc.write('<TABLE CELLSPACING="0" CELLPADDING="0" width=100% BORDER="0"><TR Bgcolor="#1c2409">');
  doc.write('<TD valign=middle align=left class=tb-menu>&nbsp;&nbsp;<A HREF="contact.htm">Contact Us</A></TD>');
  doc.write('<TD valign=middle align=right class=tb-menu>© 2006-2008 Mavrick Designs</TD>');
  doc.write('<TD align=right width=6><IMG SRC="images/spacer.gif" WIDTH="6" HEIGHT="28" BORDER="0" ALT="mini logo"></TD>');
  doc.write('</TR></TABLE>');

  doc.write('</TD><TD WIDTH="10" background="images/shadow.png"><IMG SRC="images/spacer.gif" WIDTH="10" HEIGHT="10" BORDER="0"></TD></TR>');
  doc.write('<TR><TD><TABLE CELLSPACING="0" CELLPADDING="0" BORDER="0"><TR width=100%><TD>');
  doc.write('<IMG SRC="images/spacer.gif" WIDTH="10" HEIGHT="10" BORDER="0"></TD><TD BACKGROUND="images/shadow.png" width=100%><IMG SRC="images/spacer.gif" WIDTH="10" HEIGHT="10" BORDER="0"></TD></TR></TABLE></TD>');
  doc.write('<TD height=10 background="images/shadow.png"><IMG SRC="images/spacer.gif" WIDTH="10" HEIGHT="10" BORDER="0"></TD></TR>');
  doc.write('</TABLE>');
}
