<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">

<head profile="http://www.w3.org/2000/08/w3c-synd/#">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>CrossWire Community - Papyri Transcription and Markup</title>

<script type="text/javascript" src="/community/js/jquery/jquery.min.js"></script>
<script type="text/javascript" src="/community/js/jquery.blockUI.js"></script>
<script type="text/javascript" src="/community/js/URI.min.js"></script>

<%

boolean gallery= "on".equals(request.getParameter("gallery"));
String image  = request.getParameter("image");
String site   = request.getParameter("site");
String mod    = request.getParameter("mod");
String key    = request.getParameter("key");
String top    = request.getParameter("top");
String left   = request.getParameter("left");
String ltor   = request.getParameter("ltor");
String zoom   = request.getParameter("zoom");
String boxes[]= request.getParameterValues("box");
String legal = "";
String userAgent = request.getHeader("user-agent");
boolean mobile = (userAgent != null && userAgent.toLowerCase().indexOf("mobile") > -1);

/*
if ((site != null && site.toUpperCase().indexOf("CSNTM") > -1) || (image != null && image.toUpperCase().indexOf("CSNTM") > -1)) {
	legal = "The requirements that need to be satisfied for using these images in publication vary from manuscript to manuscript. Each possessing institute or individual has its own requirements. If you wish to publish any of these images, you will need to get permission from <a href=\"http://csntm.org\">CSNTM</a> first. We can then direct you to the contact person of the institute that owns the manuscript(s) for further instructions. <a href=\"http://csntm.org\">CSNTM</a> does not charge for the use of these images, though the institute that owns the manuscripts may. At minimum, <a href=\"http://csntm.org\">CSNTM</a> needs to be credited with the photographs and the possessing institute needs to be credited with ownership of the manuscript in all research for which these images are used.";
}
*/

if (ltor == null) ltor = "true";
String imagePrefix = ""; // "/modules/papyri/repo/";
if ("CSNTM".equalsIgnoreCase(site)) {
	imagePrefix = "http://www.csntm.org/Manuscripts/";
}
else if (site != null) {
	imagePrefix = site;
}

if (image == null) {
	image = "aleppo1.jpg";
	ltor = "false";
}
/*
else {
	imagePrefix="";
}
*/

%>
<script type="text/javascript">

var u = null;
var d = null;
var c = null;
var s = null;
var p = null;

</script>


<style type="text/css">

#attribution a:link {text-decoration:none;}
#attribution a:visited {text-decoration:none;}
#attribution a:hover {text-decoration:underline;}
#attribution a:active {text-decoration:underline;}
#attribution {
	float:left;
	font-size: 15px;
	white-space:nowrap;
}
#attribution img { float:right; height:42px;}
#attribution div { padding: 5px 0px 0px 0px; display: inline-block; margin-right: 3px; }

	h1 {
		font: 20pt sans-serif;
	}
	

#sideBar {
    width: 15%;
    float: left;
    margin-top: 0px;
    margin-right-value: 0em;
    margin-bottom: 0px;
    margin-left-value: 0px;
    margin-left-ltr-source: physical;
    margin-left-rtl-source: physical;
    margin-right-ltr-source: physical;
    margin-right-rtl-source: physical;
    padding-top: 0px;
    padding-right-value: 0.5em;
    padding-bottom: 20px;
    padding-left-value: 0px;
    padding-left-ltr-source: physical;
    padding-left-rtl-source: physical;
    padding-right-ltr-source: physical;
    padding-right-rtl-source: physical;
    clear: left;
}

#bottomBar {
    width: 100%;
    float: bottom;
    margin-top: 0px;
    margin-right-value: 0em;
    margin-bottom: 0px;
    margin-left-value: 0px;
    margin-left-ltr-source: physical;
    margin-left-rtl-source: physical;
    margin-right-ltr-source: physical;
    margin-right-rtl-source: physical;
    padding-top: 0px;
    padding-right-value: 0.5em;
    padding-bottom: 0px;
    padding-left-value: 0px;
    padding-left-ltr-source: physical;
    padding-left-rtl-source: physical;
    padding-right-ltr-source: physical;
    padding-right-rtl-source: physical;
    border-top-width: 1px;
    border-top-style: solid;
    border-top-color: rgb(204, 204, 204);
}

div.legal {
font-size: 0.7em;
padding: 10px 10px 10px 10px;
}

.widget {
position:absolute;
top:60px;
left:50px;
background: #FFF;
z-index: 50;
}

body {
	margin: 0px 8px 8px 8px;
}

#transDisplay {
	float:right;
	clear:right;
}
</style>
</head>
<body onload="loaded();">

<div style="height:45px;font-family:serif; border: 1px solid grey; position: absolute; float:left; clear:right;padding:2px 5px 0px 5px;margin:1px 0px 0px 1px;">
<span id="attribution" style="float:left; font-size: 15px">
</span>
</div>

<%@ include file="/modules/papyri/viewport.jsp" %>

	<div id="debug">
		<span id="debugA"></span> &nbsp;
		<span id="debugB"></span> &nbsp;
		<span id="debugC"></span> &nbsp;
		<span id="debugD"></span> &nbsp;
		<span id="debugE"></span> &nbsp;
		<span id="debugF"></span> &nbsp;
		<span id="debugG"></span> &nbsp;
		<span id="debugH"></span> &nbsp;
		<span id="debugI"></span> &nbsp;
		<span id="debugJ"></span> 
	</div>

