/***********************************************************************
*
*  Author: joeri.van.hoof@pandora.be
*
*  Based on script Image Thumbnail Viewer II from www.dynamicdrive.com
***********************************************************************/

var subject=""

//Set image border width
var borderwidth=0;

function getimgcode(img, imglink, subject, print, ph1015) {
	var result ="";

	if( print != "" ) {
		result += '<div id="box-gallery-photo-left">';
	} else {
		result += '<div id="box-gallery-photo">';
	}

	if (imglink!="")
		result ='<a href="'+imglink+'">';

	if (subject!="")
		result +='<div id="description">' + subject + '</div>';

	result +='<img src="'+img+'" border="'+borderwidth+'"></img>';

	if (imglink!="")
		result +='</a>';

	result += '</div>';

	if( print != "" ) {
		result += '<div id="box-gallery-items">';
		if(ph1015!="")  
			result += '<a href="' + ph1015 + '">Klik hier voor je gratis 10x15 foto</a>';
		result += '<form name="order" method="post">';
		result += '<input name="itemId" value="' + print + '" type="hidden"/>';
		result += '<input name="color" value="' + subject + '" type="hidden"/>';
		result += '<ul id="box-gallery-ul"><li><input name="size" value="10x15" type="radio">&nbsp;Foto afdruk 10x15 - &euro;1,5</input></li>';
		result += '<li><input name="size" value="13x18" type="radio">&nbsp;Foto afdruk 13x18 - &euro;2,70</input></li>';
		result += '<li><input name="size" value="20x30" type="radio">&nbsp;Foto afdruk 20x30 - &euro;12</input></li>';
		result += '<li><input name="size" value="25x38" type="radio">&nbsp;Foto afdruk 25x38 - &euro;15,30</input></li>';
		result += '<li><input name="size" value="Sleutelhanger" type="radio">&nbsp;Sleutelhanger met foto - &euro;5</input></li>';
		result += '<input src="/style/checkout/cart.gif" onclick="addToCartButtonHandler1CMS(this.form);" type="image">';
		result += '</form>';
		result += '</div>';
	} else {
		result += '<div id="box-gallery-items">';

		if(ph1015!="")
			result += '<a href="' + ph1015 + '">Klik hier voor de 10x15 foto.</a>';

		result += '</div>';		
	}

	return result;
}

function getimage(loadarea, img, imglnk, subject, print, ph1015){

	if (document.getElementById){
		var imgobj=document.getElementById(loadarea)

		imgobj.innerHTML=getimgcode(img, imglnk, subject, print, ph1015)

		return false
	}
}

var req;
var batch;

function thumbnailchanger(gallery, action, count) {
	batch = count;

	var url = "/photo?gallery=" + escape(gallery) + "&action=" + escape(action) + "&count=" + escape(count);
	if( window.XMLHttpRequest ) {
		req = new XMLHttpRequest();
	} else if( window.ActiveXObject ) {
		req = new ActiveXObject("Microsoft.XMLHTTP");
	}

	req.open("GET", url, true);
	req.onreadystatechange = thumbnailloader;
	req.send(null);
}

function thumbnailloader() {

	if( req.readyState == 4 ) {
		if( req.status == 200 ) {
			var i=0;
			var filelist = req.responseXML.getElementsByTagName("file");
			var response = req.responseXML.getElementsByTagName("result");
			var size = filelist.length;
			var start = parseInt(response[0].getAttribute("start"));
			var stop = response[0].getAttribute("stop");
			var max = response[0].getAttribute("max");
			var mdiv = document.getElementById("box-gallery-thumbnails");
			var result = "";
			for( i=0; i<size; i++) {
				var href = filelist[i].getAttribute('href');
				var path = filelist[i].getAttribute('path');
				var ph1015 = filelist[i].getAttribute('ph1015');
				var description = filelist[i].getAttribute('description');
				var print = filelist[i].getAttribute('print');
				var tmp = path.split('/');
				var code = tmp[tmp.length - 1];
				result += "<a href='" + path + "' class='highslide' onclick='return hs.expand(this)'>";
				result += "<img src='" + path + "' width='80' height='53' alt='' title='' />";
				result += "</a>";
				if( description != null )
					result += "<div class='highslide-heading'>" + description + "</div>";
				else 
					result += "<div class='highslide-heading'></div>";
				result += "<div class='highslide-caption'>";
				if( print != null ) {
					if( ph1015 != null )
						result += '<a href="' + ph1015 + '">Klik hier voor je gratis 10x15 foto</a>';
					result += '<form name="order" method="post">';
					result += '<input name="itemId" value="' + print + '" type="hidden"/>';
					result += '<input name="color" value="' + code + '" type="hidden"/>';
					result += '<ul id="box-gallery-ul"><li><input name="size" value="10x15" type="radio"> Foto afdruk 10x15 - &euro;1,5</input></li>';
					result += '<li><input name="size" value="13x18" type="radio"> Foto afdruk 13x18 - &euro;2,70</input></li>';
					result += '<li><input name="size" value="20x30" type="radio"> Foto afdruk 20x30 - &euro;12</input></li>';
					result += '<li><input name="size" value="25x38" type="radio"> Foto afdruk 25x38 - &euro;15,30</input></li>';
					result += '<li><input name="size" value="Sleutelhanger" type="radio"> Sleutelhanger met foto - &euro;5</input></li>';
					result += '<input src="/style/cart.gif" onclick="addToCartButtonHandler1CMS(this.form)" type="image">';
					result += '</form>';
				} else {
					if( ph1015 != null )
						result += '<a href="' + ph1015 + '" target="_blank">Klik hier voor de 10x15 foto.</a>';
				}
				result += "</div>";
			}
			mdiv.innerHTML = result;
			var countdiv = document.getElementById("box-gallery-count");
			if( countdiv != null )
				countdiv.innerHTML = start + "-" + stop + "/" + max;
		}
	}

} 
