jQuery(function($){
		$('#style-assistant').children('div').css('width',($('#style-assistant').find('div').find('a:first').width() * $('#style-assistant').find('div').find('a').size()))

		/*
		$('.move-right').live('click', function(){
			$('#style-assistant').children('div').animate({
				'left' : '-=' + $('#style-assistant').children('div').children('a:first').width() + 'px'
			}, function(){
				$('#style-assistant div a:first').appendTo($('#style-assistant div'));
				$('#style-assistant div').css('left','0px')
			})
		})
		$('.move-left').live('click', function(){
			$('#style-assistant div a:last').prependTo($('#style-assistant div'));
			$('#style-assistant div').css('left',-$('#style-assistant').children('div').children('a:first').width() + 'px')
			$('#style-assistant').children('div').animate({
				'left' : '+=' + $('#style-assistant').children('div').children('a:first').width() + 'px'
			})
		})	
		
		*/
		
		
		var interval = '';
		var isAnimating = false;
		
		function moveLeft() {
			if (!isAnimating) {
				isAnimating = true;
				$('#style-assistant div a:last').prependTo($('#style-assistant div'));
				$('#style-assistant div').css('left',-$('#style-assistant').children('div').children('a:first').width() + 'px');
				$('#style-assistant').children('div').animate({
					'left' : '+=' + $('#style-assistant').children('div').children('a:first').width() + 'px'
				}, 950, "linear", function() {
					isAnimating = false;
				});
				
			}
		}
		
		function moveRight() {
			if (!isAnimating) {
				isAnimating = true;
				$('#style-assistant').children('div').animate({
					'left' : '-=' + $('#style-assistant').children('div').children('a:first').width() + 'px'
				}, 950, "linear", function(){
					$('#style-assistant div a:first').appendTo($('#style-assistant div'));
					$('#style-assistant div').css('left','0px');
					isAnimating = false;
				});
			}
		}
		
		
		
		
		$('.move-right').live('mouseover', function(){
			moveRight();
			interval = setInterval(moveRight, 1000);
		})
		
		
		$('.move-left').live('mouseover', function(){
			moveLeft();
			interval = setInterval(moveLeft, 1000);
		})
		
		
		$('.move-right, .move-left').live('mouseleave', function(){
			clearInterval(interval);
		})
		
		
	
	
	
	$('#style-assistant a').live('click', function(e) {

			e.preventDefault();

			var id = $(this).attr('href').split('#')[1];

			$.get('/lookbook/welcome/index/'+id, function(data) {
				$('#body-container').html(data);
				
				$('.products-shop-image img').load(function(){
					$(this).closest('.products-shop-item-container').addClass('hasimg');
					$(this).parent().siblings('.products-shop-details').hide();
				});
			});

		});	

	if ($('#style-assistant-product').size() > 0) {
		
		$('#style-assistant-product').children('.style-assistant-product-wrapper').css('width',($('#style-assistant-product').find('.style-assistant-product-wrapper').find('.style-assistant-product-item:first').width() * $('#style-assistant-product').find('.style-assistant-product-wrapper').find('.style-assistant-product-item').size()));


		var count_of_preloaded_images = 15;

		loadImages(count_of_preloaded_images);


		$('.move-right-product').live('click', function(){
			$('#style-assistant-product').children('.style-assistant-product-wrapper').stop(true,true).animate({
				'left' : '-=' + '186px'
			}, function(){
				$('#style-assistant-product .style-assistant-product-wrapper .style-assistant-product-item:first').appendTo($('#style-assistant-product .style-assistant-product-wrapper'));
				$('#style-assistant-product .style-assistant-product-wrapper').css('left','30px');
				loadImages(count_of_preloaded_images);
			});
		});


		$('.move-left-product').live('click', function(){
			$('#style-assistant-product .style-assistant-product-wrapper .style-assistant-product-item:last').prependTo($('#style-assistant-product .style-assistant-product-wrapper'));
			$('#style-assistant-product .style-assistant-product-wrapper').css('left','-150px')
			$('#style-assistant-product').children('.style-assistant-product-wrapper').stop().animate({
				'left' : '+=' + $('#style-assistant-product').children('.style-assistant-product-wrapper').children('.style-assistant-product-item:first').width() + 'px'
			}, function() {
				loadImages(count_of_preloaded_images);
			});
		});
	}


	function loadImages(num) {
		var count = $('.style-assistant-product-item').size();
		for (var i = 0; i < count; i++) {
			if ((i < num) || (i > (count - 3))) {
				var t = $('.style-assistant-product-item').eq(i);
				var imageName = t.attr("title").split("#");
				if (t.find('.style-assistant-product-image img').size() == 0) {
					t.find('.style-assistant-product-image a').append('<img src="/data/products-thumb-xl/' + imageName[0] + '" width="186" height="186" alt="Product ' + imageName[1] + '" />');
				}
			}
		}

	}


});

