/* ****************** */
/*  DIVMOVER      */
/* ****************** */
if(!window.DIVMOVER)
	DIVMOVER=new Object();

DIVMOVER.step;
DIVMOVER.interval;
DIVMOVER.items = new Array();

DIVMOVER.showUp = function(elementName, sx, sy, dx, dy, movePerStep, speed)
{
  try
  {
	  window.clearInterval(DIVMOVER.interval);
	  for( var i = 0; i < DIVMOVER.items.length; i++)
	  {
	  //window.alert("DIVMOVER.showUp " + DIVMOVER.items[i]);
	  	window.document.getElementById(DIVMOVER.items[i]).style.top = "-5000px";
	 	window.document.getElementById(DIVMOVER.items[i]).style.left = "-5000px";
	  }
	  
	  elementToShow = window.document.getElementById(elementName);
	  elementToShow.style.left   = sx + "px";
	  elementToShow.style.top    = sy + "px";
	
	  //window.alert("DIVMOVER.showUp " + elementName);
	  
	  
	  // Overrulers
	  speed = 10;
	  movePerStep = 50;
	  
	  
	  DIVMOVER.step = 0;
	  DIVMOVER.interval = window.setInterval("DIVMOVER.doStep(" + sx + "," + sy + "," + dx + "," + dy + "," + movePerStep + ",'" + elementName + "')", speed);
  }
  catch(e)
  {
	window.alert("DIVMOVER.showUp e=" + e);
  }
}

DIVMOVER.doStep = function(sX, sY, dX, dY, movePerStep, elementName)
{
try{
//  window.alert("DIVMOVER.doStep " + elementName);
 elementToShow = window.document.getElementById(elementName);
 var difX = DIVMOVER.step * movePerStep;
 var difY = DIVMOVER.step * movePerStep;
 var posX = 0;
 var posY = 0;

 if (sX < dX)
 {
   posX = sX + difX;
   if (posX > dX)
     posX = dX;
 }
 else if (sX > dX)
 {
   posX = sX - difX;
   if (posX < dX)
     posX = dX;
 }

 if (sY < dY)
 {
   posY = sY + difY;
   if (posY > dY)
     posY = dY;
 }
 else if (sY > dY)
 {
   posX = sY - difY;
   if (posY < dY)
     posY = dY;
 }
 elementToShow.style.left   = posX + "px";
 elementToShow.style.top    = posY + "px";
 DIVMOVER.step++;
 
 if (posX == dX && posY == dY)
 {
   window.clearInterval(DIVMOVER.interval);
 }

  }
  catch(e)
  {
	window.alert("DIVMOVER.doStep e=" + e);
  }
}

/* ****************** */
/*  SLIDER IMPL       */	
/* ****************** */
if(!window.SLIDER)
	SLIDER=new Object();

SLIDER.LEFT2RIGHT = 1;
SLIDER.RIGHT2LEFT = 2;
SLIDER.BOTTOM2TOP = 3;
SLIDER.TOP2BOTTOM = 4;

SLIDER.imageMatrix = new Array();
SLIDER.direction = SLIDER.LEFT2RIGHT;
SLIDER.rotator = null;
SLIDER.speed = 15;
SLIDER.detailWnd = null;
SLIDER.nSelectors = 0;
SLIDER.height = 0;
SLIDER.width = 0;
SLIDER.faderoffsets = 0;
SLIDER.counter = 0;

SLIDER.move = function(w, aImg)
{ 
  SLIDER.counter++;
  if (SLIDER.counter >= 3)
  {
	  SLIDER.counter = 0;
	  for (var n = 0; n < aImg.length; n++)
    	w.document.getElementById(aImg[n].imageID).style.left = SLIDER.movePosition(aImg[n]) + "px";
	  
	  for (var n = 0; n < aImg.length; n++)
	  {
		  var right = aImg[n].thumbLeft + aImg[n].thumbWidth;
		  if (aImg[n].thumbLeft > 0 || aImg[n].thumbLeft < 400 || right > 0 || right < 400)
	    	w.document.getElementById(aImg[n].imageID).style.left = aImg[n].thumbLeft + "px";
	  }
	  
  }
}

SLIDER.preLoadImageObjectArray = function(nSliderIndex)
{
  for (var n = 0; n < SLIDER.imageMatrix[nSliderIndex].length; n++)
  {
     SLIDER.imageMatrix[nSliderIndex][n].thumb.src = SLIDER.imageMatrix[nSliderIndex][n].thumbSrc;
     SLIDER.imageMatrix[nSliderIndex][n].detail.src = SLIDER.imageMatrix[nSliderIndex][n].detailSrc;
  }
  //window.alert("End:preLoadImageObjectArray");
}

