window.addEvent('domready', function () {
	if($('great_deals')){
		var duration = 300,
			div = document.getElement('div.feature_carousel');
			links = div.getElements('a'),
			carousel = new Carousel.Extra({
				activeClass: 'selected',
				container: 'div.item',
				scroll: 4,
				circular: true,
				mode: 'vertical',
				current: 0,
				interval: 2,
				previous: links.shift(),
				next: links.pop(),
				tabs: links,
				fx: {
					duration: duration
				}
			}),
			removed = 0;		
		function change() {	
			var panel = this.retrieve('panel');		
			if(this.checked) {
				if(!panel) {			
					if(carousel.running) {				
						carousel.addEvent('complete:once', change.bind(this));
						return
					}
					panel = carousel.remove(Math.max(0, this.value - removed));
					if(panel) {
						this.store('panel', panel);
						removed++;
					}
					this.checked = !!panel
				}			
			} else {		
				if(panel) {			
					this.eliminate('panel');
					removed--;
					carousel.add(panel.panel, panel.tab.inject(div.getFirst(), 'after'), this.value)
				}
			}
		}	
		$$('input.remove').addEvents({click: change, change: change})
	}
});

function setForeground(component, hue) {
	
	if (component == "billboard")
	{
		var title = $('billboard_title');
		title.removeClass('light');
		title.removeClass('dark');
		title.addClass(hue);
	}
}

/* -------------------------------------------------------------------

	STORE GRID

---------------------------------------------------------------------- */
var storeGrid = {
	popUp : null,
	popUpEffect : null,
	popUpTimer: null,
	closeTime: null,
	currStore: null,
	
	initialize : function() {
		storeGrid.popUp = $('store_grid_popup');
		
		arrStores = $('store_grid').getElements('.store');
		
		arrStores.each(function(item, index, array){
			item.addEvent('mouseenter', function(){
				storeGrid.currStore = this;
				storeGrid.popUpTimer = setTimeout('storeGrid.showPopup()', 400);
			});
			
			item.addEvent('mouseleave', function(){
				clearTimeout(storeGrid.popUpTimer);			
			})
		});
		
		storeGrid.popUp.addEvent('mouseleave', function(){ 
			storeGrid.closeTimer = setTimeout('storeGrid.hidePopup()', 400);
		});
		
		storeGrid.popUp.addEvent('mouseenter', function(){ 
			clearTimeout(storeGrid.closeTimer);
		});
		
		storeGrid.popUpEffect = new Fx.Morph(storeGrid.popUp, {duration: 300, transition: Fx.Transitions.Quad.easeOut});
	},
	
	showPopup : function() {
		clearTimeout(storeGrid.closeTimer);
		
		storeGrid.popUpEffect.cancel();
		storeGrid.popUp.setStyle('opacity', 0);
		
		var storeID = storeGrid.currStore.id;
		
		var storePopupContent = $(storeID + '_pop_content');
		var storeCoords = storeGrid.currStore.getCoordinates($('store_grid'));
		var newTop = storeCoords.top - 20;
		var newLeft = storeCoords.left - 25;		
		
		var clonedContent = storePopupContent.clone();
		var popUpMiddle = storeGrid.popUp.getElement('.middle');
		popUpMiddle.set('html', '');
		clonedContent.inject(popUpMiddle);
		
		storeGrid.popUp.setStyles({
			'top':newTop,
			'left':newLeft
		});
		
		storeGrid.popUp.setStyles({
			'display': 'block',
			'opacity': 0,
			'width': 200
		})
		
		// only do run the animation if it's not IE
		if (Browser.Engine.trident) {	
			storeGrid.popUpEffect.set({
				'opacity': 1
			});
		}
		else {
			storeGrid.popUpEffect.start({
				'opacity': 1
			});
		}
		
	},
	
	hidePopup : function() {
		// only do run the animation if it's not IE
		if (Browser.Engine.trident) {	
			storeGrid.popUpEffect.set({
				'opacity': 0
			});
		}
		else {
			storeGrid.popUpEffect.start({
				'opacity': 0
			});
		}
	}
}
