function SmoothMovement(_1, _2, _3) {
   _1 = Math.round(_1);
   _2 = Math.round(_2);
   _3 = (_3 ? Math.round(_3) : 0);
   this.updatePosition = function() {
      _1 += _3;
      if(_3 < 0) {
         if(_1 - _3 * (_3 - 1) / 2 < _2) {
            _3++;
            }
         else {
            if(_1 - (_3 - 1) * (_3 - 2) / 2 >= _2) {
               _3--;
               }
            }
         }
      else {
         if(_1 + _3 * (_3 + 1) / 2 > _2) {
            _3--;
            }
         else {
            if(_1 + (_3 + 1) * (_3 + 2) / 2 <= _2) {
               _3++;
               }
            }
         }
      return _1;
      };
   this.changeTarget = function(_4) {
      _2 = Math.round(_4);
      };
   this.getPosition = function() {
      return _1;
      };
   this.getVelocity = function() {
      return _3;
      };
   this.hasStopped = function() {
      return (_1 == _2 && _3 == 0);
      };
   }

var g_bInMove = false;
function SwapMainImage(D, C) {
   var B = document.getElementById("mainimageimg");
   if(B) {
      B.src = D}
   var A = document.getElementById("mainimage_caption");
   if(A) {
      A.innerHTML = C}
   return false}
function MoveCollectionLeft() {
   if(g_bInMove) {
      return }
   g_bInMove = true;
   var B = document.getElementById("photoselectioncontainer");
   if(B) {
      var G = 0;
      var E = 0;
      if(!B.style.width || B.style.width == "") {
         var D = B.getElementsByTagName("div");
         if(D && D.length > 0) {
            for(var C = 0; C < D.length; C++) {
               E += CyberCoreFindWidth(D[C]) + 8}
            }
         B.style.width = E + "px"}
      else {
         E = parseInt(B.style.width)}
      if(B.style.marginLeft != null && B.style.marginLeft != "") {
         G = parseInt(B.style.marginLeft)}
      B.style.marginLeft = G + "px";
      if(G < 0) {
         var F = G + 220;
         var A = new SmoothMovement(G, F, - 7);
         window.setTimeout(function() {
            UpdateCollectionSlide(B, A, F)}
         , 20)}
      else {
         g_bInMove = false}
      }
   }
function MoveCollectionRight() {
   if(g_bInMove) {
      return }
   g_bInMove = true;
   var C = document.getElementById("photoselectioncontainer");
   if(C) {
      var H = 0;
      var F = 0;
      if(!C.style.width || C.style.width == "") {
         var E = C.getElementsByTagName("div");
         if(E && E.length > 0) {
            for(var D = 0; D < E.length; D++) {
               F += CyberCoreFindWidth(E[D]) + 8}
            }
         C.style.width = F + "px"}
      else {
         F = parseInt(C.style.width)}
      if(C.style.marginLeft != null && C.style.marginLeft != "") {
         H = parseInt(C.style.marginLeft)}
      C.style.marginLeft = H + "px";
      var G = H - 220;
      if(Math.abs(G) < F) {
         var A = new SmoothMovement(H, G, 7);
         window.setTimeout(function() {
            UpdateCollectionSlide(C, A, G)}
         , 20)}
      else {
         g_bInMove = false;
         var B = document.getElementById("collectionnextbtn");
         B.src = "/images/nextphoto_disabled.gif"}
      }
   }
function UpdateCollectionSlide(C, A, E) {
   var F = A.updatePosition();
   C.style.marginLeft = F + "px";
   if(F != E) {
      window.setTimeout(function() {
         UpdateCollectionSlide(C, A, E)}
      , 20)}
   else {
      g_bInMove = false;
      var D = document.getElementById("collectionpreviousbtn");
      if(E >= 0) {
         D.src = "/images/previousphoto_disabled.gif"}
      else {
         D.src = "/images/previousphoto.gif"}
      var B = document.getElementById("collectionnextbtn");
      if(Math.abs(E - 258) >= parseInt(C.style.width)) {
         B.src = "/images/nextphoto_disabled.gif"}
      else {
         B.src = "/images/nextphoto.gif"}
      }
   }


function SwapMainImage_rco(D, I)
{

   var B = document.getElementById("typeimageimg");
   
   //trans21_4_209_125_413_5_12.jpg
   //trans21_4_209_100_2663_5_13.jpg
   if(B)
   {
       B.style.height = "200px";
       B.style.width = "269px";
       B.style.background = "URL("+arrangeImageSize(D,5)+") top right no-repeat";
       
     }
     var C = document.getElementById("mainimagelink");
    if(C)
    {
        c.href=arrangeImageSize(D,1).toString();
    }

   return false
}

function arrangeImageSize(D,nr)
	{
	

	var posidot = D.toString().lastIndexOf('.');
    var extsize = D.length - posidot;
	var ext = D.toString().substr(posidot,extsize);
	//extensao
   var valsemext = D.toString().substring(0,posidot);
   //valor da imagem sem extensão
   var valamudar = valsemext.toString().substr(valsemext.length-extsize);
  //valor tmnh imagem (possiveis existencias : "_4_1" ||  "4_12")
   var valanex = valsemext.toString().substring(0,valsemext.length-4);
  //Valor a que se anexa a alteração
  var e
	 if (valamudar.charAt(0)=='_')
   {
       if(valamudar.charAt(1) != nr)
       {
            e = valamudar.toString().substr(2);
            return valanex.toString()+"_"+nr.toString()+e.toString()+ext.toString();

       }
   }
   else
   	{
        if(valamudar.charAt(0) != 5)
       {
   		 e = valamudar.toString().substr(1);
   			return valanex.toString()+nr.toString()+e.toString()+ext.toString();
       }
    }
    return D;
    }







