function zm_ps_reloaded() {
 this.store_products_prefix = '/m/pl/malid:';
 this._offer_fetch_url      = '/m/_scripts/product_offer_enhanced.php';
 this._attr_prefix          = 'zm_att_';
 this.ready                 = 0;                /** interrupteur general **/
 this._moid                 = null;             /** moid demande **/
 this._current_moid         = null;             /** moid courant **/
 this._current_oid          = null;             /** oid courant **/
 this._buyable              = null;             /** offre achetable ou non **/
 this._is_universe_books    = null;             /** appartient à l'univers livre ou non **/
 this._mpid                 = null;             /** mpid courant **/
 this._mall                 = null;             /** context mall **/
 this._a_av                 = new Object();     /** tableau des av de l'offre courante **/
 this._current_a_av         = new Object();     /** tableau des av de l'offre courante **/
 this._id_map               = [                 /** mapping des id xml vers id html **/
  {'_id': 'offer_name',                '_html_id': 'zm_name'},
  {'_id': 'offer_name',                '_html_id': 'zm_name_description'},
  {'_id': 'offer_description_long',    '_html_id': 'zm_description_long'},
  {'_id': 'store_sentence',            '_html_id': 'zm_sentence'},
  {'_id': 'shipment_amount_text',      '_html_id': 'zm_shipping_cost_label'},
  {'_id': 'delivery_text',             '_html_id': 'zm_shipping_delay_label'},
  {'_id': 'availability',              '_html_id': 'zm_availability'},
  {'_id': 'warranty',                  '_html_id': 'zm_warranty'},
  {'_id': 'price_final',               '_html_id': 'zm_price_final'},
  {'_id': 'price_retail',              '_html_id': 'zm_price_retail'},
  {'_id': 'ecotax',                    '_html_id': 'zm_ecotax'},
  {'_id': 'currency',                  '_html_id': 'zm_currency'},
  {'_id': 'store_name',                '_html_id': 'zm_store_name_expedition'},
  {'_id': 'store_name',                '_html_id': 'zm_store_name_cgv'},
  {'_id': 'store_name',                '_html_id': 'zm_store_name'}
  ];


 /** initialisation generale **/
 this.init = function(_mpid, _moid, _mall) {
  this.ready  = 1;                  /** objet pret a fonctionner **/
  this._moid  = _moid;
  this._mpid  = _mpid;
  this._mall  = _mall;

  /** cgv click callback **/
  $('#zm_merchant_url').click(zm_ps.store_sheet_click_cb).addClass('hover');

  /** sales condition click callback **/
  $('#zm_sales_condition_url').click(zm_ps.store_sc_click_cb).addClass('hover');

  /** init des clic sur les valeurs d'attribut **/
  $('dl.attMenu a[id^='+this._attr_prefix+']').click(zm_ps.av_selection_cb);

  /** init pour les clics sur le lien "tous les articles" **/
  $('#zm_store_url').unbind('click').click(zm_ps.store_products_click_cb);

  

/** init titleManager **/
$(document).titleManager({'listnerEvent':'managetitle','titleMotif':"[offerTitle] [values] - Achat/Vente [offerTitle] [values] - [mpid] - [moid] - RueDuCommerce"})
if($('#zm_comparateur').length>0)$('#zm_comparateur').hide().storesManager({'listnerEvent':'managestores','mpid':_mpid,'moid':_moid});
  if(window.location.hash){         /** verification des parametres de l'url **/
   var pattern = /moid:(MO-[0-9|A-Z]+M[0-9]+)/
   var _reg = new RegExp(pattern);
   var _a_moid = _reg.exec(window.location.hash);
   var _u_moid = null ;
   if (_a_moid && _a_moid.length) {
    _u_moid = _a_moid[1] ;
   }
   if(_u_moid) {
    if( (this._moid != _u_moid)){      /** moid de l'url != moid courant => rechargement necessaire **/
     this._moid = _u_moid;
     this.fetch_offer();
     return;
    }
   }
  }
  this.fetch_offer();
  
/* XXX temporairement desactive
  this.attr_init();
  */
 }


 /** methode d'initialisation des valeurs d'attributs **/
 this.update_a_av = function(_ps_xml) {
  $(_ps_xml).find('attribute_value').each(function(_nb){
   zm_ps._current_a_av[$(this).attr('attribute_id')] = $(this).attr('value_id');
   zm_ps.update_av($(this).attr('value_id'), $(this).attr('attribute_id'), $(this).attr('value_state'));
  });
 };

 /** methode de mise à jour d'une valeur d'attribut **/
 this.update_av = function(_av_id, _a_id, _av_state) {
  switch(_av_state) {
   case 'disabled':
    var _class = 'attInactif';
    var _state = 'disabled';

    if (_a_id == "6")
      var _style = 'font-style:normal;color:#000000;';
    else
      var _style = '';
    break;
   case 'selected':
    var _class = 'attSelected';
    var _state = 'selected';
    var _style = '';
    break;
   default:
    var _class = '';
    var _state = 'default';
    var _style = '';
  }
  $('#'+this._attr_prefix+_av_id).attr('class', _class).attr('_a_id', _a_id).attr('_av_id', _av_id).attr('_state', _state).attr('style', _style);

 }


 /** chargement des infos d'une offre, par moid ou tableau de value id **/
 this.fetch_offer = function(){
  /** init setup ajax **/
  this.objAjaxSetup={
    url: this._offer_fetch_url,
    global: false,
    type: "GET",
    dataType:"xml",
    beforeSend:this.before_send_data,
    complete:this.display_offer_cb,
    error:this.display_error,
    success:this.success_send_data
  }

  var _s = '';
  var _sep = '';
  for(var _k in this._a_av) {
   _s = _s + _sep + this._a_av[_k];
   _sep = ';';
  }
  
  if(this._moid != null) {
   $.ajax(jQuery.extend(this.objAjaxSetup, {data:{mall : this._mall, moid: this._moid, mpid: this._mpid, values: _s}}));
   return;
  }

  $.ajax(jQuery.extend(this.objAjaxSetup,{data:{mall : this._mall, values: _s, mpid: this._mpid}}));
  

 }
 
 

 /** callback de traitement du XML recu **/
 this.display_offer_cb = function(_ps_xml) {
   if(! _ps_xml.responseXML) return;
  if($(_ps_xml.responseXML).find('error').attr('error_code')){
   return zm_ps.display_error();
   }
  zm_ps.display_offer(_ps_xml.responseXML,this.data);
 }


 /** methode de mise à jour générale de l'affichage de l'offre courante **/
 this.display_offer = function(_ps_xml,paramRequest) {
  /** reinit des donnees courantes **/
  var tmpNOffer=$(_ps_xml).find('offer');
  this._current_moid = tmpNOffer.attr('moid');
  if(this._current_moid){window.location.hash='moid:' + this._current_moid}
  this._current_oid = tmpNOffer.attr('id');
  this._buyable = tmpNOffer.attr('buyable');
  this._is_universe_books = tmpNOffer.attr('is_universe_books');
  this.reinit_current_a_av();
  /** mise a jour **/
  this.update_mapped_data(_ps_xml);
  this.update_a_av(_ps_xml);
  this.update_price_details($("prices_information",_ps_xml));
  this.update_store_links(_ps_xml);
  this.update_images($(_ps_xml).find('images'))
  this.update_title(_ps_xml);
  this.update_cart_button(_ps_xml);
  this.update_availability(_ps_xml);
  this.update_pour_noel(_ps_xml);
  this.update_flash(_ps_xml);
  this.update_condition(_ps_xml);
  jQuery.event.trigger("managestores", [{xmlData:_ps_xml,moid:this._current_moid}], window, false, null);
 }


 /** iterateur pour update generique **/
 this.update_mapped_data = function(_ps_xml) {
  _l = this._id_map.length;
  for(_k = 0;_k < _l; _k++){
   _data = $(_ps_xml).find(this._id_map[_k]['_id']+':first').text();          /** recuperation de valeur **/
   this.update_data(this._id_map[_k]['_html_id'], _data);           /** mise a jour sur l'element html correspondant **/
  }
 }

 this.update_condition = function(_o_xml) {
	 var container = $("div#zm_condition");
	 container.empty();
	 var condition = $(_o_xml).find('condition');
	 var html = '';
	 if (condition.length > 0) {
		 html += "&Eacute;tat : Occasion";
		 if (condition.attr('is_occasion') == "1") {
			 var detailed_condition = $(_o_xml).find('detailed_condition').text();
			 if (detailed_condition.length > 0) {
			 	html += " - " + condition.text();
			 }
		 }
	 }
	 container.append(html);	 
 }
 
 
 /** methode generique d'update de contenu **/
 this.update_data = function(_id, _val) {
   if((_id == "zm_shipping_delay_label") && (_val.indexOf("Livraison") == 0) )
     $('#'+_id).empty().html("");
   else
     $('#'+_id).empty().html(_val);
 }


	/** update price details **/
	this.update_price_details = function(dtObj){
		var container = $("#zm_prices_information");
		this.reinit_ps(container);
			
		var priceDetails=dtObj.find('price_details');
  	if (priceDetails.length==0){
  		var priceRetail=dtObj.find('retail');
		if (priceRetail.length > 0) {
			var price_retail_value = $('retail', dtObj)[0].firstChild.nodeValue;
			var price = $('price_final_without_formatter', dtObj)[0].firstChild.nodeValue;
			if (price_retail_value != 0 && (parseFloat(price_retail_value) > parseFloat(price))) {
				container.append('<div id="zm_price_retail" class="barre">'+price_retail_value + '</div>');
			}			
		}
  		return;
		}

		container.append('<div id="zm_price_details" class="zm_price_details prixEditeur"></div>');
		var container_details = $("#zm_price_details");

		var i = 0;
		var priceType = null;
		$('price_detail',priceDetails).each(function(){
		  priceType=$('price_type', this)[0].firstChild.nodeValue;
		  if(priceType == "sale"){
        construct_sales(dtObj,container_details);
        return false;
      }
		  container_details.append('<div id="zm_price_detail_'+i+'" class="margin-top zm_price_detail '+ priceType +'"></div>');

		  var container_detail = $("#zm_price_detail_"+i);

		  // MAJ PRIX BARRE
		  var previousPrice=$('previous_price', this)[0].firstChild.nodeValue;
		  var currency=$('currency', this)[0].firstChild.nodeValue;
		  
		  if(zm_ps._is_universe_books == 1)
		    construct_barred_price_for_books(previousPrice, currency, container_detail, i, priceType);
		  else
		    construct_barred_price(previousPrice, currency, container_detail, i);
		    
		  // SI PAS SOLDES DATE REMISE
		  if((priceType != "sale") && (zm_ps._is_universe_books == 0)){
		    var date_start=$(this).find('period').attr('start');
 		    var date_end=$(this).find('period').attr('end');
		    construct_date(date_start, date_end, container_detail, i);
		  }
		  
      if($('discount_percents', this)[0].firstChild){
        var discount_percents=$('discount_percents', this)[0].firstChild.nodeValue;
        if(priceType !== 'sale')
          construct_remises(discount_percents, container_detail, i, false);
        /*else
          construct_remises(discount_percents, container_detail, i, true);*/
      }
      
		  i++;
     });


     if(priceType !== 'sale'){
       $('#zm_img_patch_soldes').attr('style', 'display:none;');
     }
     else
     {
       $('#zm_img_patch_soldes').attr('style', 'display:block;');
     }
       /* PROMO PATCH */
  		/*var promo_reduc=$('promo_reduc',priceDetails)[0].firstChild;
  		var percents=$('promo_percents',priceDetails)[0].firstChild;
  		construct_promo_patch(promo_reduc, percents, priceType);*/	
	}
	
	construct_sales = function(dtObj,container){
    var previousPrice=$('previous_price', dtObj)[0].firstChild.nodeValue;
    var currency=$('currency', dtObj)[0].firstChild.nodeValue;
    var priceDetails=dtObj.find('price_details');
    
    var container_detail = $("#zm_price_detail");
    var html_detail = '<span class="remise" style="color:#525E69;font-weight:normal;">Prix de référence : </span>';
    html_detail +='<span  id="zm_previous_price" class="barre">' + previousPrice + '</span>';
    var tab_dem = new Array('1ère','2e','3e');
    var k = 0;
    var nb_det = $('price_detail',priceDetails).length;
    $('price_detail',priceDetails).each(function(i){
      var discount_percents=$('discount_percents', this)[0].firstChild.nodeValue;
      if(nb_det>1)
      {
        html_detail +='<div class="remise">' + tab_dem[i]+ ' démarque : ';
      }
      
      html_detail += '<strong> ' + discount_percents + ' de remise</strong>';

      if (nb_det>1)
      {
        html_detail += '</div>';
      }
      
    });
    container.append(html_detail);
	}
	
	construct_barred_price = function(barred_price, currency, container, i){
	  var html = '<span id="zm_previous_price_'+i+'" class="barre">';
	  html += barred_price+'</span>';
	  container.append(html);
	}
	construct_barred_price_for_books = function(barred_price, currency, container, i, priceType){
	  var lib_previous = "Prix éditeur : ";
	  if(priceType == "sale")
      var lib_previous = "Prix de référence : ";
	  var html = '<span class="remise" style="color:#525E69;font-weight:normal;">'+lib_previous+'</span><span id="zm_previous_price_'+i+'" class="barre">';
    html += barred_price+'</span>';
    container.append(html);
  }
	construct_remises = function(remise, container, i, sale){
	  if(sale)
	    var html = '<div class="remise">Soldes : <strong><span id="zm_discount_percents_'+i+'">';
	  else
	    var html = '<div class="remise">Remise : <strong><span id="zm_discount_percents_'+i+'">';
	  html += remise+'</span></strong></div>';
	  container.append(html);
	}
	
	
	construct_date = function(date_start, date_end, container, i){
	  var html = '<span id="zm_date_start_'+i+'" class="promo zm_date_start">&nbsp;';
	  html += date_start+'</span>&nbsp;';
	  html += '<span id="zm_date_end_'+i+'" class="promo zm_date_end">';
	  html += date_end+'</span>';
	  container.append(html);
	}

	construct_promo_patch = function(promo_reduc,promo_percents,price_type){
	  var container_img = $("#container_img");
    var html ='';
    var patch ='';
    var val_reduc ='';

	  if(promo_reduc){
  	 if(price_type == "promo"){
	  	 patch = 'patch_promo_economie';
	  	 val_reduc = promo_reduc.nodeValue;
	 } 	 
	 else if(price_type == "flash"){
	  	 patch = 'patch_flash_economie';
	  	 val_reduc = '-' + promo_reduc.nodeValue;
	 } 	 
  	}
  	else if(promo_percents)
  	{
      if(price_type == "promo")
        patch = 'patch_promo_percents';
      else if(price_type !== null)
        patch = 'patch_'+price_type;

  	  val_reduc = '<span class="txtxl">-&nbsp;' + promo_percents.nodeValue + '</span>';
    }

    html = '<div id="offer_patch" class="offer_patch txtblanc txtbold txtxl '+ patch +'" style="right:0;left:auto;">' + val_reduc + '</div>';

    container_img.append(html);
	}

   this.reinit_ps = function(container){
    $('*', container).empty();
    $("#offer_patch").remove();
   }

    /** methode d'update pour le bandeau "Livré avant Noel" **/
    this.update_pour_noel = function(_ps_xml) {
        var pour_noel =$(_ps_xml).find('delivery').attr('pour_noel');
        if (pour_noel=='1') {
            $(".livre_avant_noel").removeClass('nod');
        } else {
            $(".livre_avant_noel").addClass('nod');
        }
    }
    /**Méthode pour mettre à jour le décompte flash**/
    this.update_flash = function(_ps_xml){
    	$("#VF").removeClass('vfchronofp vfCountDown');
    	$("#VF").addClass('nod');
    	var date_diff = $("prices_information",_ps_xml).find('period').attr('date_diff');
    	if(date_diff > 0){
    		$("#VF").removeClass('nod');
    		$("#VF").addClass('vfchronofp vfCountDown');
    		$("#VF").attr('secs',date_diff);
    	}	
    	
    	
    }

 	/** methode d'update pour le lien vers la presentation marchand **/
	this.update_store_links = function(_ps_xml) {
		var store_name = $(_ps_xml).find('store_name').text();
		var store_id = $(_ps_xml).find('store').attr('value_id');
		var store_rate = $(_ps_xml).find('store').attr('avg_rate');
		var merchant_url =$(_ps_xml).find('store_merchant_url').text();
		var sale_condition_url = $(_ps_xml).find('store_sales_condition_url').text();
		var store_link = this.store_products_prefix + store_id;
		var current_oid=this._current_oid;
		if($('a.reviewLink').length>0) {$('a.reviewLink').data('oId',current_oid);$('a.reviewLink').data('sId',$(_ps_xml).find('store').attr('id'));}
		$('#zm_store_url').attr('onclick', null)
			.text('Voir les articles du marchand '+store_name)
			.unbind('click')
			.click(function(){window.open(store_link,'_top');});
		$('#zm_merchant_url').attr('onclick', null)
			.unbind('click')
		.click(function(){window.open(sale_condition_url,'_top');});
		$('#abus_url').attr('onclick', null)
			.unbind('click')
			.click(function(){window.open('/m/abuses/index.php?oid='+current_oid);});
	}

	/** update des images */
	this.update_images = function(im){
		var container = $("#zm_images");
		var idxImg = 1;
		var typeImg = ['small','big'];
		tmpl = $('.zm_image:first', container);
		$(container).empty();

		$('image', im).each(function(i){
			var newImg = tmpl.clone().attr('className', 'zm_image ' + typeImg[idxImg]);
			$('a',newImg).attr({'href': $('zoom', this)[0].firstChild.nodeValue,'rel':'images'});
			$('img',newImg).attr('src', $(typeImg[idxImg], this)[0].firstChild.nodeValue);

			if(i==0){
				$('a',newImg).attr('rel','images nocount');
				container.append(newImg);
				var newImg = tmpl.clone().attr('className', 'zm_image small'); //miniature pour img big
				$('img', newImg).attr('src', $('small', this)[0].firstChild.nodeValue);
				$('a', newImg).attr({'href': $('zoom', this)[0].firstChild.nodeValue,'rel':'images'});

			}

			newImg.css('background-image',"url("+$('big',this)[0].firstChild.nodeValue+")");
			container.append(newImg);
			idxImg = 0;
		});

	}

	/*** update title **/
	this.update_title = function(_ps_xml){
		var obj_title= {};
		obj_title.offerTitle = $(_ps_xml).find('offer_name').text();
		var tmpValPrefix = this._attr_prefix;
		var tmpArrAtt = [];

		jQuery.each($(this._current_a_av)[0], function(k,v){tmpArrAtt.push(tmpValPrefix+v)});
		obj_title.values = (tmpArrAtt[0]) ? tmpArrAtt.join(';') : '';
		//obj_title.values=jQuery.makeArray($('a.attSelected').map(function(){console.info($(this).text());return $(this).text()})).join(';');
		obj_title.mpid = this._mpid;
		obj_title.moid = this._current_moid;
		//jQuery.event.trigger("managetitle", [obj_title], window, false, null);
	}

 /** callback de gestion des choix de valeur - ajout d'un critere **/
 this.av_selection_cb = function(event) {
  event.preventDefault();
  if(! zm_ps.ready) return false; /** objet pas pret => on ne fait rien **/

  switch($(this).attr('_state')) {
   case 'selected':                /** choix d'une av deja selectionnee - pour l'instant on ne fait rien **/
    return;
   case 'disabled':                /** choix d'une av incompatible avec les autres - nouvelle recherche **/
    zm_ps._a_av = new Object();    /** annulation des anciens criteres **/
    zm_ps._moid = null;
    break;
   default:                        /** choix d'une av compatible avec les autres **/
    zm_ps._moid = null;
    break;
  }
  zm_ps._a_av[$(this).attr('_a_id')] = $(this).attr('_av_id');
  zm_ps.fetch_offer();              /** mise à jour générale nécessaire **/
  return;
 }

	/** before send ajax */
	this.before_send_data = function(){
		$("#loadingData").removeClass('hide');
	}

	this.success_send_data = function(){
		$("#loadingData").html('Chargement...').addClass('hide');
	}

 /** affichage erreur generique **/
 this.display_error = function() {
 	//$('#add-cart').addClass('errorScript');
 	zm_ps.desactivate_cart_button();
 	$('#loadingData').removeClass('hide').html('<br><br>L\'article est indisponible à la vente pour le moment');
 }


 /** gestion du bouton acheter et des mentions de disponibilité **/
 this.update_cart_button = function(_o_xml) {
   $('#caddie_data').empty();
   if($(_o_xml).find('store').attr('id') == 2615 || $(_o_xml).find('store').attr('id') == 2845){
   	caddie_data_content = '<input id="mpoid" type="hidden" name="merchant_product_id" value="' + $(_o_xml).find('offer').attr('merchant_offer_id') + '" />';
   	caddie_data_content += '<input id="sid" type="hidden" name="store_id" value="' + $(_o_xml).find('store').attr('id') + '" />';
   }
   else{
   	caddie_data_content = '<input id="fzm" type="hidden" name="fzm" value="1" />';
   }
   if($(_o_xml).find('offer').attr('is_for_unique_picking') == 1){ 
   	caddie_data_content += '<input id="fzmpu" type="hidden" name="fzmpu" value="1" />';   
   }
   $('#caddie_data').append(caddie_data_content);

   if(this._buyable == 0)
     this.desactivate_cart_button();
   else
     this.activate_cart_button();
   
  $('#cart-submit').val(this._current_oid);
 }
 
 this.update_availability = function(_o_xml){
   var _class = $(_o_xml).find('availability').attr('class');
   if(typeof(parseInt($(_o_xml).find('availability').attr('status')))!='number'){
     this.display_error();
   return;  
  }
  
  $('#zm_availability').empty();
  $('#zm_availability').append($(_o_xml).find('availability').text());
  
  $('#zm_availability').attr('class', 'span-4 last '+_class);
  
 }

 /** desactivation du bouton acheter **/
 this.desactivate_cart_button = function () {
  $('#cart-submit').attr('disabled', 'disabled').addClass('off');
 }
 
 /** (re)activation du bouton acheter **/
 this.activate_cart_button = function () {
  $('#cart-submit').removeAttr('disabled').removeClass('off');
 }

 /** gestion des visualisations des CGV **/
 this.store_sheet_click_cb = function(e) {
  e.preventDefault();
  window.open($(this).attr('_m_url'));
  return false;
 }

 /** gestion des visualisations des CGV **/
 this.store_sc_click_cb = function(e) {
  e.preventDefault();
  window.open($(this).attr('_sc_url'));
  return false;
 }

 /** gestion des clics sur le lien "tous les articles du marchand" **/
 this.store_products_click_cb = function(e) {
  e.preventDefault();
  document.location($(this).attr('_custom_url'));
  return false;
 }

 /** reinit des av courantes **/
 this.reinit_current_a_av = function() {
  this._current_a_av = new Object();
 }
}

