var Slide_Show = function()
{
    this.time= 5400;//30000;
    this.opacitySpeed = 2;	// Speed of opacity - switching between large images - Lower = faster
	this.opacitySteps = 10; 	// Also speed of opacity - Higher = faster

	/* Don't change anything below here */
	this.DHTMLgoodies_largeImage = document.getElementById('promoimage').getElementsByTagName('IMG')[0];
	this.DHTMLgoodies_imageToShow = false;
	this.DHTMLgoodies_currentOpacity = 100;
	this.DHTMLgoodies_slideWidth = false;
	this.DHTMLgoodies_thumbTotalWidth = false;
	this.DHTMLgoodies_viewableWidth = false;

	this.currentUnqiueOpacityId = false;
	this.DHTMLgoodies_currentActiveImage = false;
	this.DHTMLgoodies_thumbDiv = false;
	this.DHTMLgoodies_thumbSlideInProgress = false;

	this.browserIsOpera = navigator.userAgent.indexOf('Opera')>=0?true:false;
	this.promoIndex= 0;
    this.promos = [];
    this.promoButtons = [];
    this.currentIndex = 0;

    this.navigatorDiv = document.getElementById('promonavigator');
}


Slide_Show.prototype.init = function()
{
    for (var i=this.promos.length-1; i>=0 ; i--)
    {
        this.promoButtons[i] = document.createElement('DIV');
        this.promoButtons[i].className = 'promonavbutton unselected';
        this.promoButtons[i].innerHTML = ""+(i+1)+"";
        this.promoButtons[i].onclick =   new Function(' SlideShow.setIndex('+i+')');
        this.navigatorDiv.appendChild(this.promoButtons[i]);
    }
}

Slide_Show.prototype.slideShow = function(start)
{
    var index = this.currentIndex;
    if(start==true)
        index = 0;
    else
        index++;
    
    if (index== this.promos.length) { index =0; }
    this.setIndex(index);
    setTimeout('SlideShow.slideShow(false);', this.time);
}

Slide_Show.prototype.add = function(image, link)
{
    this.promos.push([image, link]);
}

Slide_Show.prototype.setIndex = function(index)
{
     this.promoButtons[this.currentIndex].className = 'promonavbutton unselected';
    this.currentIndex = index;
    this.promoButtons[index].className = 'promonavbutton selected';
    this.showPreview(this.promos[index][0]);
}


Slide_Show.prototype.showPreview = function(imagePath)
{
    this.DHTMLgoodies_imageToShow = imagePath;
	var tmpImage = new Image();
	tmpImage.src = imagePath;
	this.currentUnqiueOpacityId = Math.random();
	this.moveOpacity(this.opacitySteps*-1,this.currentUnqiueOpacityId);
}

Slide_Show.prototype.setOpacity = function()
{
    if(document.all)
	{
		this.DHTMLgoodies_largeImage.style.filter = 'alpha(opacity=' + this.DHTMLgoodies_currentOpacity + ')';
	}
    else
    {
		this.DHTMLgoodies_largeImage.style.opacity = this.DHTMLgoodies_currentOpacity/100;
	}
}

Slide_Show.prototype.moveOpacity = function(speed,uniqueId)
{

		this.DHTMLgoodies_currentOpacity = this.DHTMLgoodies_currentOpacity + speed;
		if(this.DHTMLgoodies_currentOpacity<=5 && speed<0){

			var tmpParent = this.DHTMLgoodies_largeImage.parentNode;
			this.DHTMLgoodies_largeImage.parentNode.removeChild(this.DHTMLgoodies_largeImage);
			this.DHTMLgoodies_largeImage = document.createElement('IMG');
            
            if (this.promos[this.currentIndex][1].length)
            {
                this.DHTMLgoodies_largeImage.onclick = new Function("window.open('"+this.promos[this.currentIndex][1]+"','_self')");
                this.DHTMLgoodies_largeImage.style.cursor = "pointer";
            }

           
			tmpParent.appendChild(this.DHTMLgoodies_largeImage);
			this.setOpacity();
			this.DHTMLgoodies_largeImage.src = this.DHTMLgoodies_imageToShow;

			speed=this.opacitySteps;
		}
		if(this.DHTMLgoodies_currentOpacity>=99 && speed>0)this.DHTMLgoodies_currentOpacity=99;
		this.setOpacity();
		if(this.DHTMLgoodies_currentOpacity>=99 && speed>0)return;
		if(uniqueId==this.currentUnqiueOpacityId)setTimeout('SlideShow.moveOpacity(' + speed + ',' + uniqueId + ')',this.opacitySpeed);
}


/*
addLoadEvent(function(){
    SlideShow = new Slide_Show();
    SlideShow.add('../files/Pages/headerBlueNED.jpg','');
    SlideShow.add('../files/Pages/headerGreenAquaEN.jpg','');
    SlideShow.add('../files/Pages/headerGreenAquaRO.jpg','');
    SlideShow.add('../files/Pages/headerBlueNED.jpg','');
    SlideShow.add('../files/Pages/headerGreenAquaEN.jpg','');
    SlideShow.add('../files/Pages/headerGreenAquaRO.jpg','');
    SlideShow.add('../files/Pages/headerBlueNED.jpg','');
    SlideShow.add('../files/Pages/headerPurpleNED.jpg','');
    SlideShow.init();
    SlideShow.slideShow();
});*/
