Index: extensions/gally/gally-default/js/gallyjs-tpp.js
===================================================================
--- extensions/gally/gally-default/js/gallyjs-tpp.js	(revision 12592)
+++ extensions/gally/gally-default/js/gallyjs-tpp.js	(revision 16016)
@@ -44,4 +44,5 @@
       },
       container=null,
+      initialThumbPos=null,
 
   /**
@@ -109,10 +110,4 @@
                         .bind("mousemove", function () { switchInterface('y', true); } );
     }
-
-
-    $("#navThumbPrev").css("top", $("#navThumbPrev").prop("offsetTop")+$("#theHeader").prop("offsetHeight")+$("#theHeaderAlt").prop("offsetHeight")+"px");
-    $("#navThumbNext").css("top", $("#navThumbNext").prop("offsetTop")+$("#theHeader").prop("offsetHeight")+$("#theHeaderAlt").prop("offsetHeight")+"px");
-
-    $("#theImage").css("top", $("#theImage").prop("offsetTop")+$("#theHeader").prop("offsetHeight")+$("#theHeaderAlt").prop("offsetHeight")+"px");
 
     $("#contentid").attr("rows", options.commentRows);
@@ -166,4 +161,31 @@
     );
 
+    $("#icon_derivatives").click(function()
+      {
+        var elt = $("#derivativeSwitchBox");
+
+        elt.css("left", Math.min( $(this).position().left + $('#tabRandomButtons').outerWidth(true), $(window).width() - elt.outerWidth(true) - 5))
+          .css("top", $(this).position().top)
+          .toggle();
+          $('#iSimpleTip').css('display', 'none'); // if tip activated, hide it..
+      }
+    );
+    $("#derivativeSwitchBox, #privacyLevelBox").on("mouseleave click", function()
+      {
+        $(this).hide();
+      }
+    );
+
+    $('#iPrivacyLevelLink').click(function ()
+      {
+        var elt = $("#privacyLevelBox"),
+            ePos = $("#privacyLevelLink");
+
+        elt.css("left", $(this).position().left)
+           .css("top", $(this).position().top)
+           .toggle();
+      }
+    );
+
     $(window).resize( function () { initializeImageMode("resize"); } );
 
@@ -192,4 +214,5 @@
     var thumbWidth=0,
         imgTop=0,
+        imgPos='',
         cssValues = new Object;
 
@@ -272,9 +295,13 @@
       if($("#navThumbPrev").length>0)
       {
-        $("#navThumbPrev").css("height", $("#copyright").prop("offsetTop")-$("#navThumbPrev").prop("offsetTop")-options.tabsHidden+"px");
-      }
-      if($("#navThumbNext").length>0)
-      {
-        $("#navThumbNext").css("height", $("#copyright").prop("offsetTop")-$("#navThumbNext").prop("offsetTop")-options.tabsHidden+"px");
+        initialThumbPos=$("#navThumbPrev").position().top;
+      }
+      else if($("#navThumbNext").length>0)
+      {
+        initialThumbPos=$("#navThumbNext").position().top;
+      }
+      else
+      {
+        initialThumbPos=-1;
       }
     }
@@ -311,6 +338,21 @@
     }
 
-
-
+    imgTop=initialThumbPos;
+    //if position equals -1, mean top calculate it automatically - valid for "#navThumbPrev" & "#navThumbNext"
+    if(imgTop==-1)
+    {
+      imgTop=$("#theImage").prop("offsetTop")+$("#theHeader").prop("offsetHeight")+$("#theHeaderAlt").prop("offsetHeight")+($("#theImgContainer").height()-$("#navThumbPrev").height())/2;
+    }
+
+    $("#navThumbPrev")
+        .css("top", imgTop)
+        .css("height", $("#copyright").prop("offsetTop")-$("#navThumbPrev").prop("offsetTop")-options.tabsHidden+"px");
+
+    $("#navThumbNext")
+        .css("top", imgTop)
+        .css("height", $("#copyright").prop("offsetTop")-$("#navThumbNext").prop("offsetTop")-options.tabsHidden+"px");
+
+
+    $("#theImage").css("top", $("#theImage").prop("offsetTop")+$("#theHeader").prop("offsetHeight")+$("#theHeaderAlt").prop("offsetHeight")+"px");
 
     simulateHighRes();
@@ -634,4 +676,38 @@
   };
 
+  function changeImgSrc(url,typeSave,typeMap,cookiePath)
+  {
+    $("#theMainImage")
+      .removeAttr("width height")
+      .attr("src", url)
+      .load(function ()
+        {
+          initializeImageMode("resize");
+        }
+      );
+
+    $('#derivativeSwitchBox .switchCheck').css('visibility','hidden');
+    $('#derivativeChecked'+typeSave).css('visibility','visible');
+
+    document.cookie = 'picture_deriv='+typeSave+';path='+cookiePath;
+  }
+
+  function setPrivacyLevel(rootUrl, id, level)
+  {
+    var y = new PwgWS(rootUrl);
+
+    y.callService(
+      "pwg.images.setPrivacyLevel",
+      {image_id: id, level:level} ,
+      {
+        method: "POST",
+        onFailure: function(num, text) { alert(num + " " + text); },
+        onSuccess: function(result) {
+          jQuery('#privacyLevelBox .switchCheck').css('visibility','hidden');
+          jQuery('#levelCheck'+level).css('visibility','visible');
+        }
+      }
+    );
+  }
 
   this.closeDisplayHigh = function () { closeDisplayHigh(); };
@@ -641,4 +717,6 @@
   this.getTabsProp = function () { return tabs; };
   this.openDisplayHigh = function (url) { openDisplayHigh(url); };
+  this.changeImgSrc = function (url,typeSave,typeMap,cookiePath) { changeImgSrc(url,typeSave,typeMap,cookiePath); };
+  this.setPrivacyLevel = function (rootUrl, id, level) { setPrivacyLevel(rootUrl, id, level); };
 
   init();
