var SC_AttributeHeader = function (pName){
//esta clase va a ser la encargada de manejar los atributos con rangos
//si hay que hacer listado de filtros por rango, tipo precio 200 a 400, 
//400 a 1000, etc... se crear� un header de estos por cada atributo
//por el cual se quiera hacer este tipo de filtrado.

//Funcionalidades:
// Cargar sus propios datos desde el DOM
// Crea los links necesarios para filtrar por sus valores

//
	this.attributeName = pName;
	this.elementsId = new Array();
	this.ranges = new Array();
	this.rangesCount = new Array();
	
	_SC_AttributeHeader_prototype_called = true;
	SC_AttributeHeader.prototype.getRangesCount = getRangesCount;
	SC_AttributeHeader.prototype.generateRanges = generateRanges;
	SC_AttributeHeader.prototype.createTags = createTags;
	SC_AttributeHeader.prototype.scLoad = scLoad;
	SC_AttributeHeader.prototype.scReLoad = scReLoad;
	
	
	function scLoad(pItemLst, pRanges){
		this.generateRanges(pRanges);
		this.getRangesCount(pItemLst);
	}
	
	function scReLoad(pItemLst){
		this.getRangesCount(pItemLst);
		this.createTags();
	}
	
	function generateRanges(strRanges){
		var dualValues = strRanges.split(';');
		var singleRange = "";
		for (var i=0; i<dualValues.length;i++){
			singleRange = dualValues[i].split('-');
			if ( singleRange[0] != "" && singleRange[1] != ""){
				this.ranges[this.ranges.length] = singleRange;
				this.rangesCount[this.rangesCount.length] = 0;
			}
		}
	}
	
	function getRangesCount(itemList){
		var item = null;
		var counter = 0;
		for ( var x=0;x<this.ranges.length;x++){
			for (var i=0;i<itemList.length;i++){
				item = itemList[i];
				if ( item.getNumericAttributeValueByName(this.attributeName) >= this.ranges[x][0] && item.getNumericAttributeValueByName(this.attributeName) < this.ranges[x][1] ) {
					counter++;
				}
			}
			this.rangesCount[x]=counter;
			counter = 0;
		}
	}
	
	function createTags(){
		var containerSpan = document.getElementById(this.attributeName +'-AH');
		var scTag = "";
		containerSpan.innerHTML = "";
		containerSpan.style.display="block";
		for (var i=0;i<this.ranges.length;i++){
			if ( (this.ranges.length-1) == i){
				if ( this.rangesCount[i] > 0){
				scTag = "<a href=\"javascript:addFilter('SortByAttribRange','"+this.attributeName+"',"+this.ranges[i][0]+","+this.ranges[i][1]+")\" style='display:block;'>";
				if ( this.attributeName == "Price" ) scTag += "$";
				scTag += this.ranges[i][0]+" and More";
				scTag += "<strong> ("+this.rangesCount[i]+")</strong></a>";
				containerSpan.innerHTML += scTag;
				}
			}else{
				if ( this.rangesCount[i] > 0){
				scTag = "<a href=\"javascript:addFilter('SortByAttribRange','"+this.attributeName+"',"+this.ranges[i][0]+","+this.ranges[i][1]+")\"style='display:block;'>";
				if ( this.attributeName == "Price" ) scTag += "$";
				scTag += this.ranges[i][0]+"-";
				if ( this.attributeName == "Price" ) scTag += "$";
				scTag += this.ranges[i][1];
				scTag += "<strong> ("+this.rangesCount[i]+")</strong></a>";
				containerSpan.innerHTML += scTag;
				}
			}
		}
		/*if ( containerSpan.getElementsByTagName('a').length <=1){
			document.getElementById(this.attributeName +'-AH-p').style.display = "none";
		}*/
	}
}
