



	/**
	*
	*	Scrollbox
	*
	**/
	
	document.observe('dom:loaded', function() { 
		initScrollbox(); 
		initAddToCart();
	});
	
	scrollboxItems = false;
	currentScrollItem = 0;
	doScroll_running = false;
	initScrollbox = function() {
	
		if($$('.scroll-container').length == 1) {
		
			scrollboxItems = $$('.scroll');
		
			new Insertion.Before($$('.scroll-container')[0], '<div class="scroll-navigation"><a href="#" onclick="doTheScroll(-1); return false;" id="b_scrollup">scroll up</a> <a href="#" onclick="doTheScroll(1); return false;" id="b_scrolldown">scroll down</a></div>');
			
			$('b_scrollup').className = 'scrollbutton-inactive';
		
		}
	
	}
	
	doTheScroll = function(to) {
	
		if(!doScroll_running) {

			nextScrollItem = currentScrollItem + to;

			if(nextScrollItem < 0) { return false; }
			if(nextScrollItem >= scrollboxItems.length) { return false; }



			doScroll_running = true;

			currentScrollItem = nextScrollItem;

			$$('.scroll-navigation a').each(function(a) {
				a.className = '';
			});

			if(currentScrollItem == 0) { $('b_scrollup').className = 'scrollbutton-inactive'; }
			if(currentScrollItem == (scrollboxItems.length-1)) { $('b_scrolldown').className = 'scrollbutton-inactive'; }

			$$('.scroll-innercontainer')[0].morph('margin-top: -' + (nextScrollItem * 277) + 'px', {
				duration: 0.4,
				transition: Effect.Transitions.Cubic,
				afterFinish: function() {
					doScroll_running = false;
				}
			});
			
		}
	
	}
	
	
	
	
	
	
	
	
	initAddToCart = function() {
	
		if($('cartform')) {
		
			$('cartform').observe('submit', addToCart);
			$('cartform').onsubmit = function() { return false; };
		
		}
	
	}
	
	addToCart = function(a) {
	
		$$('p.to-cart input.submit')[0].hide();
		new Insertion.Before($$('p.to-cart input.submit')[0], '<img src="/imgs/loading.gif" id="cartloading" alt="" />');
	
		window.setTimeout(function() {
		
			new Ajax.Request('/cart/', {
				parameters: $('cartform').serialize()+'&action=cart&sub=add',
				onSuccess: function(t) {

					e = eval('('+t.responseText+')');

					$$('p.to-cart input.submit')[0].show();
					$('cartloading').remove();				
					
					if(e.state == 1) {
					
						$('product_info').hide();
						
						new Insertion.Before('product_info', '<div id="product_added_to_cart"><p>The item was added to your shopping cart.</p><p><a href="/cart/">open shopping cart &raquo;</a></p><p><a href="#" onclick="closeCartNotice(); return false;">close</a></p></div>');
						
						if(!$('b_gotocart')) {
						
							new Insertion.Top('content', '<div id="b_gotocart"><a href="/cart/"><img src="/imgs/b_warenkorb.png" alt="" /></a></div>');
						
						}
					
					}

				}
			});
			
		}, 300);
	
	}
	
	
	closeCartNotice = function() {
	
		$('product_added_to_cart').remove();
		$('product_info').show();
	
	}
	
	
	
	
	
	updateQuantity = function(elmt) {
	
		new Ajax.Request('/', {
		
			parameters: $(elmt.parentNode.parentNode).serialize()+'&action=cart&sub=quantity',
			onSuccess: function(t) {
			
				e = eval('('+t.responseText+')');
				window.location.href = '/cart/';
			
			}
		
		});

	}
	
	
	
	
	deleteCartItem = function(elmt) {
	
		new Ajax.Request('/', {
		
			parameters: 'action=cart&sub=delete&id='+elmt,
			onSuccess: function(t) {
			
				e = eval('('+t.responseText+')');
				window.location.href = '/cart/';
			
			}
		
		});
	
	}
	
	
	
	
	
	
	checkOut = function() {
	
		$$('p.submit input')[0].hide();
		new Insertion.Top($$('p.submit')[0], '<div id="cartloading"><img src="/imgs/loading.gif" alt="" /></div>');
		
		window.setTimeout(function() {

			new Ajax.Request('/', {

				parameters: $('checkOutForm').serialize()+'&action=cart&sub=checkout',
				onSuccess: function(t) {

					e = eval('('+t.responseText+')');

					if(e.state == 1) {
					
						$('content').update(e.html);

					}

					else {

						if(e.obj) {
							$(e.obj).shake({
								duration: 0.3 
							});
						}
						
						$$('p.submit input')[0].show();
						$('cartloading').remove();

					}

				}

			});
			
		}, 300);
	
	}
