function dowindow(url)
{
	window.open(url, 'Loreal', '');
}

function loadBanners(x, large) 
{
  var el = document.getElementById('banner'+x);
  while (el.firstChild) { el.removeChild(el.firstChild); }

  el.style.width = (large) ? '380px' : '140px';
  el.style.height = '70px';

  for(var i=0; i<images[x-1].length; i++) 
	{
		var banner = images[x-1][i];
    var t = document.createElement('IMG');
    t.setAttribute('src',banners[banner][0]);
    t.setAttribute('width',(large) ? 380 : 140);
    t.setAttribute('height',70);
		t.setAttribute('alt', banners[banner][1]);
		t.setAttribute('title', banners[banner][1]);
		if (banners[banner][2] != '')
		{
      t.setAttribute('onclick', 'dowindow("'+banners[banner][2]+'")');
    }
    t.style.visibility = 'hidden';
		t.style.border = '1px solid black';
    el.appendChild(t);
  }

  el.firstChild.style.visibility = 'visible';
	window.setTimeout(function() { window.setTimeout(function() { startFading(x); }, 5000); }, (x-1)*1000);
}	

function startFading(x)
{
    // grab the next element and fade it in 
		var el = document.getElementById('banner'+x).childNodes[nextImage[x-1]];
    el.style.visibility = 'visible';
    el.style.zIndex = 2;
    setOpacity(el, 0);
    fadeImage(el, 0, x);

    // swap to the next img element 
		nextImage[x-1] = (nextImage[x -1] < images[x-1].length-1) ? nextImage[x-1] + 1 : 0;
}

function setOpacity(el, opacity)
{
    opacity /= 100;
    el.style.opacity = opacity;
    el.style.MozOpacity = opacity;
    el.style.filter = "alpha(opacity=" + (opacity * 100) + ")";
}				

function fadeImage(el, currentOpacity, x)
{
    // increase opacity 
		currentOpacity += 2;

    // if full opaque 
		if (currentOpacity > 100)
    {
        // reset in case over 
				setOpacity(el, 100);
					
				var prevEl = el.previousSibling ? el.previousSibling : el.parentNode.lastChild;
		    prevEl.style.visibility = 'hidden';
				
        el.style.zIndex = 1;

        // continue rotation 
				window.setTimeout(function() { startFading(x); }, 5000);
    }
    else 
		{
        // fade in 
				setOpacity(el, currentOpacity);
        window.setTimeout(function() { fadeImage(el, currentOpacity, x); }, 50);
    }
}			
