$(document).ready(function() {
	
	// custom easing
	jQuery.easing['jswing'] = jQuery.easing['swing'];
	
	jQuery.extend( jQuery.easing,
	{
		
		easeInQuad: function (x, t, b, c, d) {
			return c*(t/=d)*t + b;
		},
		easeOutQuad: function (x, t, b, c, d) {
			return -c *(t/=d)*(t-2) + b;
		}
		
	});

	// font replacment
	Cufon.replace('ol#products > li > div > p > em, h1, h2', 'div#content > div#col-right > ol.subnav > li.header');
	
	// product sliding stuff
	function product_slide() {
		
		// applying class 'last' to every 5th element
		$('ol#products > li').each(function (i) {
			if(i%3 == 2) {
				$(this).addClass('last');	
			}
		});

		$('ol#products > li').mouseenter(function() {
			$(this).children('div').animate({
				left: "-180px"
			}, 200, "easeOutQuad");
		});
		
		$('ol#products > li').mouseleave(function() {
			$(this).children('div').animate({
				left: "0"
			}, 200, "easeInQuad");
		});
		
	}
	
	// homepage sliding stuff
	function homepage_slide() {
		
		current_left_value = 6;
		
		$('ul#scroller > li > a > img').mouseenter(function(){
			$(this).css("opacity", "0.75");											 
		});
		
		$('ul#scroller > li > a > img').mouseleave(function(){
			$(this).each(function() {
				$(this).css("opacity", "1");					  
			});
		});
		
		$('a.right-arrow').click(function(){

			if(current_left_value > -2500) {
				if(current_left_value < -2600){
					//current_left_value = current_left_value - 390;
					current_left_value = current_left_value - 520;
				} else {
					current_left_value = current_left_value - 520;
				}
				$('ul#scroller').animate({
					left: current_left_value					 
				}, 550, "easeOutQuad");
				
			}
			
		});
		
		$('a.left-arrow').click(function(){

			if(current_left_value < 5) {
				if(current_left_value < -2080){
					//alert($('ul#scroller').css("left"));
					//current_left_value = current_left_value + 390;
					current_left_value = current_left_value + 520;
				} else {
					current_left_value = current_left_value + 520;
				}
				$('ul#scroller').animate({
					left: current_left_value					 
				}, 550, "easeInQuad");
				
			}
			
		});
		
	}

	
	homepage_slide();
	product_slide();
	
});
