﻿jQuery(document).ready(function(){
	var $ = jQuery;
	
	/* featuredBoxes */
	var featuredBoxes = $('#featuredBoxes').size();
	if(featuredBoxes>0){
		var featuredBoxVel = 800;
		var doNextTime = 5000;
		var doNextTimeFirst = 10000;
		var currentN = 0;
		
		$('#featuredBoxes .featuredBoxesContent').fadeOut(0);
		$('#featuredBoxes .navigation a').eq(0).addClass('current');
		$('#featuredBoxes .featuredBoxesContent').eq(0).addClass('current');
		$('#featuredBoxes .featuredBoxesContent.current').fadeIn(0);
				
		$('#featuredBoxes .navigation a').click(function(){
			if( !$(this).hasClass('current') ){
				
				currentN = $(this).index();
				doNextFeatured(currentN);
			}
			return false;
		});
		function doNextFeatured(currentN, loop){
				var currentDiv = $('#featuredBoxes').find('.featuredBoxesContent').eq(currentN);
				
				$('#featuredBoxes .featuredBoxesContent.current').fadeOut(0);
				currentDiv.addClass('current').fadeIn(featuredBoxVel, function(){
					if(loop)doNextFeaturedSlide(doNextTime);
				});
				
				$('#featuredBoxes .navigation a.current').removeClass('current');
				$('#featuredBoxes .navigation a').eq(currentN).addClass('current');
			}
		
		$('#featuredBoxes').append('<div id="rel"></div>');
		var maxFeatured = $('#featuredBoxes .navigation a').size();
		
		function doNextFeaturedSlide(time){
			$('#featuredBoxes #rel').stop().animate({'left':'520px'}, time, function(){
				
				$('#featuredBoxes #rel').css('left','0px');
				currentNN = $('#featuredBoxes .navigation a.current').index();
				currentNN++;
				if(currentNN >= maxFeatured){
					currentNN = 0;
					}
				doNextFeatured(currentNN, true);

				});
			}
		doNextFeaturedSlide(doNextTimeFirst);
		
		$('#featuredBoxes').hover(
			function(){
				$('#featuredBoxes #rel').stop();
				},
			function(){
				$('#featuredBoxes #rel').css('left','0px');
				doNextFeaturedSlide(doNextTime);
				}
			);
	}
	
	/* featuredBoxes END */
	
});
	
