$(function() {

$('#menu').find('li').css('opacity','0.8');
$('#footer').find('li').css('opacity','0.8');
$('#shopMenu').find('li').css('opacity','0.8');
$('#cart').css('opacity','0.8');

$('#menu').find('li').hover(function() { $(this).stop().animate({ opacity: 1 }, 50);}, function() {$(this).stop().animate({ opacity: 0.6 }, 600);});
$('#footer').find('li').hover(function() { $(this).stop().animate({ opacity: 1 }, 50);}, function() {$(this).stop().animate({ opacity: 0.6 }, 600);});
$('#shopMenu').find('li').hover(function() { $(this).stop().animate({ opacity: 1 }, 50);}, function() {$(this).stop().animate({ opacity: 0.6 }, 600);});

});
 
function emptyCart(){
	$.ajax({
		url: "/ajax/addToCart.php",
			global: false,
			type: "POST",
			data: "action=empty",
			dataType: "html",
			async:false,
			success: function(msg){
				$('#cart').html(msg);
				$('#cart').animate({ opacity: 1 }, 50, function(){
					$('#cart').animate({ opacity: 0.6 }, 300);
					if(window.location.href == "http://www.orcbite.com/checkout/#") window.location.reload();
					if(window.location.href == "http://www.orcbite.com/my-cart/#") window.location.reload();
				});												
			}								
	});
}


 
initCountdown();
 
$('#arrowBack').click(function() {
	if($('#headlineContainer').position().left < 0 ){ 
		$('#headlineContainer').stop().animate({ left: '+=660' }, 500, function(){
			initCountdown();
		});
	}
});
 
$('#arrowNext').click(function() {
	nextSlide();
});
 
$('.arrow').css('opacity','0.3');
$('.arrow').hover(function() { $(this).stop().animate({ opacity: 1 }, 50);}, function() {$(this).stop().animate({ opacity: 0.3 }, 300);});
 
$('#headlines').hover(function() { $('#sliderCountdown').stop(); }, function() { resumeCountdown(); });
 
function resumeCountdown(){
	
	var timer = 7000 -(7000 / 665) * $('#sliderCountdown').width();
	$('#sliderCountdown').stop().animate({ width: '665px'}, timer , 'linear', function(){
		nextSlide();
	});
}
 
function nextSlide(){	
	if(Math.abs($('#headlineContainer').position().left) < 1890 ){ 
		$('#headlineContainer').stop().animate({ left: '-=660' }, 500, function(){
			$('#sliderCountdown').css('width','0px');	
			initCountdown();
		});
	} else {
		$('#headlineContainer').stop().animate({ left: '0' }, 500, function(){
			$('#sliderCountdown').css('width','0px');
			initCountdown();
		});
	}
}
 
function initCountdown(){
	$('#sliderCountdown').stop().animate({ width: '665px'}, 7000 , 'linear', function(){
		nextSlide();
	});
}
 
