﻿//***********************************************************************//
// ImageScroller - Author:iLawton - PureNet Solutions Ltd
//***********************************************************************//

var IsScrolling = false;
var ScrollElement;
var ScrollSpeed = 3;
var ImageWidth = 170;


function ScrollLeft(ElementID)
{
    Scroll(ElementID,-ScrollSpeed);
}


function ScrollRight(ElementID)
{
    Scroll(ElementID,ScrollSpeed);
}

function Scroll(ElementID,Value)
{
    if (!IsScrolling)
    {
        ScrollElement = document.getElementById(ElementID);
        if (ScrollElement != null)
        {
            IsScrolling = true;                
            MoveImages(Value);
        }
    }
}

function StopScrolling()
{
    IsScrolling = false;
    ScrollElement.onMouseout = null;
}

function MoveImages(Value)
{
    if (IsScrolling)
    {
        var MaxLeft = 0;
        var MaxRight = ScrollElement.offsetWidth;

        for(i = 0; i <= ScrollElement.childNodes.length - 1; i++)
        {
            var Image = ScrollElement.childNodes[i];
            if (Image.style != null)
            {
				var imageLeft = Image.style.left.substr(0, Image.style.left.length - 2) * 1;
            
                Image.style.left = (imageLeft + Value) + "px";
                if (Image.offsetLeft < MaxLeft) MaxLeft = Image.offsetLeft;
                if ((Image.offsetLeft + ImageWidth) > MaxRight) MaxRight = (Image.offsetLeft + ImageWidth);
            }
        }
        
        for(i = 0; i <= ScrollElement.childNodes.length - 1; i++)
        {
            var Image = ScrollElement.childNodes[i];
            if (Image.style != null)
            {
                if((Image.offsetLeft + ImageWidth) < 0 && Value < 0)
                {
                    Image.style.left = (MaxRight) + "px";
                    MaxRight += ImageWidth;
                }
                else if((Image.offsetLeft) > ScrollElement.offsetWidth && Value > 0)
                {
                    MaxLeft -= ImageWidth;
                    Image.style.left = MaxLeft + "px";
                }
            }
        }
       
        setTimeout("MoveImages(" + Value + ");",0);
    }
}

function openFullscreen(url)
{ 
	// get the height correction for IE and set the window height and width 
	var height = screen.availHeight; 
	var width = screen.availWidth; 
	var fullscreen = (document.all) ? "no" : "yes"; 
	var resizable = "no"; 
	var toolbar = "no"; 
	var status = "no"; 
	var left = 0; 
	var top = 0; 
	//set window properties 
	props = "toolbar=no" + ",fullscreen=" + fullscreen + ",status=no" + 
			",resizable=no" + ",scrollbars=no" + ",menubar=no" + ",location=no" + ","; 
			
	dims = "width="+ width + ",height="+ height + ",left="+ left + 
			",top=" + top; 
			
	var win = window.open("", name, props + dims); 
	win.resizeTo(width, height); 
	win.location.href = url; 
	win.focus();
	
	return false;
}