//
// JavaScript: Album Generater
// 
// Internet Explorer, Konqueror, Mozilla, Netscape, Opera (Linux, OS/2, Windows)
//

// #include <common.js>

var styles = Array('red','green','blue','yellow','magenta','cyan');

var album = {theme:"",head:"",text:"",base:"",url:[],thumb:[],title:[],width:[],height:[],caption:[],footer:[],hint:[],style:[],group:[],label:[],aux:[],id:0,flag:0,ptr:0,sub:0,parm:"",
  addEntry:function(p,th,t,c,f,w,h)
  {
    this.url[this.id] = this.base + p;
    this.thumb[this.id] = this.base + th;
    this.title[this.id] = t;
    this.caption[this.id] = c;
    this.footer[this.id] = f;
    this.width[this.id] = w;
    this.height[this.id] = h;
    this.hint[this.id] = this.parm;
    this.style[this.id] = this.nextStyle();
    this.group[this.id] = this.sub++;
    this.id++;
  },
  addNull:function()
  {
    this.addEntry("","","","","",0,0);
  },
  newLine:function()
  {
    while (this.id % 4)
      this.addNull();
  },
  wrtLabel:function()
  {
    this.label[this.id] = this.parm = this.wrtLabel.arguments[0];
  },
  grpBegin:function()
  {
    this.ptr = (this.ptr + 1) % styles.length;
    this.flag = 0;
    this.sub = 0;

    if (this.grpBegin.arguments.length)
      this.label[this.id] = this.parm = this.grpBegin.arguments[0];
  },
  grpEnd:function()
  {
    if (this.grpEnd.arguments.length)
      this.parm = this.grpEnd.arguments[0];

    this.flag = 1;
  },
  grpEndLine:function()
  {
    this.newLine();
    this.grpEnd();
  },
  grpSep:function()
  {
    this.aux[this.id] |= 1;
    this.sub = 0; 
  },
  getStyle:function(i)
  {
    var t = '';

    if (this.hint[i] && this.hint[i].length)
      t = ' title="'+this.hint[i]+'"';

    return (this.style[i]? this.style[i]: 'style="background-image:url(gfx/bgnd'+styles[this.ptr]+'.png)"')+t;
  },
  nextStyle:function()
  {
    this.ptr = (this.ptr + this.flag) % styles.length;
    return 'style="background-image:url(gfx/bgnd'+styles[this.ptr]+'.png)"';
  }
};

function writeTheme()
{
  document.write(album.theme);
}

function writeHead()
{
  document.write(album.theme+ (album.head? ': '+album.head:''));
}

function drawAlbum()
{
  var i, k, n;

  if (album.text)
    document.write('<p align="left">'+album.text+'<\/p><hr width="50%">');

  document.write('<p align="center" class="small">Die Bilder zum Vergr&ouml;&szlig;ern anklicken.<\/p>');

  document.write('<table align="center" border="0" cellpadding="8" cellspacing="0">');

  n = (album.id + 3) & 0xFFFFFFFC;

  for (i = 0; i < n; i++) {

    if (i % 4 == 0)
      document.write('<tr valign="top">');

    if (document.layers)	// NS4 Bug
      document.write('<td class="small" width="25%">');
    else
      document.write('<td class="small" width="25%" '+(album.getStyle(i))+'>');

    if (album.label[i])
      document.write('<div style="position:relative;"><span style="position:absolute;left:-6px;top:-4px;"><span class="label">'+album.hint[i]+'<\/span><\/span><\/div>');

    if (i < album.id && album.width[i] > 0)
      document.write('<div style="text-align:center;margin:16px 0px;"><a href="javascript:void(0)" onclick="showImage('+i+')" onmouseover="hilite(this,1)" onmouseout="hilite(this,0)">'+album.title[i]+'<br><img border="1" src="'+album.thumb[i]+'" alt="" hspace="4" vspace="4" title="'+album.caption[i]+'"><\/a><br>'+album.footer[i]+'<\/div>');

    document.write('<\/td>');

    if (i % 4 == 3)
      document.write('<\/tr>');
  }
  document.write('<\/table>');
}

