/*
Event: Ready
> Hook up homepage load carousel and other events
*/
Ext.onReady(function() {
	var el = Ext.get('CoolCompanies');
	if (null == el) return;
	
	new Ext.ux.Carousel('CoolCompanies', {
		itemSelector: 'div.companyGroup',
		interval: 3,
		autoPlay: true,
		showPlayButton: true,
		pauseOnNavigate: true,
		freezeOnHover: true,
		transitionType: 'easeIn',
		navigationOnHover: true,
		transitionDuration: .5
	});
});

/*
Class: PromoToggler
> Handles the promo box tab click events - hides/shows the tabs

Usage:
> PromoToggler.LoadIndex calls are written into the HTML on the homepage promo area
*/
window.PromoToggler = function() {
	return {
		activeIndex: 0,

		init: function() {
			Ext.select('.promos a[target^="PollLightBox"]').each(function(el) {
				var a = Ext.get(el);
				var href = a.dom.getAttribute('href');
				a.dom.setAttribute('href', 'javascript:void(0)');
				a.dom.removeAttribute('target'); //, null

				a.on('click', function() {
					Shadowbox.open({
						content: href,
						player: "iframe",
						title: "Quick poll",
						width: 350,
						height: 300
					});
				});
			});
		},

		LoadIndex: function(sender, index) {
			if (this.activeIndex == index) return;
			Ext.fly("Promo" + this.activeIndex).setStyle("display", "none");

			Ext.fly("Promo" + index).fadeIn({
				easing: 'easeIn',
				duration: .3,
				remove: false,
				useDisplay: true
			});

			this.activeIndex = index;
		}
	};
} ();
Ext.onReady(window.PromoToggler.init, window.PromoToggler);