/**
 * Send ajax request to the Magento store in order to insert dynamic content into the
 * static page delivered from Varnish
 *
 * @author Fabrizio Branca
 */
//jQuery.noConflict();
jQuery(document).ready(function($) {

	var data = { getBlocks: {} };
    jQuery.ajaxSetup({cache: false});
	// add placeholders
	jQuery('.placeholder').each(function() {
		data.getBlocks[jQuery(this).attr('id')] = jQuery(this).attr('rel');
		//alert(data.getBlocks[jQuery(this).attr('id')]);
	});

	// add current product
	//if (typeof CURRENTPRODUCTID !== 'undefined' && CURRENTPRODUCTID) {
	//	data.currentProductId = CURRENTPRODUCTID;
	//}

	// E.T. phone home
	jQuery.get(
		AJAXHOME_URL,
		data,
		function (data) {
		    //alert(data.blocks);
			for(var id in data.blocks) {
			//jQuery('#' + id).html('');
			//alert(data.blocks[id]);
			//alert(jQuery('#' + id).html());
			jQuery('#' + id).replaceWith('<span>'+data.blocks[id]+'</span>');
			//alert(id);
		    //alert(jQuery('#' + id));
			//jQuery('#recentlyview').html(data.blocks[id]);
			}
			//jQuery.cookie('frontend', data.sid, { path: '/' });
		},
		'json'
	);

});
