/* 
Derived from a script by Alejandro Gervasio. 
Modified to take class names by Andy Miller
*/
matchDivs=function(divclass){ 

     var divs,contDivs,maxHeight,divHeight,d; 
     // get all <div> elements in the document 
     divs=document.getElementsByTagName('div'); 
     contDivs=[]; 
     // initialize maximum height value 
     maxHeight=0; 
     // iterate over all <div> elements in the document 
     for(var i=0;i<divs.length;i++){ 
          // make collection with <div> elements with class attribute 'container' 
	      var reg = new RegExp("\\b" + divclass + "\\b");
          if(reg.test(divs[i].className)){ 
                d=divs[i]; 
                contDivs[contDivs.length]=d; 
                // determine height for <div> element 
                if(d.offsetHeight){ 
                     divHeight=d.offsetHeight; 					
                } 
                else if(d.style.pixelHeight){ 
                     divHeight=d.style.pixelHeight;					 
                } 
                // calculate maximum height 
                maxHeight=Math.max(maxHeight,divHeight); 
          } 
     } 
     // assign maximum height value to all of container <div> elements 
     for(var i=0;i<contDivs.length;i++){ 
          contDivs[i].style.height=maxHeight + "px"; 
     } 
} 


sizeimg=function(imgclass){ 

     var imgs,contImgs,imgmaxHeight,imgmaxWidth,imgWidth,imgHeight,d,newHeight,newWidth; 
     // get all <div> elements in the document 
     imgs=document.getElementsByTagName('img'); 
     contImgs=[]; 
     // initialize maximum height value 
     imgmaxHeight=200;
     imgmaxWidth =250;
     
     // iterate over all <img> elements in the document 
     for(var i=0;i<imgs.length;i++){ 

          // make collection with <img> elements with class attribute 'container' 
	      var reg = new RegExp("\\b" + imgclass + "\\b");
          if(reg.test(imgs[i].className)){ 
                d=imgs[i]; 
                contImgs[contImgs.length]=d; 
                // determine height for img element 
                if(d.offsetHeight){ 
                     imgHeight=d.offsetHeight; 					
                } 
                else if(d.style.pixelHeight){ 
                     imgHeight=d.style.pixelHeight;					 
                }
		   // determine width for img element 
                if(d.offsetWidth){ 
                     imgWidth=d.offsetWidth; 					
                } 
                else if(d.style.pixelWidth){ 
                     imgWidth=d.style.pixelWidth;					 
                }  
		  //check if pic is higher than width
		 
		    if (imgHeight >= imgWidth) {
		   	if (imgHeight > imgmaxHeight) {
			
					newHeight = imgmaxHeight;
					newWidth = Math.floor((newHeight/imgHeight) * imgWidth);
				
			}	
			imgWidth=newWidth;

				if (imgWidth > imgmaxWidth) {
						newWidth = imgmaxWidth;
					
						newHeight = Math.floor(newWidth/imgWidth * imgHeight);
					
				} 
			 
			
		    } else {
			if (imgWidth >= imgmaxWidth) {
					newWidth = imgmaxWidth;
					newHeight = Math.floor((newWidth/imgWidth) * imgHeight);
									
			} 
				 if (imgHeight > imgmaxHeight) {
						newHeight = imgmaxHeight;
						newWidth = Math.floor((newHeight/imgHeight) * imgWidth);
									
			        } 
			

		  }  
		imgs[i].style.height=newHeight + "px"; 
	       imgs[i].style.width=newWidth + "px";
		imgs[i].style.marginTop=((200-newHeight) / 2)  + "px";
		imgs[i].style.marginBottom=((200-newHeight) / 2)  + "px";

	             
          } 
     } 
     // assign new height&width value to all of  <img> elements 
     for(var i=0;i<contImgs.length;i++){ 
          //contImgs[i].style.height=newHeight + "px"; 
	   //contImgs[i].style.width=newWidth + "px"; 
     } 
} 


//non invasive way to add function to onload()
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

addLoadEvent(function(){ 
     if(document.getElementsByTagName){ 
        matchDivs("container");
      	 sizeimg("thumb_img");
	 matchDivs("productListing1ColPriceInfo");



     }
});



