


/**********************************************
*Function addItemsToItem
*Parameters: items_item - the 'item' or the div is made draggable this way
**********************************************/

function addItemToItems(items_item) {
	var dropTarget = $('cart');
	var dropFx = dropTarget.effect('background-color', {wait: false}); // wait is needed so that to toggle the effect,
	
	items_item.addEvent('mousedown', function(e) {
		e = new Event(e).stop();
 
		var clone = this.clone()
			.setStyles(this.getCoordinates()) // this returns an object with left/top/bottom/right, so its perfect
			.setStyles({'opacity': 0.7, 'position': 'absolute'})
			.addEvent('emptydrop', function() {
				this.remove();
				dropTarget.removeEvents();
				
			}).inject(document.body);
 
		dropTarget.addEvents({
			'drop': function() {	
				dropTarget.removeEvents();
				clone.remove();
				
				items_item.removeEvents();
				items_item.inject(dropTarget);
				
				dropFx.start('7389AE').chain(dropFx.start.pass('f8f2e3', dropFx));
				
				//gets the Actor and Rating from the string and splits it
				var theId = items_item.id.split('666666');
				items_item.style.width="90px";
				
				
				
				//the cookie
				place(items_item.style.backgroundImage,items_item.firstChild.firstChild.firstChild.nodeValue,theId[0], theId[1]);
				
				
				//passes variables into the cart
				addItemToCart(items_item,items_item.style.backgroundImage,items_item.firstChild.firstChild.firstChild.nodeValue,cookie_array.length, theId[0], theId[1]);
			
				//adds the elements to the cookie array
				cookie_array.push(items_item.style.backgroundImage);
				cookie_array.push(items_item.firstChild.firstChild.firstChild.nodeValue);
				cookie_array.push(theId[0]);
				cookie_array.push(theId[1]);
				
			},
			'over': function() {
				dropFx.start('98B5C1');
			},
			'leave': function() {
				dropFx.start('ffffff');
			}
		});
 
		var drag = clone.makeDraggable({
			droppables: [dropTarget]
		}); // this returns the dragged element

		drag.start(e); // start the event manual
	});
}

 
 
 /**********************************************
*Function addItemsToCart
*Parameters: cart_item - the 'item' or the div is made draggable this way
* cart_pic- the url of the picture of the movie
*cart_title-title of the movie
*myNum- the number that it is in the array
*cart_Actor- the actor(s) in the movie
*cart_rating - the rating of the movie
**********************************************/
function addItemToCart(cart_item, cart_pic,cart_title,myNum, cart_actor, cart_rating) {

	var dropReturn = $('trash');
	var dropReturnFx = dropReturn.effect('background-color', {wait: false}); // wait is needed so that to toggle the effect,
	cart_item.setAttribute('title',cart_title + " :: "+ "<b> Actor: </b>" + cart_actor + "<b> Rating: </b>" + cart_rating);
	doToolTips(cart_item);
 
	cart_item.addEvent('mousedown', function(f) {
		f = new Event(f).stop();
		
		
		document.getElementById("trashImg").src = "images/newtrashEMPTY.png";
 
		var cloneReturn = this.clone()
			.setStyles(this.getCoordinates()) // this returns an object with left/top/bottom/right, so its perfect
			.setStyles({'opacity': 0.7, 'position': 'absolute'})
			.addEvent('emptydrop', function() {
				this.remove();
				dropReturn.removeEvents();
				
				document.getElementById("trashImg").src = "images/newtrashEMPTY.png";
			}).inject(document.body);
 
		//when it is dropped in the trash
		dropReturn.addEvents({
			'drop': function() {
				dropReturn.removeEvents();
				cloneReturn.remove();
				cart_item.remove();
				
				cart_item.removeEvents();
			
				//splits up the pic url
				var myP = cart_pic.split("(");
				var myP2 = myP[1].split(")");
				
				
				//removes the cookie, passes in the number that it is in the array
				remove(myNum);
				document.getElementById("trashImg").src = "images/newtrashEMPTY.png";
			
			},
			'over': function() {
				//when you rollover the trash it goes full
				document.getElementById("trashImg").src = "images/newtrashFULL.png";
			},
			'leave': function() {
				
				document.getElementById("trashImg").src = "images/newtrashEMPTY.png";
			}
		});
 
		var dragReturn = cloneReturn.makeDraggable({
			droppables: [dropReturn]
		}); // this returns the dragged element		

		dragReturn.start(f); // start the event manual
	});
}






