var siteTimer;

var siteList = new Array("lecourrierduvin","labrise","marymoody","bellinganName","bluebaguette","cassagnes", "allfraImport", "anneRotherham", "belmontet", "bgSurveyor", "futureResults", "gitePomarede", "labateliere", "leprieurebiron", "lifeMatters", "number28", "paulineJurquet", "perleFr", "pescadoires", "petitemaisonbleue", "prodimad", "tonel", "voyagesFrance");
/*
var wwwList = new Array("lecourrierduvin.com","labrise.co.uk","marymoody.com.au","bellingan.name","bluebaguette.com","cassagnes.fr", "allfraImport.com", "anneRotherham.com", "belmontet.com", "bgSurveyor.com", "futureResultsnow.com", "gite-Pomarede.com", "labateliere.fr", "leprieurebiron.com", "lifeMatters.com", "number28.co.uk", "paulineJurquet.com", "perle.Fr", "pescadoires.com", "petitemaisonbleue.com", "prodimad.fr", "tonel.fr", "voyages-france-impressions.com");
*/

/*
Triggered every few seconds. Causes fade in/out over a few more seconds
Enter with showingSiteNo showing
End with showingSiteNo showing new site image/text

For the images just need showingSiteNo, which will be faded out and nextSiteNo which will be faded in. 
Always put showingSiteNo image in the showing contentHolderX - prevents image load flicker (?)

For the text divs, do the same for siteNameShowing and siteNameNext but also need to know siteNameLast as well so it can be hidden. For the backSite() function, nextSiteNo, siteNameLast etc are all restated as they are different from forwardSite()
*/
//temporary code until site pages setup!
//var sitesRoot = "/en/webCreation/sites.aspx";
//if(location.pathname.toLowerCase().indexOf("francais.aspx") > -1) sitesRoot = "/fr/webCreation/sites.aspx";
var sitesRoot = "/en/webCreation/siteList/";
if(location.pathname.indexOf("francais.aspx") > -1) sitesRoot = "/fr/webCreation/siteList/";
var imagesRoot = "/img/clientSite/600wLo/";
var siteListTotal = siteList.length;
var showingSiteNo = 0; //need to start one back as forwardSite() increments on initialisation
var lastSiteNo = siteListTotal - 1;
var nextSiteNo = 1; //for simple startup
var showingHolder = 0;
var siteNameLast = siteList[lastSiteNo]; 
var siteNameShowing = siteList[showingSiteNo];
var siteNameNext = siteList[nextSiteNo];

/*forwardSite()***************************************************/
function forwardSite()
{
//showingSiteNo and lastSiteNo are  set up at end of transitions but need to initialise nextSiteNo
if(showingSiteNo < siteListTotal - 1)
{
nextSiteNo = showingSiteNo + 1;
}
else
{
nextSiteNo = 0;
}
siteNameLast = siteList[lastSiteNo]; 
siteNameShowing = siteList[showingSiteNo];
siteNameNext = siteList[nextSiteNo];
siteNumberObj.innerHTML = "Site No: " + (nextSiteNo + 1);
if(showingHolder == 0)
{
imgObj0.src = imagesRoot + siteList[showingSiteNo] + ".jpg";
imgObj1.src = imagesRoot + siteList[nextSiteNo] + ".jpg";
Effect.Appear('contentHolder1', { duration: 3.0 });
Effect.Fade('contentHolder0', { duration: 3.0 });
document.getElementById(siteNameLast + "_site1").style.display = "none";
document.getElementById(siteNameLast + "_site0").style.display = "none";
document.getElementById(siteNameShowing + "_site0").style.display = "inherit";
document.getElementById(siteNameNext + "_site1").style.display = "inherit";
Effect.Appear('sliceHolder1', { duration: 3.0 });
Effect.Fade('sliceHolder0', { duration: 3.0 });
//Set next holder to be showing
showingHolder = 1;
}
else  //if showingHolder == 1
{
imgObj1.src = imagesRoot + siteList[showingSiteNo] + ".jpg";
imgObj0.src = imagesRoot + siteList[nextSiteNo] + ".jpg";
Effect.Appear('contentHolder0', { duration: 3.0 });
Effect.Fade('contentHolder1', { duration: 3.0 });
document.getElementById(siteNameLast + "_site0").style.display = "none";
document.getElementById(siteNameLast + "_site1").style.display = "none";
document.getElementById(siteNameShowing + "_site1").style.display = "inherit";
document.getElementById(siteNameNext + "_site0").style.display = "inherit";
Effect.Appear('sliceHolder0', { duration: 3.0 });
Effect.Fade('sliceHolder1', { duration: 3.0 });
showingHolder = 0;
}
//Now update showingSiteNo from old nextSiteNo, and lastSiteNo to reflect fade changes. 
//showingSiteNo in conditions refers to state before the fade change.  
showingSiteNo = nextSiteNo;
//Using current showingSiteNo to update lastSiteNo
if(showingSiteNo > 0)
{
lastSiteNo = showingSiteNo - 1;
}
else
{
lastSiteNo = siteListTotal - 1;
}
linkObj0.href = sitesRoot + siteList[showingSiteNo] + ".aspx";
//until set up pages for each site use below!
//linkObj0.href = sitesRoot;
}

