var totalpages=0;
var curpicture=0;
var media='photo';
var taghelped='false';
var colgreen="#060";
var colred="#800";
var divcounter=eval(page-1);
var xpicscount=0;
var slideshowid=0;
var slidetime=10000;
function setattr(element,attr,state)
{
 $("#"+element).attr(attr,state);
}
function giant(imgid)
{
 var ghtml="";
 ghtml+="<img src='' alt='preload' id='preload-img' style='width: 1px; height: 1px; position: absolute; top: -1px; left: -1px;' />";
 ghtml+="<img src='images/closeslideshow.png' alt='close' title='Minimize' id='close-slideshow' style='display: none; position: absolute; top: 90px; right: 110px; z-index: 99999999; height: 25px; cursor: pointer;' />";
 ghtml+="<img src='images/slideshow.png' alt='slideshow' title='Start slide show' id='start-slideshow' style='display: none; position: absolute; top: 85px; left: 110px; height: 30px; cursor: pointer; z-index: 99999999;' />";
 ghtml+="<div id='darken' style='display: none; z-index: 99999997; position: absolute; top: 0px; left: 0px; height: "+$(document).height()+"px; width: "+$(document).width()+"px; background-color: #000;'>&nbsp;</div>";
 ghtml+="<div id='giant-image' style='display: none; z-index: 99999998; position: absolute; top: 100px; left: 125px; width: "+eval($(window).width()-290)+"px; background-color: #fff; padding: 20px;'><a href='full.cgi/"+imgid+".jpg' id='full-size-link' target='_blank' title='Click full original sized image...'><img src='images/checking.gif' alt='Loading...' id='giant-img' style='width: "+eval($(window).width()-290)+"px;' /></a></div>";
 $("body").prepend(ghtml);
 $("#darken").css({opacity: "0.8"});
 $("#darken").fadeIn(1000, function() { $("#giant-image").show(); $("#close-slideshow").show(); $("#start-slideshow").show(); }).click(function() { closeslideshow(); });
 $("#close-slideshow").click(function() { closeslideshow(); });
 $("#giant-img").attr("src","giant.cgi/"+imgid+".jpg");
 $("#start-slideshow").click(function() { startslideshow(); $(this).attr("title","Pause slide show").attr("src","images/pause.png").unbind("click").click(function() { stopslideshow("pause"); }); });
}
function startslideshow()
{
 xpicscount=imagexml.imagelist[divcounter].image.indexOf("_ID",curpicture);
 slideshowid = setInterval(function() { slideshow(); }, slidetime);
}
function stopslideshow(state)
{
 if ( state == "pause" ) {
  $("#start-slideshow").attr("title","Start slide show").attr("src","images/slideshow.png").unbind("click").click(function() { startslideshow(); $(this).attr("title","Pause slide show").attr("src","images/pause.png").unbind("click").click(function() { stopslideshow("pause"); }); });
 }
 clearInterval(slideshowid);
}
function slideshow()
{
 if ( $("#thumbnail-image-"+imagexml.imagelist[divcounter].image[xpicscount]._ID).attr("MP4") != "y") { enlarge(imagexml.imagelist[divcounter].image[xpicscount]._ID); }
 $("#giant-img").fadeTo(300,0, function() {
  $("#giant-img").attr("src","giant.cgi/"+imagexml.imagelist[divcounter].image[xpicscount]._ID+".jpg");
  $("#full-size-link").attr("href","full.cgi/"+imagexml.imagelist[divcounter].image[xpicscount]._ID+".jpg");
 });
 $("#giant-img").load(function() {
  $(this).fadeTo(300,1);
  $("html,body").animate({scrollTop: "80px"}, 300);
  $("#darken").animate({height: $(document).height()+"px"}, 300);
 });
 xpicscount++;
 if ( divcounter == eval(imagexml.totalimages[0].Text-1) && xpicscount == imagexml.imagelist[imagexml.totalimages[0].Text-1].image.length ) { xpicscount=0; divcounter=0; }
 if ( xpicscount == xpics ) { xpicscount=0; divcounter++; slideto(divcounter+1); }
 $("#preload-img").attr("src","giant.cgi/"+imagexml.imagelist[divcounter].image[xpicscount]._ID+".jpg");
}
function closeslideshow()
{
 stopslideshow();
 $("#darken").fadeOut(500, function() {$(this).remove();});
 $("#giant-image").fadeOut(500, function() {$(this).remove();});
 $("#close-slideshow").fadeOut(500, function() {$(this).remove();});
 $("#start-slideshow").fadeOut(500, function() {$(this).remove();});
}
function play(vid,size)
{
 $("#playercont").html("You must have flash player in order to view this content...");
 var fo = new SWFObject("FlowPlayerDark.swf", "FlowPlayer", "370", "280", "9", "#fff", true); 
 fo.addParam("allowfullscreen","true");
 fo.addVariable("config", "{videoFile: 'vid.cgi/"+vid+".flv', autoRewind: 'true', splashImageFile: '"+size+".cgi/"+vid+".jpg', scaleSplash: 'true', initialScale: 'scale', loop: 'false'}");
 fo.write("playercont");
 $("#enlarge").hide();
 $("#playercont").show();
}
function setrating(pic)
{
 $("img[type=rateme]").css({cursor: "pointer"});
 $("img[type=rateme]").click(function() {
  $.ajax({url: "votepic.cgi?pic="+pic+"&vote="+$(this).attr("rate"), dataType: "xml", complete: function(data) {
  var votedetails = $.xmlToJSON(data.responseXML);
  if ( eval(votedetails.vote[0].Text) > 1 ) { var plural="s"; }
  else { var plural=""; }
   enlarge(pic,unvote);
   function unvote()
   {
    $("#ratehelp").html("Thank you for your vote of "+votedetails.vote[0].Text+" star"+plural);
    $("img[type=rateme]").each(function() {
     $(this).unbind("click");
     $(this).unbind("mouseover");
     $(this).css({cursor: "auto"});
     $(this).attr("title","Thank you for your vote");
     $("#thumbnail-image-"+pic).attr("voted","true");
    });
   }
  }});
 })
 .mouseover(function() {
  $("img:lt("+eval($(this).attr("rate"))+")[type=rateme]").attr("src","images/star.png");
  $("img:gt("+eval($(this).attr("rate")-1)+")[type=rateme]").attr("src","images/grey-star.png");
 })
 .mouseout(function() {$("img[type=rateme]").each(function() {$(this).attr("src",$(this).attr("oldsrc"));}); });
}
function getsuggestions(like,element,field)
{
 $.ajax({url: "suggestions.cgi?like="+like+"&field="+field, cache: false, dataType: "xml", complete: function(data) {
  var suggestxml = $.xmlToJSON(data.responseXML);
  var suggesthtml="";
  if ( suggestxml.suggestions[0].Text == 0 ) { $("#suggestions").css({display: "none"}); $("#suggestions-bg").css({display: "none"}); }
  else {
   for(var i = 0; i < suggestxml.suggestion.length; i++) {
    suggesthtml+="<div type='clickfill' val='"+suggestxml.suggestion[i].Text+"'>"+suggestxml.suggestion[i].Text+"</div>";
   }
   $("#suggestions").html(suggesthtml).css({top: eval(eval(7 + $("#"+element).height()) + eval($("#"+element).offset().top))+"px", left: eval(2 + $("#"+element).offset().left)+"px", display: "block", width: $("#"+element).width()+"px"});
   $("#suggestions-bg").css({width: $("#suggestions").width()+"px", height: $("#suggestions").height()+"px", top: $("#suggestions").offset().top+"px", left: $("#suggestions").offset().left+"px", display: "block", opacity: "0.8"});
   $("[type=clickfill]").each(function() {
    var value=$(this).attr("val");
    $(this).mousedown(function() {
     $("#"+element).val(value);
    });
   });
  }
 }});
}
function enlarge(pic,callback)
{
 if ( showall == "false" ) {
  $("[type=tagdiv]").remove();
  curpicture=pic;
  $("[id=loginto-image]").val(curpicture);
  loadcomments();
  $.ajax({url: "viewpic.cgi?pic="+pic, cache: false, dataType: "xml", complete: function(data) {
   var imagedetails = $.xmlToJSON(data.responseXML);
   var MP4=imagedetails.MP4[0].Text;
   var JPG=imagedetails.JPG[0].Text;
   var photographer=imagedetails.photographer[0].Text;
   var copyright=imagedetails.copyright[0].Text;
   var views=imagedetails.views[0].Text;
   var camera=imagedetails.camera[0].Text;
   var added=imagedetails.added[0].Text;
   var aperture=imagedetails.aperture[0].Text;
   var exposure=imagedetails.exposure[0].Text;
   var permission=imagedetails.permission[0].Text;
   var itype=imagedetails.itype[0].Text;
   if ( exposure != 0 ) {
    if ( exposure < 1 ) {
     exposure="1/"+Math.round(1/exposure)+"s";;
    }
    else {
     exposure=Math.floor( exposure * 10)/10+"s";
    }
   }
   var ISO=imagedetails.ISO[0].Text;
   var W=imagedetails.W[0].Text;
   var H=imagedetails.H[0].Text;
   var length=imagedetails.length[0].Text;
   var taken=imagedetails.taken[0].Text;
   var lon=imagedetails.lon[0].Text;
   var lat=imagedetails.lat[0].Text;
   var votes=eval(imagedetails.votes[0].Text);
   var score=eval(imagedetails.score[0].Text);
   var rating=eval(score)/eval(votes);
   rating=Math.floor(rating);
   var caption=imagedetails.caption[0].Text;
   if ( MP4 == "y" ) { media="video"; }
   else { media='photo'; }
   if ( imagedetails.tags[0]._tags != "0" && ( permission != "0" || (itype == "V" || itype == "S") ) ) {
    var fadespeed=0;
    var maphtml="";
     var mapcount=90;
    for(var t = 0; t < imagedetails.tags[0].tag.length; t++) {
     mapcount+=1;
     var x=imagedetails.tags[0].tag[t]._xpos;
     var y=imagedetails.tags[0].tag[t]._ypos;
     var x1=imagedetails.tags[0].tag[t]._xpos1;
     var y1=imagedetails.tags[0].tag[t]._ypos1;
     var tagid=imagedetails.tags[0].tag[t]._TAGID;
     maphtml+="<a href='bigtag.cgi?pic="+pic+"&tag="+tagid+"' target='_blank'  type='tagdiv' alt='"+esc(imagedetails.tags[0].tag[t]._name)+"' style='display: block; position: absolute; height: "+eval(eval(eval(y1)-eval(y))+10)+"px; width: "+eval(eval(x1)-eval(x))+"px; z-index: "+mapcount+"; top: "+y+"px; left: "+x+"px; background-position: -"+x+"px -"+y+"px; background-image: url(large.cgi/"+pic+".jpg);' class='tagdiv'>&nbsp;</a>";
    }
    $("#enlarge-div").prepend(maphtml);
    if ( imagedetails.dtags[0]._tags > 0 ) {
     if ( imagedetails.dtags[0]._tags == 1 ) { var people="person"; }
     else { var people="people"; }
     var dtaghtml=imagedetails.dtags[0]._tags+" "+people+" in this "+media+": ";
     dtagcount=0;
     for(var d = 0; d < imagedetails.dtags[0].tag.length; d++) {
      dtagcount+=1;
      var fullname=forename+" "+surname;
      if ( fullname == imagedetails.dtags[0].tag[d]._name || usertype == "admin" ) { var tagdel="&nbsp;(<a href='#0' alt='"+esc(imagedetails.dtags[0].tag[d]._name)+"' pic='"+pic+"' type='tagdel'>Remove tag</a>)"; }
      else { var tagdel=""; }
      var tagid=imagedetails.tags[0].tag[d]._TAGID;
      dtaghtml+="<a href='bigtag.cgi?pic="+pic+"&tag="+tagid+"' target='_blank' alt='"+esc(imagedetails.dtags[0].tag[d]._name)+"' type='tagdiv' hidetag='false'>"+imagedetails.dtags[0].tag[d]._name+"</a>"+tagdel;
      if ( dtagcount < imagedetails.dtags[0]._tags ) { dtaghtml+=",&nbsp;"; }
     }
     $("#tagnames").html(dtaghtml).fadeIn(fadespeed);
    }
    $("[type=tagdel]").each(function() {
     $(this).click(function() {
      $.ajax({url: "deltag.cgi?pic="+pic+"&tagname="+$(this).attr("alt"), cache: false, dataType: "xml", complete: function(data) {
       enlarge(pic);
      }});
     });
    });
    $("[type=tagdiv]").mouseout(function() {
     $("[type=tagdiv]").fadeIn(fadespeed);
     $("[id=tagfade]").fadeOut(fadespeed, function() { $(this).remove(); });
     $("[id=tag-name-show]").fadeOut(fadespeed, function() { $(this).remove(); });
    });
    $("[type=tagdiv]").each(function() {
     $(this).mouseover(function(e) {
      e.preventDefault();
      var xpos=$(this).offset().left;
      var ypos=$(this).offset().top;
      $("[type=tagdiv][alt!="+$(this).attr("alt")+"][hidetag!=false]").fadeOut(fadespeed);
      $("#enlarge-div").prepend("<div id='tagfade' style='background-color: #000; position: absolute; top: 0px; left: 0px; display: none;'>&nbsp;</div>");
      if ( $(this).attr("hidetag") != "false" ) {
       $("body").prepend("<div id='tag-name-show' class='description' style='-moz-border-radius: 5px; -webkit-border-radius: 5px; font-size: 12px; position: absolute; top: "+eval(e.pageY+10)+"px; left: "+eval(e.pageX+10)+"px; background-color: #000; padding: 5px; color: #fff; z-index: 1200;'>"+$(this).attr("alt")+"</div>");
       $("[id=tag-name-show]").css({opacity: "0.7"});
      }
      $("#tagfade").css({width: $("#enlarge-div").width(), height: $("#enlarge").height(), opacity: "0.5", zIndex: "80"}).fadeIn(fadespeed);
     }).mousemove(function(e) {
      if ( $(this).attr("hidetag") != "false" ) {
       $("[id=tag-name-show]").css({top: eval(e.pageY+15)+"px", left: eval(e.pageX+15)+"px"});
      }
     });
    });
   }
   else { $("#tagnames").html(""); }
   if ( $("#thumbnail-image-"+pic).attr("allowbig") == "true" ) {
    $("#enlarge").load(function() {
    $("[type=thumb]").each(function() { $(this).attr("src",$(this).attr("oldsrc")); });
    $("#thumbnail-image-"+pic).attr("src","images/filmstrip.gif");
     $(this).unbind("load");
     $("#enlarge").load(function() {
      $("#thumbnail-image-"+pic).attr("src","images/filmstrip-whiteb"+MP4+".png");
     });
     $("#enlarge").attr("src","large.cgi/"+pic+".jpg").css({backgroundImage: "none"});
    });
    $("#enlarge-link").attr("href","giant.cgi/"+pic+".jpg");
    $("#enlarge-link").unbind("click").click(function(e) { e.preventDefault(); giant(pic);});
    $("#enlarge-link").attr("target","_blank");
    if ( $("#name").val() != "" ) { $("#comment").focus(); }
    else { $("#name").focus() }
   }
   else {
    $("#enlarge").unbind("load");
    $("[type=thumb]").each(function() { $(this).attr("src",$(this).attr("oldsrc")); });
    $("#thumbnail-image-"+pic).attr("src","images/filmstrip-whiteb"+MP4+".png");
    $("#event-login-password").focus();
    $("#enlarge-link").attr("href","small.cgi/"+pic+".jpg");
    $("#enlarge-link").attr("target","_blank");
   }
   $("#enlarge").attr("src","small.cgi/"+pic+".jpg");
   var infohtml="";
   infohtml+="<table class='infotable' cellpadding='0px' cellspacing='0px'>";
   if ( photographer != "" && photographer != "Photographer" ) { infohtml+="<tr><td class='detail'>Photographer(s):</td><td class='info-cell'>"+photographer; }
   if ( copyright != "" && copyright != photographer && copyright != "Copyright" ) { infohtml+="&nbsp;(<i>Copyright&nbsp;"+copyright+"</i>)"; }
   infohtml+="</td></tr>";
   infohtml+="<tr><td class='detail'>Views:</td><td class='info-cell'>"+views+"</td></tr>";
   if ( camera != "" ) { infohtml+="<tr><td class='detail'>Camera:</td><td class='info-cell'>"+camera+"</td></tr>"; }
   if ( aperture != 0 ) { infohtml+="<tr><td class='detail'>Aperture:</td><td class='info-cell'>f / "+aperture+"</td></tr>"; }
   if ( exposure != 0 ) { infohtml+="<tr><td class='detail'>Exposure:</td><td class='info-cell'>"+exposure+"</td></tr>"; }
   if ( length != 0 ) { infohtml+="<tr><td class='detail'>ISO:</td><td class='info-cell'>"+ISO+"</td></tr>"; }
   if ( ISO != 0 ) { infohtml+="<tr><td class='detail'>Focal&nbsp;Length:</td><td class='info-cell'>"+length+"mm</td></tr>"; }
   if ( W != 0 ) { infohtml+="<tr><td class='detail'>Image&nbsp;Size:</td><td class='info-cell'>"+W+"x"+H+"</td></tr>"; }
   if ( taken != 0 ) { infohtml+="<tr><td class='detail'>Taken:</td><td class='info-cell'>"+taken+"</td></tr>"; }
   if ( lat != 0 ) { infohtml+="<tr><td class='detail'>Latitude:</td><td class='info-cell'>"+lat+"</td></tr>"; }
   if ( lon != 0 ) { infohtml+="<tr><td class='detail'>Longitude:<br /><a href='http://maps.google.co.uk/maps?q="+lat+","+lon+"' target='_blank' class='footnote' title='View the location that this picture was taken on Google Maps'>(View on google)</a></td><td class='info-cell'>"+lon+"</td></tr>"; }
   $("#newcaption").val(caption);
   if ( caption == "" ) { caption=nocaptiontext; }
   $("#caption").html(caption);
    $("#caption").show("slow");
   $("#change-caption").hide("slow");
   infohtml+="<tr><td class='detail'>Average&nbsp;Rating:</td><td>";
   for(var i = 0; i < 5; i++) {
    if ( i < rating ) { var src=''; }
    else { var src='grey-'; }
     infohtml+="<img src='images/"+src+"star.png' oldsrc='images/"+src+"star.png' alt='star' class='star' type='rateme' rate='"+eval(i+1)+"' title='Vote this "+media+" "+eval(i+1)+" stars' />";
   }
   infohtml+="<div class='footnote' id='ratehelp'>^&nbsp;Click on a star to rate this "+media+"</div></td></tr>";
   infohtml+="<tr><td class='detail'><br />Permanent Link:</td><td class='info-cell'><br /><span class='url'><a href='http://"+host+"/"+pic+"' target='_blank'>http://"+host+"/"+pic+"</a></span></td></tr>";
   infohtml+="</table>";
   $("#info").html(infohtml);
   if ( $("#thumbnail-image-"+pic).attr("voted") != "true" ) {
    setrating(pic);
   }
   else {
    $("#ratehelp").html("You have already rated this "+media);
   }
   if ( callback != undefined ) { callback(); }
  $("#enlarge").show();
  $("#playercont").hide().html("");
  if ( MP4 == "y" && $("#thumbnail-image-"+pic).attr("allowbig") == "true" ) {
   if ( $("#thumbnail-image-"+pic).attr("allowbig") == "true" ) { var size='large'; }
   else { var size='small'; }
   play(curpicture,size);
  }
  }});
 }
 else {
  $("#hidethecomments").css({display: "none"});
  $("#left-arrow-event").css({display: "none"});
  $("#right-arrow-event").css({display: "none"});
  $("#enlargecell").css({display: "none"});
  $("#infocell").css({display: "none"});
  $("#pages-event").hide();
 }
}
function setdel()
{
 $("[type=deletecomment]").html("Delete");
 $("[type=deletecomment]").css({cursor: "pointer"});
 $("[type=deletecomment]").unbind("click").click(function() {
  $("#comment-"+$(this).attr("comment")).hide("slide", {direction: "up"}, 500);
  $.ajax({url: "deletecomment.cgi?comment="+$(this).attr("comment"), cache: false, dataType: "xml", complete: function(data) {
   var deletexml = $.xmlToJSON(data.responseXML);
   if ( $("#name").val() != "" ) { $("#comment").focus(); }
   else { $("#name").val(deletexml.name[0].Text); $("#comment").focus(); }
  }});
 });
}
function addcomment(type)
{
 $("[type=addingcomment]").attr("disabled","true");
 if ( $("#comment").val() != "" && $("#name").val() != "" ) {
  $.ajax({url: "addcomment.cgi?name="+$("#name").val()+"&type="+type+"&pic="+curpicture+"&comment="+escape($("#comment").val()), cache: false, dataType: "xml", complete: function(data) {
   var commentxml = $.xmlToJSON(data.responseXML);
   var commenthtml="";
   commenthtml+="<div id='comment-"+commentxml.comment[0]._ID+"' style='display: none; position: relative;'><div class='comment-header'>";
   commenthtml+="<b>"+commentxml.comment[0]._name+"</b></div><div class='comment'>"+commentxml.comment[0].Text+"<br />";
   commenthtml+="<div class='footnote' style='text-align: right;'>Added "+commentxml.added[0].Text;
   commenthtml+="<img src='images/trash-white.png'  type='deletecomment' comment='"+commentxml.comment[0]._ID+"' class='delete' title='Delete this comment' alt='delete' />";
   commenthtml+="</div></div><br /></div>";
   $("#comment-cont").append(commenthtml);
   $("#comment-"+commentxml.comment[0]._ID).show("slide", {direction: "up"}, 500, function() {
    $("html,body").animate({scrollTop: eval($("#comment-cont").offset().top+$("#comment-cont").height())+"px"}, 1000);
   });
   setdel();
  $("[type=addingcomment]").attr("disabled","false");
   $("#comment").val("");
   $("#comment").focus();
  }});
 }
 if ( $("#name").val() == "" ) { alert1("Please enter your Name",'',colred); $("#name").focus(); }
 if ( $("#comment").val() == "" && $("#name").val() != "" ) { alert1("Please enter your Comment",'',colred); $("#comment").focus(); }
}
function loadcomments()
{
 $("#comment-cont").html("");
 $.ajax({url: "getcomments.cgi?pic="+curpicture, cache: false, dataType: "xml", complete: function(data) {
  var commentxml = $.xmlToJSON(data.responseXML);
  if ( commentxml.comment != undefined ) {
   for(var i = 0; i < commentxml.comment.length; i++) {
    var commenthtml="";
    commenthtml+="<div id='comment-"+commentxml.comment[i]._ID+"' style='position: relative;'><div class='comment-header'>";
    commenthtml+="<b>"+commentxml.comment[i]._name+"</b></div><div class='comment'>"+commentxml.comment[i].Text+"<br />";
    commenthtml+="<div class='footnote' style='text-align: right;'>Added "+commentxml.added[i].Text;
    if ( ip == commentxml.comment[i]._ip || usertype == 'admin' ) {
     commenthtml+="<img src='images/trash-white.png' type='deletecomment' comment='"+commentxml.comment[i]._ID+"' class='delete' title='Delete this comment' alt='delete' />";
    }
    commenthtml+="</div></div><br /></div>";
    $("#comment-cont").append(commenthtml);
   }
   setdel();
  }
 }});
}
function resizeadmin()
{
 if ( eval(($(document).width()-950)/2) < 150 && eval(($(document).width()-950)/2) > 60 ) {
  $("#admin").width(eval($(document).width()-950)/2);
  $("#admininner").width(eval($(document).width()-950)/2);
 }
 if ( eval(($(document).width()-950)/2) > 150 ) {
  $("#admin").width("150px");
  $("#admininner").width("150px");
 }
 if (  eval(($(document).width()-950)/2) < 60 ) {
  $("#admin").width("60px");
  $("#admininner").width("60px");
  $("#main-div").css({paddingLeft: "80px"});
 }
 var adminh=eval($(window).height()-eval( $("#topmenu").height()-$().scrollTop() ))-20;
 var admintop=eval(1+$().scrollTop())+eval($("#topmenu").height()-$().scrollTop());
 if ( adminh > $(window).height() ) { adminh = eval($(window).height()-20) }
 if ( $().scrollTop() > $("#topmenu").height() ) { admintop = $().scrollTop(); }
 $("#admininner").css({top: eval(10+admintop)+"px", height: adminh+"px"});
 $("#admin").css({top: admintop+"px", height: eval(adminh)+"px"});
}
function showadmin()
{
 if ( edittitle != "0" || usertype == "admin" ) { 
  $("#event-title-div").css({cursor: "pointer"}).attr("title","Click here to change the title of this event");
  $("#event-title-div").click(function() {
   $(this).hide("slow");
   $("#change-title").show("slow",function() {
    $("#newtitle").focus();
   });
   $("#newtitle").width(eval(900-eval($("#submit-title-change").width()+35)));
  });
 }
 if ( editcaption != "0" || usertype == "admin" ) { 
  $("#caption").css({cursor: "pointer"});
  $("#caption").click(function() {
   $("#newcaption").width( eval($(".center").width()-145)+"px" );
   $(this).hide("slow");
   $("#change-caption").show("slow",function () {
    $("#newcaption").focus();
   });
  });
 }
 $("#admin").css({top: eval($("#topmenu").height()+1)+"px", opacity: "0.65", height: $("#admininner").height()+"px"});
 $("#admininner").css({top: eval($("#topmenu").height()+11)+"px", opacity: "1"});
  $("[type=admin-control]").unbind("click");
  $("[type=admin-control]").click(function() {
  thumbclick($(this).attr("val"));
  $("[type=admin-control]").each(function() { $(this).attr("src",$(this).attr("tsrc")); });
  $(this).attr("src",$(this).attr("nsrc"));
 });
 $("#give-access").click(function() {
  $.ajax({url: "getmembers.cgi", dataType: "xml", complete: function(data) {
   var accesshtml="<form action='' id='give-access-form'>";
   accesshtml+="Member: <select id='access-member'>";
   var memberxml = $.xmlToJSON(data.responseXML);   
   for(var m = 0; m < memberxml.members[0].member.length; m++) {
    accesshtml+="<option value='"+memberxml.members[0].member[m]._ID+"'>"+memberxml.members[0].member[m]._name+"</option>";
   }
   accesshtml+="</select><br />";
   accesshtml+="Permission: <select id='access-permission'>";
   accesshtml+="<option value='tag'>Tag Images</option>";
   accesshtml+="<option value='caption'>Change Image Caption</option>";
   accesshtml+="<option value='type'>Change Image Class</option>";
   accesshtml+="<option value='move'>Move photos/videos out of this event</option>";
   accesshtml+="<option value='upload'>Upload To This Event</option>";
   accesshtml+="<option value='title'>Change Event Title</option>";
   accesshtml+="<option value='changepw'>Change Event Password</option>";
   accesshtml+="</select>";
   accesshtml+="<input type='submit' class='submit' value='Add Permission' /></form>";
   box(accesshtml,"Cancel",'100','','','fixed','','');
   $("#give-access-form").ajaxForm().submit(function() {
    $.ajax({url: "givepermission.cgi?member="+$("#access-member").val()+"&event="+event+"&access="+$("#access-permission").val(), dataType: "xml", complete: function(data) {
     alert1("Permission added successfully","1000",colgreen);
     $("#closebox").html("Finish");
    }});
   });
  }});
 });
 $("#remove-access").click(function() {
  $.ajax({url: "getmembers.cgi", dataType: "xml", complete: function(data) {
   var accesshtml="<form action='' id='remove-access-form'>";
   accesshtml+="Member: <select id='access-member'>";
   var memberxml = $.xmlToJSON(data.responseXML);
   for(var m = 0; m < memberxml.members[0].member.length; m++) {
    accesshtml+="<option value='"+memberxml.members[0].member[m]._ID+"'>"+memberxml.members[0].member[m]._name+"</option>";
   }
   accesshtml+="</select><br />";
   accesshtml+="Permission: <select id='access-permission'>";
   accesshtml+="<option value='tag'>Tag Images</option>";
   accesshtml+="<option value='caption'>Change Image Caption</option>";
   accesshtml+="<option value='type'>Change Image Class</option>";
   accesshtml+="<option value='move'>Move photos/videos out of this event</option>";
   accesshtml+="<option value='upload'>Upload To This Event</option>";
   accesshtml+="<option value='title'>Change Event Title</option>";
   accesshtml+="<option value='changepw'>Change Event Password</option>";
   accesshtml+="</select>";
   accesshtml+="<input type='submit' class='submit' value='Remove Permission' /></form>";
   box(accesshtml,"Cancel",'100','','','fixed','','');
   $("#remove-access-form").ajaxForm().submit(function() {
    $.ajax({url: "takepermission.cgi?member="+$("#access-member").val()+"&event="+event+"&access="+$("#access-permission").val(), dataType: "xml", complete: function(data) {
     alert1("Permission removed successfully","1000",colgreen);
     $("#closebox").html("Finish");
    }});
   });
  }});
 });
 if ( usertype == "admin" || mover != "0" ) {
  $("#move-images").click(function() {
   thumbclick("move");
   $("body").css({cursor: "move"});
   $("img[type=thumb]").css({cursor: "move"});
   $(this).css({cursor: "move"});
   alert1("Click on the thumbnails you wish to move,<br />Then select the event you wish to move them to on the right hand side,<br />Finally click &#39;Move Photos&#39; to move them to that event",10000);
   $.ajax({url: "getevents.cgi?site="+site+"&event="+event, dataType: "xml", complete: function(data) {
    var eventxml = $.xmlToJSON(data.responseXML);
    var movepichtml="<form action='' id='movepic-form'>Move pictures to:<br /><select id='move-event'>";
    for(var e = 0; e < eventxml.events[0].event.length; e++) {
     movepichtml+="<option value='"+eventxml.events[0].event[e]._ID+"'>"+eventxml.events[0].event[e]._event+"</option>";
    }
    movepichtml+="</select><br />";
    movepichtml+="<input type='submit' class='submit' value='Move Photos' /></form>";
    box(movepichtml,"Close",eval($("#topmenu").height()+11),$(document).width()-eval($(document).width()-891)/2,eval($(document).width()-960)/2,'fixed','','');
    $("#closebox").click(function() {
     thumbclick("normal");
     $("body").css({cursor: "auto"});
     $(this).css({cursor: "auto"});
     $("img[type=thumb]").css({cursor: "pointer"});
    });
    $("#movepic-form").ajaxForm().submit(function() {
     $.ajax({url: "movepics.cgi?moveto="+$("#move-event").val()+"&event="+event, dataType: "xml", complete: function(data) {
      getpics('event',event,'getpics',xpics,'event',"no");
      alert1("All tagged images/videos were successfully moved to "+$("#move-event > option[value="+$("#move-event").val()+"]").html(),1000,colgreen);
     }});
    });
   }});
  });
 }
}
function setshowhint(hint)
{
 var newhint="You must be logged in to view all images and videos</span><br />Password Hint: <i>"+hint+"</i>";
 box(newhint,"false",eval($("#topmenu").height()+11),eval($(document).width()-$("#box").width()-14),400,'absolute','','');
 $("#box").hide();
 $("#innerbox").hide();
 $("#givehint").click(function() { $("#event-login-password").focus(); });
 $("#event-login-password").focus(function() {
  box(newhint,"false",eval($("#topmenu").height()+11),eval($(document).width()-$("#box").width()-14),400,'absolute','','');
 });
 $("#event-login-password").blur(function() {
  $("#box").fadeOut(1000);
  $("#innerbox").fadeOut(1000);
 });
}
$(document).ready(function() {
 if ( usertype == "admin" ) {
  $(window).resize(function() {
   resizeadmin();
  });
 }
 $("#upload-single").click(function() {
  var uploadhtml="";
  uploadhtml+="<form action='newuploadimage.cgi' method='post' enctype='multipart/form-data' id='upload-form'>";
  uploadhtml+="<input type='hidden' name='site' value='"+site+"' />";
  uploadhtml+="<input type='hidden' name='album' value='"+album+"' />";
  uploadhtml+="<input type='hidden' name='event' value='"+event+"' />";
  uploadhtml+="<input type='file' name='filename' /><br />";
  uploadhtml+="<select id='upload-itype' name='itype'>";
  uploadhtml+="<option value='V'>Visible</option>";
  uploadhtml+="<option value='P'>Private</option>";
  uploadhtml+="<option value='I'>Indexed</option>";
  uploadhtml+="<option value='S'>Album Cover</option>";
  uploadhtml+="</select><br />";
  uploadhtml+="<input type='text' id='upload-photographer' name='photographer' value='"+forename+" "+surname+"' /><br />";
  uploadhtml+="<input type='text' id='upload-copyright' name='copyright' value='"+forename+" "+surname+"' /><br >";
  uploadhtml+="<input type='text' id='upload-caption' name='caption' /><br >";
  uploadhtml+="<input type='submit' class='submit' value='Upload' id='upload-submit' />";
  uploadhtml+="</form>";
  box(uploadhtml,"Cancel",'100','','','fixed','','');
  $("#upload-form").submit(function() {
   $("#upload-submit").val("Uploading...").addClass("submiting");
   $("#box").height(eval($("#innerbox").height()+20));
  });
  greylogin('upload-photographer','Photographer');
  greylogin('upload-copyright','Copyright');
  greylogin('upload-caption','Caption');
 });
 $("#tag-control").click(function() {
  if ( taghelped == "false" ) {
   alert1("Type in the name of the person you want to tag,<br />Then click and drag the area on the image you would like to tag (Do not click and drag a tag area if tagging a video),<br />Finally click 'Add Tag' and the tag will appear once you have clicked 'Finish Tagging'.",10000);
  }
  $("#enlarge-link").unbind("click");
  $("[type=tagdiv][hidetag!=false]").css({display: "none"});
  $("#enlarge-link").attr("href","#0").attr("target","");
  $("#enlarge-map").remove();
  $("[id=tagbox]").remove();
  var taghtml="";
  taghtml+="<form action='' id='tagform'><table cellpadding='0px' cellspacing='0px'><tr><td>";
  taghtml+="<input type='text' name='eggphotos"+Math.random()+"' id='tagname' dropdown='true' field='name' size='15' /><br />";
  taghtml+="<input type='submit' value='Add Tag' class='submit' /></td><td>";
  taghtml+="<input disabled='true' type='hidden' name='tagx' id='tagx' size='2' />&nbsp;";
  taghtml+="<input disabled='true' type='hidden' name='tagy' id='tagy' size='2' />&nbsp;";
  taghtml+="<input disabled='true' type='hidden' name='tagx1' id='tagx1' size='2' />&nbsp;";
  taghtml+="<input disabled='true' type='hidden' name='tagy1' id='tagy1' size='2' />&nbsp;";
  taghtml+="</td></tr></table></form>";
  box(taghtml,"Finish Tagging",eval($("#topmenu").height()+11),$(document).width()-eval($(document).width()-891)/2,eval($(document).width()-960)/2,'fixed','','');
  $("#closealertbox").click(function() { taghelped='true'; });
  $("#tagname").focus(function(e) { e.preventDefault(); });
  greylogin('tagname','Name');
  $("#tagname").focus();
  $("#tagform").ajaxForm();
  $("#tagform").unbind("submit").submit(function () {
   if ( $("#name").val() != "" ) {
    $.ajax({url: "addtag.cgi?pic="+curpicture+"&xpos="+$("#tagx").val()+"&ypos="+$("#tagy").val()+"&name="+$("#tagname").val()+"&xpos1="+$("#tagx1").val()+"&ypos1="+$("#tagy1").val(), dataType: "xml", complete: function(data) {
     var person=$("#tagname").val();
     if ( person == "Me" || person == "me" ) { person="Yourself"; }
     alert1("You have successfully tagged <b>"+person+"</b> in this "+media,1500,colgreen);
     $("#tagbox").hide();
     $("#tagx").val("");
     $("#tagy").val("");
     $("#tagx1").val("");
     $("#tagy1").val("");
     $("#tagname").attr("name","eggphotos"+Math.random());
    }});
   }
  });
  $("#closebox").click(function() {
   $("#tagbox").hide();
   $("#enlarge").unbind("click").unbind("mousemove").unbind("mousedown").unbind("mouseup");
   enlarge(curpicture);
  });
  $("body").prepend("<div class='tagbox' style='display: none;' id='tagbox'>&nbsp;</div>");
  $("#enlarge").unbind("mousedown");
   $("#enlarge").mousedown(function(event) {
   $("#tagbox").css({width: "1px", height: "1px"}).show();
   $("#tagbox").css({top: eval(event.pageY)+"px", left: eval(event.pageX)+"px"});
    event.preventDefault();
    var tagy=eval(eval($("#tagbox").offset().top - $(this).offset().top));
    var tagx=eval(eval($("#tagbox").offset().left - $(this).offset().left));
    $("#tagx").val(tagx);
    $("#tagy").val(tagy);
    $("#enlarge").unbind("mousemove").mousemove(function(ee) { $("#tagbox").css({width: eval(ee.pageX-$("#tagbox").offset().left)-5+"px", height: eval(ee.pageY-$("#tagbox").offset().top)-5+"px"});
     var tagx1=eval(eval(ee.pageX - $(this).offset().top))-5;
     var tagy1=eval(eval(ee.pageY - $(this).offset().left))-5;
     $("#tagx1").val(tagx1);
     $("#tagy1").val(tagy1);
    });
   });
   $("#enlarge").mouseup(function(ee) {
    $("#enlarge").unbind("mousemove");
    $("#tagbox").unbind("mousemove");
    $("#tagname").focus();
    $("#tagname").select();
   });
  $("[dropdown=true]").each(function() {
   $("#"+$(this).attr("id")).keyup(function() { getsuggestions($(this).val(),$(this).attr("id"),$(this).attr("field")); }).focus(function() { $(this).select(); getsuggestions($(this).val(),$(this).attr("id"),$(this).attr("field")); }).blur(function() { $("#suggestions").hide(); $("#suggestions-bg").hide(); });
  });
 });
 $("#comment-form").ajaxForm();
 $("#change-title-form").ajaxForm();
 $("#change-title-form").submit(function() {
  $.ajax({url: "changeeventtitle.cgi?event="+event+"&newtitle="+$("#newtitle").val(), dataType: "xml", complete: function(data) {
   $("#change-title").hide("slow");
   $("[type=event-title]").html($("#newtitle").val());
   $("#event-title-div").show("slow");
  }});
 });
 $("#change-caption-form").ajaxForm();
 $("#change-caption-form").submit(function() {
  $.ajax({url: "changecaption.cgi?newval="+$("#newcaption").val()+"&ID="+curpicture, dataType: "xml", complete: function(data) {
   $("#change-caption").hide("slow");
   if ( $("#newcaption").val() != "" ) { $("#caption").html( esc($("#newcaption").val()) ); }
   else { $("#caption").html(nocaptiontext);}
   $("#caption").show("slow");
   $("[type=thumb][pic="+curpicture+"]").attr("title",esc($("#newcaption").val()) );
  }});
 });
 $("#comment-form").submit(function() { addcomment("pic");});
 getpics('event',event,'getpics',xpics,'event',"no");
 if ( usertype == "admin" ) { $().scroll(function() { resizeadmin(); }); }
 $("#change-eventpw").click(function() {
  var cepw="<form action='changeeventpassword.cgi' id='cepw-form'>";
  cepw+="<table><tr><td>New Password:</td><td><input type='password' name='newpew' id='newepw' /></td></tr>";
  cepw+="<tr><td>Confirm:</td><td><input type='password' name='confepw' id='confepw' /></td></tr>";
  cepw+="<tr><td>New Clue:</td><td><input type='text' name='neweclue' id='neweclue' size='50' /></td></tr>";
  cepw+="<tr><td></td><td><input type='submit' class='submit' value='Change Event Password' /></td></tr></table></form>";
  box(cepw,"Cancel",'100','','','fixed');
  $("#newepw").focus();
  $("#cepw-form").ajaxForm().submit(function() {
   $.ajax({url: "changeeventpassword.cgi?event="+event+"&newclue="+$("#neweclue").val()+"&newpw="+$("#newepw").val()+"&confnewpw="+$("#confepw").val(), dataType: "xml", complete: function(data) {
    var cepwx = $.xmlToJSON(data.responseXML);
    alert1(cepwx.response[0].Text,cepwx.response[0]._time,cepwx.response[0]._col);
    if ( cepwx.response[0]._changed == "true" ) {
     $("#box").fadeOut(1000, function() {$(this).remove();});
     $("#innerbox").fadeOut(1000, function() {$(this).remove();});
    }
   }});
  });
 });
 $("#delete-event").click(function() {
  var delevent="<p style='text-align: center;'>Are you sure you want to delete this event and all images/videos within it?";
  delevent+="<form action='delevent.cgi' style='text-align: center;'><input type='hidden' name='event' value='"+event+"' />";
  delevent+="<input class='submit' type='submit' value='Yes' />&nbsp;";
  delevent+="<input class='submit' type='button' value='No, Cancel!' id='cancel-del' /></form></p>";
  box(delevent,"false",'100','','','fixed','','');
  $("#cancel-del").click(function() {
   $("#box").fadeOut(1000, function() { $(this).remove(); });
   $("#innerbox").fadeOut(1000, function() { $(this).remove(); });
  });
 });
 $("#set-event").click(function() {
  $.ajax({url: "set-event-upload.cgi?event="+event, dataType: "xml", complete: function(data) {}});
   $("#set-event-cont").hide();
   alert1("This event is now your default to upload to.");
  });
});
