var floater = false;
var DoSubInit = false;

function Init() {
  // highlight a piece of art when given an ID hash
  h = ""+document.location.search;
  m = (h.match(/^\?show=(\d+)$/));
  if (m) {
    if (document.getElementsByName) {
      e = document.getElementsByName(m[1]);
      if (e.length > 0) {
	e = e[0];
	if (e.parentNode) {
	  s = e.parentNode.style;
	  s.borderWidth = "4";
	  s.borderColor = "#E1A38A";
	  s.borderStyle = "solid";
	  window.scrollBy(0,-50);

	  t = "";
	  t = e.parentNode.childNodes[1].childNodes[0].childNodes[0].innerHTML;
	  ShowPic(e, t);
	}
      }
    }
  }
  if (DoSubInit) {SubInit();}
}

function ShowPic(l, title) {
  if (!(document.getElementById)) {return true;}
  floater = document.getElementById("FloatingPic");
  if (!(floater)) {return true;}
  agt = ""+navigator.userAgent;

  de = false;
  if (l.parentNode) {
    pcs = l.parentNode.childNodes;
    if (pcs) {
      for (n=0; n<pcs.length; n++) {
	if (pcs[n].className == "thumbbox") {
	  de = pcs[n];
	}
      }
    }
  }

  flashw = 800;
  flashh = 600;
  if (de) {
    h = de.innerHTML;
    h = h.replace(/^<b><a.*?\n?.*?<div.*?<\/div>/i, "");
    h = h.replace(/<div.*?<\/div>.*?Drawn on .*$/i, "");
    if (PollingFixFloater == false) {
      PollingFixFloater = true;
      window.setTimeout("FixFloater()", 50);
    }
    if (de.getAttribute("flashw")) {flashw = de.getAttribute("flashw");}
    if (de.getAttribute("flashh")) {flashh = de.getAttribute("flashh");}
  }
  var c = '<table cellspacing="0" style="width: 100%;"><tr><td align="center" onClick="ClearImage()"';
  if ( (agt.match(/gecko/i)) || (agt.match(/opera/i)) ) {c += ' class="fadebehind"';}
  c += '>';
  if (title) {c += '<table cellspacing="0" style="margin-bottom: -2px;"><tr><td class=\"floatbarL"></td><td class=\"floatbarC"><b>'+title+'</b></td><td class=\"floatbarR"></td></tr></table>';}
  c += '<table cellspacing="0"><tr><td class="FloaterImage" align="center"><a href="javascript:ClearImage()">';
  if (l.href.match(/\.swf$/)) {
    c += '<div class="FlashDiv"><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="'+flashw+'" height="'+flashh+'" id="TheFlash" align="middle"><param name="allowScriptAccess" value="sameDomain" /><param name="movie" value="'+l.href+'" /><param name="quality" value="high" /><param name="bgcolor" value="#B36B37" /><embed src="'+l.href+'" quality="high" bgcolor="#B36B37" width="'+flashw+'" height="'+flashh+'" name="TheFlash" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object></div>';
  } else {
    c += '<img src="'+l.href+'" id="TheImage">';
  }
  if (de) {
    c += '<tr><td style="width: 300px;" id="FixMe"><div style="background-color: #FF9413; border: 2px solid #B36B37; border-top-width: 0px; margin: 0px; padding: 5px;">'+h+'</td></tr>';
  }
  c += '</a></td></tr>';
  c += '</table>';
  c += '<table cellspacing="0" style="margin-top: -2px;"><tr><td class=\"floatbarL"></td><td class=\"floatbarC"><a href="javascript:ClearImage()">';
  if (l.href.match(/\.swf$/)) {
    c += 'Click Outside Animation to Close';
  } else {
    c += 'Click Image to Close';
  }
  c += '</a></td><td class=\"floatbarR"></td></tr></table></td></tr></table>';
  AlignFloat();
  floater.innerHTML = c;
  window.focus();

  return false;
}

var PollingFixFloater = false;
function FixFloater() {
  e = document.getElementById("FixMe");
  i = document.getElementById("TheImage");
  if (e) {
    if (i) {
      if (i.width > 50) {
	e.style.width = (i.width+4)+"px";
	PollingFixFloater = false;
	return;
      }
    }
  }
  window.setTimeout("FixFloater()", 50);
}

function ClearImage() {
  floater.innerHTML = "";
  window.focus();
}

function AlignFloat() {
  var t = 0;
  if (window.pageYOffset) {t = window.pageYOffset;}
  else if (document.body) {
    if (document.body.scrollTop) {t = document.body.scrollTop;}
  }
  if (t<80) {t=80;}
  tf = document.getElementById("TopForm");
  if (tf) {
    tfy = tf.offsetHeight;
    tfy += tf.offsetTop;
    while (tf.offsetParent) {
      tf = tf.offsetParent;
      tfy += tf.offsetTop;
    }
    if (t<tfy) {t=tfy;}
  }
  floater.style.top = t+10;
}

function ChangeFilterCat(cat) {
  if (!(Filters)) {return;}
  var c = "";
  if (Filters[cat]) {
    c += '<select name="subcat" onChange="document.location=\'art.php?filter=\'+this.options[this.selectedIndex].value">';
    c += '<option value="" style="color: #AAA;">Choose...</option>';
    for (flag in Filters[cat]) {
      label = Filters[cat][flag];
      c += '<option value="'+flag+'">'+label+'</option>';
    }
    c += '</select>';
  } else {
    document.location = "art.php?filter=none";
  }
  document.getElementById("subcat").innerHTML = c;
}
