//<script>
//<!-- Copyright 1999-2003 Alexa Internet, Inc.  All Rights Reserved.

function LabelSet(oButton) {
	var o = new AlxObj();
	o.oType = "LabelSet";
	o.activeset = g_oCookie.readPersist(REG_SHOWNAMES);
	o.parentButton = oButton;
	o.root = oButton.imgName;
	o.mode = oButton.parent.sStateMode;
	o.sets = new Array();
	o.init = LabelSet_init;
	o.get = LabelSet_get;
	o.switchSet = LabelSet_switchSet;
//	o.onLabelChange = LabelSet_onLabelChange;
	o.create();
//	et.register("onLabelChange",o);
	return o;
	
	function LabelSet_onLabelChange(aArgs) {
		this.switchSet();
		return true;
	}
	function LabelSet_init() {
		if (arguments[0]) {
			// passed in object prototype
			var oProto = arguments[0];
		} else {
			var oProto = ImageSet;
		}
		// init based on what kind of set this is
		// first, create basic template.

		// as a result, we now create three sets based on how mode looks
		// set0 = labels
		// set1 = selected labels
		// set2 = no labels
		this.sets['icons_text'] = new oProto(this, 0);
		switch(this.mode) {
			// in this case, we only have one imageset, so we mirror labels onto nolabels and selected
			case 0:
				this.sets['icons_stext'] = this.sets['icons_text'];
				this.sets['icons_only'] = this.sets['icons_text'];
				break;
			case 1:
				// in this case, we have a labeled button that shows icons in nolabels and selected
				// icons only
				this.sets['icons_only'] = new oProto(this,2);
				this.sets['icons_stext'] = this.sets['icons_only'];
				break;
			case 2:
				// in this case, labeled button shows selected icon and nolabels button.
				this.sets['icons_stext'] = new oProto(this,1);
				this.sets['icons_only'] = new oProto(this,2);
				break;
			default:
				this.sets['icons_stext'] = this.sets['icons_text'];
				this.sets['icons_only'] = this.sets['icons_text'];
				break;
		}
		// load whichever set we have as default
		this.switchSet();
		return true;
	}
	function LabelSet_switchSet() {
		this.activeset = g_oCookie.readPersist(REG_SHOWNAMES);
		if (this.sets[this.activeset]) {
			if (!this.sets[this.activeset].loaded) {
				this.sets[this.activeset].init();
			}
		} else {
			this.activeset = "icons_stext";
			if (!this.sets[this.activeset].loaded) {
				this.sets[this.activeset].init();
			}
		}
		return true;
	}
		
	function LabelSet_get(nState) {
		// nState: 0 = out, 1 = over, 2 = clk
		var rVal = this.sets[this.activeset].img[nState];
		return rVal;
	}
}

function Image_onError() {
	// try again
}

g_sImagePath = RESOURCE_URI + "IMAGE";
g_sImagePrefix = "button_";
g_sImageSuffix = ".gif";
g_oImageTemplate = window.document.createElement("IMG");
g_oImageTemplate.onError = Image_onError;

function ImageSet(oObj,nType) {
	var o = new AlxObj();
	o.oType = "ImageSet";
	o.parent = oObj;
	o.nType = nType;
	o.img = new Array();
	o.img[0] = new Object();
	o.img[1] = new Object();
	o.img[2] = new Object();
	o.loaded = false;
	o.init = ImageSet_init;
	o.create();
	return o;
	function ImageSet_init() {
		this.img[0].image = g_oImageTemplate.cloneNode(true);
		this.img[0].image.btn = this.parent.parentButton;
		this.img[0].image.src = g_sImagePath + "/" + this.nType + g_sImagePrefix + this.parent.root + "_0" + g_sImageSuffix;
		this.img[0].width = this.parent.parentButton.parent['state'+this.nType+'width'];
		this.img[1].image = g_oImageTemplate.cloneNode(true);
		this.img[1].image.btn = this.parent.parentButton;
		this.img[1].image.src = g_sImagePath + "/" + this.nType + g_sImagePrefix + this.parent.root + "_1" + g_sImageSuffix;
		this.img[1].width = this.parent.parentButton.parent['state'+this.nType+'width'];
		if (this.parent.parentButton.threeState == false) {
			this.img[2] = this.img[1];
		} else {
			this.img[2].image = g_oImageTemplate.cloneNode(true);
			this.img[2].image.btn = this.parent.parentButton;
			this.img[2].image.src = g_sImagePath + "/" + this.nType + g_sImagePrefix + this.parent.root + "_2" + g_sImageSuffix;
			this.img[2].width = this.parent.parentButton.parent['state'+this.nType+'width'];
		}
		this.loaded = true;
	}
}

function BrandImageSet(oObj,nType) {
	var o = new ImageSet(oObj, nType);
	o.oType = "BrandImageSet";
	o.init = BrandImageSet_init;
	o.create();
	return o;
	function BrandImageSet_init() {
		// override image path
		var sPath = new String(BrowserProxy.Update.WebDirectory); 
		var sAssocID = new String(BrowserProxy.System.ReadClientState(REG_AMZNID)); 
		var sFullPath = sPath + sAssocID + g_sImageSuffix;
		/* Use the web service for images! */
		//sFullPath = "http://s3.amazonaws.com/alexa-toolbar/" + sAssocID + ".gif";
		sFullPath = "http://cgi.alexa.com/toolbars/" + sAssocID + "/image";
		this.img[0].image = g_oImageTemplate.cloneNode(true);
		this.img[0].image.btn = this.parent.parentButton;
		this.img[0].image.src = sFullPath;
		this.img[0].width = this.parent.parentButton.parent['state'+this.nType+'width'];
		this.img[1].image = g_oImageTemplate.cloneNode(true);
		this.img[1].image.btn = this.parent.parentButton;
		this.img[1].image.src = sFullPath;
		this.img[1].width = this.parent.parentButton.parent['state'+this.nType+'width'];
		if (this.parent.parentButton.threeState == false) {
			this.img[2] = this.img[1];
		} else {
			this.img[2].image = g_oImageTemplate.cloneNode(true);
			this.img[2].image.btn = this.parent.parentButton;
			this.img[2].image.src = sFullPath;
			this.img[2].width = this.parent.parentButton.parent['state'+this.nType+'width'];
		}
		this.loaded = true;
	}
}
if ( typeof(oScriptReport) == 'object' )
	oScriptReport.load('img.class.js');