<script type="text/javascript">
var shownWidget='';
var gadgetBaseURL='';
var imagesURL = '';

function showWidget(name) {
	if (shownWidget == name) {
		$('#'+name).hide();
		shownWidget='';
		return false;
	}
	if (shownWidget != '') $('#'+shownWidget).hide();
	$('#'+name).show();
	shownWidget = name;
	return false;
}

var first_load = true;
var counter = 0;


function modalWait(message) {
	$.blockUI({ message: '<h2><img src="'+gadgetBaseURL+'/images/loading.gif" /> '+ message+'</h2>', fadeIn: 0, fadeOut: 0 });
}

function modalUnWait() {
	$.unblockUI();
}


function imageLoadedCallback() {
	if (first_load) {
		first_load = false;
<%
		if (boxes != null) {
			for (int i = 0; i < boxes.length; i++) {
				int s = 0;
				int e = boxes[i].indexOf("/");
				String x = boxes[i].substring(s, e);
				s=e+1; e = boxes[i].indexOf("/", s);
				String y = boxes[i].substring(s, e);
				s=e+1; e = boxes[i].indexOf("/", s);
				String w = boxes[i].substring(s, e);
				s=e+1; e = boxes[i].indexOf("/", s);
				String h = boxes[i].substring(s, e);
				s=e+1;
//				String t = boxes[i].substring(s);
				String t = java.net.URLEncoder.encode(boxes[i].substring(s), "UTF-8");
				t = t.replace("+", "%20");
%>
				b = insertBox(<%=x%>,<%=y%>,<%=w%>,<%=h%>,'<%=t%>','key<%=i%>');
<%
			}
		}
		if ((top != null) && (left != null)) {
%>
			panImage(<%=left%>, <%=top%>, false);
<%
		}
%>
	}
}

var MARGIN=10;

function expandFillPageClients() {
	$('#scan').each(function () {
		$(this).height(window.innerHeight - $(this).offset().top - MARGIN);
	});
}


var counter = 0;
function addTempAnnotation() {
	document.body.style.cursor = 'url('+imagesURL+'/drawboxcursor.png), auto';
	$('#addAnnotationControl').css('cursor', 'url('+imagesURL+'/drawboxcursor.png), auto');
	startBoxTool(getPrivatePrefix()+(counter++), function (box) {
		document.body.style.cursor = 'default';
		$('#addAnnotationControl').css('cursor', 'default');
		if (box) personalAnnotations = true;
	});
}


function loaded() {
	gadgetBaseURL = URI('../../').absoluteTo(window.location.href);
	imagesURL = URI('../../images').absoluteTo(window.location.href);
	myloadImage();
	$(window).resize(function() {
		expandFillPageClients();
	});
	expandFillPageClients();
	var span = document.getElementById('moreControlsBefore');
	span.innerHTML = ' <span class="toolbuttonSpan" onclick="addTempAnnotation();return false;" title="Add Temporary Annotation For Linking or Discussion"><img id="addAnnotationControl" class="toolbutton" height="32" src="'+imagesURL+'/tbicons/30x-Crop.png"/></span> ';
}

function customAddImageLocation() {
	if ('<%=imagePrefix%>' != 'INTF' && '<%=imagePrefix%>' != 'VMR') {
		return addImageLocation();
	}
	else {
		return '&site=INTF&image=<%=image%>';
	}
}


function getAttributionElement() {
	return $('#attribution');
}

function myloadImage() {
	setMobile(<%=mobile%>);
	if ('<%=imagePrefix%>' != 'INTF' && '<%=imagePrefix%>' != 'VMR') {
		init_papyri_viewport('<%=imagePrefix%>', '<%=image%>', <%=ltor%><%=(zoom != null)?","+zoom:""%>);
	}
	else {
		init_papyri_viewport();
		showLoading();
		var url = gadgetBaseURL+'/modules/papyri/imageget.jsp';

		var p = 0;
		var s = 0;
		var c = 0;
		var st = 0;
		var image = '<%=image%>';
		var e = image.indexOf("/");
		var d = image.substring(st, e);
		st=e+1; e = image.indexOf("/", st);
		var u = image.substring(st, e);
		st=e+1; e = image.indexOf("/", st);
		if (e > -1) {
			p = image.substring(st, e);
			st=e+1; e = image.indexOf("/", st);
			s = image.substring(st, e);
			st=e+1; c = image.substring(st);
		}
		else {
			p = u; u = 0;
			s = image.substring(st);
		}

		var postData = 'd='+d+'&p='+p+'&s='+s+'&z='+c;

		$.post(url, postData, function(data) {
			var offset = data.indexOf('|');
			var attribution = null;
			if (offset > -1) {
				attribution = data.substring(0, offset);
				data = data.substring(offset+1);
			}
			var isRawData = (data.slice(0, 'http'.length) != 'http') && (data.slice(0, 'iiif://'.length) != 'iiif://') && (data.slice(0, 1) != '/');
			if (isRawData) {
				init_papyri_viewport('data:image/jpeg;base64,', data, <%=ltor%><%=(zoom != null)?","+zoom:""%>);
			}
			else {
				init_papyri_viewport('', data, <%=ltor%><%=(zoom != null)?","+zoom:""%>);
			}
			if (attribution) setAttribution(attribution);
		});
	}
}
</script>
</body>
</html>
