var imageloadtimeout;
var timeoutimage;
var dodots = 0;
var dottimeout = 10;

function popupWindow(url) {
		window.open(url,'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,width=100,height=100,screenX=150,screenY=150,top=150,left=150')
	}
	var maxID=0; //USED FOR IWD IMAGE ROTATER
	
	
	function dpNoSmartLink(u,n,w,h,p,theclick) { // v1.4 by David Powers // Based On dpSmartLink AM
  var a,j,k,x,y,f='';
 	var topval = 0;
	var leftval = 0;
	var widthval = 0;
	var heightval = 0;
  	if(!n){
	  	n='';
	}
	if(w){
		f+='width='+w+',';
		widthval = w;
	}
	if(h){
		f+='height='+h+',';
		heightval = h;
	}
  	if(p){
		p=p.split(':');
		if(p[0]!='z'){
			p[0]=='c'?(x=(screen.width-w)/2):x=p[0];
			f+='left='+x+',';
			leftval = x;
		}
  		if(p[1]!='z'){
			if(p[0]=='c'){
				y=(screen.height-h-p[1])/2;
				if(navigator.appName.indexOf('Op')!=-1){
  					y-=96;
					y=y<0?0:y;
				}
			}
			else{
				y=p[1];
			}
			f+='top='+y+',';
			topval = y;
		}
	}
	a=arguments.length;
	if(a>5){
		for (k=5;k<a;k++){
  			switch(arguments[k]){
				case 'all':
					f+='toolbar,menubar,location,scrollbars,status,resizable,';
					break;
  				case 't':
					f+='toolbar,';
					break;
				case 'm':
					f+='menubar,';
					break;
				case 'l':
					f+='location,';
					break;
  				case 'sc':
					f+='scrollbars,';
					break;
				case 's':
					f+='status,';
					break;
				case 'r':
					f+='resizable,';
			}
		}
	}
 	if(f.charAt(f.length-1)==','){
		f=f.slice(0,-1);
	}
	
	var g=document.getElementById("zoomimage");
	
	var scr_w = screen.availWidth;
	var scr_h = screen.availHeight;
	var browseWidth, browseHeight;
	
	floatingdivwidth = widthval;
	floatingdivheight = heightval;

	var ScrollTop = document.body.scrollTop;
	if (ScrollTop == 0){
    if (window.pageYOffset)
		ScrollTop = window.pageYOffset;
	else
	    ScrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
	}
	var ScrollLeft = document.body.scrollLeft;
	if (ScrollLeft == 0){
    if (window.pageXOffset)
		ScrollLeft = window.pageXOffset;
	else 
		ScrollLeft = (document.body.parentElement) ? document.body.parentElement.scrollLeft : 0;	
	}
	windowWidth = document.documentElement.clientWidth;
	windowHeight = document.documentElement.clientHeight;
	if(window.opera){
		windowWidth = window.innerWidth;
		windowHeight = window.innerHeight;
	}
	
	var g=document.getElementById("zoomimage");
	cx = parseInt(cx); pv = ''; nx = ''; cl = ''; pvx = cx - 1;	nxx = cx+1;
	if(picstot > 1){
		//'Previous', 'Next' and 'Close' buttons are arranged here:
		
		if(cx > 1){pv = '<a href="'+zpics[pvx].src+'" onclick="zoomtest(zpics['+pvx+']); return false;"><strong>[Prev]</strong></a>&nbsp;';}
		else{ pv = '<a href="'+zpics[picstot].src+'" onclick="zoomtest(zpics['+picstot+']); return false;"><strong>[Prev]</strong></a>&nbsp;'; }
		if(cx < picstot){nx = '&nbsp;<a href="'+zpics[nxx].src+'" onclick="zoomtest(zpics['+nxx+']); return false;"><strong>[Next]</strong></a>';}
		else{nx = '&nbsp;<a href="'+zpics[1].src+'" onclick="zoomtest(zpics[1]); return false;"><strong>[Next]</strong></a>';}
	}
	cl = '<a href="javascript:closezoomdiv();"><strong>[Close]</strong></a>';
	
	g.innerHTML = "<div id=\"innerzoom\"><div id=\"innerzoommesesage\" style=\"display:none; position:absolute; width:100px; height:40px; border:1px solid #666666; left:100px; top:130px; font-weight:bold; text-align:center; padding-top:0px;\"></div><img src=\"" + u + "\" onclick=\"closezoomdiv();\" id=\"theimage\" align=\"absmiddle\"></div><div id=\"zoombuttons\">"+buttons+"<div>"+pv+nx+'&nbsp;&nbsp;&nbsp;&nbsp;'+cl+"</div>";
	g.style.width=(floatingdivwidth)+"px";
	g.style.height=(floatingdivheight+75)+"px";
	g.style.left=ScrollLeft + parseInt(((windowWidth - (floatingdivwidth)) / 2)-10)+"px";
	g.style.top=ScrollTop + parseInt((windowHeight - (floatingdivheight+70)) / 3)+"px";
	g.style.display = 'block';


	var d=document.getElementById("formblocker");
	d.style.width=(floatingdivwidth)+"px";
	d.style.height=(floatingdivheight+75)+"px";
	d.style.left=ScrollLeft + parseInt(((windowWidth - (floatingdivwidth)) / 2)-10)+"px";
	d.style.top=ScrollTop + parseInt((windowHeight - (floatingdivheight+70)) / 3)+"px";
	d.style.display = 'block';


	var iz = document.getElementById("innerzoom");
	iz.style.width=floatingdivwidth+"px";
	iz.style.height=floatingdivheight+"px";

	iz = document.getElementById("theimage");
	iz.style.width=current.width;
	iz.style.height=current.height;
	// since the frame suits the largest images, center smaller images with appropriate additional padding
	iz.style.paddingTop=((imagex - current.height)/2) + 'px';
	iz.style.paddingLeft=((imagey - current.width)/2) + 'px';
	iz = document.getElementById('zoombutton'+cx);
	iz.style.border = '1px solid #666666';
//	iz.style.borderBottom = '#666666;';
//	iz.style.borderLeft = '#666666;';
	iz.style.borderTop = 'none';
//	iz.style.height= '50px';

	floatingdivname = "zoomimage";
	recentering=true;
	document.MM_returnValue=false;
}

