/*<script>/* */

var carousel,pageCarousel;
window.addEvents({
  'domready': function(){
    $$('body').each(function(el){el.addClass('hasjs')});
    
    /* thumbnails example , div containers */
    if ($('carousel')) {
    
      $$('#carousel li').each(function(item){
        item.addClass('SlideItMoo_element');
      });
      
    }
    
    // ie 6 fix
    fixPng();
  
		// check carousel exists then create it
    if ($('carousel')) {
			// load carousel options
			if ($('carousel').hasClass('large')) {
				carousel = new SlideItMoo({
					overallContainer: 'carousel',
					elementScrolled: 'SlideItMoo_inner',
					thumbsContainer: 'SlideItMoo_items',
					itemsVisible: 1,
					showControls: 0,
					itemsSelector: '.SlideItMoo_element',
					transition: Fx.Transitions.Sine.easeInOut,
					duration: 400,
					autoSlide: 5000
				});
			}
			else {
				carousel = new SlideItMoo({
					overallContainer: 'carousel',
					elementScrolled: 'SlideItMoo_inner',
					thumbsContainer: 'SlideItMoo_items',
					itemsVisible: 4,
					itemsSelector: '.SlideItMoo_element',
					showControls: 1,
					transition: Fx.Transitions.Sine.easeInOut,
					duration: 400,
					autoSlide: 5000
				});
			}
		}
  /*},
  'load': function(){*/
		
		if ($('pages')) {
			pageCarousel = new SlideItMoo({
					overallContainer: 'description',
					elementScrolled: 'SlideItMoo_inner',
					thumbsContainer: 'pages',
					itemsVisible: 1,
					showControls: 0,
					itemsSelector: '.page',
					transition: Fx.Transitions.Sine.easeInOut,
					duration: 400
				});
				
        $$('a.next').each(function(elm){
          elm.addEvent('click', function(event){
            event.stop();
            pageCarousel.next();
          });
        });
				
        $$('a.prev').each(function(elm){
          elm.addEvent('click', function(event){
            event.stop();
            pageCarousel.previous();
          });
        });
		}
  }
});

// fixes png transparency in IE6 - inline images only
function fixPng() {
  // check for IE <= 6
  if (Browser.Engine.trident && Browser.Engine.version < 5) {
    // set path to spacer image
    var spacer = 'http://www.mccashins.co.nz/images/spacer.png'; // 8-bit transparent png
    // get all images on page
    var images = $$('img[src$=".png"]');
    // loop through images
    for (var i = 0; i < images.length; i++) {
      //alert(images);
      // if image is png, load transparency
      if (images[i].src.indexOf('.png') != -1) {
        // stop image from collapsing if no width/height set
        $(images[i]).set('styles', {'width':images[i].width + 'px','height':images[i].height + 'px','filter':'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="'+images[i].src+'", sizingMethod="image")'});
        // hide src image
        images[i].src = spacer;
      }
    }
  }
}