<ja:if test=<%=chameleon.voiceAnnotations && !chameleon.isMovie%>><script type="text/javascript" src="$resPath/embedmovie.js"></script></ja:if>
<ja:if test=<%=chameleon.includeGuestBookTop || chameleon.includeGuestBookBottom%>><script type="text/javascript" src="$resPath/embedguestbook.js"></script></ja:if>
<script type="text/javascript">
/* <![CDATA[ */
<ja:if test=<%=!chameleon.fitImageNone%>>
function getRatio() {
	if (ww = window.innerWidth) wh = window.innerHeight;
	else if(document.documentElement) {
		ww = document.documentElement.clientWidth;
		wh = document.documentElement.clientHeight;
	} 
	else return 1;
	rw = (ww - ${widthDecr}) / ${mImageWidth}; 
	rh = (wh - ${heightDecr}) / ${mImageHeight};
	if (rw > rh) rw = rh;
<ja:if test=${fitImageEnlarge}>	if (rw <= 1.0) return 1;</ja:if>
<ja:if test=${fitImageShrink}>	if (rw >= 1.0) return 1;</ja:if>
	return rw;
}
var coords;
function saveCoords(el) {
	coords = el.areas[i].coords.split(',');
}
function correctImage() {
	var ratio = getRatio();
	if ((el = document.getElementById("slide")) != null) {
		el.width = ${mImageWidth} * ratio;
		el.height = ${mImageHeight} * ratio;
	}
	if ((el = document.getElementById("imap")) != null) {
		var cs;
		if (coords == null) {
			var s;
			coords = new Array(el.areas.length);
			for (i = 0; i < el.areas.length; i++) {
				cs = el.areas[i].coords.split(',');
				coords[i] = new Array(cs.length);
				for (j = 0; j < cs.length; j++)
					coords[i][j] = parseInt(cs[j], 10);
			}
		}
		for (i = 0; i < el.areas.length; i++) {
			cs = "";
			for (j = 0; j < coords[i].length; j++) {
				if (j > 0) cs += ','; 
				cs += parseInt(coords[i][j] * ratio);
			}
			el.areas[i].coords = cs;
		}
	}
}
</ja:if>
<ja:if test=<%=(chameleon.enableKeyboard || chameleon.enableMousewheel)%>>
function preventDefault(e) {
	if (document.addEventListener) e.preventDefault();
	else e.returnValue=false;
	return false;
}
<ja:if test=${enableMousewheel}>
function mousewheel(e) {
	if(typeof _jaWidgetFocus != 'undefined' && _jaWidgetFocus) return true;
	var delta = 0;
	if(!e) var e=window.event;
	if(e.wheelDelta) delta=e.wheelDelta/120;
	else if(e.detail) delta=-e.detail/3;
	<ja:if exists="previousPage">if(delta > 0) { window.location="$previousPage"+"${internalLink}"; return preventDefault(e); }</ja:if>
	<ja:if exists="nextPage">if(delta < 0) { window.location="$nextPage"+"${internalLink}"; return preventDefault(e); }</ja:if>
	return true;
}</ja:if>
<ja:if test=${enableKeyboard}>
function keypress(e) {
	if(typeof _jaWidgetFocus != 'undefined' && _jaWidgetFocus) return true;
	if(document.activeElement && document.activeElement.nodeName == 'input') return true;
	if(!e) var e=window.event;
	if(e.keyCode) keyCode=e.keyCode; 
	else if(e.which) keyCode=e.which;
	switch(keyCode) {
		case 8: window.location="../$indexPage"; return preventDefault(e); break;
		<ja:if exists="nextPage">case 63235: case 39: window.location="$nextPage"+"${internalLink}"; return preventDefault(e); break;</ja:if>
		<ja:if exists="previousPage">case 63234: case 37: window.location="$previousPage"+"${internalLink}"; return preventDefault(e); break;</ja:if>
		<ja:if exists="firstPage">case 63273: case 36: window.location="$firstPage"+"${internalLink}"; return preventDefault(e); break;</ja:if>
		<ja:if exists="lastPage">case 63275: case 35: window.location="$lastPage"+"${internalLink}"; return preventDefault(e); break;</ja:if>
		<ja:if test=${doSlideShow}>case 32: show_down(); setTimeout('show_out()', 200); return preventDefault(e); break;</ja:if>
	}
	return true;
}</ja:if>
function setuplisteners() {
	var isFF = navigator.userAgent.indexOf('Gecko') > -1 && navigator.userAgent.indexOf('KHTML') == -1;
	if (document.addEventListener) {
		<ja:if test=${enableKeyboard}>document.addEventListener('keypress',keypress,false);</ja:if>
		<ja:if test=${enableMousewheel}>document.addEventListener(isFF? 'DOMMouseScroll':'mousewheel',mousewheel,false);</ja:if>
	}
	else if (document.attachEvent) {
		<ja:if test=${enableKeyboard}>document.attachEvent('onkeydown',keypress);</ja:if>
		<ja:if test=${enableMousewheel}>document.attachEvent('onmousewheel',mousewheel);</ja:if>
	}
}
</ja:if>
idx0 = new Image(31,31); idx0.src = "$resPath/idx.gif";
idx1 = new Image(31,31); idx1.src = "$resPath/idx1.gif";
next0 = new Image(31,31);next0.src = "$resPath/next.gif";
next1 = new Image(31,31);next1.src = "$resPath/next1.gif";
prev0 = new Image(31,31);prev0.src = "$resPath/prev.gif";
prev1 = new Image(31,31);prev1.src = "$resPath/prev1.gif";
<ja:if test=${doSlideShow}>
show0 = new Image(31,31);show0.src = "$resPath/show.gif";
show1 = new Image(31,31);show1.src = "$resPath/show1.gif";
stop0 = new Image(31,31);stop0.src = "$resPath/stop.gif";
stop1 = new Image(31,31);stop1.src = "$resPath/stop1.gif";

