﻿

window.addEvent('domready', function(){

//on page load, make the timer start
		//window.addEvent('load', function() {
  		//window.alert('it has started')
  		//});



//new rollover effects
//commeneted all of this out because it was a mess in FF3, choppy and made product of the week disappear MS 2-10-09

//	fadeFx = new Fx.Styles('gottahaveit', { duration: 100, transition: Fx.Transitions.Sine.easeOut });
	
//	$('rollit').addEvent('mouseenter', function(f){
//		f = new Event(f);
//		fadeFx.start({ wait: false, 'margin-top': [-10] });
//		f.stop();
//	});
	
//		$('rollit').addEvent('mouseleave', function(g){
//		g = new Event(g);
//		fadeFx.start({ wait: false, 'margin-top': [0] } );
//		g.stop();
//	});
	
//		$('gottahaveit').addEvent('mouseenter', function(h){
//		h = new Event(h);
//		fadeFx.start({ wait: false, 'margin-top': [-10] });
//		h.stop();
//	});
	
//		$('gottahaveit').addEvent('mouseleave', function(i){
//		i = new Event(i);
//		fadeFx.start({ wait: false, 'margin-top': [0] } );
//		i.stop();
//	});
	
//previously commented out

//	$('gottahaveit').addEvent('mouseleave', function(i){
//		i = new Event(i);
//		fadeFx.start({ wait: false, 'margin-top': [0], 'opacity': [.7] } );
//		i.stop();
//	});


//define the sideways scroller movement
	
	/*	BEGIN
		---------------------------------------- */
	
	// Variables
	var productsPerSection = 5; // Change this to reflect the number of products on a single 'page'. 
	var totalProducts = 0;
	var productCounter = 0; 
	var scrollPoints = new Array(['item_1']); // Array containing the DIV ID's for each section to scroll.toElement, first DIV added dy default.
	var currentIndex = 0; // Current position in the Array, used to calculate next scroll action
	// Target DOM
	var leftArrow = $('leftarrow'); 
	var rightArrow = $('rightarrow'); 
	var products = $$('#marquis div');
	// Count the Products
	products.each(function(el){totalProducts = totalProducts+1});
	// MOOTOOLS Scroll Class
	var scroller = new Fx.Scroll('marquiswrapper', {
	   wait: false,
	   duration: 1500,
	   transition: Fx.Transitions.Quint.easeInOut,
	   onComplete: disableButtons
	});

	// Establish Scroll Points
	establishScrollPoints(); 
	// Assign Button Actions
	leftArrow.addEvent('click', function(){
		currentIndex = currentIndex-1;
		if(currentIndex < 0) currentIndex = 0; //currentIndex = (scrollPoints.length-1);
		if(currentIndex <= (scrollPoints.length-1)){
			scroller.toElement(''+scrollPoints[currentIndex]+'');
		}
	});
	rightArrow.addEvent('click', function(){
		currentIndex = currentIndex+1;
		if(currentIndex > (scrollPoints.length-1)) currentIndex = (scrollPoints.length-1) //currentIndex = 0;
		if(currentIndex >= 0){
			scroller.toElement(''+scrollPoints[currentIndex]+'');
		}
	});


	
	/*	END
		---------------------------------------- */


	/*	FUNCTIONS
		---------------------------------------- */	
	function establishScrollPoints(){
		if((productCounter+productsPerSection) < totalProducts){
			scrollPoints.extend(['item_'+(productCounter+productsPerSection+1)]);
			productCounter = productCounter+productsPerSection; 
			establishScrollPoints();
		}
	}	
	function disableButtons(){
		if(currentIndex == (scrollPoints.length-1)) {
			rightArrow.setStyle('opacity','0.5');
			leftArrow.setStyle('opacity','1');
		}
		else if(currentIndex == 0) {
			leftArrow.setStyle('opacity','0.5');
			rightArrow.setStyle('opacity','1');
		}
		else {
			leftArrow.setStyle('opacity','1');
			rightArrow.setStyle('opacity','1');
		}
	}
	
	
	
 
 
 //tool tips function
var Tips2 = new Tips($$('.tooltips'), {
	initialize:function(){
		this.fx = new Fx.Style(this.toolTip, 'opacity', {duration: 500, wait: false}).set(0);
	},
	onShow: function(toolTip) {
		this.fx.start(1);
	},
	onHide: function(toolTip) {
		this.fx.start(0);
	},
	offsets: {'x': 17, 'y': 12}
});
  		
  		
//scripts for the contest boxes

									
	contestFx = new Fx.Styles('potw',
		{
		duration: 200, transition: Fx.Transitions.Quad.easeOut
	});
	
		$('potw').addEvent('mouseenter', function(l)
		{
		l = new Event(l);
		contestFx.start({ wait: false, 'background-color': ['#333333'], 'height': [140], 'opacity': [.9] });
		l.stop();
	});
	
		$('potw').addEvent('mouseleave', function(m)
		{
		m = new Event(m);
		contestFx.start({ wait: false, 'background-color': ['#666666'], 'height': [10], 'opacity': [.8] });
		m.stop();
	});
	

});