var strRootPath = "";
//var strRootPath = "/portfolio/mymedicalchest.com.group/mymedicalchest.com.2008.01.12";


window.addEvent('domready', function(){
	getContentLoad("cart",strRootPath + "/products/ajax_load_book_shop.php");
	getContentLoad("cart_total",strRootPath + "/products/ajax_load_cart_total.php");

	// Tips
	var Tips1 = new Tips($$('.item'));


	// Drag Shop
	var drop = $('cart');
	var dropFx = drop.effect('background-color', {wait: false});
	
	$$('.item').each(function(item){
	
		item.addEvent('mousedown', function(e) {
			e = new Event(e).stop();
			var clone = this.clone()
				.setStyles(this.getCoordinates())
				.setStyles({'opacity': 0.7, 'position': 'absolute'})
				.addEvent('emptydrop', function() {
					this.remove();
					drop.removeEvents();
				}).inject(document.body);
	
			drop.addEvents({
				'drop': function() {				
					getContentLoad("cart",strRootPath + "/products/ajax_load_book_shop.php?id="+item.getAttribute('book')+"&action=add");
					getContentLoad("cart_total",strRootPath + "/products/ajax_load_cart_total.php");
					
					$$('.tool-tip').setStyle('visibility', 'hidden');

					drop.removeEvents();
					clone.remove();
					dropFx.start('FFFFCC').chain(dropFx.start.pass('ffffff', dropFx));
					
				},
				'over': function() {
					dropFx.start('FFFFCC');
				},
				'leave': function() {
					dropFx.start('ffffff');
				}
			});
	
			var drag = clone.makeDraggable({
				droppables: [drop]
			});
	
			drag.start(e);
		});
	
	});
}); 


/*
AJAX
*/
function newXmlHttp(){
	var xmlhttp = false;
	
	try{
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	}catch(e){
		try{
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}catch(e){
			xmlhttp = false;
		}
	}

	if(!xmlhttp && document.createElement){
		xmlhttp = new XMLHttpRequest();
	}
	return xmlhttp;
}

/*
getContentLoad(strDivName,strUrl)
*/
function getContentLoad(strDivName,strUrl){
	var xmlhttp = Array();
	xmlhttp[strDivName] = newXmlHttp();
	xmlhttp[strDivName].onreadystatechange=function(){
		if(xmlhttp[strDivName].readyState == 4 && xmlhttp[strDivName].status==200){
			document.getElementById(strDivName).innerHTML = xmlhttp[strDivName].responseText;
		}else{
			document.getElementById(strDivName).innerHTML = "<img src='" + strRootPath + "/images/loading.gif'>";
		}
	}
	xmlhttp[strDivName].open("GET", strUrl, true);
	xmlhttp[strDivName].send(null); 
}
