/* ******************************************************************************

'pszgallery.js', by Professional Solutions

Professional Solutions Zoom Gallery

Permission is granted to use and modify this script for any purpose,
provided that this credit header is retained, unmodified, in the script.

Requirements

files:
	pszgallery.jz   This file
	pszgallery.css  The CSS (edit to match the website)
	magminus.cur    Magnifying glass cursor
	magplus.cur     Magnifying glass cursor


*1* in the <head>
	<!-- *********** Professional Solutions Zoom Gallery *********** -->
	<link rel="stylesheet" type="text/css" href="pszg/pszgallery.css">
	<script language="JavaScript">
 		var pszg_imgdir    = "products/";
 		var pszg_zoomsufix = "z";
 		var pszg_imgtype   = ".jpg";
 		var pszg_zWidth    = 550; pszg_zHeight   = 616;
 		var pszg_imgWidth  = 365; pszg_imgHeight = 409;
 		var pszg_tWidth    = 74;  pszg_tHeight   = 82;
 		pszg_prodpics = new Array("alanapink","alanablack","alanawhite","alanablue","alanalilac","alanared");
 		pszg_prodalt  = new Array("Alana Pink","Alana Black","Alana White","Alana Blue","Alana Lilac","Alana Red");
 	</script>
 	<script src="pszg/pszgallery.js" language="JavaScript"></script>
	<!-- *********************************************************** -->

*2* in the <body>, an anchor to insert the zoomed image code
	<div id="pszgz" class="pszgz" onclick="zoomoff('pszgz');"></div>

*3* in the <body>, where to display the gallery
	<script language="JavaScript">pszg_display();</script>

******************************************************************************** */

<!--

var pzzg_currentindex = 0; // start with this image

/* ***************************************************************************** */
// Internal functions
/* ***************************************************************************** */
//to remove the zoomed picture when clicked
function pszg_zoomoff(zObj) {
//alert("zoomoff");

	if (""!=zObj){
		var x=document.getElementById(zObj);
		x.innerHTML = "";
		ps_zoomed = "";
	}
}


/* ***************************************************************************** */
//
/* ***************************************************************************** */
function setZoom(img, dir, width, height, margin, zIndex, delay) {
//  zoomon=eval("document.zoomsettings.zoomon");
//  if (zoomon.checked){

  setTimeout(function() {
    if (img.dir==dir) {
      img.style.width=width;
      img.style.height=height;
      img.style.margin=margin;
      img.style.zIndex=zIndex;
    }
  }, delay);

//  }
}

function larger(img, width, height) {
  img.dir='rtl';
  now=parseInt(img.style.zIndex);
  for (i=now+1; i<=10; i++) {
    w=(width*(10+i))/20+'px';
    h=(height*(10+i))/20+'px';
    m=(-i)+'px 0 0 '+(-width*i/40)+'px';
    setZoom(img, 'rtl', w, h, m, i, 20*(i-now));
  }
}

function smaller(img, width, height) {
  img.dir='ltr';
  now=parseInt(img.style.zIndex);
  for (i=now-1; i>=0; i--) {
    w=(width*(10+i))/20+'px';
    h=(height*(10+i))/20+'px';
    m=(-i)+'px 0 0 '+(-width*i/40)+'px';
    setZoom(img, 'ltr', w, h, m, i, 20*(now-i));
  }
}


/* ***************************************************************************** */
// pad a single digit number to two e.g '5' becomes '05'
function pszg_padout(number) { return (number < 10) ? '0' + number : number; }

