/*
 * mooTools slider functionality
 */
try {
var Site = {
   start: function(){
      if($('fader')) Site.fader();
   },
   
   toggleElement: function(show, hide) {
      $$('#link' + hide + ' img').fade(0);
      $$('#productslider ul li')[hide-1].getChildren('a')[0].removeClass('active');
      
      $$('#fader a#link' + show + ' img').fade(1);
      $$('#productslider ul li)')[show-1].getChildren('a')[0].addClass('active');
      
      // change z-index
      $$('#fader a#link' + hide).setStyle('z-index','1');
      $$('#fader a#link' + show).setStyle('z-index','100');
   },
				
   fader: function(){
      var headings = $$('#productslider ul li');
   
      headings.each( function(heading, i) {
            heading.onclick = function(){
      
            // get actual item
            var active = $$('#productslider ul li a.active').getParent().getProperty('class').toString();
            match = active.match(/nav([0-9]+)/ig);
            if (match) {
               activeId = RegExp.$1;
            }

            // check link
            if (activeId == (i+1)) {
               return false;
            }

            var spacerImage = 'files/spacer.gif';
            if ($$('#fader a#link' + (i+1) + ' img').getProperty('src') == spacerImage) {
               $('activity-indicator').fade(1);

               var loader = new Asset.images(naviContentImages[i], {  
                  onComplete: function() {  
                        $$('#fader a#link' + (i+1) + ' img').setStyle('opacity', 0);
                        $$('#fader a#link' + (i+1) + ' img').setProperty('src',   naviContentImages[i]);
                        $$('#fader a#link' + (i+1) + ' img').setProperty('alt',   naviContentImagesAlt[i]);
                        $$('#fader a#link' + (i+1) + ' img').setProperty('title', naviContentImagesAlt[i]);
                        
                        $('activity-indicator').fade(0);
                        
                        Site.toggleElement((i+1), activeId);
                     }  
               });  
            }
            else {
               Site.toggleElement((i+1), activeId);
            }
				return false;
			}
			
		});
	}

};

window.addEvent('domready', function() {
	var activeTab = 0;
	match = window.location.href.match(/p=([0-9]{1})/ig);
	if (match) {
		activeTab = (RegExp.$1)-1;
	}
	if (activeTab >= $$('#fader a img').length) {
		activeTab = 0;
	}

	$$('#fader a img').each( function(img, i) {
		if (i != activeTab) {
			img.fade(0);
		}
	});

      // time to implement basic show / hide
      Element.implement({
         //implement show
         show: function() {
            this.setStyle('display','block');
         },
         //implement hide
         hide: function() {
            this.setStyle('display','none');
         }
      });
      
      Element.implement({  
         //implement show  
         fancyShow: function(speed) {  
            this.fade('in', {duration: speed});  
         },  
         //implement hide  
         fancyHide: function(speed) {  
            this.fade('out', {duration: speed});  
         }  
      });
      Site.start();
   }
);

}
catch (e) {
}
