$(document).ready(function(){
    /* COTENT */
    
    var speedSlide = 200;
    var speedItemSelect = 500;
    /* for auto scroll*/
    var cooldown = 12000; //milli-seconds

    /* auto scroll  */
    var showProductsAuto = setInterval("nextProduct("+speedSlide+")", cooldown);
    /* MENU CHOICE */
	
    /* products */
     $('.productShow_choice_item').click(function() {
        clearInterval(showProductsAuto); //stop autoscroll
		// VIEW PRODUCT
        var newestElementId = $(this).attr('num');
		
         //hide actual element
        $(".productShow_info_item:visible").hide('slide', {direction: 'left'}, speedSlide, function() {
              //show the newest
             $('#item'+newestElementId).show('slide', {direction: 'right'}, speedSlide);
        });
		// ITEM SELECT
		var pos = $(this).offset(),
			pos2 = $('#productShow_choice_select').offset();
		
		
        $("#productShow_choice_select").animate({
                backgroundPosition: (pos.left-pos2.left) + 'px ' + '0px'
            },
            speedItemSelect,
            'easeOutQuart'
        );
    });
    /*  menu */
    // $('.productShow_choice_item').click(function() {
        // clearInterval(showProductsAuto);
		// var pos = $(this).offset(),
			// pos2 = $('#productShow_choice_select').offset();
        // $("#productShow_choice_select").animate({
                // backgroundPosition: (pos.left-pos2.left) + 'px ' + '0px'
            // },
            // speedItemSelect,
            // 'easeOutQuart'
        // );
    // });
    /* discover it button */
    $('.discoverIt').hover(function() {
        enableHover($(this));
    }, function() {
        disableHover($(this));
    });
    /* MENU PRODUCT */
    $('.productShow_info_item_menu ul li a').hover(function() {
		$(this).stop().animate({ paddingLeft: 45 }, 'fast');
	}, function() {
		$(this).stop().animate({ paddingLeft: 35 }, 'fast');
	});
});
function nextProduct(speedSlide) {
		
	var nbDefault = parseInt($("#productShow_choice_select").attr('default'));
	var current = parseInt($("#productShow_choice_select").attr('current'));
	var nbMax = parseInt($(".productShow_choice_item").length);
	
	var newestElementId = 1;
	
	if(current+1 <= nbMax) { //back to first
		newestElementId = current + 1;
	}else { //show next
		newestElementId = nbDefault;
	}
	$("#productShow_choice_select").attr('current', newestElementId);
	
	// Show info
	$(".productShow_info_item:visible").hide('slide', {direction: 'left'}, speedSlide, function() {
		  //show the newest
		 $('#item'+newestElementId).show('slide', {direction: 'right'}, speedSlide);
	}); 
	// Select item
	var pos = $('.productShow_choice_item[num="'+newestElementId+'"]').offset(),
		pos2 = $('#productShow_choice_select').offset();
	
	
	$("#productShow_choice_select").animate({
			backgroundPosition: (pos.left-pos2.left) + 'px ' + '0px'
		},
		500,
		'easeOutQuart'
	);
}

/* function nextProduct(speedSlide) {
	currentId = $("#productShow_choice_select").attr('class');
    var productVisible = $(".productShow_info_item:visible");
    next = productVisible.next('div.productShow_info_item');
    
    if(next.html() != null) {
         //hide actual element
        $(productVisible).hide('slide', {direction: 'left'}, speedSlide, function() {
              //show the newest
             $(next).show('slide', {direction: 'right'}, speedSlide);
        });
		// ITEM SELECT
		var pos = $(this).offset(),
			pos2 = $('#productShow_choice_select').offset();
        $("#productShow_choice_select").animate({
                backgroundPosition: (pos.left-pos2.left) + 'px ' + '0px'
            },
            speedItemSelect,
            'easeOutQuart'
        );
       
    }else {
		$("#productShow_choice_select").attr('class', $("#productShow_choice_select").attr('default'));
          //hide actual element
        $(productVisible).hide('slide', {direction: 'left'}, speedSlide, function() {
              //show the newest
             $(".productShow_info_item:first-child").show('slide', {direction: 'left'}, speedSlide);
        });
    }
        
} */
