// the old affiliate logo carousel is back!
window.addEvent('domready', function(){
	var affiliates = new ImageSlider();
	
	
	// easy/peasy dropdowns
	//var links = $$('.top.navigation span a');
	
	var showDropdown = function(el){ //el could be either anchor
			
			span = el.getParent('span');
			li = span.getParent('li');
			links = span.getChildren('a');
			links.addClass('active');
			
			dropdowns = li.getChildren('ul');
			dropdowns.addClass('visible');
			dropdowns.tween('opacity',1);
			
			
			li.addEvent('mouseleave', function(){
				
				links.removeClass('active');
				dropdowns.tween('opacity',0).removeClass('visible');
				
			});
	}//end show dropdown function
	
	$$('.tabs li ul').set('opacity',0);
	
	//also need to set it on the span mouseover event for those browsers that support it
	
	$$('a.dropdown-button').each(function(button){ //button clicks for touchscreens
		button.addEvent('click', function(e){
			e.stop(); //get rid of the jerkiness
			showDropdown(button);
		});
	});
	
	$$('.tabs span a').each(function(a){
		a.addEvent('mouseenter', function(e){
			showDropdown(a);
		});
	});
	
});//end DomReady
	
	
//==========================================================================================
	
	var ImageSlider = new Class({
	
	Implements: [Options],
	options: {
		sliders: 'affiliates-list',
		transitionduration:7500,
		autorotate:true,
		transition:Fx.Transitions.linear
	},
	initialize: function(options) {
		this.setOptions(options);
		var c = this;
		var op = this.options;
		if(op.autorotate) this.animate();
		
		if ( typeOf( $(op.sliders)) == 'element' ){
			$(op.sliders).addEvent('mouseover',function(){op.SlideFX.pause();});
			$(op.sliders).addEvent('mouseleave',function(){op.SlideFX.resume();});
		}
		
	},
	animate:function(){
		var c = this;
		var op = this.options;
		var sliders = $$('#'+op.sliders+' li');
		if(sliders.length>0){
			op.SlideFX = new Fx.Tween(sliders[0],{'transition':op.transition,'duration':op.transitionduration,'onComplete':function(){
				sliders[0].inject($(op.sliders));
				sliders[0].setStyle('margin-left',0);
				c.animate();
			}});
			op.SlideFX.start('margin-left', -sliders[0].getSize().x);
		}
	}
});
