
window.addEvent('domready', function() {
   setupCarousel();
   initGallery();
}); 

//pass image source to resizer.php
//resizer.php?imgfile=img.png&max_width=itemW&max_height=180
function setupCarousel(){
   var bounds = $('feature').getSize();
   var itemW = (bounds.x+10)/5;
   var items = $$('img.featureItem');
   
   var maxW = 240;
   var maxH = 180;
   
   items.each( function(item){
      var myBounds = item.getSize();
      var xRatio = maxW / myBounds.x;
      var yRatio = maxH / myBounds.y;
   
      if( ((myBounds.x<=maxW) && (myBounds.y<=maxH)) ){
         //var html_data = $('left_bumper').get('html');
         //$('left_bumper').set('html',html_data+'used the default size ||');
      } else if( (myBounds.x*yRatio)<maxW ){
         item.setStyle('width',Math.ceil(myBounds.x*yRatio));
         item.setStyle('height',maxH);
         
         //var html_data = $('left_bumper').get('html');
         //$('left_bumper').set('html',html_data+'used the MaxH - yRatio ||');
      } else if( (myBounds.y*xRatio)<maxH ){
         item.setStyle('width',maxW);
         item.setStyle('height',Math.ceil(myBounds.y*xRatio));
         
         //var html_data = $('left_bumper').get('html');
         //$('left_bumper').set('html',html_data+'used the MaxW - xRatio ||');
      } else {
         //var html_data = $('left_bumper').get('html');
         //$('left_bumper').set('html',html_data+'used neither of the options ||');
      }
   
      //if( $full_height ){
      //   $tn_width = ceil($y_ratio * $width);
      //   $tn_height = $max_height;
	   //} else if (($width <= $max_width) && ($height <= $max_height) ) {
		//   $tn_width = $width;
		//   $tn_height = $height;
	   //} else if (($x_ratio * $height) < $max_height) {
		//   $tn_height = ceil($x_ratio * $height);
		//   $tn_width = $max_width;
	   //} else {
		//   $tn_width = ceil($y_ratio * $width);
		//   $tn_height = $max_height;
	   //}
   
      //var html_data = $('left_bumper').get('html');
      //$('left_bumper').set('html',html_data+' '+xRatio+':'+Math.ceil(myBounds.y*xRatio)+' '+yRatio+':'+Math.ceil(myBounds.x*yRatio)+' || ');
   
      //item.setStyle('width',itemW);
      item.setStyle('height',180);
   });
};

function initGallery(){
   var myscrollGallery = new scrollGallery({
      start:0,
      speed:0.2,
      autoScroll: true,
      thumbarea: 'feature',
      imagearea: 'placeholder'      
   });
}