var current = ''; //the current image object
var cx = 1;				//the index of the current image within the pics array
var picstot = 0;	//the total number of images in the pics array

function zoomtest(im){
	//do some stuff before calling the actual popup function
	current = im;		//image object
	if(im.src == ''){
		im.src = im.srchref;
		timeoutimage = im;
		
		dodots = 0;
		
		imagex = 300;		//minimum width
		imagey = 300; 	//minimum height
		
		var g=document.getElementById("zoomimage");
		
		cl = '<a href="javascript:closezoomdiv();"><strong>[Close]</strong></a>';
	
		g.innerHTML = "<div id=\"innerzoom\"><div id=\"innerzoommesesage\" style=\"display:none; position:absolute; width:100px; height:40px; border:1px solid #666666; left:100px; top:130px; font-weight:bold; text-align:center; padding-top:0px;\"></div></div><div id=\"zoombuttons\"><div>"+'&nbsp;&nbsp;&nbsp;&nbsp;'+cl+"</div>";
		
		floatingdivwidth = 300;
		floatingdivheight = 300;
		
		var g=document.getElementById("zoomimage");
	
		var scr_w = screen.availWidth;
		var scr_h = screen.availHeight;
		var browseWidth, browseHeight;
	
		var ScrollTop = document.body.scrollTop;
		if (ScrollTop == 0){
		if (window.pageYOffset)
			ScrollTop = window.pageYOffset;
		else
			ScrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
		}
		var ScrollLeft = document.body.scrollLeft;
		if (ScrollLeft == 0){
		if (window.pageXOffset)
			ScrollLeft = window.pageXOffset;
		else 
			ScrollLeft = (document.body.parentElement) ? document.body.parentElement.scrollLeft : 0;	
		}
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
		if(window.opera){
			windowWidth = window.innerWidth;
			windowHeight = window.innerHeight;
		}
		
		g.style.width=(300)+"px";
		g.style.height=(300+75)+"px";
		g.style.left=ScrollLeft + parseInt(((windowWidth - (floatingdivwidth)) / 2)-10)+"px";
		g.style.top=ScrollTop + parseInt((windowHeight - (floatingdivheight+70)) / 3)+"px";
		g.style.display = 'block';
		
		var d=document.getElementById("formblocker");
		d.style.width=(floatingdivwidth)+"px";
		d.style.height=(floatingdivheight+75)+"px";
		d.style.left=ScrollLeft + parseInt(((windowWidth - (floatingdivwidth)) / 2)-10)+"px";
		d.style.top=ScrollTop + parseInt((windowHeight - (floatingdivheight+70)) / 3)+"px";
		d.style.display = 'block';
	
	
		var iz = document.getElementById("innerzoom");
		iz.style.width=floatingdivwidth+"px";
		iz.style.height=floatingdivheight+"px";
		
		var someval = document.getElementById('innerzoommesesage');
		if(someval != null){
			someval.innerHTML = 'Please Wait,<br>Loading Image<br>';
			someval.style.display = 'block';
			dodots = 0;
			var someval2 = document.getElementById('theimage');
			if(someval2 != null){
				someval2.style.display = 'none';
			}
		}
		
		clearTimeout(imageloadtimeout);
		imageloadtimeout = setTimeout("zoomloaded()",75);
		return;
	}
	picstot = 0;		//begin counting
	imagex = 300;		//minimum width
	imagey = 300; 	//minimum height
	for(x in zpics){
		//find largest required dimentions for height and width of 'popup'
		if(zpics[x].width > imagex){imagex = zpics[x].width}
		if(zpics[x].height > imagey){imagey = zpics[x].height}
		if(im == zpics[x]){cx=x;} //locate the 'current' image's index within pics array
		picstot++;
	}
	dpNoSmartLink(im.src,'newWin',imagex,imagey,'c:0',0);
}

