var iCurrentOpacity;
var itemID;

//fade in hero pic
function nextOpacity(){
	if (iCurrentOpacity == 100){
		return;
	}
	iCurrentOpacity += 5;
	if (iCurrentOpacity > 100){
		iCurrentOpacity = 100;
	}
	changeOpac(iCurrentOpacity,itemID);
	if (iCurrentOpacity != 100){
		setTimeout("nextOpacity()", 40);
	}					
}

function fadein(item){
    iCurrentOpacity=0;
    itemID=item.id;
    nextOpacity();
}

//change opacity of an element
function changeOpac(opacity, id) {
	var object = document.getElementById(id).style;
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
} 

function features(imageControl, HeadingControl, DetailControl,MoreDealControl, ValidatorControl, DestinationCode) {
  this._features= new Array();
  this._CurrentItem=0;
  this._imgCtl=imageControl;
  this._headCtl=HeadingControl;
  this._detCtl=DetailControl;
  this._moreCtl=MoreDealControl;
  this._validatorCtl=ValidatorControl;
  this._hidDestCodeCtl=DestinationCode;
  this._timerID;

  features.prototype.Add=function(sHeading, sImage, sDetailTop,sMoreDeals, sDestinationCode) {
    var oFeature=new feature(sHeading, sImage, sDetailTop,sMoreDeals, sDestinationCode);
    this._features.push(oFeature);
  }
  
  features.prototype.NextFeature=function(direction){
    
    this._CurrentItem += direction;

    if (this._CurrentItem >= this._features.length){
      this._CurrentItem = 0;
    } else {
      if ( this._CurrentItem < 0)
        this._CurrentItem = this._features.length -1;

    }
    
    this._imgCtl.src = this._features[this._CurrentItem]._Image;
    this._imgCtl.title = this._features[this._CurrentItem]._Heading;
    this._headCtl.innerHTML = this._features[this._CurrentItem]._Heading!=""?this._features[this._CurrentItem]._Heading:this._headCtl.innerHTML;
    if(this._detCtl!=null){
        this._detCtl.innerHTML = this._features[this._CurrentItem]._DetailTop!=""?this._features[this._CurrentItem]._DetailTop:this._detCtl.innerHTML;
    }
    this._moreCtl.innerHTML = this._features[this._CurrentItem]._MoreDeals!=""?this._features[this._CurrentItem]._MoreDeals:this._moreCtl.innerHTML;
    this._hidDestCodeCtl.value = this._features[this._CurrentItem]._DestinationCode;
    this._validatorCtl.style.display="none";
    
    fadein(this._imgCtl);
  }

  features.prototype.Start=function(){
    this._timerID=setInterval("gFE.NextFeature(1)",10000);
  }
}

function feature(sHeading, sImage, sDetailTop, sMoreDeals, sDestinationCode){
  this._Heading=sHeading;
  this._Image=sImage;
  this._DetailTop=sDetailTop;
  this._MoreDeals=sMoreDeals;
  this._DestinationCode=sDestinationCode;
}