
var ART_CONTENT_DIR = "art_content/";
var MIDDLE_COLUMN_ID = "middle_column";

function showPic (whichpic) {
 if (document.getElementById) {
  document.getElementById('placeholder').src = whichpic.href;
  if (whichpic.title) {
	  $('desc').innerHTML = whichpic.title;
  } else {
	  $('desc').innerHTML = whichpic.childNodes[0].nodeValue;  
  }
  return false;
 } else {
  return true;
 }
}


function getArtContent (currentArt) {
	
	var id = currentArt.id;
	var url = ART_CONTENT_DIR + id + ".html";
	
	new Ajax.Updater(MIDDLE_COLUMN_ID, url, {
          method: 'get',
		  onFailure: function () { alert("could not find file: " + url); } 
		});
	return false;
}

var moving = false;
var moveEffect;
var clickCountUp = 0;
var clickCountDown = 0;
function startMoveCall() { moving = true; }
function stopMoveCall() { moving = false; }

function moveUp()
{
	var top;
	clickCountDown = 0;
    if (!moving)
    {
        clickCountUp = 0;
    	//check if we can move up... we can't move up if the div's "top" is >= 0
        top = getImageHolderTopValue();
        if (top <= -390) {
            moveEffect = new Effect.Move('image_holder', { duration: 1.5, x: 0, y: 390, beforeStart: startMoveCall, afterFinish: stopMoveCall });
            } else if (top < 0 && top > -390) {
                var lastMove = top * -1;
                moveEffect = new Effect.Move('image_holder', { duration: 1.5, x: 0, y: lastMove, beforeStart: startMoveCall, afterFinish: stopMoveCall });
            }
    } else {
    	top = getImageHolderTopValue();
    	clickCountUp++;
    	if (top < -390)
    	{
    		moveEffect.cancel();
    		var distance = (top * -1) % 390;
    		var maxClicks = (390 * clickCountUp) + distance;
    		var yAmount;
    		if ((top + maxClicks) < 0)
    		{
    			yAmount = maxClicks;    		
    		}else
    		{
    			yAmount = top * -1;
    		}
    		moveEffect = new Effect.Move('image_holder', { duration: 1.5, x: 0, y: yAmount, beforeStart: startMoveCall, afterFinish: stopMoveCall });
    		
    	}
    }
    return false;
}

function moveDown()
{
	clickCountUp = 0;
	var top;
	var imageViewHeight;
    var imageHolderHeight;
    if (!moving)
    {
    	clickCountDown = 0;
        top = getImageHolderTopValue();
        imageViewHeight = $('image_view').offsetHeight;
        imageHolderHeight = $('image_holder').offsetHeight;
        if (top >= (imageViewHeight - imageHolderHeight + 390)) {
           moveEffect = new Effect.Move('image_holder', { duration: 1.5, x: 0, y: -390, beforeStart: startMoveCall, afterFinish: stopMoveCall });
           } else if (top > (imageViewHeight - imageHolderHeight) && top < (imageViewHeight - imageHolderHeight + 390)) {
                var lastMove = imageViewHeight - imageHolderHeight - top;
                moveEffect = new Effect.Move('image_holder', { duration: 1.5, x: 0, y: lastMove, beforeStart: startMoveCall, afterFinish: stopMoveCall });
            }
    }else
    {
    	top = getImageHolderTopValue();
        imageViewHeight = $('image_view').offsetHeight;
        imageHolderHeight = $('image_holder').offsetHeight;
        clickCountDown++;
        if (top > (imageViewHeight - imageHolderHeight + 390))
        {
        	moveEffect.cancel();
        	var distance = 390 - ((top * -1) % 390);
        	var maxClicks = (-390 * clickCountDown) - distance;
        	var yAmount;
        	if ((top + maxClicks) > (imageViewHeight - imageHolderHeight))
        	{
        		yAmount = maxClicks;
        	}else
        	{
        		yAmount = imageViewHeight - imageHolderHeight - top;
        	}
        	
        	moveEffect = new Effect.Move('image_holder', { duration: 1.5, x: 0, y: yAmount, beforeStart: startMoveCall, afterFinish: stopMoveCall });
        }
    }
    return false;
}

function getImageHolderTopValue()
{
    var topValue = $('image_holder').style.top;
    return getIntegerFromUnitString(topValue);
}

