﻿var imagewidth = 125;var imagefolder = "";scrollcomplete = true;leftcount=0;rightcount=0;i_Arr=new Array();
var p0_left = -imagewidth;p1_left = 0;p2_left = imagewidth;p3_left = imagewidth*2;p4_left = imagewidth*3;
var p_div=new Array();p_div[0]="imageDiv0";p_div[1]="imageDiv1";p_div[2]="imageDiv2";p_div[3]="imageDiv3";p_div[4]="imageDiv4";
var site = "";var firstscroll=true;

function initialise(){document.getElementById(p_div[0]).style.left = p0_left + "px"; document.getElementById(p_div[1]).style.left = p1_left + "px"; document.getElementById(p_div[2]).style.left = p2_left + "px"; document.getElementById(p_div[3]).style.left = p3_left + "px"; document.getElementById(p_div[4]).style.left = p4_left + "px"; for(i=0; i<document.getElementById('allimages').getElementsByTagName('span').length; i++){i_Arr[i] = new URL ( document.getElementById('allimages').getElementsByTagName('span')[i].innerHTML, document.getElementById('allimages').getElementsByTagName('i')[i].innerHTML );}for(x=0;x<5;x++){document.getElementById(p_div[x]).getElementsByTagName('img')[0].src = imagefolder + i_Arr[x].image;document.getElementById(p_div[x]).getElementsByTagName('a')[0].href = site + i_Arr[x].target;}hideOverlap("left"); hideOverlap("right");}
function scroll(direction){if(finishedScrolling()){firstScroll(direction);if(direction=='right'){hideOverlap(direction);flyToPoint(p_div[0],p1_left,"");flyToPoint(p_div[1],p2_left,"");flyToPoint(p_div[2],p3_left,"");flyToPoint(p_div[3],p4_left,"");flyToPoint(p_div[4],p0_left,"fast");reset(direction);}else{hideOverlap(direction);flyToPoint(p_div[0],p4_left,"fast");flyToPoint(p_div[1],p0_left,"");flyToPoint(p_div[2],p1_left,"");flyToPoint(p_div[3],p2_left,"");flyToPoint(p_div[4],p3_left,"");reset(direction);}}}
function reset(direction){if(direction=='right'){for(x=0;x<5;x++){if(parseInt(p_div[x].substring(p_div[x].length-1))>0){p_div[x] = "imageDiv" + (parseInt(p_div[x].substring(p_div[x].length-1))-1);}else{p_div[x] = "imageDiv4";}}setImages(direction);}else{for(x=0;x<5;x++){if(parseInt(p_div[x].substring(p_div[x].length-1))<4){p_div[x] = "imageDiv" + (parseInt(p_div[x].substring(p_div[x].length-1))+1);}else{p_div[x] = "imageDiv0";}}setImages(direction);}}
function finishedScrolling(){if(scrollcomplete){return true;}else{setTimeout("finishedScrolling()",200);}}
function hideOverlap(direction){for(x=0;x<5;x++){document.getElementById(p_div[x]).style.display="block"; document.getElementById(p_div[x]).style.zIndex=9;}if(direction=='right') {document.getElementById(p_div[4]).style.display="none";} else{document.getElementById(p_div[0]).style.display="none";}}
function URL( image,target){this.image=image;this.target=target;}
function checkCount()
{
    if(rightcount < 0)
    {
        rightcount=i_Arr.length-1;
    }
    if(leftcount < 0)
    {
        leftcount=i_Arr.length-1;
    }
    if(leftcount > i_Arr.length-1)
    {
        leftcount = 0;
    }
    if(rightcount >= i_Arr.length)
    {
        rightcount = 0;
    }
}
function firstScroll(direction){if(firstscroll){rightcount = i_Arr.length-1;leftcount = 4;firstscroll = false;}}
function setImages(direction){if(direction=='right'){document.getElementById(p_div[0]).getElementsByTagName('img')[0].src = imagefolder + i_Arr[rightcount].image;document.getElementById(p_div[0]).getElementsByTagName('a')[0].href = site + i_Arr[rightcount].target;leftcount = leftcount-1;rightcount = rightcount-1;checkCount();}else{rightcount = rightcount+1;leftcount = leftcount+1;checkCount();document.getElementById(p_div[4]).getElementsByTagName('img')[0].src = imagefolder + i_Arr[leftcount].image;document.getElementById(p_div[4]).getElementsByTagName('a')[0].href = site + i_Arr[leftcount].target;if((leftcount) == (i_Arr.length)){leftcount=0;}}}

function flyToPoint(targetDivID, targetLeft,speed)
{
    var moveAmount = 2; //lower num = smoother but slower
    var delayAmount = 7; //lower num = faster;
    if(speed=="fast")
    {
        var moveAmount = 400; //lower num = smoother but slower !!this number has to be less than the width of the window for firefox
        var delayAmount = 0; //lower num = faster;
    }

        var curLeft = parseInt(document.getElementById(targetDivID).style.left);
        var leftIsAligned = false;
        if (curLeft < targetLeft)
        {
            var diffInLeft = targetLeft - curLeft;if (diffInLeft > moveAmount){document.getElementById(targetDivID).style.left = (curLeft + moveAmount) + "px";}else{document.getElementById(targetDivID).style.left = targetLeft;leftIsAligned = true;}scrollcomplete = false;}else if (curLeft > targetLeft){var diffInLeft = curLeft - targetLeft;if (diffInLeft > moveAmount){document.getElementById(targetDivID).style.left = (curLeft - moveAmount) + "px";}else{document.getElementById(targetDivID).style.left = targetLeft;leftIsAligned = true;}scrollcomplete = false;}else{leftIsAligned = true;}if (!(leftIsAligned)){setTimeout("flyToPoint('" + targetDivID + "', " + targetLeft +")", delayAmount);}else{if(speed!='fast'){scrollcomplete = true;}}}

sfHover = function() {
	        var sfEls = document.getElementById("window").getElementsByTagName("a");
	        for (var i=0; i<sfEls.length; i++) {
		        sfEls[i].onmouseover=function() {
			        this.className+=" sfhover";
		        }
		        sfEls[i].onmouseout=function() {
			        this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		        }
	        }
        }
        if (window.attachEvent) window.attachEvent("onload", sfHover);