/* ***************************************************************************** */
// Displays the Galery *3*
function pszg_display() {
//alert("pszg_display");

var outStr;
var i;
var L; // number of lines
var c; // current index
var k; // work index

	// display the main image
//	outStr = "<div id='pzzg_frame01' width='" + pszg_imgWidth + "' height='" + pszg_imgHeight + "'><div id='pzzg'><img id='pic01'";
	outStr = "<div id='pzzg' width='" + pszg_imgWidth + "' height='" + pszg_imgHeight + "'><img id='pic01'";
	outStr = outStr + " onClick='pszg_zoomurla(\"pszgz\")'";
	outStr = outStr + " class='pzzg_mag'";

	//outStr = outStr + " width=" + pszg_imgWidth;
	//outStr = outStr + " height=" + pszg_imgHeight;
/*
	var StoreWidth = imgObj.width;
	var StoreHeight = imgObj.height;
	if (imgObj.width>pszg_zWidth) {
		//alert("1");
		imgObj.width = pszg_zWidth;
		//imgObj.height = pszg_zHeight * imgObj.height/imgObj.width;
		imgObj.height = imgObj.height * pszg_zWidth/StoreWidth;
	}
	if (imgObj.height>pszg_zHeight) {
		//alert("2");
		imgObj.height = pszg_zHeight;
		imgObj.width = imgObj.width * pszg_zHeight/StoreHeight;
	}

*/


	outStr = outStr + " src=" + pszg_imgdir + pszg_prodpics[0] + pszg_imgtype;
	outStr = outStr + " title='" + pszg_prodalt[0] + "\nClick image to enlarge'";
	outStr = outStr + " name='" + pszg_prodalt[0] + "'></div>\n";
	document.write (outStr);

	if (pszg_captionon == true) {	// Display caption
		outStr = "<div class='pzzg_title' align='center' id='pzzg_title'>";
		outStr = outStr +  pszg_prodalt[0];
		if (pszg_captionon == true) {
			outStr = outStr +  '<br><p>Click image to enlarge</p>';
		}
		outStr = outStr + " </div>\n";
		document.write (outStr);
	}

	document.write('<div class="pzzg_thumbs" align="center" wi>\n');

	var colsperrow;
	colsperrow = 4;

	// now display the thumbnail images
	L = Math.round((pszg_prodpics.length + 1)/colsperrow); // calc number of lines
	for (k=1; k<(L+1); k++){ // loop for lines
		for (i=1; i<(colsperrow + 1); i++){ // loop for thumbnails

			c = (k-1) * colsperrow + i; // calc current index
			if (c > pszg_prodpics.length - 1){ // no more pics so exit loop
				break;
			}

			outStr = "<div id=preview><img id='pic" + pszg_padout(c+1) + "'";
			outStr = outStr + " onClick='pszg_swoppic(this.id)'";
			switch(i){
				case 1:
					outStr = outStr + " class='pzzg_thumbs-l'";
					break
				case 5:
					outStr = outStr + " class='pzzg_thumbs-r'";
					break
				default:
					outStr = outStr + " class='pzzg_thumbs-c'";
			}
			outStr = outStr + " width='" + pszg_tWidth + "'";
			outStr = outStr + " height=" + pszg_tHeight + "'";
			outStr = outStr + " src='" + pszg_imgdir + pszg_prodpics[c] + pszg_imgtype + "'";
			outStr = outStr + " alt='" + pszg_prodalt[c] + "\nClick image to enlarge'";

			//outStr = outStr + " name='" + pszg_prodalt[c] + "'";
			outStr = outStr + " name='thumb" + pszg_padout(c+1) + "'";

// Include these lines to make hover over popups active - flakey at present!
//			outStr = outStr + " onmouseover='larger(this," + pszg_pWidth + "," + pszg_pHeight + ")'";
//			outStr = outStr + " onmouseout='smaller(this," + pszg_tWidth * 2 + "," + pszg_tHeight * 2 + ")'";

			outStr = outStr + "></div>";

			document.write (outStr);
		}
	}

	document.write('</div>\n');

}

/* ***************************************************************************** */
// Global (only required if zoompic.js not used in same page)
// Flag, set to img.id if a window is currently displayed otherwise empty
var ps_zoomed = "";