function zoomloaded(){
	if(timeoutimage != null){
		var im = timeoutimage;
		//dodots = 0;
		//var dottimeout
		dodots = dodots + 1;
		if(dodots < dottimeout){
			var someval = document.getElementById('innerzoommesesage');
			if(someval != null){
				someval.innerHTML = someval.innerHTML + '.';
			}
			imageloadtimeout = setTimeout("zoomloaded()",75);
		}
		else{
			if(im.complete == true){
				var someval = document.getElementById('innerzoommesesage');
				if(someval != null){
					someval.innerHTML = '';
					someval.style.display = 'none';
				}
				var someval2 = document.getElementById('theimage');
				if(someval2 != null){
					someval2.style.display = 'inline';
				}
				picstot = 0;		//begin counting
				imagex = 300;		//minimum width
				imagey = 300; 	//minimum height
				for(x in zpics){
					//find largest required dimentions for height and width of 'popup'
					if(zpics[x].width > imagex){imagex = zpics[x].width}
					if(zpics[x].height > imagey){imagey = zpics[x].height}
					if(im == zpics[x]){cx=x;} //locate the 'current' image's index within pics array
					picstot++;
				}
				dpNoSmartLink(im.src,'newWin',imagex,imagey,'c:0',0);
			}
			else{
				var someval = document.getElementById('innerzoommesesage');
				if(someval != null){
					someval.innerHTML = 'Please Wait,<br>Loading Image<br>';
					someval.style.display = 'block';
					dodots = 0;
					var someval2 = document.getElementById('theimage');
					if(someval2 != null){
						someval2.style.display = 'none';
					}
				}
				imageloadtimeout = setTimeout("zoomloaded()",50);
			}
		}
	}
}

function closezoomdiv(){
	if(recentering){
		if(!(floatingdivname == '')){
			var g=document.getElementById(floatingdivname);
			floatingdivname = '';
			g.style.width="0px";
			g.style.height="0px";
			g.style.display = 'none';

				g.innerHTML = '';
				recentering = false;
				loading = true;
		}
	}
	var d=document.getElementById("formblocker");
	d.style.display = 'none';
}

function buildCentreCont2(x){
	if(pics[x] != null){
		document.images['prodim'].src = pics[x].srchref;
		current = zpics[x];
		cx = x;
	}
}