SLIDER.writeImageTags = function(w, nSliderIndex)
{
  //window.alert("Start:writeImageTags");
  w.document.open();
  for (var n = 0; n < SLIDER.imageMatrix[nSliderIndex].length; n++)
  {  
    //window.alert("<img class=\"imageSliderImg" + nSliderIndex + "\" id=\"" + SLIDER.imageMatrix[nSliderIndex][n].imageID + "\" + style=\"width:" + SLIDER.imageMatrix[nSliderIndex][n].thumbWidth + "px; -moz-opacity:1.0; filter:alpha(opacity=100);\">");
    w.document.writeln("<a href=\"javascript:SLIDER.showImageDetail('" + SLIDER.imageMatrix[nSliderIndex][n].imageID + "' , " + nSliderIndex + ")\">");
  	if (SLIDER.direction == SLIDER.LEFT2RIGHT || SLIDER.direction == SLIDER.RIGHT2LEFT)
		w.document.writeln("<img class=\"imageSliderImg" + nSliderIndex + "\" id=\"" + SLIDER.imageMatrix[nSliderIndex][n].imageID + "\" + style=\"width:" + SLIDER.imageMatrix[nSliderIndex][n].thumbWidth + "px; -moz-opacity:1.0; filter:alpha(opacity=100);\">");
  	else if (SLIDER.direction == SLIDER.BOTTOM2TOP || SLIDER.direction == SLIDER.TOP2BOTTOM)
   		w.document.writeln("<img class=\"imageSliderImg" + nSliderIndex + "\" id=\"" + SLIDER.imageMatrix[nSliderIndex][n].imageID + "\" + style=\"height:" + SLIDER.imageMatrix[nSliderIndex][n].thumbHeight + "px; -moz-opacity:1.0; filter:alpha(opacity=100);\">");
    w.document.writeln("</a>");
  }
  w.document.close();

  for (var n = 0; n < SLIDER.imageMatrix[nSliderIndex].length; n++)
    w.document.getElementById(SLIDER.imageMatrix[nSliderIndex][n].imageID).src = SLIDER.imageMatrix[nSliderIndex][n].thumb.src;
    
  SLIDER.showImageDetail(SLIDER.imageMatrix[nSliderIndex][0].imageID, nSliderIndex);
//  window.alert("End:writeImageTags");

}

SLIDER.showImageDetail = function(imgID, nSliderIndex)
{
	var nDim0;
	var nDim1;
	for (var m = 0; m < SLIDER.imageMatrix.length; m++)
 	{
 		for (var n = 0; n < SLIDER.imageMatrix[m].length; n++)
		{
			if (SLIDER.imageMatrix[m][n].imageID == imgID)
			{
				nDim0 = m;
				nDim1 = n;
			}
		}
	}

	window.document.getElementById("divContentCollectionLargeImg" + nSliderIndex).style.backgroundImage = 'url(' + SLIDER.imageMatrix[nDim0][nDim1].detailSrc +')';
//    window.alert("showImageDetail:2");
}

SLIDER.initializeThumb = function(id, thump, detail, thumbOffs, thumbW, thumbH, detW, detH, prevImageObject)
{
	imgObject = new Object();
	imgObject.imageID				= id;
	imgObject.thumb    				= new Image();
	imgObject.thumbSrc 				= thump;
	imgObject.detail      			= new Image();
	imgObject.detailSrc   			= detail;
	imgObject.thumpTopLeftOffset	= thumbOffs;
	imgObject.thumbWidth     		= thumbW;
	imgObject.thumbHeight    		= thumbH;
	imgObject.detailWidth    		= detW;
	imgObject.detailHeight   		= detH;
	imgObject.previousObject 		= prevImageObject;
	if (prevImageObject == null)
	{
   		  	if (SLIDER.direction == SLIDER.LEFT2RIGHT)
		  	{
				imgObject.thumbLeft   = thumbOffs;
		  	}
		  	else if (SLIDER.direction == SLIDER.RIGHT2LEFT)
		  	{
		  	}
		  	else if (SLIDER.direction == SLIDER.BOTTOM2TOP)
		  	{
		  		imgObject.thumbTop   = thumbOffs;
		  	}
		  	else if (SLIDER.direction == SLIDER.TOP2BOTTOM)
		  	{
		  	}
	}
	else
	{
   		  	if (SLIDER.direction == SLIDER.LEFT2RIGHT)
		  	{
				imgObject.thumbLeft   = SLIDER.getThumbNext(imgObject);
		  	}
		  	else if (SLIDER.direction == SLIDER.RIGHT2LEFT)
		  	{
		  	}
		  	else if (SLIDER.direction == SLIDER.BOTTOM2TOP)
		  	{
				imgObject.thumbTop   = SLIDER.getThumbNext(imgObject);
		  	}
		  	else if (SLIDER.direction == SLIDER.TOP2BOTTOM)
		  	{
		  	}
	}
	return imgObject;
}


SLIDER.movePosition = function(o)
{
	o.thumbLeft--;
	if ( (o.thumbLeft + o.thumbWidth) < 0)
		o.thumbLeft = o.previousObject.thumbLeft + o.previousObject.thumbWidth + o.thumpTopLeftOffset;
	return o.thumbLeft;
}

SLIDER.getThumbNext = function(o)
{
	  return o.previousObject.thumbLeft + o.previousObject.thumbWidth + o.thumpTopLeftOffset;
}

SLIDER.cleanUp = function(rotator)
{
  window.clearInterval(rotator);
}

SLIDER.popupImageDetailWnd = function(imgID)
{
  SLIDER.detailWnd = SLIDER.popupImageDetail(imgID, SLIDER.detailWnd);
}

SLIDER.init = function(nSliderIndex, width, height, offs)
{
try{
  SLIDER.nSelectors++;
  
  SLIDER.preLoadImageObjectArray(nSliderIndex);
  SLIDER.writeImageTags(window, nSliderIndex);
  SLIDER.width = width;
  SLIDER.height = height;
  SLIDER.faderoffsets = offs;
  //window.alert("init:01");
  
  }
  catch(e)
  {
	window.alert("SLIDER.init e=" + e);
  }
	
}

SLIDER.start = function(nSliderIndex)
{
try{
	SLIDER.rotator = window.setInterval("SLIDER.move(window, SLIDER.imageMatrix[" + nSliderIndex + "])", SLIDER.speed);
	
  //window.alert("start:02 " + nSliderIndex);
  }
  catch(e)
  {
	window.alert("SLIDER.start e=" + e);
  }
}

SLIDER.stop = function()
{
try{
	SLIDER.cleanUp(SLIDER.rotator);
	SLIDER.rotator = null;
  //window.alert("stop:02");
  }
  catch(e)
  {
	window.alert("SLIDER.stop e=" + e);
  }
	
}
