Event.observe(window, 'load', function(event) {

if((document.all)&&(navigator.appVersion.indexOf("MSIE 7.")!=-1)){
}

else{

var testers = $$('div.module_container');

for (var i=0; i<testers.length; i++){
	if(testers[i].parentNode.getAttribute('id') == 'new_books' || testers[i].parentNode.getAttribute('id') == 'search_results'){
		testers[i].className += ' drag';
	} else {
		testers[i].className += ' no_drag';	
	}
}

 // Make all the products draggable in a special queue
 // so you can apply additional effects later
 $$('div.module_container.drag').each(function(e) {
 new Draggable(e,{
 revert:true,
 reverteffect: function(element, top_offset, left_offset) {
 	var dur = Math.sqrt(Math.abs(top_offset^2)+Math.abs(left_offset^2))*0.02;
	element._revert = new Effect.Move(element, { x: -left_offset, y: -top_offset, duration:0});
 },
 endeffect: function(element) {
	new Effect.Opacity(element, {duration:0.8, from:0.1, to:1.0});
},
 queue:'cart_draggables'
 });
 });

 // Make all the existing cart items draggable in a special queue
 // so you can remove them from the cart later by applying
 // additional effects.
 



 // Create a boolen that will be used to indicate
 // if an item should be removed
 var keepMe = false;

 // Make the cart droppable
 Droppables.add($('bookshelf'),{

 // Accept on products and cart items
 accept:['module_container'],

 // Change the class of the cart to indicate when it's the target
 hoverclass:'drop-it',

 // Add items to the car as necessary
 onDrop:function(draggable, droppable, event) {

 // Items dropped on the cary won't be deleted
 // this will prevent cart item be being removed if
 // they're dropped within the cart.
 keepMe = true;

 // Only add .product-item classes
 if(draggable.className == 'module_container drag' || draggable.className == 'module_container long drag') {
 // Create a new DOM node for the list with
 	newItem = draggable.cloneNode(false);
	newItem2 = draggable;
	newItem.innerHTML = newItem2.innerHTML;
	newItem.className = 'cart_container';
 	$('bookshelf_module').appendChild(newItem);
	newItem.style.cssText = 'display:block;';
 	addTrashObserver2();
	bookshelfCookie2();
 }
 }
 });
 
 function createCookie(name,value,days) {
			if (days) {
				var date = new Date();
				date.setTime(date.getTime()+(days*24*60*60*1000));
				var expires = "; expires="+date.toGMTString();
			}
			else var expires = "";
			document.cookie = name+"="+value+expires+"; path=/";
		}
 
 function bookshelfCookie2() {
			var container = $('bookshelf_module');
			var modules = document.getElementsByClassName('cart_container', 'div');
			var bookshelf_books = new Array();
			for(i=0; i<modules.length; i++){
				var module_id = modules[i].getAttribute('id');
				bookshelf_books.push(module_id);
			}
			createCookie('bookshelf', bookshelf_books, 1);
	}

 
 function addTrashObserver2() {
		var removers = document.getElementsByClassName('trash', 'A');
		var chicklets = document.getElementsByClassName('cart_container', 'DIV');
		
		if (chicklets.length <1) {
			$('bookshelf').className = 'empty';	
		} else {
			$('bookshelf').className = '';	
		}
		
		
		for (var i=0; i<removers.length; i++) {
			ADS.addEvent(removers[i], 'click', function(W3CEVENT){
				var box3 = this.parentNode.parentNode;
				var boxId3 = this.parentNode.parentNode.getAttribute('id');
				var container3 = $('bookshelf_module');
				var trash_can3 = $('trash_can');
				/*createCookie(boxId, "", -1);*/
				box3.className = 'module_container';
				$('trash_can').appendChild(box3);
				$('trash_can').removeChild(box3);
				bookshelfCookie2();
			});
		}
		}
}
});

