window.addEvent('domready', function(){
	var divs = $$(['docs', 'js', 'html', 'css']);
	divs.each(function(div){
		var link = $(div.id + 'code');
		div.setStyle('display', 'none');
		link.addEvent('click', function(e){
			e = new Event(e);
			divs.each(function(other){
				if (other != div) other.setStyle('display', 'none');
			});
			div.setStyle('display', (div.getStyle('display') == 'block') ? 'none' : 'block');
			e.stop();
		});
	});
});
		var i = 0;
		function drag_tag(page)
		{
		
		//window.addEvent('domready', function(){
			var dropArticles = $('cart');
			var dropFxArticles = dropArticles.effect('background-color', {wait: false}); // wait is needed so that to toggle the effect,
			
			$$('.item').each(function(item){
				//alert($$('.item').length);
				item.addEvent('mousedown', function(e) {						
				
					e = new Event(e).stop();
					
					var cloneArticles = this.clone()
						
						.setStyles(this.getCoordinates()) // this returns an object with left/top/bottom/right, so its perfect
						.setStyles({'opacity': 1, 'position': 'absolute'})
						.addEvent('emptydrop', function() {							
							this.remove();
							dropArticles.removeEvents(); // On le lache hors du panier							
						}).inject(document.body);
			
					dropArticles.addEvents({
						'drop': function() {
							dropArticles.removeEvents();
							cloneArticles.remove();
							item.clone().inject(dropArticles);
							//dropFxArticles.start('ffffff').chain(dropFxArticles.start.pass('ffffff', dropFxArticles)); // On le lache dans le panier
							//alert('ff'); return false;
							loadCart(cloneArticles.innerHTML,'add');							
						},
						'over': function() {
							dropFxArticles.start('ffffff');
						},
						'leave': function() {
							dropFxArticles.start('ffffff');
							//cloneArticles.remove();
						}
					});
			
					var dragArticles = cloneArticles.makeDraggable({
						droppables: [dropArticles]
						
					}); // this returns the dragged element
			
					dragArticles.start(e); // start the event manual
					//alert(i);
				});
			
			});
		//}); 
		}
		drag_tag(page);
		
		
		function loadCart(which, action)
		{
			var myCART = which;		
			//alert(myCART);
			var myXHR = new XHR({
			method: 'post', 
				onSuccess: function(){
					this.response = {
						'text': this.transport.responseText,
						'xml': this.transport.responseXML
					};
					
					var theResponse= this.transport.responseText;					
					document.getElementById('cart').innerHTML = theResponse;
					//drag_tag(page);
				}
			}).send('script/load_cart.php', 'val='+myCART);
		}
		
		function delCart()
		{
			var myXHR = new XHR({
			method: 'get', 
				onSuccess: function(){
					this.response = {
						'text': this.transport.responseText,
						'xml': this.transport.responseXML
					};
					var theResponse= this.transport.responseText;
					document.getElementById('myCartReloaded').innerHTML = theResponse;
					drag_tag();
				}
			}).send('script/delCart.php');
		}
		
		

