var lastRO = null;

function brandSelector(me) {
	this.me = me;
	this.currentBrand=-1;
	this.divSelectedBottle = null;
	this.divBottles = null;
	this.imgSelectedBottle = null;
	this.scrollerObj = null;
	this.brandDetailsDiv = new Array();
	this.brandImage = new Array();
	this.brands = null;
}

brandSelector.prototype.init = function() {
	// Assign initial properties
	this.divSelectedBottle = document.getElementById("brandSelected");
	this.divBottles = document.getElementById("brandBottles");
	this.brands = this.brandDetailsDiv.length;
	this.imgSelectedBottle = document.getElementById("selectedBottle");
	
	// Generate bottles table	
	bottles = "<table class='tableBottles' cellpadding='0' cellspacing='0'><tr>";
	for(i=0; i< this.brands; i++) {
		bottles+="<td><img id='bott" + i +"'  src='" + this.brandImage[i] + "' alt='' onmouseover='rollOver(this);' onmouseout='rollOut(this);' onclick='" + this.me + ".selectBrand(" + i + ");' class='btn'></td>" 
	}
	bottles+= '</tr></table>';
	
	this.divBottles.innerHTML = bottles;
	this.selectBrand(0);
	if(this.scrollerObj.refresh) { this.scrollerObj.refresh(); }
}

brandSelector.prototype.clearLastRollover = function(){
	if(lastRO !== null){ rollOut(lastRO); }
}

brandSelector.prototype.addBrand = function(divId, image) {
	this.brandImage.push(image.replace("_ov","_of"));
	this.brandDetailsDiv.push(document.getElementById(divId));
}

brandSelector.prototype.selectBrand = function(which) {
	// Deselect last selection
	if(this.currentBrand > -1) {
		this.brandDetailsDiv[this.currentBrand].style.display="none";
		if(document.getElementById(this.brandDetailsDiv[this.currentBrand].id + "P2")){
			document.getElementById(this.brandDetailsDiv[this.currentBrand].id + "P2").style.display = "none";
		}
	}
	
	// Select new one
	this.brandDetailsDiv[which].style.display="inline";
	this.imgSelectedBottle.src =  this.brandImage[which].replace(/_o[fv]/,"");
	this.currentBrand=which;
}

brandSelector.prototype.nextPage = function() {
	this.brandDetailsDiv[this.currentBrand].style.display="none";
	d = document.getElementById(this.brandDetailsDiv[this.currentBrand].id + "P2");
	d.style.display="block";
}

brandSelector.prototype.prevPage = function() {
	d = document.getElementById(this.brandDetailsDiv[this.currentBrand].id + "P2");
	d.style.display="none";
	this.brandDetailsDiv[this.currentBrand].style.display="block";
}