﻿var folder = 'billboard_images/';
var phwidth = 210;
var phheight = 210;
var photosize = 200;
var seconds = 5;
var randomize_photos = 1;
var display_caption = 0;
var caption_height = 50;
var caption_border = 0;
var pan_zoom = 1.3;
var trans = "crossfade";
var effect = "none";
var cur_pic = 0;
var trans_amount = 20;
var effect_amount = 100;
var testing_mode = 0;
var flicker_time = 300;
var opacity_time = 50;
var trans_time = 32;
var effect_time = 45;
var pictures = new Array();
var ie = (document.all)
var picture = "picture";
var picture2 = "picture2";
var pwidth;
var pheight;
var zwidth;
var zheight;
var ztimer;
var zxstep;
var zystep;
var zleft = 0;
var ztop = 0;
var cleft = 0;
var ctop = 0;
function none(amount, none)
{
if (none == '1')
setTimeout('changepic();', pictures[cur_pic].time);
}
function toHTML (myString)
{
htmlString = myString.split("&lt;").join("<");
htmlString = htmlString.split("&gt;").join(">");
htmlString = htmlString.split("&quot;").join("\"");
htmlString = htmlString.split("&apos;").join("\'");
return htmlString;
}
function loadpics()
{
var pic_array = new Array();
var pic_list = document.getElementById('piclist').innerHTML;
var pic_list_length = pic_list.length;
var temp = new Array();
var temp2 = 'hi';
var file;
pic_list = pic_list.replace(/\r/gi, "");
if (pic_list.charAt(1) == '\n')
pic_list = pic_list.substr(1);
if (pic_list.charAt(0) == '\n')
pic_list = pic_list.substr(1);
if (pic_list.charAt(pic_list_length-3) == '\n')
pic_list = pic_list.substr(0, pic_list_length-3);
if (pic_list.charAt(pic_list_length-2) == '\n')
pic_list = pic_list.substr(0, pic_list_length-2);
if (pic_list.charAt(pic_list_length-1) == '\n')
pic_list = pic_list.substr(0, pic_list_length-1);
pic_array = pic_list.split('\n');
for (i = 0; i < pic_array.length; i++)
{
temp = pic_array[i].split('##');
file = folder+temp[0];
if (typeof(temp[1]) != 'string')
temp[1] = '';
temp[1] = toHTML(temp[1]);
temp2 = temp[1];
temp2 = temp2.replace(/<trans[^>]*>/gi, "");
temp2 = temp2.replace(/<effect[^>]*>/gi, "");
temp2 = temp2.replace(/<title[^>]*>/gi, "");
temp2 = temp2.replace(/<time[^>]*>/gi, "");
pictures[i] = {	photo: new Image,
description: temp[1],
caption: temp2,
trans: '',
effect: '',
time: '',
title: '',
url: ''};
pictures[i].photo.src = file;
}
if (randomize_photos == 1)
shuffle_photos();
setup_functions();
init_show();
}
function init_show()
{
document.getElementById('pictureholder').innerHTML = '<div style="text-align: center;'+
'position: absolute; vertical-align: middle; font-size: 1.5em; width: 100%;">' +
'LOADING'+
'<span id="bar"></span></div>';
for (i = 0; i < pictures.length && i < 5; i++)
{	pcomplete = pictures[i].photo.complete;
if (pcomplete)
document.getElementById('bar').innerHTML = '<hr width="'
+((phwidth/5)*i)+'" size="12" noshade="noshade" />';
}
if (!pcomplete)
{
setTimeout("init_show()", 10);
return;
}
document.getElementById('pictureholder').innerHTML='<img id="picture" class="picture"'+
' style="top: 0px; left: 0px; overflow:hidden; position:absolute;">'+
'<img id="picture2" class="picture"'+
' style="top: 0px; left: 0px; overflow:hidden; position:absolute;">';
set_opacity('picture', 0);
set_opacity('picture2',0);
document.getElementById('picture2').src = pictures[cur_pic].photo.src;
document.getElementById('picture2').width = pictures[cur_pic].photo.width;
document.getElementById('picture2').height = pictures[cur_pic].photo.height;
document.getElementById('picture2').style.left = 0 + 'px';
document.getElementById('picture2').style.top = 0 + 'px';
center_image('picture2');
effectsetup();
setTimeout(pictures[cur_pic].trans, 0);
}
function center_image(obj)
{	cwidth = parseFloat(pictures[cur_pic].photo.width);
cheight = parseFloat(pictures[cur_pic].photo.height);
if (cwidth > photosize)
{
perc = cwidth / photosize;
cwidth = Math.floor(cwidth / perc);
cheight = Math.floor(cheight / perc);
}
cleft = (phwidth - cwidth) / 2;
ctop = (phheight - cheight) / 2;
document.getElementById(obj).style.left = cleft + 'px';
document.getElementById(obj).style.top = ctop + 'px';	document.getElementById(obj).width = cwidth;
document.getElementById(obj).height = cheight;
}
function shuffle_photos()
{
pictures.sort(function()
{
return 0.5 - Math.random()
})
}
function randomize_trans(i)
{
rand = Math.floor(Math.random()*4)
if (rand == 0)
ftype = "crossfade";
if (rand == 1)
ftype = "wipe";
if (rand == 2)
ftype = "slide";
if (rand == 3)
ftype = "zoom";	if (ftype == "wipe")
rand = Math.floor(Math.random()*5)
else
rand = Math.floor(Math.random()*9)
if (rand == 0)
foption = "left";
if (rand == 1)
foption = "right";	if (rand == 2)
foption = "top";
if (rand == 3)
foption = "bottom";
if (rand == 4)
foption = "center";
if (rand == 5)
foption = "upperright";
if (rand == 6)
foption = "lowerleft";
if (rand == 7)
foption = "lowerright";
if (rand == 8)
foption = "upperleft";	if (ftype == "slide" && rand == 4)
foption = "left";
if (ftype == "crossfade")
pictures[i].trans = "crossfade(0);";
else	pictures[i].trans = ftype+"(0, '"+foption+"')";
}
function randomize_effect(i)
{
rand = Math.floor(Math.random()*4)
if (rand == 0)
ftype = "none";
if (rand == 1)
ftype = "zoomin";
if (rand == 2)
ftype = "zoomout";
if (rand == 3)
ftype = "pan";	if (ftype == "pan")
rand = Math.floor(Math.random()*8)
else
rand = Math.floor(Math.random()*9)
if (rand == 0)
foption = "left";
if (rand == 1)
foption = "right";	if (rand == 2)
foption = "top";
if (rand == 3)
foption = "bottom";
if (rand == 4)
foption = "upperleft";
if (rand == 5)
foption = "upperright";
if (rand == 6)
foption = "lowerleft";
if (rand == 7)
foption = "lowerright";
if (rand == 8)
foption = "center";	if (ftype == "none")
pictures[i].effect = ftype;
else	pictures[i].effect = ftype+"(0, '"+foption+"')";
}
function setup_functions()
{
if (trans == "none")
trans = "none(1)";
for (i = 0; i < pictures.length; i++)
{
if (trans == "random")
randomize_trans(i);
else	{
ftype = trans.replace(/['">)']/gi, "");
foption = ftype.split('(');
if (eval('typeof('+foption[0]+')') == 'function')
pictures[i].trans = foption[0]+"(0, '"+foption[1]+"');";
else
pictures[i].trans = 'crossfade(0)';
}
if (effect == "random")
randomize_effect(i);
else
{
ftype = effect.replace(/['">)']/gi, "");
foption = ftype.split('(');
if (eval('typeof('+foption[0]+')') == 'function')
pictures[i].effect = foption[0]+"(0, '"+foption[1]+"');";
else
pictures[i].effect = 'none(0)';
}
pictures[i].time = seconds*1000;
pictures[i].title = '';
pictures[i].url = '';
}
for (i = 0; i < pictures.length; i++)
{
if (pictures[i].description)
{
functions = pictures[i].description.split('<');
for (f = 0; f < functions.length; f++)
{
functions[f] = functions[f].replace(/ = /gi, "=");
functions[f] = functions[f].toLowerCase();
ftype = functions[f].split('=');
if (ftype[1])
{
ftype[1] = ftype[1].replace(/['")']/gi, "");
ftype[1] = ftype[1].replace(/>[\s\S]*/gi, "");
foption = ftype[1].split('(');
if (ftype[0] == "trans")
{
if (foption[0] == 'random')
randomize_trans(i);
if ((foption[0] == 'none' || foption[0] == 'crossfade'
|| foption[0] == 'zoom' || foption[0] == 'wipe' || foption[0] == 'slide')
&& (foption[1] == 'upperleft' || foption[1] == 'top' || foption[1] == 'upperright'
|| foption[1] == 'left' || foption[1] == 'center' || foption[1] == 'right'
|| foption[1] == 'lowerleft' || foption[1] == 'bottom' || foption[1] == 'lowerright'))
pictures[i].trans = foption[0]+"(0, '"+foption[1]+"')";
}	else if (ftype[0] == "effect")
{	if (foption[0] == 'random')
randomize_effect(i);
if ((foption[0] == 'none' || foption[0] == 'zoomin'
|| foption[0] == 'zoomout' || foption[0] == 'pan')
&& (foption[1] == 'upperleft' || foption[1] == 'top' || foption[1] == 'upperright'
|| foption[1] == 'left' || foption[1] == 'center' || foption[1] == 'right'
|| foption[1] == 'lowerleft' || foption[1] == 'bottom' || foption[1] == 'lowerright'))
pictures[i].effect = foption[0]+"(0, '"+foption[1]+"')";
}
else if (ftype[0] == "time")
{	pictures[i].time = parseFloat(foption[0])*1000;
}
else if (ftype[0] == "title")
{	pictures[i].title = ftype[0];
}
else if (ftype[0] == "url")
{	pictures[i].url = foption[0];
}
}
}
}
}	}
function set_opacity(object, level)
{
if(ie)
{
document.getElementById(object).style.filter="alpha(opacity="+level+")";
}
else
{
if (level == 100)
level = 99.999;
document.getElementById(object).style.MozOpacity = level/100;
document.getElementById(object).style.KHTMLOpacity = level/100;
document.getElementById(object).style.opacity = level/100;
}
}
function crossfade(opacity)
{
if (document.getElementById)
{
if (opacity <= 100)
{
set_opacity('picture2', opacity);
set_opacity('picture', 100 - opacity);
opacity += 10;
window.setTimeout("crossfade("+opacity+")", trans_time);
}
else
{
setTimeout('changepic();', trans_time);
}
}
}
function wipe(amount, from)
{
pwidth = document.getElementById('picture2').width;
pheight = document.getElementById('picture2').height;
xstep = pwidth / trans_amount * amount;
ystep = pheight / trans_amount * amount;
if (from == "left")
{
document.getElementById('picture2').style.clip = 'rect(' +
'0px, ' +
Math.round(0+xstep) + 'px, ' +
pheight + 'px, ' +
'0px)';
}
else if (from == "right")
{
document.getElementById('picture2').style.clip = 'rect(' +
'0px, ' +
pwidth + 'px, ' +
pheight + 'px, ' +
Math.round(pwidth-xstep) + 'px)';
}
else if (from == "top")
{
document.getElementById('picture2').style.clip = 'rect(' +
'0px, ' +
pwidth + 'px, ' +
Math.round(ystep) + 'px, ' +
'0px)';
}
else if (from == "bottom")
{
document.getElementById('picture2').style.clip = 'rect(' +
Math.round(pheight-ystep) + 'px, ' +
pwidth + 'px, ' +
pheight + 'px, ' +
'0px)';
}
else
{
xcenter = pwidth / 2;
ycenter = pheight / 2;
xstep = xcenter / trans_amount * amount;
ystep = ycenter / trans_amount * amount;
document.getElementById('picture2').style.clip = 'rect(' +
Math.round(ycenter-ystep) + 'px, ' +
Math.round(xcenter+xstep) + 'px, ' +
Math.round(ycenter+ystep) + 'px, ' +
Math.round(xcenter-xstep) + 'px)';
}
if (amount == 1)
set_opacity('picture2', 100);
amount++;
if (amount < trans_amount)
window.setTimeout("wipe("+amount+", '"+from+"');", trans_time);
else
{
document.getElementById('picture2').style.clip = 'rect(auto, auto, auto, auto)';
setTimeout('changepic();', trans_time);
}
}
function zoomin(amount, to)
{
if (amount == 0)
{
zwidth = document.getElementById('picture').width;
zheight = document.getElementById('picture').height;
zxstep = 3;
zystep = 3;
if (zwidth > zheight)
zxstep = (zwidth / zheight)*3;
if (zheight > zwidth)
zystep = (zheight / zwidth)*3;
}
zwidth = zwidth + zxstep;
zheight = zheight + zystep;
document.getElementById('picture').width = zwidth;
document.getElementById('picture').height = zheight;
zzleft = parseFloat(document.getElementById('picture').style.left);
zztop = parseFloat(document.getElementById('picture').style.top);
if (to == "upperright" || to == "right" || to == "lowerright")
document.getElementById('picture').style.left = zzleft - zxstep + 'px';
if (to == "top" || to == "bottom" || to == "center")
document.getElementById('picture').style.left = zzleft - zxstep/2 + 'px';
if (to == "lowerleft" || to == "bottom" || to == "lowerright")	document.getElementById('picture').style.top = zztop - zystep + 'px';
if (to == "left" || to == "center" || to == "right")
document.getElementById('picture').style.top = zztop - zystep/2 + 'px';
amount++;
if (amount <= effect_amount)
ztimer = window.setTimeout("zoomin("+amount+", '"+to+"');", effect_time);
else
{
}
}
function effectsetup()
{
ftype = pictures[cur_pic].effect.replace(/['">);']/gi, "");
foption = ftype.split('(0, ');
if (foption[1])
to = foption[1];
else
to = "";
if (foption[0] == "zoomout")
{
document.getElementById('picture2').width = parseFloat(document.getElementById('picture2').width*2);
document.getElementById('picture2').height = parseFloat(document.getElementById('picture2').height*2);
cwidth = parseFloat(document.getElementById('picture2').width*2);
cheight = parseFloat(document.getElementById('picture2').height*2);
ztop = 0;
zleft = 0;
if (to == "upperright" || to == "right" || to == "lowerright")
zleft = (cwidth/4) * -1;
if (to == "top" || to == "bottom" || to == "center")
zleft = (cwidth/8) * -1;	if (to == "lowerleft" || to == "bottom" || to == "lowerright")
ztop = (cheight/4) * -1;
if (to == "left" || to == "center" || to == "right")	ztop = (cheight/8) * -1;
cleft = cleft + zleft;
ctop = ctop + ztop;
document.getElementById('picture2').style.top = ctop + 'px';
document.getElementById('picture2').style.left = cleft + 'px';
ztop = ctop;
zleft = cleft;
}
if (foption[0] == "pan")
{
document.getElementById('picture2').width = parseFloat(document.getElementById('picture2').width*pan_zoom);
document.getElementById('picture2').height = parseFloat(document.getElementById('picture2').height*pan_zoom);
cwidth = parseFloat(document.getElementById('picture2').width*pan_zoom);
cheight = parseFloat(document.getElementById('picture2').height*pan_zoom);
ztop = 0;
zleft = 0;
if (to == "upperright" || to == "right" || to == "lowerright")
zleft = (cwidth/4) * -1;
if (to == "top" || to == "bottom" || to == "center")
zleft = (cwidth/8) * -1;	if (to == "lowerleft" || to == "bottom" || to == "lowerright")
ztop = (cheight/4) * -1;
if (to == "left" || to == "center" || to == "right")	ztop = (cheight/8) * -1;
cleft = cleft + zleft;
ctop = ctop + ztop;
document.getElementById('picture2').style.top = ctop + 'px';
document.getElementById('picture2').style.left = cleft + 'px';
ztop = ctop;
zleft = cleft;
}
}
function zoomout(amount, to)
{
if (amount == 0)
{
zwidth = parseFloat(document.getElementById('picture').width*2);
zheight = parseFloat(document.getElementById('picture').height*2);
document.getElementById('picture').style.top = ztop + 'px';
document.getElementById('picture').style.left = zleft + 'px';
zxstep = 3;
zystep = 3;
if (zwidth > zheight)
zxstep = (zwidth / zheight)*3;
if (zheight > zwidth)
zystep = (zheight / zwidth)*3;	}
zwidth = zwidth - zxstep;
zheight = zheight - zystep;
document.getElementById('picture').width = zwidth;
document.getElementById('picture').height = zheight;
zzleft = parseFloat(document.getElementById('picture').style.left);
zztop = parseFloat(document.getElementById('picture').style.top);
if (to == "upperright" || to == "right" || to == "lowerright")
document.getElementById('picture').style.left = zzleft + zxstep + 'px';
if (to == "top" || to == "bottom" || to == "center")
document.getElementById('picture').style.left = zzleft + zxstep/2 + 'px';
if (to == "lowerleft" || to == "bottom" || to == "lowerright")	document.getElementById('picture').style.top = zztop + zystep + 'px';
if (to == "left" || to == "center" || to == "right")
document.getElementById('picture').style.top = zztop + zystep/2 + 'px';
amount++;
if (amount <= effect_amount)
ztimer = window.setTimeout("zoomout("+amount+", '"+to+"');", effect_time);
else
{
}
}
function pan(amount, to)
{
if (amount == 0)
{
zwidth = parseFloat(document.getElementById('picture').width*pan_zoom);
zheight = parseFloat(document.getElementById('picture').height*pan_zoom);
document.getElementById('picture').width = zwidth;
document.getElementById('picture').height = zheight;
document.getElementById('picture').style.top = ztop + 'px';
document.getElementById('picture').style.left = zleft + 'px';
zxstep = 1;
zystep = 1;
if (zwidth > zheight)
zxstep = (zwidth / zheight);
if (zheight > zwidth)
zystep = (zheight / zwidth);	}
zzleft = parseFloat(document.getElementById('picture').style.left);
zztop = parseFloat(document.getElementById('picture').style.top);
if (to == "upperright" || to == "right" || to == "lowerright")
document.getElementById('picture').style.left = zzleft + zxstep + 'px';
if (to == "upperleft" || to == "left" || to == "lowerleft")
document.getElementById('picture').style.left = zzleft - zxstep + 'px';
if (to == "lowerleft" || to == "bottom" || to == "lowerright")	document.getElementById('picture').style.top = zztop + zystep + 'px';
if (to == "upperleft" || to == "top" || to == "upperright")
document.getElementById('picture').style.top = zztop - zystep + 'px';
amount++;
if (amount <= effect_amount)
ztimer = window.setTimeout("pan("+amount+", '"+to+"');", effect_time);
}
function zoom(amount, from)
{
pcomplete = document.getElementById('picture2').complete;
if (!pcomplete)
{
setTimeout('zoom(0,"'+from+'")', 100);
return;
}
if (amount == 0)
{
pwidth = document.getElementById('picture2').width;
pheight = document.getElementById('picture2').height;
set_opacity('picture2', 100);
}	xstep = pwidth / trans_amount * amount;
ystep = pheight / trans_amount * amount;
document.getElementById('picture2').width = xstep;
document.getElementById('picture2').height = ystep;
if (from == "left" || from == "center" || from == "right")
document.getElementById('picture2').style.top = (pheight+ctop) / 2 - (ystep-ctop) / 2 + 'px';
if (from == "top" || from == "center" || from =="bottom")
document.getElementById('picture2').style.left = (pwidth+cleft) / 2 - (xstep-cleft) / 2 + 'px';
if (from == "lowerleft" || from == "lowerright" || from=="bottom")
document.getElementById('picture2').style.top = (pheight+ctop) - ystep + 'px';
if (from == "upperright" || from == "lowerright" || from=="right")
document.getElementById('picture2').style.left = (pwidth+cleft) - xstep + 'px';
amount++;
if (amount <= trans_amount)
window.setTimeout("zoom("+amount+", '"+from+"');", trans_time);
else
{
setTimeout('changepic();', trans_time);
}
}
function slide(amount, from)
{
pwidth = document.getElementById('picture2').width;
pheight = document.getElementById('picture2').height;
if (from == null || from == 'undefined')
from = 'left';
if (from == "left" || from == "lowerleft" || from == "upperleft")
{
xstep = Math.round((pwidth+cleft) / trans_amount * amount);
xstep = pwidth - (pwidth*2) + xstep;
document.getElementById('picture2').style.left = xstep + 'px';
}
else if (from == "right" || from == "lowerright" || from == "upperright")
{
xstep = Math.round((pwidth-cleft) / trans_amount * amount);
xstep = pwidth - xstep;
document.getElementById('picture2').style.left = xstep + 'px';
}
if (from == "top" || from == "upperleft" || from == "upperright")
{
ystep = Math.round((pheight+ctop) / trans_amount * amount);
ystep = pheight - (pheight*2) + ystep;
document.getElementById('picture2').style.top = ystep + 'px';
}
else if (from == "bottom" || from == "lowerleft" || from == "lowerright")
{
ystep = Math.round((pheight-ctop) / trans_amount * amount);
ystep = pheight - ystep;
document.getElementById('picture2').style.top = ystep + 'px';
}
if (amount == 0)
set_opacity('picture2', 100);
amount++;
if (amount <= trans_amount)
window.setTimeout("slide("+amount+", '"+from+"');", trans_time);
else
{
setTimeout('changepic();', trans_time);
}	}
function change_url()
{
if (cur_pic == 0)
pic_num = pictures.length - 1;
else
pic_num = cur_pic - 1;
if (pictures[pic_num].url != '')
window.location=pictures[pic_num].url;
}
function changepic()
{
var pictures_length = pictures.length;
if (testing_mode == 1)
testingbox.innerHTML = cur_pic+". Transition: "+pictures[cur_pic].trans+". Effect: "+pictures[cur_pic].effect+
". Time: "+pictures[cur_pic].time;
". Width:"+document.getElementById('picture').width+", "+document.getElementById('picture').height;
var milliseconds = pictures[cur_pic].time;
if (display_caption == 1)
document.getElementById('captionholder').innerHTML = pictures[cur_pic].caption;
clearTimeout(ztimer);
document.getElementById('picture').src = pictures[cur_pic].photo.src;
document.getElementById('picture').width = pictures[cur_pic].photo.width;
document.getElementById('picture').height = pictures[cur_pic].photo.height;
document.getElementById('picture').style.left = 0 + 'px';
document.getElementById('picture').style.top = 0 + 'px';
document.getElementById('pictureholder').title = pictures[cur_pic].url;
center_image('picture');
if (testing_mode == 1)
testingbox.innerHTML += ". Width:"+document.getElementById('picture').width+
", "+document.getElementById('picture').height;
setTimeout("set_opacity('picture',100);", opacity_time)
setTimeout("set_opacity('picture2',0);", opacity_time)
eval(pictures[cur_pic].effect);
if (testing_mode == 1)
testingbox.innerHTML += ". url="+pictures[cur_pic].url;
cur_pic++;
if (cur_pic == pictures_length)
{
cur_pic = 0;
if (randomize_photos == 1)
shuffle_photos();	}
setTimeout("document.getElementById('picture2').src = pictures["+cur_pic+"].photo.src;", flicker_time);
setTimeout("document.getElementById('picture2').width = pictures["+cur_pic+"].photo.width;", flicker_time+20);
setTimeout("document.getElementById('picture2').height = pictures["+cur_pic+"].photo.height;", flicker_time+20);
setTimeout("document.getElementById('picture2').style.left = 0 + 'px';", flicker_time+20);
setTimeout("document.getElementById('picture2').style.top = 0 + 'px';", flicker_time+20);
setTimeout('center_image("picture2");', flicker_time+50);
setTimeout('effectsetup();', flicker_time+100);
setTimeout(pictures[cur_pic].trans, milliseconds);
}
if (testing_mode == 1)
{
document.write('<div id="testing">testing Mode</div>');
testingbox = document.getElementById('testing');
}
document.write('<div id="pictureholder" class="pictureholder" onclick="change_url();"'+
' style="width: '+phwidth+'px; height: '+phheight+'px; overflow: hidden; position: relative;">');
document.write('</div>');
if (display_caption == 1)
document.write('<div id="captionholder" class="captionholder"'+
' style="width:'+phwidth+'px; height: '+caption_height+
'px; border-width:'+caption_border+'px; border-style:solid;'+
' margin-top: 5px; padding: 5px; text-align: center;"></div>');
window.onload = loadpics;