/* ***************************************************************************** */
/* ***************************************************************************** */
function pszg_zoomurla(toObj) {
//alert("pszg_zoomurla");

	pszg_zoomoff(ps_zoomed); // close any open zoomed image
	if (""==ps_zoomed) {

		var imgObj = document.createElement('img');
		imgObj.src = pszg_imgdir + pszg_prodpics[0] + "z" + pszg_imgtype;
		imgObj.alt = pszg_prodalt[0] + "\nClick image to close";
		imgObj.id = "zoomed";

		var StoreWidth = imgObj.width;
		var StoreHeight = imgObj.height;
		if (imgObj.width>pszg_zWidth) {
			//alert("1");
			imgObj.width = pszg_zWidth;
			//imgObj.height = pszg_zHeight * imgObj.height/imgObj.width;
			imgObj.height = imgObj.height * pszg_zWidth/StoreWidth;
		}
		if (imgObj.height>pszg_zHeight) {
			//alert("2");
			imgObj.height = pszg_zHeight;
			imgObj.width = imgObj.width * pszg_zHeight/StoreHeight;
		}

//		imgObj.width = pszg_zWidth;
//		imgObj.height = pszg_zHeight;

		imgObj.align = "center";
//		imgObj.style = "background:url(pszg/back90.png) repeat;";

		var x = document.getElementById(toObj);
		x.appendChild(imgObj);

		ps_zoomed = toObj;
	}
}

/* ***************************************************************************** */
//
/* ***************************************************************************** */
function pszg_swoppic(ThisPic) {
//alert("pszg_swoppic");

var tmpSrc;
var tmpAlt;
var tmpName;

	var c	= ThisPic.substring(3) - 1;
	var p = pszg_prodpics[c];
	var a = pszg_prodalt[c];

	pszg_prodpics[c] = pszg_prodpics[0];
	pszg_prodalt[c] = pszg_prodalt[0];

	pszg_prodpics[0] = p;
	pszg_prodalt[0] = a;

	document.pic01.src = pszg_imgdir + pszg_prodpics[0] + pszg_imgtype;
	document.pic01.alt = pszg_prodalt[0] + "\nClick image to enlarge";

	document.getElementById(ThisPic).src = pszg_imgdir + pszg_prodpics[c] + pszg_imgtype;
	document.getElementById(ThisPic).alt = pszg_prodalt[c] + "\nClick image to enlarge";

	if (pszg_captionon == true) {	// Display caption
		if (pszg_captionon == true) {
			document.getElementById('pzzg_title').innerHTML = pszg_prodalt[0] +  '<br><p>Click image to enlarge</p>';
		} else {
			document.getElementById('pzzg_title').innerHTML = pszg_prodalt[0];
		}
	}
}

/* ***************************************************************************** */
//
/* ***************************************************************************** */
function pszg_randpic(moreHTML) {
//alert("pszg_randpic");

var randID = Math.round(Math.random()*(pszg_index));

pzzg_currentindex = randID;

	document.write("<img src=" + pszg_imgdir + pszg_prodpics[randID] + pszg_imgtype +" alt='" + pszg_prodalt[randID] + "\nClick for next image' " +" title='" + pszg_prodalt[randID] + "\nClick image to change' " + moreHTML + ">");

	if (pszg_captionon == true) {	// Display caption
		document.write ("<div class='pzzg_title' align='center' id='pzzg_title'>" + pszg_prodalt[randID] + "</div>\n");
	}


}

/* ***************************************************************************** */
//
/* ***************************************************************************** */
function pszg_randpicclick(ThisPic) {
//alert("pszg_randpicclick");

//var randID = Math.round(Math.random()*(pszg_index));

pzzg_currentindex++;
if (pzzg_currentindex > pszg_index){
		pzzg_currentindex = 0;
}

oElement = document.getElementById(ThisPic)

	//document.getElementById(ThisPic).src = pszg_imgdir + pszg_prodpics[pzzg_currentindex] + pszg_imgtype;

	oElement.setAttribute('src', pszg_imgdir + pszg_prodpics[pzzg_currentindex] + pszg_imgtype);
	oElement.setAttribute('alt', pszg_prodalt[pzzg_currentindex] + "\nClick for next image");
	oElement.setAttribute('title', pszg_prodalt[pzzg_currentindex] + "\nClick for next image");

	if (pszg_captionon == true) {	// Display caption
		if (pszg_captionon == true) {
			document.getElementById('pzzg_title').innerHTML = pszg_prodalt[pzzg_currentindex];
		}
	}

//	document.getElementById('pzzg_title').innerHTML = pszg_prodalt[randID] + "<br><p>Click to change</p>";
}



//-->
