var crop = false;
var gold = false;

function goup(hrf) 
{
document.getElementById('downar').style.display="";
document.getElementById('downarh').href='#comment'+hrf;
}


var bw=false;
function toggleBW(id)
{
if (bw = !bw)
document.getElementById('btnbw').src = "/i/c/bw1.gif";
else
document.getElementById('btnbw').src = "/i/c/bw0.gif";
var vw = document.getElementById('viewer');
if (id == 'n') return;
if (xDef(vw.style.filter))
{ vw.style.filter = "Gray"; vw.filters["Gray"].enabled = bw;}
else { if (bw) vw.src = '/p/bw/'+id+'.jpeg';  else vw.src = '/p/f/'+id+'.jpeg'; }
}

function toggleCrop()
{crop = !crop;
var vf = document.getElementById('vf');
var insc = document.getElementById('insc');
if(crop) 
{document.getElementById('btncrp').src = "/i/c/crop1.gif"; vf.style.display = ""; 
if (xDef(document.comment))
    insc.style.display="";
return;}
document.getElementById('btncrp').src = "/i/c/crop0.gif";  vf.style.display = "none"; insc.style.display="none";}

function toggleGold()
{gold = !gold;
if(gold)
{ if(!crop) toggleCrop();
document.getElementById('btngld').src = "/i/c/gold1.gif";document.getElementById('grid').style.visibility = "visible"; return;}
document.getElementById('btngld').src = "/i/c/gold0.gif";document.getElementById('grid').style.visibility = "hidden";}


var CurrentSide = null;
var x0 = 0; var y0 = 0;

function MDown(ev, side) {
CurrentSide = side; 
if(typeof(ev.clientX)=='number' && typeof(ev.clientY)=='number')
{ x0 = ev.clientX; y0 = ev.clientY; }
else {x0 = ev.x;y0 = ev.y;}
}

function MUp(ev)
{CurrentSide = null;}

function MMove(ev, maxw, maxh)
{

if (navigator.userAgent.toLowerCase().indexOf('gecko') != -1)
    mbtn = 1;
else
    mbtn = ev.button;
 
if ((CurrentSide == null)||(mbtn != 1))
    return;

if(typeof(ev.clientX)=='number' && typeof(ev.clientY)=='number')
{ rx = ev.clientX; ry = ev.clientY; }
else {rx = ev.x;ry = ev.y;}

dx = rx - x0;
dy = ry - y0;

ob = document.getElementById(CurrentSide);
style = ob.style;
switch (CurrentSide)
{
case "top":
px = xHeight(ob); if (!px) px = 0;
if (((px < maxh - 64)||(dy<0))&&(px >= 8)) xHeight(ob, px+dy);
if(px < 8) xHeight(ob, 8);
else {x0 = rx; y0 = ry;}

bt = document.getElementById('bottom');
if ( xHeight(bt) + xHeight(ob) + 64 > maxh)
    xHeight(bt, maxh - xHeight(ob) - 64);
break;

case "bottom":
px = xHeight(ob); if (!px) px = 0;
if ((px >= 8)) xHeight(ob, px-dy);
if(px < 8) xHeight(ob, 8);
else {x0 = rx; y0 = ry;}

bt = document.getElementById('top');
if ( xHeight(ob) + xHeight(bt) + 64 > maxh)
    xHeight(ob, maxh - xHeight(bt) - 64);
break;

case "left":
px = xWidth(ob); if(!px) px = 0;
if(px >= 8) xWidth(ob, px + dx);
if(px < 8) xWidth(ob, 8);
else {x0 = rx; y0 = ry;}
break;

case "right":
px = xWidth(ob); if(!px) px = 0;
if(px >= 8) xWidth(ob, px - dx);
if(px < 8) xWidth(ob, 8);
else {x0 = rx; y0 = ry;}
break;
}
}

function ComCrop(a, b, c, d)
{
if(!crop) toggleCrop();
xHeight(document.getElementById('top'), a);
xHeight(document.getElementById('bottom'), b);
xWidth(document.getElementById('left'), c);
xWidth(document.getElementById('right'), d);
xHeight(document.getElementById('top'), a);
xHeight(document.getElementById('bottom'), b);
//window.scrollTo(0,0);
}

function AddToComment() {
a = xHeight(document.getElementById('top')); if(a < 8) a = 8;
b = xHeight(document.getElementById('bottom')); if(b < 8) a = 8;
c = xWidth(document.getElementById('left')); if(c < 8) c = 8;
d = xWidth(document.getElementById('right')); if(d < 8) d = 8;
tmp = '[crop=('+a+','+b+','+c+','+d+')]';
document.comment.writer.value += tmp; document.comment.writer.focus();
}

// x_core.js, X v3.15.3, Cross-Browser.com DHTML Library
// Copyright (c) 2004 Michael Foster, Licensed LGPL (gnu.org)
var xVersion='3.15.3',xNN4,xOp7,xOp5or6,xIE4Up,xIE4,xIE5,xMac,xUA=navigator.userAgent.toLowerCase();
if (window.opera){
xOp7=(xUA.indexOf('opera 7')!=-1 || xUA.indexOf('opera/7')!=-1);
if (!xOp7) xOp5or6=(xUA.indexOf('opera 5')!=-1 || xUA.indexOf('opera/5')!=-1 || xUA.indexOf('opera 6')!=-1 || xUA.indexOf('opera/6')!=-1);
}
else if (document.all && xUA.indexOf('msie')!=-1) {
xIE4Up=parseInt(navigator.appVersion)>=4;
xIE4=xUA.indexOf('msie 4')!=-1;
xIE5=xUA.indexOf('msie 5')!=-1;
}
else if (document.layers) {xNN4=true;}
xMac=xUA.indexOf('mac')!=-1;

