/*--------------------------------------------------------------------------
 *  YOJA-WEB.COM : module Apercu
 *  Copyright (c) Jamal Chaqouri, Yohann Fontaine, of yoja team (http://www.yoja-web.com)
 *
 *  module Apercu is a yoja-web.com work.
 *  For details, see the yoja web site: http://www.yoja-web.com
 *  For V3.5 Zlioshop
/*--------------------------------------------------------------------------*/

function openAjaxWindow(settings) {
	 $j.get(settings.href, function (data) {
	 	var _content = settings.formater(data);
	 	$j.nyroModalManual({
	 		 height : "325",
	 		 width : "600",
	 		 content: _content,
             endFillContent : settings.animer
	 	});
	 });
};


function formaterApercu(html) {
	var apercu = $j("<div></div>");
	var slideShow  = $j("<div id='slideShow'></div>");
	var nav = $j("<ul id='nav'></ul>");
	slideShow.appendTo(apercu);
	nav.prependTo(apercu);
	var produits = $j(".product_list_content .product_item:not(:has(.module-adsense))", html);
    produits.each(function() {
    	var lien = $j(".center a", $j(this));    
    	lien.removeAttr("href");
    	//lien.append("<span>Aperçu</span>")
    	var produit = $j("img:first", lien);
    	produit.attr({height:"50", width:"50"});
    	produit.removeAttr("onclick");
    	var srcImg = produit.attr("src").replace(/medium/,"large");
    	var description = $j('<div><img src="'+srcImg+'" width="200" height="200" /></div>');
    	description.append($j(".product_actions_v", $j(this)));
    	slideShow.append(description);
    	nav.append(lien);
    	lien.wrap("<li></li>");    	
    });
    return apercu;
}

function animerApercu(elts, settings) {
   	var slideShow = $j("#slideShow", elts.contentWrapper)
   	slideShow.cycle({
   		fx:     'fade', 
        speed:  'fast', 
        timeout: 0, 
        pager:  '#nav',
        pagerAnchorBuilder: function(idx, slide) { 
          // return selector string for existing anchor 
          return '#nav a:eq(' + idx + ')'; 
        } 
   	});  
}

AjaxApercu = {

   traiter : function() {
     
     var listCategories = $j("div.category_item");
	 
     listCategories.each(function(i){
     	 var lien = $j(".see_more a", $j(this));
         //var hrefToload = lien.attr("href");
     	 var hrefToload = $j(".subcategories_list a:first, .see_more a:first", $j(this)).attr("href");
         lien.removeAttr("href");
         lien.css({fontSize : "13px", cursor: "pointer"});
         lien.html("Voir un aper&ccedil;u");         
         //$j(".category_go", $j(this)).removeClass("category_go");
         lien.click(function(e) {
               openAjaxWindow({href : hrefToload, formater : formaterApercu, animer : animerApercu});        
          });
     });
     
   }
   
};

function loadAjaxApercu() {
  AjaxApercu.traiter();
}

DocumentReadyExecuter.addTraitement(loadAjaxApercu);