/*backSite()***************************************************/
/*
showingStiteNo starts off referring to the showing site before the last transition!!

First Back move: 
showingStiteNo refers to last shown site, so new showingStiteNo should be one on from that. 
nextSiteNo should be old showingStiteNo

Successive Back moves:
showingStiteNo refers to last shown site, so new showingStiteNo should be one less than that. 
nextSiteNo should be new showingStiteNo less one

*/
function backSite()
{
if(showingSiteNo > 0)
{
nextSiteNo = showingSiteNo - 1;
}
else
{
nextSiteNo = siteListTotal - 1;
}
siteNameLast = siteList[lastSiteNo]; 
siteNameShowing = siteList[showingSiteNo];
siteNameNext = siteList[nextSiteNo];
siteNumberObj.innerHTML = "Site No: " + (nextSiteNo + 1);
if(showingHolder == 0)
{
imgObj0.src = imagesRoot + siteList[showingSiteNo] + ".jpg";
imgObj1.src = imagesRoot + siteList[nextSiteNo] + ".jpg";
Effect.Appear('contentHolder1', { duration: 3.0 });
Effect.Fade('contentHolder0', { duration: 3.0 });
document.getElementById(siteNameLast + "_site0").style.display = "none";
document.getElementById(siteNameLast + "_site1").style.display = "none";
document.getElementById(siteNameShowing + "_site0").style.display = "inherit";
document.getElementById(siteNameNext + "_site1").style.display = "inherit";
Effect.Appear('sliceHolder1', { duration: 3.0 });
Effect.Fade('sliceHolder0', { duration: 3.0 });
//Set next holder to be showing
showingHolder = 1;
}
else  //if showingHolder == 1
{
imgObj1.src = imagesRoot + siteList[showingSiteNo] + ".jpg";
imgObj0.src = imagesRoot + siteList[nextSiteNo] + ".jpg";
Effect.Appear('contentHolder0', { duration: 3.0 });
Effect.Fade('contentHolder1', { duration: 3.0 });
document.getElementById(siteNameLast + "_site0").style.display = "none";
document.getElementById(siteNameLast + "_site1").style.display = "none";
document.getElementById(siteNameShowing + "_site1").style.display = "inherit";
document.getElementById(siteNameNext + "_site0").style.display = "inherit";
Effect.Appear('sliceHolder0', { duration: 3.0 });
Effect.Fade('sliceHolder1', { duration: 3.0 });
showingHolder = 0;
}
//Now update showingSiteNo from old nextSiteNo, and lastSiteNo to reflect fade changes. 
//showingSiteNo in conditions refers to state before the fade change.  
showingSiteNo = nextSiteNo;
//Now use updated showingSiteNo to update lastSiteNo
if(showingSiteNo < siteListTotal - 1)
{
lastSiteNo = showingSiteNo + 1;
}
else
{
lastSiteNo = 0;
}
linkObj0.href = sitesRoot + siteList[showingSiteNo] + ".aspx";
//until set up pages for each site use below!
//linkObj0.href = sitesRoot;
}

/**************************/
function goBackAppear()
{
	Effect.Appear('backLink', { duration: 0.5 });
}

function goForwardAppear()
{
	Effect.Appear('forwardLink', { duration: 0.5 });
}

function continueAppear()
{
	Effect.Appear('continueLink', { duration: 0.5 });
}

function goBack()
{
clearTimeout(siteTimer);
Effect.Fade('backLink', { duration: 0 });
setTimeout("goBackAppear()", 3000);
Effect.Fade('forwardLink', { duration: 0 });
setTimeout("goForwardAppear()", 3000);
Effect.Fade('continueLink', { duration: 0 });
setTimeout("continueAppear()", 3000);
backSite();
}

function goForward()
{
clearTimeout(siteTimer);
Effect.Fade('backLink', { duration: 0 });
setTimeout("goBackAppear()", 3000);
Effect.Fade('forwardLink', { duration: 0 });
setTimeout("goForwardAppear()", 3000);
Effect.Fade('continueLink', { duration: 0 });
setTimeout("continueAppear()", 3000);
forwardSite();
}

function freeze()
{
backLinkObj.style.color = "#006afa";
backLinkObj.href = "javascript:goBack();";
freezeLinkObj.style.color = "#999999";
freezeLinkObj.href = "javascript:void(0);";
continueLinkObj.style.color = "#006afa";
continueLinkObj.href = "javascript:resumeChanger();";
forwardLinkObj.style.color = "#006afa";
forwardLinkObj.href = "javascript:goForward();";
clearTimeout(siteTimer);
}

function resumeChanger()
{
backLinkObj.style.color = "#999999";
backLinkObj.href = "javascript:void(0);";
freezeLinkObj.style.color = "#006afa";
freezeLinkObj.href = "javascript:freeze();";
continueLinkObj.style.color = "#999999";
continueLinkObj.href = "javascript:void(0);";
forwardLinkObj.style.color = "#999999";
forwardLinkObj.href = "javascript:void(0);";	
clearTimeout(siteTimer);
forwardSite();
siteTimer = setInterval("forwardSite()", 4000);
}
