$(document).ready(function() {
	
	/* Newsletter Form Validation - is in template */
 	/* Subscribe Form Validation - is in template */
	
	
	/* Special Deals Carousel */
	if($('.deals')){
	$('.deals').jCarouselLite({
        btnNext : ".deals-right",
        btnPrev : ".deals-left",
        auto: 3000,
        speed: 1500,
        visible : 5.7
    });
    }
	
	/* Ad Slideshows */
	if($('.slideshow')){
	$('.slideshow').each(function(){
        $(this).cycle({
            fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
            timeout: 3000,
			speed: 1000,
			random: 1,  //random sequence and start
			fit: 1,		//fit into container
			pause: 1	// pause on hover
   		});
	});   
    }
	
	/* Hero Images Slider */
	if( $('#pictures div.pic-holder') ){	
		var inAnimation = false;
		var all = $('#pictures div.pic-holder');
		var alltext = $('#pictures div.pic-holder div.rimage-text');  
		var zmin = 1001;
		var zmax = zmin + all.length - 1;
		var i = 0; 
		
		all.each(function() { 
		$(this).css('z-index', zmin+i);
		i++; 
		});
		
		function swapFirstLast(Prev) {
		if(inAnimation) return false; //if already swapping pictures just return
		else inAnimation = true; //set the flag that we process a image
		
		//animate( params, [duration], [easing], [callback] ) 
		//hide text 
		alltext.each(function() { $(this).hide() } );
		
		if(Prev){
		    
		    all.each(function() {  
			  if( parseInt($(this).css('z-index')) > zmin) {    
				$(this).css('z-index', parseInt($(this).css('z-index')) - 1); 
		      }else{
		      	$(this).css('left', -$(this).width());
		      	$(this).css('z-index', zmax);
				$(this).animate({'left': '0px'}, 500, 'linear', function() { 
					//show text
					alltext.each(function() { $(this).show() } ); 
				});  
			  }
		    }); 
		
		}
		else{
			
		    all.each(function() {	    	
		    	if( parseInt($(this).css('z-index')) >= zmax) { 
		        $(this).animate({'left': '-' + $(this).width() + 'px' }, 500, 'linear', function() {          	
		          	
		          	all.each(function() {          		
					  if( parseInt($(this).css('z-index')) < zmax) {    
						$(this).css('z-index', parseInt($(this).css('z-index')) + 1); 
				      }
				    });
				    
				    $(this).css('z-index', zmin);
		          	$(this).css('left', 0);
		          	
		          	//show text
					alltext.each(function() { $(this).show() } );
		        });
		      }		
			});
		}   	
		
		inAnimation = false;    
		return false; //don't follow the clicked link
		}
		
		$('#rim-next').click(function() {
		return swapFirstLast(true);
		});
		
		$('#rim-prev').click(function() {
		return swapFirstLast(false);
		});
	}
});