function xGetElementById(e) {
if(typeof(e)!='string') return e;
if(document.getElementById) e=document.getElementById(e);
else if(document.all) e=document.all[e];
else e=null;
return e;
}

function xDef() {
for(var i=0; i<arguments.length; ++i){if(typeof(arguments[i])=='undefined') return false;}
return true;
}

function xStr() {
for(var i=0; i<arguments.length; ++i){if(typeof(arguments[i])!='string') return false;}
return true;
}

function xNum() {
for(var i=0; i<arguments.length; ++i){if(typeof(arguments[i])!='number') return false;}
return true;
}

function xLeft(e,iX) {
if(!(e=xGetElementById(e))) return 0;
var css=xDef(e.style);
if (css && xStr(e.style.left)) {
if(xNum(iX)) e.style.left=iX+'px';
else {
iX=parseInt(e.style.left);
if(isNaN(iX)) iX=0;
}
}
else if(css && xDef(e.style.pixelLeft)) {
if(xNum(iX)) e.style.pixelLeft=iX;
else iX=e.style.pixelLeft;
}
return iX;
}

function xTop(e,iY) {
if(!(e=xGetElementById(e))) return 0;
var css=xDef(e.style);
if(css && xStr(e.style.top)) {
if(xNum(iY)) e.style.top=iY+'px';
else {
iY=parseInt(e.style.top);
if(isNaN(iY)) iY=0;
}
}
else if(css && xDef(e.style.pixelTop)) {
if(xNum(iY)) e.style.pixelTop=iY;
else iY=e.style.pixelTop;
}
return iY;
}


function xWidth(e,uW) {
if(!(e=xGetElementById(e))) return 0;
if (xNum(uW)) {
if (uW<0) uW = 0;
else uW=Math.round(uW);
}
else uW=-1;
var css=xDef(e.style);
if(css && xDef(e.offsetWidth) && xStr(e.style.width)) {
if(uW>=0) xSetCW(e, uW);
uW=e.offsetWidth;
}
else if(css && xDef(e.style.pixelWidth)) {
if(uW>=0) e.style.pixelWidth=uW;
uW=e.style.pixelWidth;
}
if (!xDef(uW)) return 0;
return uW;
}


function xHeight(e,uH) {
if(!(e=xGetElementById(e))) return 0;
if (xNum(uH)) {
if (uH<0) uH = 0;
else uH=Math.round(uH);
}
else uH=-1;
var css=xDef(e.style);
if(css && xDef(e.style.pixelHeight)) {
if(uH>=0) xSetCH(e, uH);
uH=e.offsetHeight;
} else if(css && xDef(e.offsetHeight) && xStr(e.style.height))  {
if(uH>=0) e.style.pixelHeight=uH;
uH=e.style.pixelHeight;
}
if (!xDef(uH)) return 0;
return uH;
}

function xGetCS(ele,sP){return parseInt(document.defaultView.getComputedStyle(ele,'').getPropertyValue(sP));}

function xSetCH(ele,uH){
var pt=0,pb=0,bt=0,bb=0;
if(xDef(document.defaultView) && xDef(document.defaultView.getComputedStyle)){
pt=xGetCS(ele,'padding-top');
pb=xGetCS(ele,'padding-bottom');
bt=xGetCS(ele,'border-top-width');
bb=xGetCS(ele,'border-bottom-width');
}
else if(xDef(ele.currentStyle,document.compatMode)){
if(document.compatMode=='CSS1Compat'){
pt=parseInt(ele.currentStyle.paddingTop);
pb=parseInt(ele.currentStyle.paddingBottom);
bt=parseInt(ele.currentStyle.borderTopWidth);
bb=parseInt(ele.currentStyle.borderBottomWidth);
}
}
else if(xDef(ele.offsetHeight,ele.style.height)){ // ?
ele.style.height=uH+'px';
pt=ele.offsetHeight-uH;
}
if(isNaN(pt)) pt=0; if(isNaN(pb)) pb=0; if(isNaN(bt)) bt=0; if(isNaN(bb)) bb=0;
var cssH=uH-(pt+pb+bt+bb);
if(isNaN(cssH)||cssH<0) return;
else ele.style.height=cssH+'px';
}

function xSetCW(ele,uW){
var pl=0,pr=0,bl=0,br=0;
if(xDef(document.defaultView) && xDef(document.defaultView.getComputedStyle)){
pl=xGetCS(ele,'padding-left');
pr=xGetCS(ele,'padding-right');
bl=xGetCS(ele,'border-left-width');
br=xGetCS(ele,'border-right-width');
}
else if(xDef(ele.currentStyle,document.compatMode)){
if(document.compatMode=='CSS1Compat'){
pl=parseInt(ele.currentStyle.paddingLeft);
pr=parseInt(ele.currentStyle.paddingRight);
bl=parseInt(ele.currentStyle.borderLeftWidth);
br=parseInt(ele.currentStyle.borderRightWidth);
}
}
else if(xDef(ele.offsetWidth,ele.style.width)){ // ?
ele.style.width=uW+'px';
pl=ele.offsetWidth-uW;
}
if(isNaN(pl)) pl=0; if(isNaN(pr)) pr=0; if(isNaN(bl)) bl=0; if(isNaN(br)) br=0;
var cssW=uW-(pl+pr+bl+br);
if(isNaN(cssW)||cssW<0) return;
else ele.style.width=cssW+'px';
}

