//Copyright of Samuel Morling.
//Don't you dare take this script!
//I've worked too hard on it to have someone rip it.
//Please respect my request.
if (IE4 || NS4) {
var nrClips;
var tv = new Array();
var parentWidth;
var layerWidth = 196;
var layerHeight = 215;
var hSpace = 10;
var vSpace = 4;
var leftCorrection = 132;
var rightCorrection = 31;
var newRowCorrection = 10;
var parentWidthCorrection = 0;
var resized = false;
if (IE4) {
var offsetTop;
var offsetLeft;
var offsetLeftCorrection = 5;
var description;}
else if (NS4) {
var grandparent;
var parent;
var nrClipsLoaded = 0;
var screenClickedX;
var screenClickedY;
var windowWidth;}}
function init() {
if (NS4){
nrClips = clips.length;
windowWidth = window.innerWidth;
window.captureEvents(Event.CLICK);
window.onClick=clickHandler;
grandparent = document.layers["grandparent"];
parent = grandparent.document.layers["parent"];
for (i = 0; i < nrClips; i++) {
tv[i] = new TV(parent.document.layers['tv' + i], parent.document.layers['tvPanel' + i], clips[i]);}
parent.width = screen.availWidth - parentWidthCorrection - leftCorrection - rightCorrection;
parent.height = nrClips * (layerHeight + hSpace);
layOutLayers();
setInterval("reLayOutIfNeeded()", 1000);
for (i = 0; i < tv.length; i++) {
var info = tv[i].clip.info;
var re = /'/g;
info = info.replace(re, '\\\'');
var doc = tv[i].panel.document;
doc.open();
doc.write('<table width="192" height="215" border="1" cellpadding="0" cellspacing="0"><tr><td width="192" height="160"><img src="' + tvImage.src + '" vspace="0" hspace="0" border="0" width="192" height="160"></td></tr><tr><td align="center" height="51"><a href="clips/' + tv[i].clip.filename + '" title="' + tv[i].clip.info + '" onMouseOver="window.status=\'' + info + '\';return true" onMouseOut="window.status=\' \'; return true;" target="' + tv[i].clip.title + '">' + tv[i].clip.title + '</a></td></tr></table>');
doc.close();}
resizeWindow();
resized = true;}
if (IE4) {
nrClips = clips.length;
offsetTop = document.all["tbl"].offsetTop;
offsetLeft = document.all["tbl"].offsetLeft + document.all["tbl"].offsetWidth + offsetLeftCorrection;
description = document.all["edescription"];
description.style.position="absolute";
var s = "";
var re = /'/g;
var info;
for (i = 0; i < nrClips; i++) {
info = (clips[i].info);
info = info.replace(re, '\\\'');
s += '<table id="tvPanel' + i + '" style="position : absolute" width="192" height="215" border="1" cellpadding="0" cellspacing="0"><tr><td id="tv' + i + '" width="192" height="160"><img src="' + tvImage.src + '" vspace="0" hspace="0" width="192" height="160"></td></tr><tr><td align="center" height="51"><a href="clips/' + clips[i].filename + '" title="' + clips[i].info + '" onMouseOver="window.status=\'' + info + '\';return true" onMouseOut="window.status=\' \'; return true;" target="' + clips[i].title + '" onClick="window.status=\'' + info + '\';turnOnTV(' + i + '); return false">' + clips[i].title + '</a></td></tr></table>';}
document.all["eparent"].innerHTML = s;
for (i = 0; i < nrClips; i++) {
tv[i] = new TV(document.all['tv' + i], document.all['tvPanel' + i], clips[i]);}
layOutLayers();}
inited = true;}
function layOutLayers() {
if (NS4) {
parentWidth = window.innerWidth - leftCorrection - rightCorrection;}
else if(IE4) {
parentWidth = bdy.clientWidth - leftCorrection - rightCorrection;}
if (parentWidth <= 0){
parentWidth = 1;}
var totLayerWidth = (nrClips * layerWidth + (hSpace * nrClips - 1));
var maxNrOfClipsInRow = 0;
var accumWidth = layerWidth;
while(accumWidth < parentWidth - newRowCorrection) {
accumWidth += layerWidth + hSpace;
maxNrOfClipsInRow++;}
if (maxNrOfClipsInRow == 0){
maxNrOfClipsInRow = 1;}
var nrOfRows = Math.ceil(nrClips / maxNrOfClipsInRow);
var center = Math.floor(parentWidth / 2);
var nrOfClipsInRow = new Array(nrOfRows);
if (nrClips < maxNrOfClipsInRow) {
nrOfClipsInRow[0] = nrClips;}
else {
var remainder = nrClips % maxNrOfClipsInRow;
for (i = 0; i < nrOfClipsInRow.length; i++) {
if (remainder != 0 && i == (nrOfRows -1)) {
nrOfClipsInRow[i] = remainder;}
else {
nrOfClipsInRow[i] = maxNrOfClipsInRow;}}}
var left = new Array(nrOfRows);
for (i = 0; i < left.length; i++) {
left[i] = center - Math.floor(layerWidth * nrOfClipsInRow[i] * 0.5 + hSpace * (nrOfClipsInRow[i] - 1) * 0.5);
if (left[i] < 0) {
left[i] = 0;}}
if (NS4) {
parent.clip.right = left[0] + nrOfClipsInRow[0] * (layerWidth + hSpace) - Math.floor(hSpace/2);
parent.clip.bottom = nrOfRows * (layerHeight + vSpace);}
if (IE4) {
if (!resized && description.offsetWidth > parentWidth + 1) {
var desWidth = parentWidth + 1;
resized = true;}
else {
var desWidth = description.offsetWidth;}
description.style.top = nrOfRows * (layerHeight + vSpace) + offsetTop;
description.style.left = offsetLeft + center - Math.floor(desWidth /2);}
var k = 0;
for (i = 0; i < nrOfRows; i++) {
for(j = 0; j < nrOfClipsInRow[i]; j++) {
var leftT = (left[i] + j * (layerWidth + hSpace));
var top = (i * (layerHeight + vSpace) + vSpace / 2);
if (IE4){
top  += offsetTop;
leftT += offsetLeft;}
moveTVTo(tv[k], leftT, top);
k++;}}
if (NS4 && resized){
resizeWindow();}}
function TV(screenLayer, panelLayer, clip){
this.screen = screenLayer;
this.originalScreen = screenLayer;
this.panel = panelLayer;
this.clip = clip;
this.on = false;
this.onNr = -1;}
function turnOnTV(nr) {
if (NS4) {
if (!tv[nr].on) {
var doc = tv[nr].panel.document;
doc = tv[nr].screen.document;
doc.open();
doc.write('<embed src="clips/' + tv[nr].clip.filename + '" height="160" width="192" hspace="0" pluginspace="http://www.apple.com/quicktime/download/" type="video/quicktime">');
doc.close();
tv[nr].on = true;
tv[nr].onNr = nrClipsLoaded;
nrClipsLoaded++;
fixOrderOfScreens();}
else {
var screenX = screenClickedX - Math.floor(layerWidth/2);
var screenY = screenClickedY - Math.floor(layerHeight);
var s = tv[nr].clip.filename;
s = s.slice(0, s.length - 4);
winName = s.replace(/-/g, '');
winName = winName.replace(/ /g, '');
window.open('clips/' + s + '.html', winName, "screenX=" + screenX + ",screenY=" + screenY + ",innerHeight=160,innerWidth=192,scrollbars=false,toolbar=false,location=false,menubar=false");}}
else if (IE4) {
tv[nr].screen.innerHTML = ('<embed src="clips/' + tv[nr].clip.filename + '" height="160" width="192" hspace="0" pluginspace="http://www.apple.com/quicktime/download/" type="video/quicktime">');}}
function moveTVTo(tv, left, top){
if (NS4) {
tv.panel.left = left;
tv.panel.top = top;
tv.screen.left = left + 2;
tv.screen.top = top + 2;}
else if (IE4) {
tv.panel.style.left = left;
tv.panel.style.top = top;}}
function resizeWindow() {
var windowW = window.innerWidth;
var windowHeight = window.innerHeight;
var screenWidth = screen.availWidth;
if ((screen.width - windowWidth) < 5){				
resizeTo(windowW - 10, windowHeight);
windowWidth = windowW - 10;}
else {
resizeTo((windowWidth - 1),windowHeight);
windowWidth = windowW - 1;}
resizeTo(windowW,windowHeight);
windowWidth = windowW;}
function reLayOutIfNeeded() {
if (windowWidth != window.innerWidth){
windowWidth = window.innerWidth;
layOutLayers();}}
function	fixOrderOfScreens() {
for (i = 0; i < tv.length; i++) {
if(tv[i].on) {
var index;
var countOn = -1;
for (index = 0; index < tv.length; index++) {
if (tv[index].on) {
countOn++;}
if (tv[i].onNr == countOn) {
break;}}
tv[i].screen = tv[index].originalScreen;}}}
function clickHandler(e) {
var s = new String(e.target);
var index = s.lastIndexOf("/");
if (index != -1 || index!= s.length - 1) {
s = s.slice(index + 1);
for (i = 0; i < tv.length; i++){
if (s == tv[i].clip.filename) {
screenClickedX = e.screenX
screenClickedY = e.screenY;
turnOnTV(i);
return false;}}}
return true;}
loaded = true;

