imgObj.pre=new Array();
imgObj.property=new Array();
imgObj.obj1=new Array(); // indexed Array, not hash
imgObj.obj=new Array();i_index=0;
var saved_id = 1;
var slideshow_id=1;
var slideshow=0;
var transition='revealTrans(duration=3, transition=50)';
var gallery_div_content='';
var timer_id;



if (document.body && typeof document.body.clientWidth!='undefined')
 browser_width=document.body.clientWidth
if (typeof window.innerWidth!='undefined')
 browser_width=window.innerWidth

function imgObj(id_field,image_name,title,aspect,text,l_desc){
this.index=i_index;
i_index++;
this.id_field=id_field;
this.image_name=image_name;
this.title=title;
this.text=text;
this.aspect=aspect;
this.l_desc=l_desc;
this.s_desc='';
imgObj.obj[id_field]=this;
imgObj.obj1[this.index]=this;
this.test=test;
this.checkNext=getNext;
this.getNext=getNext;
this.getLast=getLast;
this.findID=findID;
this.preLoad=preLoad;
}

function findID(){

}

function preLoad(index_){
// var index_=this.index;
++index_;
if(index_ < imgObj.obj1.length){
imgObj.pre[index_] = new Image();
var image_name=imgObj.obj1[index_].image_name;
image_name=image_name.replace(/350a-/g,'700a-');
imgObj.pre[index_].src=image_name;
}else{
imgObj.pre[0] = new Image();
imgObj.pre[0].src=imgObj[1].image_name;
}
}

function slideShow(){
if(slideshow_id > imgObj.obj1.length){
restoreContent();
clearTimeout(timer_id);
}else{
slideshow_id++;
timer_id=setTimeout('slideShow()', '4000');
imgObj.obj1[slideshow_id].test(1);}
var slideshow=document.getElementById('slideshow');
slideshow.innerHTML='<a href="javascript:stopSlideShow()">STOP</a>';
}

function stopSlideShow(){
clearTimeout(timer_id);
var slideshow=document.getElementById('slideshow');
slideshow.innerHTML='<a href="javascript:slideShow()">PLAY</a>';
}

function getNext(){
var index_=this.index;
saved_id=index_;
++index_;
if(index_ < imgObj.obj1.length){
imgObj.obj1[index_].test(1);
}else{
imgObj.obj1[0].test(1);
}
}

function getLast(){
var index_=this.index;
saved_id=index_;
--index_;
if(index_ > -1){
imgObj.obj1[index_].test(1);
}else{
imgObj.obj1[((imgObj.obj1.length)-1)].test(1);
}
}

function test(check){
if(! document.getElementById){
return true;
}

var nav='<div style="margin-top: 11px" class="pop_nav"><a href="javascript:restoreContent()">view thumbnails</a> &nbsp; <span style="whitespace: nowrap"><a href="javascript:imgObj.obj['+this.id_field+'].getLast()">&lt; previous</a> &#149; <a href="javascript:imgObj.obj['+this.id_field+'].getNext()">next &gt;</a></span> &nbsp; <span id="slideshow"><a href="javascript:slideShow()">PLAY</a></span></div>';

var def_width=700;

var aspect=this.aspect;

if(! aspect){aspect = 1;}

var height=def_width+5;
var width=def_width+190;

var htmlAll = '';

htmlAll += '<style type="text/css">\n';
htmlAll += 'a,body,table,.td{font-family: sans-serif;font-size: 12px}\n';
htmlAll += '.td{font-size: 12px}\n';
htmlAll += '</style>\n';
htmlAll += '<table><tr><td rowspan="2">';
htmlAll += '<img src="^image_name^" id="main_image"  onload="preLoad(\'^id_field^\')">';
htmlAll += '</td><td valign="top" height="20">^nav^</td></tr>\n';
htmlAll += '<tr><td class="pop_text" valign="top">^text^</td></tr>\n';
htmlAll += '\n</table>\n';


var htmlWide = '';

htmlWide += '<style type="text/css">\n';
htmlWide += 'a,body,table,.td{font-family: sans-serif;font-size: 12px}\n';
htmlWide += '.td{font-size: 12px}\n';
htmlWide += '</style>\n';
htmlWide += '<table><tr><td>^nav^</td></tr>\n';
htmlWide += '<tr><td class="pop_text" valign="top">^text^</td></tr>\n';
htmlWide += '<tr><td><img src="^image_name^" id="main_image" onload="preLoad(\'^id_field^\')"></td></tr>\n';
htmlWide += '\n</table>\n';

if(aspect >= 1){width=parseInt((def_width/aspect)+200);
html=htmlAll;
}
if(aspect < 1){height=parseInt((def_width*aspect)+5);
width=def_width+200;
html=htmlAll;
}

html=htmlAll;

if(aspect < 1.25){html=htmlWide}

if(! this.title){this.title = 'Gallery Popup';}


this.image_name=this.image_name.replace(/350a-/g,'700a-');
var title=this.title
html = html.replace(/\^title\^/g ,this.title);
html = html.replace(/\^id_field\^/g ,this.id_field);
html = html.replace(/\^image_name\^/g ,this.image_name);
html = html.replace(/\^s_desc\^/g ,this.s_desc);
html = html.replace(/\^image_author\^/g ,this.image_author);
html = html.replace(/\^text\^/g ,this.text);
html = html.replace(/\^nav\^/g ,nav);

// var body_ref=document.getElementsByTagName('body')[0];
// if(! check){imgObj.property['saved_html']=body_ref.innerHTML;};
// body_ref.innerHTML=html;

var id_field=this.id_field;

makeWindow(html,width,height,id_field);

var img=document.getElementById('main_image');

if(img.filters){
img.src=imgObj.obj1[saved_id].image_name;
img.style.filter=transition;
img.filters[0].apply();
img.src=this.image_name;
img.filters[0].play();
}

// this.preLoad()
return false;
}

function restoreContent(){document.getElementById('side_nav').style.display='block';
document.getElementById('gallery_div').innerHTML=gallery_div_content;
}

function makeWindow(contents,width,height,id_field){
document.getElementById('side_nav').style.display='none';
if(! gallery_div_content){
gallery_div_content=document.getElementById('gallery_div').innerHTML;
}

document.getElementById('gallery_div').innerHTML=contents;

}

function closeWindows(id_field){

}

function restore(){document.getElementById('side_nav').style.display='block';
document.getElementsByTagName('body')[0].innerHTML=imgObj.property['saved_html'];
return false;
}
