/*
  This script extends the funtionality of effects.js. These 2 functions were copied directly
  from http://scriptaculous.jakewendt.com/scriptaculous_files/jw_effects.js (SlideRightOut & SlideLeftIn)
*/
/*
	BlindRight needs to have the content of the element wrapped in a container element with fixed width!
*/
Effect.BlindRight = function(element) {
	element = $(element).cleanWhitespace();
	var elementDimensions = element.getDimensions();
	return new Effect.Scale(element, 100, 
		Object.extend({ 
			scaleContent: false, 
			scaleY: false, 
			scaleFrom: window.opera ? 0 : 1,
			scaleMode: {originalHeight: elementDimensions.height, originalWidth: elementDimensions.width},
			restoreAfterFinish: true,
			afterSetup: function(effect) {
				effect.element.makePositioned();
				effect.element.down().makePositioned();
				if(window.opera) effect.element.setStyle({left: ''});
				effect.element.makeClipping().setStyle({width: '0px'}).show(); 
			},
			afterUpdateInternal: function(effect) {
				effect.element.down().setStyle({right: (effect.dims[1] - effect.element.clientWidth) + 'px' }); 
			},
			afterFinishInternal: function(effect) {
				effect.element.undoClipping().undoPositioned();
				effect.element.down().undoPositioned();
			}
		}, arguments[1] || {})
	);
}

/*
	BlindLeft needs to have the content of the element wrapped in a container element with fixed width
	otherwise any text or images begin to wrap in strange ways!
*/
Effect.BlindLeft = function(element) {
	element = $(element).cleanWhitespace();
	return new Effect.Scale(element, window.opera ? 0 : 1,
		Object.extend({ 
			scaleContent: false, 
			scaleY: false, 
			scaleMode: 'box',
			scaleFrom: 100,
			restoreAfterFinish: true,
			beforeStartInternal: function(effect) {
				effect.element.makePositioned();
				effect.element.down().makePositioned();
				if(window.opera) effect.element.setStyle({left: ''});
				effect.element.makeClipping().show();
			},  
			afterUpdateInternal: function(effect) {
				effect.element.down().setStyle(
					{right: (effect.dims[1] - effect.element.clientWidth) + 'px' }
				);
			},
			afterFinishInternal: function(effect) {
				effect.element.hide().undoClipping().undoPositioned();
				effect.element.down().undoPositioned();
			}
		}, arguments[1] || {})
	);
}

/*
  ToggleOut moves the comment and description panel out
*/
function ToggleOut() {
   object1 = document.getElementById('commentToggleOut');
   object2 = document.getElementById('commentToggleIn');
   
   object1.style.visibility='hidden';
   object2.style.visibility='visible';
   Effect.BlindRight('imageComments');
   new Effect.Move('commentToggleIn', { x: 420, y: 100 , mode: 'absolute' });
   new Effect.Move('commentToggleOut', { x: 420, y: 100 , mode: 'absolute' });
   document.commentform.message.focus();
   
   return false;
}

/*
  ToggleIn moves the comment and description panel in
*/
function ToggleIn() {
   object1 = document.getElementById('commentToggleIn');
   object2 = document.getElementById('commentToggleOut');
      
   new Effect.Move('commentToggleIn', { x: 0, y: 100 , mode: 'absolute' });
   new Effect.Move('commentToggleOut', { x: 0, y: 100 , mode: 'absolute' });
   Effect.BlindLeft('imageComments');  
   object1.style.visibility='hidden';
   object2.style.visibility='visible';
   
   return false;
}

/*
  ToggleComments moves the comment and description panel
  in and out when you click on the comments text
  This is another way to reveal and conceal the comments panel
*/
function ToggleComments() {
   object1 = document.getElementById('commentToggleOut');
   object2 = document.getElementById('commentToggleIn');
   
   if ((object1.style.visibility=='visible') && (object2.style.visibility=='hidden') && (object1.offsetLeft == 0)) {
      ToggleOut();
      return false;
   }
   
   if ((object1.style.visibility=='hidden') && (object2.style.visibility=='visible') && (object1.offsetLeft == 420)) {
      ToggleIn();
      return false;
   }
   
}

/*
  ToggleOriginalImage toggles the images between the posted 
  image and the original image before any post processing
*/
function ToggleOriginalImage(option) {
   source = document.getElementById('image').src;
   
   if (source.lastIndexOf('/') !=-1) {
      firstpos=source.lastIndexOf('/')+1;
      lastpos=source.length;
      filename=source.substring(firstpos, lastpos);
      path=source.substring(0, firstpos);
   }
   
   if (option == 'S'){
      if (filename.substring(0, 2) != 'o_') {
            newfilename = 'o_' + filename;
            document.getElementById('image').src = path + newfilename;
      }
   }
   else {
      if (filename.substring(0, 2) == 'o_'){
            newfilename = filename.substring(2, lastpos);
            document.getElementById('image').src = path + newfilename;
      }
   }
}