var show_param = -1;
if (window.location.search.length > 1) {
	var parms = window.location.search.substring(1,location.search.length).split("&");
	for (var i = 0; i < parms.length; i++) {		
		if(parms[i].substring(0, parms[i].indexOf("=")) == "show_param") 
			delay = show_param = parms[i].substring(parms[i].indexOf("=") + 1, parms[i].length);
	}
}
var show_delay = show_param;
function show_timer() {
	if (show_delay >= 0) {
		show_delay--;
		if (show_delay < 0 && show_param > 0) {
			<ja:if exists="nextPage">window.location="$nextPage?show_param=" + show_param + "${internalLink}";</ja:if>
			<ja:else><ja:if test=${slideShowLoop}>window.location="$firstPage?show_param=" + show_param + "${internalLink}";</ja:if><ja:else>show_down(); setTimeout('show_out()', 200);</ja:else></ja:else>
		}
		else if(show_param > 0) 
			window.status='Time left: '+(show_delay + 1)+' s';
	}
	setTimeout('show_timer()', 1000);	
}
function show_over() {
	document.getElementById("show").src = (show_param >= 0)? stop1.src : show1.src;
	window.status = '$text.startStopSlideShow - $text.changeSpeed';
}
function show_out() {
	document.getElementById("show").src = (show_param >= 0)? stop0.src : show0.src;
}
function show_down() {
	el = document.getElementById("show");
	if (show_param >= 0) { 
		show_param = -1; 
		el.src = stop1.src; 
		window.status=''; 
	} 
	else { 
		show_param = ${slideShowDelay}; 
		el.src = show1.src; 
	} 
	show_delay = show_param; 
}
function change_delay() {
	delay = prompt('$text.delay', (show_param < 0)? ${slideShowDelay} : show_param);
	show_param = show_delay = delay; 
	document.getElementById("show").src = show1.src;
}
</ja:if>
<ja:if test=${newLabel}>
function generatenew(fDays) {
  now = new Date();
  nDays = now.getTime() / 86400000;
  if((nDays - fDays) <= ${newLabelDaysCount})
    document.write('<span class="newlabel">&nbsp;$text.new&nbsp;<\/span><%=("$text.new".length() > 4)? "<br />":"&nbsp;"%>');
}
</ja:if>
<ja:if test=<%=(chameleon.includeGuestBookTop || chameleon.includeGuestBookBottom)%>>
var color = "#cccccc";
var bgcolor = "#333333";
function rgb2hex(c) {
	if (c.charAt(0) == '#') return c;
	var i = c.indexOf('(');
	if (i > 0) {
		c = c.substring(i+1).split(',');
		var s = '#', n;
		for (i = 0; i < 3; i++) {
			if ((n = parseInt(c[i])) != 'NaN') s += ((n < 16)? '0':'') + n.toString(16);
			else s += '00';
		}
		return s;
	}
	else return '#cccccc';
}
function getColors() {
	var el = document.getElementById("body");
	if (!el) return;
	var computedStyle = null;
	if (typeof el.currentStyle != "undefined")
		computedStyle = el.currentStyle;
	else
		computedStyle = document.defaultView.getComputedStyle(el, null);	
	color = rgb2hex(computedStyle['color']);
	bgcolor = rgb2hex(computedStyle['backgroundColor']);
	if (color == bgcolor) color = '#cccccc';
}

