
function getLinkParam(_this) {
	var url = $(_this).attr('href').split("?");
	return url[1];
}

$(document).ready(function () {
	$('#add_to_cart').removeAttr('onclick');
	////////////////////////////////////////////////////////////////////////////////////////////////////[ #add_to_cart ]
	$('#add_to_cart').live('click', function () {
		var img_selector = '#image';
		if($(img_selector).offset()){
			img_selector = '#image';
		}else{
			img_selector = '.MagicZoomPlus img';
		}
		var image = $(img_selector).offset();
		
		var cart  = $('#module_cart').offset();
		
		
		var temp = $('<img src="' + $(img_selector).attr('src') + '" id="temp" style="position: absolute; top: ' + image.top + 'px; left: ' + image.left + 'px;z-index:1000;" />');
		
		$('body').before(temp);

		params = {
			top : cart.top + 'px',
			left : cart.left + 'px',
			opacity : 0.0,
			width : $('#module_cart').width(),  
			height : $('#module_cart').height()
		};		

		$(temp).animate(params, 'slow', false, function () {
			$(temp).remove();
			$('#module_cart .middle').html('<div class="ajax_load">&nbsp;</div>');
			
			$.ajax({
				type: 'post',
				url: 'index.php?route=module/cart/callback',
				dataType: 'html',
				data: $('#product :input'),
				success: function (html) {
					$('#module_cart .middle').html(html);
				}		
			});			
		});
	
		return false;
	});	

	////////////////////////////////////////////////////////////////////////////////////////////////////[ .add_to_cart ]
	$('.add_to_cart').removeAttr('onclick').live('click', function () {
		var _this = this;
		var link_parm = getLinkParam(_this);
		
		var parent = $(_this).parent(".item");
		var image_obj = $('.thumb img', parent);
		var image = $(image_obj).offset();
		var cart  = $('#module_cart').offset();
		
		var temp = $('<img src="' + $(image_obj).attr('src') + '" id="temp" style="position: absolute; top: ' + image.top + 'px; left: ' + image.left + 'px;z-index:1000;" />');
		$('body').append(temp);

		params = {
			top : cart.top + 'px',
			left : cart.left + 'px',
			opacity : 0.0,
			width : $('#module_cart').width(),  
			height : $('#module_cart').height()
		};		

		$(temp).animate(params, 'slow', false, function () {
			// Animation complete.
			$(temp).remove();
			$('#module_cart .middle').html('<div class="ajax_load">&nbsp;</div>');
			
			$.ajax({
				url: 'index.php?route=module/cart/callback',
				data: link_parm,
				success: function (html) {
					$('#module_cart .middle').html(html);
				}	
			});			
			
		});
		return false;
	});			
	////////////////////////////////////////////////////////////////////////////////////////////////////[ .add_to_cart ]
});
