﻿///////////////////////////////////////////////////////////////////////////////
// LotDetailLightBox.js
// LotDetail specific javascript code for lightbox image viewer support
///////////////////////////////////////////////////////////////////////////////
function ShowImage(DisplayOrder)
{
    if ((_totalChange < -5) || (_totalChange >5)) 
    {
	    return false;
    }
		
    document.getElementById('fullimage').style.display="block";

    var ImageId = getImageName(DisplayOrder);	
    var strImagePath = imagePath + ImageId;

    document.getElementById('fullimage').src = strImagePath + "_med.jpeg";
    document.getElementById('xxxyyyzzz').href = strImagePath + "_lg.jpeg";		
}

function getImageName(DisplayOrder)
{
    var ImageId;
    switch (DisplayOrder)
    {
	    case 1:
	    ImageId = image1name;
	    break;
	    case 2:
	    ImageId = image2name;
	    break;
	    case 3:
	    ImageId = image3name;
	    break;
	    case 4:
	    ImageId = image4name;
	    break;
	    case 5:
	    ImageId = image5name;
	    break;
	    case 6:
	    ImageId = image6name;
	    break;
	    case 7:
	    ImageId = image7name;
	    break;
	    case 8:
	    ImageId = image8name;
	    break;
	    case 9:
	    ImageId = image9name;
	    break;
	    case 10:
	    ImageId = image10name;
	    break;
	    case 11:
	    ImageId = image11name;
	    break;
	    case 12:
	    ImageId = image12name;
	    break;
    }
	
    return ImageId;
}

function importData()
{
    var j=0;
    for (var i = 1; i <= 12; i++) 
    { 
        var thisImageName = getImageName(i);
	    if (thisImageName != '')
	    {
		    _allImages[j] = new Image();
		    _allImages[j].onload = imageLoaded;
		    _allImages[j].src = imagePath + thisImageName + '_mid.jpeg';
		    j++;
	    }
    }
}

function imageLoaded()
{
    var i;
    for (i = 0; i < _numImages; i++)
    {
	    if (_allImages[i].src == this.src)
	    {
		    _imagesLoaded++;
	    }
    }
	
    if (_imagesLoaded == _numImages)
    {
	    var temp = '';
	    for (i = 0; i < _numImages; i++)
	    {
		    if (i == _videoIndex)
		    {
			    temp += '<img src="' + _allImages[i].src + '" class="thumbnail" width="' + _allImages[i].width + 
				    'px" height="' + _allImages[i].height + 'px" style="margin-right:5px;" onMouseUp="ShowVideo(' + (i+1) + ')">';
		    }
		    else
		    {
			    temp += '<img src="' + _allImages[i].src + '" class="thumbnail" width="' + _allImages[i].width + 
				    'px" height="' + _allImages[i].height + 'px" style="margin-right:5px;" onMouseUp="ShowImage(' + (i+1) + ')">';
		    }
		    _filmWidth += _allImages[i].width + 5;
	    }
		
	    _filmstrip.innerHTML = temp;
    }
}

// These functions help anchor the filmstrip to the landingZone table

function findPos(obj)
{
    // Credit for this function: http://www.quirksmode.org/js/findpos.html
    // Visit the URL for a complete tutorial on this function
    var curleft = curtop = 0;
    if (obj.offsetParent)
    {
	    curleft = obj.offsetLeft
	    curtop = obj.offsetTop
	    curwidth = obj.offsetWidth;
	    while (obj = obj.offsetParent)
	    {
		    curleft += obj.offsetLeft;
		    curtop += obj.offsetTop;
	    }
    }
	
    return [curleft,curtop,curwidth];
}

// moves filmstrip into the landingZone table.
function bindStrip()
{                                             
    ofs=findPos(_landingZone);                                      // Find the left/top & width of table
    _filmstrip.style.top=ofs[1] + 1 +'px';                          // Set filmstrip's top location
    _filmstrip.style.left=ofs[0] +'px';                              // Set filmstrip's left location
    _topOffset = ofs[1];                                            // Remember top offset globally
    _leftOffset= ofs[0];                                            // Remember the left offset globally
    // The next line crops the filmstrip and shows only a small section of it
    _filmstrip.style.clip='rect(0px,'+(_landingZone.offsetWidth+_totalOffset-1)+'px,210px,'+(_totalOffset)+'px)';
    _filmstrip.style.left=(_leftOffset-_totalOffset)+'px';          // set the left offset of the filmstrip
}

// End filmstrip anchor functions.

// Begin Drag/Scroll Handlers

function scrollHandler(e)
{
    // This function handles the draging of the filmstrip from left to right
    if (e == null) { e = window.event; }                         // Get event data
    if (e.button<=1&&_scrollOK)
    {                                                            // Is mouse down and scroll enabled?
	    if (_filmWidth <= _landingZone.offsetWidth - 5)
	    {
		    return;
	    }
		
	    _totalOffset=_originalOffset+(_dragXoffset-e.clientX);   // Find the distance mouse has moved
		
	    if ((_totalOffset) < 0)
	    {                                                        // Are we scrolling too far left?
		    _totalOffset=0;                                      // Yes, set the offset to 0
		    _originalOffset=0;                                   // and the original
		    _dragXoffset=e.clientX;                              // and reset the mouse.
	    }
		
	    if ((_totalOffset+_landingZone.offsetWidth)>=(_filmWidth-5))
	    {                                                           // Are we too far right?
		    _totalOffset=(_filmWidth-_landingZone.offsetWidth-5);   // Yes, set offset to max
		    _originalOffset=(_filmWidth-_landingZone.offsetWidth-5);// and the original
		    _dragXoffset=e.clientX;                                 // reset the mouse
	    }
		
	    _totalChange=(_dragXoffset-e.clientX);                   // Calculate total movement
	    // Set the visible clip here.
	    _filmstrip.style.clip='rect(0px,'+(_landingZone.offsetWidth+_totalOffset-1)+'px,210px,'+(_totalOffset+1)+'px)';
	    // And set the left offset
	    _filmstrip.style.left=(_leftOffset-_totalOffset)+'px';
	    // return false so the browser won't try to do it's events!
	    return false;
    }
}

function cleanup(e) 
{                                                         // called when user releases a mouse button after a drag event
    _scrollOK = false;                                    // Setting this to false disables scrollHandler
    _savedTarget.style.cursor=_orgCursor;                 // Change back to the original cursor shape
    document.onmousemove=null;                            // Disable the mousemove handler
    document.onmouseup=null;                              // Disable the mouseup handler
}

function dragHandler(e)
{
    _totalChange=0;                                            // Total pixels moved
    var cursorType='-moz-grabbing';                            // Set hand to "grab"
    if (e == null) { e = window.event; cursorType='w-resize';} // Package event for IE
    var target = e.target != null ? e.target : e.srcElement;   // Get the target object
    //Handle filmstrip
    if (target.className=="filmstrip"||target.className=="thumbnail") 
    {                                                           // Check if event over filmstrip
	    _savedTarget=target;                                    // This is our target object
	    _orgCursor=target.style.cursor;                         // This was our orginal cursor
	    _originalOffset=_totalOffset;                           // Mark the current offset
	    target.style.cursor=cursorType;                         // Set mouse to grab if possible
	    _scrollOK=true;                                         // flag filmstrip as scrollable
	    _dragXoffset=e.clientX;                                 // remember original X position
	    document.onmousemove=scrollHandler;                     // set up a mouse-move handler
	    document.onmouseup=cleanup;                             // set up a button-up handler
	    return false;                                           // return FALSE -- IMPORTANT!!!!
    }
}
// End drag/scroll Handlers