function getIntegerFromUnitString(str)
{
    if (!str)
        return 0;
        
    if (isInteger(str))
        return parseInt(str);
    
    //here we assume the string ends in something like "px" or "em", etc
    return parseInt(str.substring(0, str.length-2));
}

function isInteger(s) {
    return (s.toString().search(/^-?[0-9]+$/) == 0);
}

var movingTwo = false;
var clickCountUpTwo = 0;
var clickCountDownTwo = 0;

function startMoveCallTwo() { movingTwo = true; }
function stopMoveCallTwo() { movingTwo = false; }

function getImageHolderTopValueTwo()
{
    var topValue = $('image_holder_two').style.top;
    return getIntegerFromUnitString(topValue);
}

function moveUpTwo()
{
    clickCountDownTwo = 0;
	var top;
	if (!movingTwo)
    {
		clickCountUpTwo = 0;
        //check if we can move up... we can't move up if the div's "top" is >= 0
        top = getImageHolderTopValueTwo();
       if (top <= -390) {
           moveEffect = new Effect.Move('image_holder_two', { duration: 1.5, x: 0, y: 390, beforeStart: startMoveCallTwo, afterFinish: stopMoveCallTwo });
           } else if (top < 0 && top > -390) {
                var lastMove = top * -1;
                moveEffect = new Effect.Move('image_holder_two', { duration: 1.5, x: 0, y: lastMove, beforeStart: startMoveCallTwo, afterFinish: stopMoveCallTwo });
            }
    }else {
    	top = getImageHolderTopValueTwo();
    	clickCountUpTwo++;
    	if (top < -390)
    	{
    		moveEffect.cancel();
    		var distance = (top * -1) % 390;
    		var maxClicks = (390 * clickCountUpTwo) + distance;
    		var yAmount;
    		if ((top + maxClicks) < 0)
    		{
    			yAmount = maxClicks;    		
    		}else
    		{
    			yAmount = top * -1;
    		}
    		moveEffect = new Effect.Move('image_holder_two', { duration: 1.5, x: 0, y: yAmount, beforeStart: startMoveCallTwo, afterFinish: stopMoveCallTwo });
    		
    	}
    }
    return false;
}

function moveDownTwo()
{
	clickCountUpTwo = 0;
	var top;
	var imageViewHeight;
    var imageHolderHeight;
    if (!movingTwo)
    {
    	clickCountDownTwo = 0;
        top = getImageHolderTopValueTwo();
        imageViewHeight = $('image_view_two').offsetHeight;
        imageHolderHeight = $('image_holder_two').offsetHeight;
        if (top >= (imageViewHeight - imageHolderHeight + 390)) {
           moveEffect = new Effect.Move('image_holder_two', { duration: 1.5, x: 0, y: -390, beforeStart: startMoveCallTwo, afterFinish: stopMoveCallTwo });
           } else if (top > (imageViewHeight - imageHolderHeight) && top < (imageViewHeight - imageHolderHeight + 390)) {
                var lastMove = imageViewHeight - imageHolderHeight - top;
                moveEffect = new Effect.Move('image_holder_two', { duration: 1.5, x: 0, y: lastMove, beforeStart: startMoveCallTwo, afterFinish: stopMoveCallTwo });
            }
    }else
    {
    	top = getImageHolderTopValueTwo();
        imageViewHeight = $('image_view_two').offsetHeight;
        imageHolderHeight = $('image_holder_two').offsetHeight;
        clickCountDownTwo++;
        if (top > (imageViewHeight - imageHolderHeight + 390))
        {
        	moveEffect.cancel();
        	var distance = 390 - ((top * -1) % 390);
        	var maxClicks = (-390 * clickCountDownTwo) - distance;
        	var yAmount;
        	if ((top + maxClicks) > (imageViewHeight - imageHolderHeight))
        	{
        		yAmount = maxClicks;
        	}else
        	{
        		yAmount = imageViewHeight - imageHolderHeight - top;
        	}
        	
        	moveEffect = new Effect.Move('image_holder_two', { duration: 1.5, x: 0, y: yAmount, beforeStart: startMoveCallTwo, afterFinish: stopMoveCallTwo });
        }
    }
    return false;
}







