var adjustAssets = function(){

   // stretch short pages
   /**
   var bh = 
      window.innerHeight ? window.innerHeight : document.documentElement.clientHeight 
      ? document.documentElement.clientHeight : document.body.clientHeight;

   if (Ext.get('wrapper').getHeight() < bh)
   {
      var hh = Ext.get('ctl00_header').getHeight();
      var fh = Ext.get('ctl00_footer').getHeight();
      
      Ext.get('ctl00_centerColumn').setHeight(bh - hh - fh - 20);
   }
   */

}
var loadSearch = function() { 
   var searchText = document.getElementById("ttHeaderSearchTextbox"); 
   var searchButton = document.getElementById("ttHeaderSearchButton");

   var searchButtonOff = '/_media/SearchFindIt.gif';
   var searchButtonOn  = '/_media/SearchFindIt_o.gif';

   searchText.onkeyup = function() { 
      if (event.keyCode=='13') { searchButton.click();} 
   }; 

   searchButton.onmouseover = function() { 
      this.src = searchButtonOn; 
   };

   searchButton.onmouseout = function() { 
      this.src = searchButtonOff; 
   }; 

   searchButton.onclick = function() { 
      if (searchText.value != 'FOOBAR') { 
         window.location = '/search.aspx?find=' + encodeURIComponent(searchText.value).replace(/%20/g, '+'); 
         return false; 
      } 
   }; 
} 

var showPreview = function(imagePath, imageIndex){
   var subImages = document.getElementById('ttImagePane').getElementsByTagName('IMG');
   var img;

   if (subImages.length == 0) {
      img = document.createElement('IMG');
      document.getElementById('ttImagePane').appendChild(img);
   } else {
      img = subImages[0];
   }
      
   img.src = imagePath;
      
   var thumb = document.getElementById('ttImageGalleryImages').getElementsByTagName('IMG');

   for(var no=0; no < thumb.length; no++){
      if (imageIndex == no) {
         thumb[no].style.border = '2px solid #000000';
      } else {
         thumb[no].style.border = '1px solid #CCCCCC';
      }
   }
}

var writeImage = function(displayImage, imageCount) {

   var galleryHolder = Ext.get("ttImageGalleryImages");
   var html = '';

   html += '<a href="#" onclick="showPreview(\'' + displayImage + '\' ,\'' + imageCount + '\');return false">';

   html += '<img '

   if (imageCount == 0) {
      html += 'class="first" ';
   }

   html += 'src="' + displayImage + '" />'
   html += '</a>';

   galleryHolder.insertHtml("beforeEnd", html, false);
}

function imageHolder(image, category) {
   this.img = image;
   this.cat = category;
}

var writeHomepageImage = function() {
   var imgCat = new Array();
   var i = 0;
   imgCat[i++] = new imageHolder('SN_Tables.jpg', 593);
   imgCat[i++] = new imageHolder('SN_Planwheel.jpg', 107);
   imgCat[i++] = new imageHolder('SN_Pencils.jpg', 85);
   imgCat[i++] = new imageHolder('SN_ParallelBar.jpg', 73);
   imgCat[i++] = new imageHolder('SN_Markers.jpg', 163);
   imgCat[i++] = new imageHolder('SN_Chairs.jpg', 63);

   var max = imgCat.length - 1;

   i = Math.round(Math.random()*(max));

   if (i < 0 || i > max) {
      i = 0;
   }

   document.write('<a href="\/search.aspx?find=&category='+ imgCat[i].cat + '"><img src="\/_media\/banners\/'+ imgCat[i].img + '"></a>');

}



Ext.BLANK_IMAGE_URL = '/_media/js/ext/s.gif';

Ext.onReady(function(){
   // auto adjust everything on page load or window resize
   //window.onresize = adjustAssets;
   //adjustAssets();
   loadSearch();
   

});
