
function ps_hide_children(children,childnumber) {
	var hidden = false;
	for (var i=0;i<children.length;i++) {
		if (i>childnumber) {
			jQuery(children[i]).hide();
			hidden = true;
		}
	}
	return hidden;
}

function showCart(url) {
	jQuery('#cart_load_indicator').show();
	jQuery.get(url,function(html) {
        	jQuery('#cart_container').hide();
		$('cart_container').innerHTML = html;
		jQuery('#cart_container #lightbox').height(jQuery('#wrap_all').height());
		jQuery('#cart_container #cart_container').remove(); // remove duplicates
		jQuery('#cart_container').html(jQuery('#cart_container #ajaxemulator').html());
		jQuery('#cart_container').show();
		jQuery('#cart_load_indicator').hide();
		jQuery('html, body').animate({scrollTop:0}, 'fast');
		jQuery('#close_btn').click(function() {jQuery('#lightbox').remove();});
		jQuery('#lightbox').show();
	});
}

function updateAvailability2(spConfig)
{
    var productId;
        productId= null;
    for(var i=spConfig.settings.length-1;i>=0;i--){
        var selected = spConfig.settings[i].options[spConfig.settings[i].selectedIndex];
        if(selected.config){
        	if (productId == null)
	            productId = selected.config.products[0];
        }
    }

    var information = null;
    for (var i=0;i<spConfig.config.subProductsAvailability.length;i++)
    {
    	if (spConfig.config.subProductsAvailability[i].id == productId)
    		information = spConfig.config.subProductsAvailability[i];
    }

    jQuery('#attic').hide();
    
    if (information && information.availability != 'In Stock') {
            jQuery('#addtocart_btn').css('opacity','0.4');
	    jQuery.post('/ajaxcat/check/index/id/'+spConfig.config.productId,{productId:productId,availability:information.availability},function(response) {
			jQuery('#placeholder').html(response);
			jQuery('#placeholder').show('slow');
                        jQuery('#addtocart_btn').css('opacity','1');
			//jQuery('html, body').animate({ scrollTop: jQuery("#options_wrap").offset().top }, 500);
	    });
    }
}

function addToCart(id) {
	jQuery.post('/checkout/cart/add',{product:id,qty:1,related_product:''},function (response) {
		jQuery('#attic').html(response);
		jQuery('#attic #attic').remove(); // remove duplicates
		jQuery('#attic').html(jQuery('#attic #ajaxemulator').html());
		jQuery('#attic #lightbox').height(jQuery('#wrap_all').height());
		if (jQuery('#quantity_input').val() > 1)
		jQuery('#item_added_qty').html(jQuery('#quantity_input').val()+' Items');
		jQuery('#attic').show();
    	jQuery('#addtocart_btn').css('opacity','1');		
	});
}

function reloadMinicart(url) {
	jQuery('html, body').animate({scrollTop:0}, 'fast');
        if(jQuery('#grand_total').length) reloadPart('delivery_methods');
	jQuery('#minicart').load(url, function () {
		jQuery('.minicart_btn').click(function () { 
			jQuery('#cart_flyout').toggle();
		});
		jQuery('#cart_flyout').hover(function() {},function() {
				$(this).hide();
			});
		});	
}