function showGuestbook() {
	getColors();
	embedGuestbook("${guestBookPath}/guestbook.swf", ${guestBookWidth}, ${guestBookHeight}, "xmlfile=${guestBookFile}.xml&xmlphp_path=${guestBookPath}/&width=${guestBookWidth}&width=${guestBookHeight}&basefontsize=${guestbookBaseFontSize}&bgcolor=" + bgcolor + "&countcolor=" + color + "&usercolor=${guestbookHighlightColor}&commentscolor=" + color + "&pagelabel=$text.page&namelabel=$text.name&msglabel=$text.message&nameerror=$text.enterName&msgerror=$text.enterMessage&welcomemsg=$text.welcomeMessage&showrating=${guestBookRating}&ratinglabel=$text.rating&avgratinglabel=$text.avgRating&ascending=${guestbookAscending}&dateFormat=${gbDateFormat}&msgscount=${guestbookEntries}");
}
</ja:if>
<ja:if test=<%=!chameleon.paypalCustom && chameleon.paypalTop || chameleon.paypalBottom%>>
var ppitems = new Array(${paypalItemsArray});

<ja:if test=${paypalInline}>
function submitPaypal() {
	form = document.forms['paypal'];
<ja:if test=<%=chameleon.paypalItemsCount > 1%>>
	for (sel = 0; sel < ${paypalItemsCount}; sel++)
		if (form.options[sel].checked)
			break;
	if (sel == ${paypalItemsCount}) {
		alert("$text.noneSelectedAlert");
		return;
	}
</ja:if><ja:else>
	var sel = 0;
</ja:else>

	form['item_name'].value = ppitems[sel][0];
	form['item_number'].value = "<%=chameleon.stripNonWeb(chameleon.simplePath) + "/" + label%> (" + ppitems[sel][3] + ")";
	form['amount'].value = ppitems[sel][1];
<ja:if test=${paypalShippingUsed}>	form['shipping'].value = ppitems[sel][2];</ja:if>
	form['add'].value = "1";
	form.target = "paypal";
	form.submit();
}

<ja:if test=<%=chameleon.paypalItemsCount > 1%>>
function updatePrice(sel) {
	form = document.forms['paypal'];
	if (form.options[sel].checked) {
		if (ppitems[sel][2].length > 0)
			form['price'].value = "${paypalCurrency} " + ppitems[sel][1] + " (+" + ppitems[sel][2] + ")";
		else
			form['price'].value = "${paypalCurrency} " + ppitems[sel][1];
	}
}</ja:if>
</ja:if><ja:else>
function submitPaypal(sel) {
	form = document.forms['paypal'];
	form['item_name'].value = ppitems[sel][0];
	form['item_number'].value = "<%=chameleon.stripNonWeb(chameleon.simplePath + "/" + label)%> (" + ppitems[sel][3] + ")";
	form['amount'].value = ppitems[sel][1];
	form['add'].value = "1";
<ja:if test=${paypalUseSelect}>	form['os0'].value = form['select' + sel].value;</ja:if>
<ja:if test=${paypalShippingUsed}>	form['shipping'].value = ppitems[sel][2];</ja:if>
<ja:if test=${paypalUseQuantity}>	form['quantity'].value = form['quantity' + sel].value;</ja:if>
	form.target = "paypal";
	form.submit();
}
</ja:else>
function viewPaypal() {
	form = document.forms['paypalview'];
	form.target = "paypal";
	form.submit();
}
</ja:if>
window.onload = function() {
	<ja:if test=<%=enableKeyboard || enableMousewheel%>>setuplisteners();</ja:if>
	<ja:if test=${doSlideShow}>show_timer(); show_out();</ja:if>
	<ja:if test=<%=!chameleon.fitImageNone%>>correctImage();
	window.onresize = correctImage;</ja:if>
};
/* ]]> */
</script>
<ja:if test=<%=chameleon.printingPhotobox && chameleon.printOrderOn%>><script type="text/javascript" src="http://printbutton.com/${companyId}.js"></script></ja:if>

