/**
 * aheadWorks Co.
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the EULA
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://ecommerce.aheadworks.com/LICENSE-M1.txt
 *
 * @category   AW
 * @package    AW_Ajaxcartpro
 * @copyright  Copyright (c) 2009-2010 aheadWorks Co. (http://www.aheadworks.com)
 * @license    http://ecommerce.aheadworks.com/LICENSE-M1.txt
 */

window.intPrevious = setInterval(function(){
	if(typeof AW_ACP != 'undefined' && document.body){
		if(typeof aw_cartDivClass == 'undefined'){
			 aw_cartDivClass =
				AW_ACP.theme == 'blank' ?
					'.block-cart' :
					'.mini-cart';

			if(!$$(aw_cartDivClass).length || !$$(aw_cartDivClass)[0].tagName){
				 aw_cartDivClass =  '.block-cart'
			}
		}
		if(typeof aw_topLinkCartClass == 'undefined'){
			 aw_topLinkCartClass = '.top-link-cart';
		}
		if(typeof aw_addToCartButtonClass == 'undefined'){
			 aw_addToCartButtonClass = '.btn';
		}
		if(typeof aw_bigCartClass == 'undefined'){
			 aw_bigCartClass = '.cart';
		}
		if(typeof aw_topcart == 'undefined'){
			 aw_topcart = '#top-cart';
		}

		if (window.location.toString().search('/product_compare/') != -1){
			win = window.opener;
		}
		else{
			win = window;
		}
		clearInterval(intPrevious)
	}
}, 500);

function ajaxcartprodelete(url){
	showProgressAnimation();
	url = getCommonUrl(url)
    new Ajax.Request(url, {
		onSuccess: function(resp){
			try{
				if (typeof(resp.responseText) == 'string') eval('resp = ' + resp.responseText);			
			}catch(e){		
				return;
			}
			hideProgressAnimation();
			__onACPRender()
			updateCartView(resp, '');
		}
	});
}

function updateCartView(resp){
	
	jQuery('#top-cart').fadeOut('fast', function () {
		jQuery('#top-cart').html(resp.top_cart);
		jQuery('#top-cart').fadeIn('fast');
	});
	if (AW_ACP.isCartPage) return updateBigCartView(resp);
	var __cartObj = $$(aw_cartDivClass)[0];
	if(!__cartObj) return false;

	if (typeof(__cartObj.length) == 'number') __cartObj = __cartObj[0];
	var oldHeight = __cartObj.offsetHeight;
	var tmpDiv = win.document.createElement('div');
	tmpDiv.innerHTML = resp.cart;

	var tmpParent = __cartObj.parentNode;
	tmpParent.replaceChild(tmpDiv.firstChild, __cartObj);

	/* Details popup support */
	var __cartObj = $$(aw_cartDivClass)[0];
	var newHeight = __cartObj.offsetHeight;

	if (aw_ajaxcartpro_cartanim == 'opacity'){
        $(__cartObj).hide();
        new Effect.Appear(__cartObj);
	}
	if (aw_ajaxcartpro_cartanim == 'grow'){
        $(__cartObj).hide();
        new Effect.BlindDown(__cartObj);
	}
	if (aw_ajaxcartpro_cartanim == 'blink'){ 
        new Effect.Pulsate(__cartObj);
	}
	updateDeleteLinks();
	updateTopLinks(resp);
}
