﻿var boxesShown = sliderWidth;
var currentBox = boxesShown + 1;
var maxBoxes = numberOfSliderContentItems + (boxesShown * 2);
var increment = sliderIncrement;
var moving = false;
function movingOn() { moving = true; }
function movingOff() 
{ 
	moving = false;
	clearTimeout(globalSliderMoverTimer);
	globalSliderMoverTimer = setTimeout("scrollBy(ClientIDs.sliderItemsWindow, -increment)", 10000);
}
function scrollBy(object, amount)
{
	if(!moving && allowSlide)
	{	
		new Effect.Move($(object), { x: amount, mode: 'relative', beforeStart: movingOn, afterFinish: movingOff });
		if(amount < 0) 
		{ 
			currentBox += 1; 
			//alert(currentBox);
			if(currentBox > (numberOfSliderContentItems + boxesShown))
			{
				$(object).setStyle({left: "-" + ((increment * boxesShown) - sliderLeftOffset) + "px" }); 
				currentBox = boxesShown + 1;
			}
		}
		else
		{ 
			currentBox -= 1; 
			//alert(currentBox);
			if(currentBox < 0)
			{
				$(object).setStyle({left: "-" + ((increment * (numberOfSliderContentItems)) - sliderLeftOffset) + "px" }); 
				currentBox = numberOfSliderContentItems - 1;
			}
		}
		
	}
	
}

// Load the slider images asynchronously
// the reason this is done old style is so that we 
// can control whether or not the data that's returned is
// modified or not. We basically don't want it to be modified since it's
// binary data and will break things if it is.
function loadImageAsync(imgSrc, imgId)
{
    var xmlHttp = null;
      
    try
    {
        xmlHttp = new XMLHttpRequest();  
    }
    catch (e)
    {
        try
        {
            xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e)
        {
            try
            {
                xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (e) { }
        }    
    }

    if(xmlHttp != null)
    { 
        xmlHttp.open('get', imgSrc, true);

        xmlHttp.onreadystatechange = function()
        { 
            if(xmlHttp.readyState == 4)
            {
                $(imgId).src = imgSrc;
            }
        }
    
        xmlHttp.send(null);
    }
}

var globalSliderMoverTimer = 0;
if(allowSlide)
{
	Event.observe(window, "load", function () 
	{ 
		new Effect.Move($(ClientIDs.sliderItemsWindow), { x: (increment * boxesShown) - sliderLeftOffset, mode: 'relative', afterFinish: setToBasic, duration: 0.75 });
		
		globalSliderMoverTimer = setTimeout("scrollBy(ClientIDs.sliderItemsWindow, -increment)", 10000);
	});
}
else { Event.observe(window, "load", function () { setToBasic(); }); }

function setToBasic()
{
	$(ClientIDs.sliderItemsWindow).setStyle({left: "-" + ((increment * boxesShown) - sliderLeftOffset) + "px" });
	currentBox = boxesShown;
}