function drawGallery()
{
  var i;

  document.write('<table align="center" width="100%" border="0" cellpadding="8" cellspacing="0">');

  for (i = 0; i < album.id; i++) {

    if (i && (album.aux[i] == 1 || !album.group[i]))
      document.write('<\/table>'+(album.aux[i] == 1?'':'<hr width="75%">')+'<table align="center" width="100%" border="0" cellpadding="8" cellspacing="0">');

    if (!album.group[i] && album.hint[i] && album.hint[i].length)
      document.write('<tr valign="top"><align="center" class="small" colspan="4"><b>'+album.hint[i]+'<\/b><\/td><\/tr>');

    if (album.group[i] % 4 == 0)
      document.write('<tr valign="top">');

    if (album.width[i] && album.height[i])
      document.write('<td align="center" class="small">'+album.title[i]+'<br><a href="'+album.url[i]+'" target="canvas" onclick="showImage('+i+')" onmouseover="hilite(this,1)" onmouseout="hilite(this,0)"><img border="1" src="'+album.thumb[i]+'" alt="" hspace="4" vspace="4" title="'+album.caption[i]+'"><\/a><br>'+album.footer[i]+'<\/td>');
    else
      document.write('<td align="center" class="small">'+album.title[i]+'<br>'+album.url[i]+'<br>'+album.footer[i]+'<\/td>');

    if (album.group[i] % 4 == 3)
      document.write('<\/tr>');
  }

  document.write('<\/table>');
}

function showImage(i)
{
  with (album)
    __showImage(url[i],title[i],caption[i],width[i],height[i]);
}

function __showImage(u,t,c,w,h)
{
  var x = w, y = h;

  if (screen) {
    x = (x < screen.availWidth) ? x : screen.availWidth;
    y = (y < screen.availHeight) ? y : screen.availHheight;
  }

  img_x = x;
  img_y = y;

  if (!__canvas || __canvas.closed)
    __canvas = window.open("","canvas","width="+x+",height="+y+",resizable=yes,scrollbars=yes,menubar=no,location=no,status=yes,left=1,top=1");//,dependent=yes");

  __canvas.document.open("text/html");
  __canvas.document.write('<html><head><title>'+c+'<\/title><\/head><body style="margin:0;padding:0" oncontextmenu="return false;"><div style="position:absolute;left:0px;top:0px"><img src="'+u+'" alt="'+t+'" title="'+t+'" width="'+w+'" height="'+h+'" border="0"><\/div><\/body><\/html>');
  __canvas.document.close();

  __canvas.focus();

  window.setTimeout("resizeimg()", 500);
}

function flv_player(url, x, y, l, i)
{
  var b='', p; 

  if ((cfg & 0x00F0) == 0x0000)
    return '<a href="'+url+'" type="video/flv" title="Download des Videos"><img src="gfx/bgnomedia.gif" alt="Multimedia ist abgestellt!" border="0" hspace="16" vspace="16"><\/a>';

  if (l)
    b += '&logo='+((l == true)? 'gfx/mugu-logo.jpg': l);

  if (i)
    b += '&image='+((i == true)? 'gfx/logo.jpg': i);

  p = '<embed src="sounds/mplayer.swf" type="application/x-shockwave-flash" width="'+x+'" height="'+y+'" allowfullscreen="true" quality="high" flashvars="file='+url+'%26x.flv'+b+'&width='+x+'&height='+y+'&repeat=false&showdigits=true&showdownload=true&shownavigation=true&link='+url+'"><\/embed>';

  if ((cfg & 0x00F0) == 0x0010)
    return '<br>'+p+'<br>';

  return '<br><obj'+'ect width="'+x+'" height="'+y+'"><param name="movie" value="sounds/mplayer.swf"><param name="quality" value="high"><param name="flashvars" value="file='+url+'%26x.flv'+b+'&width='+x+'&height='+y+'&repeat=false&showdigits=true&showdownload=true&shownavigation=true&link='+url+'">'+p+'<\/object><br>';
}

