// ----------------------------------------------------------------------
// Dynamically rotate some images content
// Dominic Winsor, Design Haus UK Ltd.
// 2007-09-27
// ----------------------------------------------------------------------

var imagePath = "images/scroll/", rotateTimeLogo = 4000, // configuration: a comma separated list of graphics to be displayed
    imageString = "banana.gif,boswells.gif,camille.gif,cotton.gif,double_two.gif,jaeger.gif,julian.gif,lillywhites.gif,moss.gif,paper_mill.gif,pavers.gif,pilot.gif,roman.gif,room.gif,samsonite.gif,select.gif,starbucks.gif,top_table.gif,tresspass.gif,easyliving.gif,frankie-bennys.gif,";

// array to hold list of images
var imageList = [], logoIndex = 0, imageCount = 0;

// starting point
function initLogoRotate()
{
    // quit if no images in imagestring
    if (imageString.length==0)  return;
    
    // trim any trailing comma
    if (imageString.charAt(imageString.length-1)==",")   imageString  = imageString.substr(0,imageString.length-1);
    
    // make an array of images from the string
    imageList  = imageString.split(",");
    imageCount = (imageList.length-1);
    displayLogo(logoIndex);
    //debugRotate();
}




// show one specific logo from the list
function displayLogo( logoID )
{

    // exit if no article, no newscount or articleID outside of range
    if (logoID==NaN || logoID>imageList.length) return;
   
    // set the other logoID to halfway along the array relative (and wrap if at end)
    var offset = (logoID > (Math.floor(imageCount/2))) ? parseInt((Math.floor(imageCount/2))-imageCount) : parseInt((Math.ceil(imageCount/2)));
    var logoID2 = parseInt(logoID + offset);
    
    // correct the offset if off-scale
    //if (logoID2 == imageCount) --logoID2;

    // create the images
	var logo1 = document.getElementById("logo1"), logo2 = document.getElementById("logo2");
    logo1.src = imagePath + imageList[logoID];
    logo2.src = imagePath + imageList[logoID2];
    logo1.alt = logoID +": "+ imageList[logoID];
    logo2.alt = logoID +": "+ imageList[logoID2];
    
    // move to next article, or wrap around to start if at end
    logoIndex= (logoIndex<imageCount) ? logoIndex+1 : 0;
    
    // call self, after a brief delay
    window.setTimeout("displayLogo(logoIndex)",rotateTimeLogo);
}



// write the full logic to screen
function debugRotate()
{
    // get reference to body
	var doc = document.getElementsByTagName("BODY");
	doc = doc[0];
	
	// create a debug div
	var div = document.createElement("div");
	
	// write array length
	var status = document.createElement("p");
	status.innerHTML = "length="+imageList.length;
	div.appendChild(status);
	
	
	// iterate teh image list
	for( logoID in imageList )
	{
	
		// exit if no article, no newscount or articleID outside of range
        if (logoID==NaN || logoID>imageList.length) return;
        
        logoID = parseInt(logoID);
        
        // set the other logoID to halfway along the array relative (and wrap if at end)
        var offset = (logoID > (Math.floor(imageList.length/2))) ? parseInt((Math.floor(imageList.length/2))-imageList.length) : parseInt((Math.ceil(imageList.length/2)));
        var logoID2 = parseInt(logoID + offset);
        
        // correct the offset if off-scale
        if (logoID2 == imageList.length) --logoID2;
	
	    // create the images
		var logo1 = document.createElement("img");
		var logo2 = document.createElement("img");
		logo1.src = imagePath + imageList[logoID];
        logo2.src = imagePath + imageList[logoID2];
        logo1.alt = logoID
        logo2.alt = logoID2
        logo1.title = logoID
        logo2.title = logoID2
        logo1.border = "1";
        logo2.border = "1";
        
        //append to the div
		div.appendChild(logo1);
		div.appendChild(logo2);
		var os = document.createElement("p");
	    os.innerHTML = "offset="+offset+"<br/> logoID="+logoID+"<br/> logoID2="+logoID2+"<br/> logo1.src="+logo1.src+"<br/> logo2.src="+logo2.src
	    div.appendChild(os);
		div.appendChild(document.createElement("hr"));
	}
	
	// write the debug div to the document
	doc.appendChild(div);
}