function ImageRow( p_container_key, p_element_class, p_firstelem_class, p_container_width, p_img_width ){		
  this.o_container;
  if( p_container_key != "undefined" ){  this.o_container = document.getElementById(p_container_key);  }
	this.n_container_width = p_container_width;
	this.n_img_width = p_img_width;
	this.element_class = p_element_class;
	this.firstelem_class = p_firstelem_class;
	this.o_imgrowsarray;
	
	if(typeof ImageRow._initialized == "undefined"){
  	
  	ImageRow.prototype.loadArray = function(){
  		if( this.o_container != "undefined" ){
  			this.o_imgrowsarray = new Array();  			
  			children = this.o_container.childNodes;
  			row_num = -1; col_num = 0;
  			for(i=0; i<children.length; i++){
  				if( children[i].className == this.firstelem_class ){
  					col_num=0;
  					this.o_imgrowsarray[++row_num] = new Array();
  					this.o_imgrowsarray[row_num][col_num] = children[i];
  				}
  				if( children[i].className == this.element_class ){
  					this.o_imgrowsarray[row_num][++col_num] = children[i]; 					
  				}
  			}
  		}
  	};
  	
		ImageRow.prototype.spaceImages = function(){		
			  this.loadArray();
				for( r=0; r<this.o_imgrowsarray.length; r++ ){
					var a_row = this.o_imgrowsarray[r];
					n_cat_width = (this.n_container_width - (a_row.length * this.n_img_width)) / (a_row.length + 1);
					n_cat_width = Math.floor(n_cat_width);
					for( c=0; c<a_row.length; c++ ){
						a_row[c].style.width=(n_cat_width + this.n_img_width) + "px";						
					}
					n_cat_total = a_row.length * (n_cat_width + this.n_img_width) + n_cat_width;
					n_cat_remainder = Math.floor((this.n_container_width - n_cat_total) / 2);
					if(a_row.length) a_row[0].style.width = ((n_cat_width + this.n_img_width) + n_cat_remainder) + "px";
				}
		};	
			
	};
  ImageRow._initialized="true";

};

function CategoryImageRow(p_container_width, p_img_width){
	ImageRow.call(this, "categories", "category", "categorystart", p_container_width, p_img_width );
}
CategoryImageRow.prototype = new ImageRow();

function ProductImageRow(p_container_width, p_img_width){
	ImageRow.call(this, "products", "product", "productstart", p_container_width, p_img_width );	
	
	ProductImageRow.prototype.findOverlay = function(productDom){
		var o_overlay = null;
  	children = productDom.childNodes;
  	for(i=0; i<children.length; i++){
  		if( children[i].className == "overlay" ){	o_overlay = children[i]; break;}
  	}
  	return o_overlay;
	};
	ProductImageRow.prototype.spaceImages = function(){
		ImageRow.prototype.spaceImages.call(this);
		if( this.o_imgrowsarray != "undefined" && this.o_imgrowsarray.length > 0 ){
			for( r=0; r<this.o_imgrowsarray.length; r++ ){
					var a_row = this.o_imgrowsarray[r];
					for( c=0; c<a_row.length; c++ ){
						var o_overlay = this.findOverlay( a_row[c] );
						if( o_overlay != null ){
							o_overlay.style.width = a_row[c].style.width;
						}						
					}
			}
		}
	};	
	
};
ProductImageRow.prototype = new ImageRow();