zm_ps = new zm_ps_reloaded();

/**********************************************************************/
_.q.a(function($) {
jQuery.fn.storesManager = function(options){

	options = jQuery.extend({
		listnerEvent:'',
		value_id:''
		}, options);

	function initialize(dataFixed, element){
	  jQuery.extend(options, dataFixed);
		options.eltable = element[0];
	  parseData(options.xmlData, 'success');
	  
	  $('#zm_comparateur *[id^=rd_]').click(function(e){
	    var elm = $(this).attr('id').split('_');
	    e.preventDefault();
	    if(! zm_ps.ready) return false; /** objet pas pret => on ne fait rien **/
	    
	    zm_ps._a_av = new Object();    /** annulation des anciens criteres **/
      zm_ps._moid = null;
	    zm_ps._a_av['6'] = elm[1];
	    zm_ps.fetch_offer();
	    return;
	  });
	  
	  /*$(options.eltable).unbind().click(function(e){
			var target = null;
			var element = $(e.target);
			var pattern = 'a[id^=oc_]';

			if(element.is(pattern)){
				target = element;
			} else if(element.parent('a').is(pattern)){
				target = element.parent('a');
			} else{
				return;
			}

			e.preventDefault();
			
			loadOffer(target);
		});*/
	}

	var loadTableStores =function(){
		tb_show("","/m/_scripts/get_offers_comparateurs.php?moid=" + options.moid +"&width=810&height=530&rule=PRICE");
	}	

	var loadOffer = function(target){
		var elm = $(target).attr('id').split('_');
		$('*[id$=' + elm[1] + ']').trigger('click');
	}

	var parseData = function(rep, msg){
		var eltable = (this.elTable) ? $('#'+this.elTable) : $(options.eltable);
		$('tbody', eltable).empty();

		var storeList = $(rep).find('offer_comparable');
		var storeNumber = storeList.length;
		if(storeNumber == 0) {
			$('.comparateur').css('display', 'none');
			return;
		}
		var store_selected = $(rep).find('store').attr('value_id');
		
		storeList.each(function(){
		    var _store=$('oc_store',this)[0];
		    var store_id =_store.getAttribute("value_id");
		    var marchandObj={         
			         bt_radio: tmplRadio({store:_store,
			           moid: options.moid,
			           store_selected: store_selected}),    
			         store: tmplStore({
			            moid: options.moid,
			            store: _store,
			            availability: $('oc_availability', this)[0],
			            shipments:$('oc_shipments',this)[0]
			        }),
			        price: tmplPrice({
			          price:$('oc_price',this)[0],
			          store:_store}
			          )
			        }
  			$('tbody',eltable).append(createTr(marchandObj,store_id,store_selected));
		});		

		$('tfoot td',eltable).empty().append(
			$('<a/>').attr({'href': '#', 'title': 'Comparez'})
				.bind('click', function(){loadTableStores();return false;})
				.html('Comparer toutes les offres des marchands (' + (storeNumber) + ')')
		);
		eltable.css('display','block');
	}
	var tmplRadio = function(sObj){
	  var sel = "";
	  if(sObj.store.getAttribute("value_id") == sObj.store_selected)
	    var sel = "checked";
	  
	  var strHtml = '<input '+sel+' type="radio" value="'+sObj.store.getAttribute("value_id")+'" name="rd_store" id="rd_'+sObj.store.getAttribute("value_id")+'">';
	  return strHtml;
	}
	var tmplStore = function(sObj){
		var store_name = $(sObj.store).text();
	  var currency = sObj.currency || '&euro;';
	  var strHtml = "";
	  /*if($(sObj.availability).attr('status')> 0)
	    strHtml += '<a href="#moid:'+sObj.moid+'" id="oc_'+sObj.store.getAttribute("value_id")+'"  title="Voir l\'offre de '+ store_name +'">';*/
	  strHtml+= "<span class='titre_marchand'>"+ $.trim(store_name) +"</span>";
	  
	   /* Desactivation temporaire de l'affichage de la notation des marchands
		if(sObj.store.getAttribute("avg_rate") !== '0')
		{	
			var avgStore = sObj.store.getAttribute("avg_rate");
			strHtml+= '<div class="stars"><div style="width:'+(avgStore*20)+'%"></div></div> ';	
		}
		*/	
		
	  
	  var txt = $(sObj.availability).text();
		var _class = $(sObj.availability).attr('class');
		strHtml+= '<span class="' + _class + '">'+ $.trim(txt) +'</span>';
		
		
		//strHtml+='<br><span class="txtsm">'+$('oc_shipment_name',shipping).text()+' '+$('oc_shipment_amount currency',shipping).text()+'</span>';
		strHtml+= '<span class="text_liv">'+$('oc_shipment_amount_text',sObj.shipments).text()+'</span>';
			
		/*if($(sObj.availability).attr('status')> 0)
		  strHtml+= '</a>';*/

		return strHtml;
	}
	var tmplPrice = function(priceInformations){
		/*	var currency=$('currency',priceInformations).get(0).firstChild.nodeValue;*/
		var priceInformations = priceInformations.price;
		var strHtml = "";
	
		if (priceInformations) {
			strHtml+= '<div class="prix_retail">' + $('price_retail', priceInformations).text() + '</span>';
			var priceDetails = $(priceInformations).children('price_details').get(0);
			if (priceDetails) {
				$('price_detail', priceDetails).each(function(){
					strHtml+= "<span class='"+ $('price_type', this).text() +"'>";
					strHtml+= '<span class="previous">' + $('previous_price', this).text()  + '</span>';
					//strHtml+= '<span class="discountP">' + $('discount_percents', this).text() + '</span>';
					//strHtml+= '<span class="discountA">' + $('discount_amount', this).text()  + '</span>';
					strHtml+= "</span>";
				});
				strHtml+= "<br/>";
			}
			strHtml+= '<span class="comparateurprice">' + $('price_final', priceInformations).text() + '</span>';
		}

		return strHtml;
		
	}

	var tmplAcheter = function(sObj){
	  offId = sObj.offer_id;
	  
	  if($(sObj.availability).attr('status')>0)
	    var strHtml = '<input type="submit" id="cart-submit-' + offId + '" name="offer_id" value="' + offId +'" class="zm_acheter_mini" />';
	  else
	    var strHtml = '<input type="button" id="cart-submit-' + offId + '" name="offer_id" value="' + offId +'" class="zm_acheter_mini_off" />';
	  
		return strHtml;
	}

	var createTr = function(marchand){
		var code = "<td valign='top' width='4%'>" + marchand['bt_radio'] + "</td>";
		code += "<td width='96%'>" + marchand['store'] + " " + marchand['price'] + "</td>";
		var tr = $('<tr/>').html(code);
				
		return tr;
	}
	
	return $(window).bind(options.listnerEvent,this,function(event,data){
	  initialize(data,event.data)});
};
}, 1);




