
var curURL = document.location.href;
var isHome = curURL.indexOf("index.html");
var isNews = curURL.indexOf("nPage");

if (isHome != -1) {

	mainLogo = new Image();
	mainLogo.src = "images/extras/titles/title_roberto.JPG";
	secondLogo = new Image();
	secondLogo.src = "images/extras/titles/title_purveyors.JPG";
	thirdLogo = new Image();
	thirdLogo.src = "images/extras/titles/title_since.JPG";
	fourthLogo = new Image();
	fourthLogo.src = "images/comp_titleb.JPG";

} else if (isNews != -1) {
	mainLogo = new Image();
	mainLogo.src = "../../images/extras/titles/title_roberto.JPG";
	secondLogo = new Image();
	secondLogo.src = "../../images/extras/titles/title_purveyors.JPG";
	thirdLogo = new Image();
	thirdLogo.src = "../../images/extras/titles/title_since.JPG";
	fourthLogo = new Image();
	fourthLogo.src = "../../images/comp_titleb.JPG";
} else {
	mainLogo = new Image();
	mainLogo.src = "../images/extras/titles/title_roberto.JPG";
	secondLogo = new Image();
	secondLogo.src = "../images/extras/titles/title_purveyors.JPG";
	thirdLogo = new Image();
	thirdLogo.src = "../images/extras/titles/title_since.JPG";
	fourthLogo = new Image();
	fourthLogo.src = "../images/comp_titleb.JPG";
}

var stopFade = true;
function swapFadeLogo(mode) {

	if (mode == 1) {
		stopFade = false;
		changeLogo();
	} else {
		//document.getElementById('mainLogo').src = mainLogo.src;
	}

}

var imgCount = 1;
var rotCount = 0;
var fadeRate = 1;
var secondFadeRate = 100;
function changeLogo() {

	if (stopFade != true) {
		if (imgCount > 1) {
			stopFade = true;
		}

		switch(imgCount) {
			case 1:
   			  document.getElementById('mainLogo').src = mainLogo.src;
			  var nextImage = secondLogo.src;
			  // Calls starting fade routine
	   		  FadeInImage('mainLogo',nextImage,'logo-loc');
	   		  imgCount++;
			  break;
			case 2:
			  nextImage = thirdLogo.src;
			  // Calls starting fade routine
	   		  FadeInImage('mainLogo',nextImage,'logo-loc');
	   		  imgCount++;
			  break;
		    default:
  	    	  document.getElementById('mainLogo').src = mainLogo.src;
		      imgCount = 1;
		      break;
		}
		t=setTimeout("changeLogo()",1600);

	} else {
		clearTimeout(t);
		imgCount = 1;
	    nextImage = mainLogo.src;
		FadeInImage('mainLogo',nextImage,'logo-loc');
		//document.getElementById('mainLogo').src = mainLogo.src;
	}
}


// Set fadeout functions
function SetOpacity(object,opacityPct)
{
  // IE.
  object.style.filter = 'alpha(opacity=' + opacityPct + ')';
  // Old mozilla and firefox
  object.style.MozOpacity = opacityPct/100;
  // Everything else.
  object.style.opacity = opacityPct/100;
}
function ChangeOpacity(id,msDuration,msStart,fromO,toO)
{

  var element=document.getElementById(id);
  var opacity = element.style.opacity * 100;
  var msNow = (new Date()).getTime();
  opacity = fromO + (toO - fromO) * (msNow - msStart) / msDuration;
  if (opacity<0)
    SetOpacity(element,0)
  else if (opacity>100)
    SetOpacity(element,100)
  else
  {
    SetOpacity(element,opacity);
    element.timer = window.setTimeout("ChangeOpacity('" + id + "'," + msDuration + "," + msStart + "," + fromO + "," + toO + ")",1);
  }
}
function FadeIn(id)
{
  var element=document.getElementById(id);
  if (element.timer) window.clearTimeout(element.timer);
  var startMS = (new Date()).getTime();
  element.timer = window.setTimeout("ChangeOpacity('" + id + "',1000," + startMS + ",0,100)",1);
}
function FadeOut(id)
{
  var element=document.getElementById(id);
  if (element.timer) window.clearTimeout(element.timer);
  var startMS = (new Date()).getTime();
  element.timer = window.setTimeout("ChangeOpacity('" + id + "',1000," + startMS + ",100,0)",1);
}
function FadeInImage(foregroundID,newImage,backgroundID)
{
  var foreground=document.getElementById(foregroundID);
  if (backgroundID)
  {
    var background=document.getElementById(backgroundID);
    if (background)
    {
      background.style.backgroundImage = 'url(' + foreground.src + ')';
      background.style.backgroundRepeat = 'no-repeat';
    }
  }
  SetOpacity(foreground,0);
  foreground.src = newImage;
  if (foreground.timer) window.clearTimeout(foreground.timer);
  var startMS = (new Date()).getTime();
  foreground.timer = window.setTimeout("ChangeOpacity('" + foregroundID + "',1000," + startMS + ",0,100)",100);
}

