$(function() {
	$('#bottom-cart-text-field').click(function() {
		$(this).toggleClass('up');
		$('#select-arrow').toggleClass('select-arrow-down');
		$('#bottom-cart-item-list').slideToggle(250);
	});
	$('#delivery_method_value').change(function() {
		if ($(this).val() == 3) {
        		$('#officesList').empty();
			$('#matkahuolto_loading').show();
        		$('#officesList').load('/store/ajax/getDeliveryOffices', function () {
				$('#matkahuolto_loading').hide();
			});
        	}
        	else {
        		$('#officesList').empty();
        	}
        });

	$('.add2cart').click(function() {
		$.add2cart($('#slideshow a:visible'), function() {
                    $('#bottom-cart-text-field').children(':first').text('Tuote lisätty ostoskoriin').end().effect('highlight', {}, 1000, function() {
                        $('#bottom-cart-text-field').load('page/10/ajax_cart', function() {
                            $('#cart-amount').html($('#bottom-cart-item-text strong').text());
                        });                        
                    });
			//var addition = parseInt( $('input[name*="amount"]').attr("value") );
			//var cart_count = parseInt( $('#cart-amount').html() );
			//$('#cart-amount').html($('#bottom-cart-item-text strong').text);
		 	//$('#bottom-cart-text-field').children(':first').text('Tuote lisätty ostoskoriin').end().effect('highlight', {}, 3000, function() {
			//	$('#bottom-cart-item-text').html('Ostoskorissasi on <strong> ' + (cart_count + addition) + ' </strong>tuotetta');
			//});
			//$('#bottom-cart-item-list ul').append('<li><a href="#">'+ $('#product-details h1').html() +' (' + $('#product-details span').val() + ')</a><span class="bottom-cart-amount-indicator">x '+ addition+'</span></li>');
                        
		});
		return false;
	});

});

(function($) {

	$.extend({
		add2cart: function(source_id, callback) {

      			var $source = source_id;
      			var $target = $('#target');

			var $shadow = $('<div/>', {
				css: {
					display: 'none',
					backgroundColor: '#fff',
					border: '1px solid #CFDDB1',
					top: '0px',
					position: 'static',
					zIndex: 10000
					},
				html: $('<img>', {
					src: $source.attr('href'),
					width: '100%'
				})
			}).prependTo('body');

      			$shadow.width($source.css('width')).height($source.css('height'))
				.css({
					top: $source.offset().top,
					left: $source.offset().left,
					opacity: 0.3				})
				.show();
			$shadow.css('position', 'absolute');

      			$shadow.animate({
				width: $target.innerWidth(),
				height: $target.innerHeight(),
				top: $target.offset().top,
				left: $target.offset().left
			}, { duration: 800 }).animate({ opacity: 0 }, { duration: 300, complete: callback });
      		}
	});
})(jQuery);

