var Products=new Class({plates:null,dekors:null,infos:null,containers:[],connector:null,loader:null,settings:{language:"pl",unit:"cm",image_path:""},locale:{},collection:null,colour:null,choice_request:null,initialize:function(b){$extend(this.settings,b||{});this.containers=[this.plates=$("products-surfaces").getFirst("div"),this.decors=$("products-decors").getFirst("div"),this.infos=$("products-infos").getFirst("div")];var c=$$("#products-colours .colours li"),a=0;c.each(function(d){a=d.getSize().y>a?d.getSize().y:a});c.each(function(d){d.setStyle("height",a)});this.loaders=new Asset.images(["/htdoc/images/n/ajax-loader.gif","/htdoc/images/n/ajax-loader-small.gif"]);this.connector=new Request.JSON({url:"/"+this.settings.language+"/products/getcolour",method:"post",link:"cancel",data:{language:this.settings.language},onRequest:function(){this.containers.each(function(d){d.empty().addClass("empty");this.loader_insert(d)},this)}.bind(this),onSuccess:function(e,d){this.containers.each(function(f){f.empty().removeClass("empty")},this);this.collection=e.collection;this.colour=e.colour;this.surfaces_insert(e.surfaces).decors_insert(e.decors).infos_insert(e.infos)}.bind(this),onFailure:function(){}.bind(this)});$$("#products-colours a").each(function(d){d.addEvent("click",function(){if(d.hasClass("name-active")){return}$$("#products-colours .name-active").removeClass("name-active");d.getParent().getNext("div").addClass("name-active");this.get_data({colour:d.get("rel")})}.bind(this))},this)},get_data:function(a){$("products-colours").store("colour",a.colour);if(a.collection){this.connector.options.data={collection:a.collection,colour:a.colour}}else{this.connector.options.data={collection:this.collection.id,colour:a.colour}}this.connector.send()},add_locale:function(a){this.locale=a;return this},loader_insert:function(a){this.loaders[0].clone().inject(a)},surfaces_insert:function(c){var b=this.plates,m=new Element("a",{href:"javascript:void(null)"}).addClass("surface-selector"),k=new Element("div").addClass("plates-container"),j=new Element("div").addClass("plate-container"),g={colour:this.colour,collection:this.collection};new Element("img",{alt:""}).inject(new Element("a",{href:"javascript:void(null);"}).inject(j));new Element("div").addClass("plate-size").inject(j);var q=[],e=null,n=[],d=[];for(var r in c){n.push(r.toInt());m.clone().set({text:c[r].name,rel:r}).addClass("checked").addEvent("click",function(l){l.stop();d=b.retrieve("checked_surfaces");if(this.hasClass("checked")&&b.retrieve("checked_surfaces").length>1){this.removeClass("checked");$("surface-type-"+this.get("rel")).setStyle("display","none");d[d.indexOf(this.get("rel").toInt())]=null;b.store("checked_surfaces",d.clean())}else{if(!this.hasClass("checked")){this.addClass("checked");$("surface-type-"+this.get("rel")).setStyle("display","block");d.push(this.get("rel").toInt());b.store("checked_surfaces",d)}}}).inject(b);q.push(k.clone().set("id","surface-type-"+r));var h=[],i=0;var a=0;for(p in c[r].plates){h[i]=j.clone();h[i].getElement("a").set({title:c[r].plates[p].size+this.settings.unit+", "+c[r].name,rel:r,ref:p}).setStyles({position:"relative",overflow:"hidden"}).addClass("p"+c[r].plates[p].size).addEvent("click",this.plates_zoom.bindWithEvent(h[i].getElement("a"),this));if(this.settings.token){var o=this,e=null;h[i].getElement("a").addEvent("mouseenter",function(l){if(this.getElement("a").retrieve("selected")){return false}e=$clear(e);var s=this;e=(function(){var t=new Element("a",{styles:{display:"block",position:"absolute",top:"1px",right:"1px",width:"20px",height:"20px",background:"url(/Module/Products/Page/images/choice_add.gif) no-repeat"}});t.addEvent("click",o.my_choice_add.bindWithEvent(t,{data:{collection:g.collection.id,colour:g.colour.id,type:"plate"},"$this":o})).inject(s.getElement("a"))}).delay(500);l.stopPropagation()}.bind(h[i]));h[i].getElement("a").addEvent("mouseleave",function(l){if(this.getElement("a").retrieve("selected")){return false}e=$clear(e);if(this.getElement("a").getElement("a")){this.getElement("a").getElement("a").destroy()}l.stopPropagation()}.bind(h[i]))}h[i].getElement("img").set({alt:c[r].plates[p].size+this.settings.unit+", "+c[r].name,src:this.settings.image_path+"/"+c[r].plates[p].image+"/thumb."+c[r].plates[p].extension});var f=c[r].plates[p].size;h[i].addClass("p"+c[r].plates[p].size+"-ext");h[i].getElement("div[class=plate-size]").set("text",c[r].plates[p].size+this.settings.unit);h[i].inject(q[q.length-1]);++i}new Element("div").addClass("clearfix").setStyle("height","20px").inject(q[q.length-1])}b.store("checked_surfaces",n);q.each(function(s,l){if(l==0){s.inject(b)}else{s.inject(q[l-1],"after")}},this);return this},plates_zoom:function(g,h){g.stop();var b=h.container(this),a=[],f=[],e={surface:0,plate:0,max_surface:0,max_plate:0};h.plates.getElements("div[class=plates-container]").each(function(l,k){a[k]={img:[],alt:[]};var j=l.getElements("img");j.each(function(m,i){a[k].img.push(j[i].get("src"));a[k].alt.push(j[i].get("alt"))});if(l.get("id")==("surface-type-"+this.get("rel"))){e.surface=k;e.plate=a[k].img.indexOf(this.getElement("img").get("src"))}a[k].img.each(function(m,i){a[k].img[i]=a[k].img[i].replace("thumb","main")})},this);e.max_surface=a.length-1;e.max_plate=a[e.surface].img.length-1;var d=this,c=new Element("div").setStyles({"text-align":"center",color:"#003976","font-weight":"bold","padding-top":"5px","font-size":"7pt"}).set("text","0%").inject(b);a.each(function(k,j){if(j==e.surface){f[j]=new Asset.images(a[j].img,{onProgress:function(i,l){b.getElement("div").set("text",((i+1)*100/a[j].img.length).toInt()+"%")},onComplete:function(){b.erase("html");new Fx.Morph(b,{duration:"500",fps:25}).start({left:[b.getPosition().x,(0.5*($(document.body).getSize().x-850)).toInt()],top:[b.getPosition().y,$(document.body).getScroll().y+(0.5*($(document.body).getSize().y-670)).toInt()],width:[b.getSize().x,850],height:[b.getSize().y,670],opacity:[0.6,1]}).chain(function(){b.setStyle("background","#e3e4d6");var i=new Element("div").setStyles({background:"#ffffff url("+f[j][e.plate].get("src")+") center top no-repeat",position:"relative",margin:"20px auto 5px",width:"800px",height:"30px","padding-top":"570px","text-align":"center",color:"#464646"}).set("html","<strong>"+h.collection.name+", "+h.colour.code+" "+h.colour.title+", "+d.get("title")+"</strong>").inject(b);new Element("div",{"class":"switch-size"}).addClass("switch-size-"+h.settings.language).inject(b);new Element("a",{href:"javascript:void(null);",id:"products-zoom-pp"}).addClass("size-previous").addEvent("click",function(l){l.stop();if(e.plate-1>=0){if(e.plate==e.max_plate){$("products-zoom-pn").setStyle("opacity",1)}i.setStyle("background","#ffffff url("+f[e.surface][--e.plate].get("src")+") center top no-repeat");i.set("html","<strong>"+h.collection.name+", "+h.colour.code+" "+h.colour.title+", "+a[e.surface].alt[e.plate]+"</strong>").inject(b);if(e.plate==0){this.setStyle("opacity",0.2)}}}).setStyle("opacity",e.plate==0?0.2:1).inject(b);new Element("a",{href:"javascript:void(null);",id:"products-zoom-pn"}).addClass("size-next").addEvent("click",function(l){l.stop();if(e.plate+1<=e.max_plate){if(e.plate==0){$("products-zoom-pp").setStyle("opacity",1)}i.setStyle("background","#ffffff url("+f[e.surface][++e.plate].get("src")+") center top no-repeat");i.set("html","<strong>"+h.collection.name+", "+h.colour.code+" "+h.colour.title+", "+a[e.surface].alt[e.plate]+"</strong>").inject(b);if(e.plate==e.max_plate){this.setStyle("opacity",0.2)}}}).setStyle("opacity",e.plate==e.max_plate?0.2:1).inject(b);new Element("div",{"class":"switch-surface"}).addClass("switch-surface-"+h.settings.language).inject(b);new Element("a",{href:"javascript:void(null);",id:"products-zoom-sp"}).addClass("surface-previous").addEvent("click",function(l){l.stop();if(e.surface-1>=0){if(e.surface==e.max_surface){$("products-zoom-sn").setStyle("opacity",1)}--e.surface;i.setStyle("background","#ffffff url("+f[e.surface][e.plate].get("src")+") center top no-repeat");i.set("html","<strong>"+h.collection.name+", "+h.colour.code+" "+h.colour.title+", "+a[e.surface].alt[e.plate]+"</strong>").inject(b);if(e.surface==0){this.set("opacity",0.2)}}}).setStyle("opacity",e.surface==0?0.2:1).inject(b);new Element("a",{href:"javascript:void(null);",id:"products-zoom-sn"}).addClass("surface-next").addEvent("click",function(l){l.stop();if(e.surface+1<=e.max_surface){if(e.surface==0){$("products-zoom-sp").setStyle("opacity",1)}++e.surface;i.setStyle("background","#ffffff url("+f[e.surface][e.plate].get("src")+") center top no-repeat");i.set("html","<strong>"+h.collection.name+", "+h.colour.code+" "+h.colour.title+", "+a[e.surface].alt[e.plate]+"</strong>").inject(b);if(e.surface==e.max_surface){this.set("opacity",0.2)}}}).setStyle("opacity",e.surface==e.max_surface?0.2:1).inject(b);new Element("a",{href:"javascript:void(null)"}).addClass("products-close").addEvent("click",function(l){l.stop();b.destroy();$("products-overlay").destroy()}).inject(b)})}})}else{f[j]=new Asset.images(a[j].img)}})},decors_insert:function(k){if(k.decors===null){return this}var a=this.decors.store("selected",0),c=new Element("a",{href:"javascript:void(null)"}).addClass("decor-selector").addClass("checked"),e={colour:this.colour,collection:this.collection},d=[];a.store("checked_groups",[]);for(var h in k.groups){c.clone().set({text:k.groups[h].name,rel:h,id:"decor-selector-"+h}).addEvent("click",function(){d=a.retrieve("checked_groups");if(this.hasClass("checked")&&d.length>1){this.removeClass("checked");n.getElements(".decor-container").each(function(g){if(g.getElement("a").retrieve("group")==this.get("rel")){g.setStyle("display","none")}},this);d[d.indexOf(this.get("rel").toInt())]=null;a.store("checked_groups",d.clean())}else{if(!this.hasClass("checked")){this.addClass("checked");n.getElements(".decor-container").each(function(g){if(g.getElement("a").retrieve("group")==this.get("rel")){g.setStyle("display","inline")}},this);this.addClass("checked");d.push(this.get("rel").toInt());a.store("checked_groups",d)}}}).setStyle("display","none").inject(a)}new Element("div").addClass("clearfix").inject(a);var n=new Element("div").inject(a),q=new Element("div").addClass("decor-container");new Element("div").addClass("decor-image").inject(q);new Element("a",{href:"javascript:void(null)"}).inject(q.getElement("div"));new Element("img",{alt:""}).inject(q.getElement("a"));new Element("div").addClass("decor-name").inject(q);var j=k.decors.length,o=[],l=0;for(var f=0;f<j;f++){o[f]=q.clone();o[f].getElement("img").set("src",this.settings.image_path+"/"+k.decors[f].image+"/thumb."+k.decors[f].extension);o[f].getElement("div[class=decor-name]").set("text",k.decors[f].title);o[f].getElement("a").set({title:k.groups[k.decors[f].group].name+", "+k.decors[f].title,rel:k.decors[f].group+":"+k.decors[f].id}).store("group",k.decors[f].group).addEvent("click",this.decors_zoom.bindWithEvent(o[f].getElement("a"),this));if(this.settings.token){var m=this,b=null;o[f].getElement("a").addEvent("mouseenter",function(g){if(this.getElement("a").retrieve("selected")){return false}b=$clear(b);var i=this;b=(function(){var r=new Element("a",{href:"javascript:void(null)",styles:{display:"block",position:"absolute",top:"1px",right:"1px",width:"20px",height:"20px",background:"url(/Module/Products/Page/images/choice_add.gif) no-repeat"}});r.addEvent("click",m.my_choice_add.bindWithEvent(r,{data:{collection:e.collection.id,colour:e.colour.id,type:"decor"},"$this":m})).inject(i.getElement("a"))}).delay(500);g.stopPropagation()}.bind(o[f]));o[f].getElement("a").addEvent("mouseleave",function(g){if(this.getElement("a").retrieve("selected")){return false}b=$clear(b);if(this.getElement("a").getElement("a")){this.getElement("a").getElement("a").destroy()}g.stopPropagation()}.bind(o[f]))}o[f].inject(n);$("decor-selector-"+k.decors[f].group).setStyle("display","inline");if(!a.retrieve("checked_groups").contains(k.decors[f].group.toInt())){d=a.retrieve("checked_groups");d.push(k.decors[f].group.toInt());a.store("checked_groups",d)}if(o[f].getSize().y>l){l=o[f].getSize().y}}o.each(function(g){g.setStyle("height",l)});new Element("div").addClass("clearfix").inject(a);$("products-decors-show").addEvent("click",function(){a.getElements(".decor-selector").each(function(g){if(!g.hasClass("checked")){g.fireEvent("click")}})});return this},decors_zoom:function(b,f){b.stop();var c=f.container(this.getParent()),e=f.decors.retrieve("checked_groups"),g=f.decors.getElements("img").filter(function(j){return e.contains(j.getParent("a").get("rel").split(":")[0].toInt())}),i=[],d={current:0,last:0};d={current:g.indexOf(this.getElement("img")),last:g.length-1};g.each(function(k,j){i.push(k.get("src").replace("thumb","main"))});var h=this,a=new Element("div").setStyles({"text-align":"center",color:"#003976","font-weight":"bold","padding-top":"55px","font-size":"7pt"}).set("text","0%").inject(c);i=new Asset.images(i,{onProgress:function(j,k){c.getElement("div").set("text",((j+1)*100/g.length).toInt()+"%")},onComplete:function(){c.erase("html");new Fx.Morph(c,{duration:"500",fps:25}).start({left:[c.getPosition().x,(0.5*($(document.body).getSize().x-850)).toInt()],top:[c.getPosition().y,$(document.body).getScroll().y+(0.5*($(document.body).getSize().y-670)).toInt()],width:[c.getSize().x,850],height:[c.getSize().y,670],opacity:[0.6,1]}).chain(function(){c.setStyle("background","#e3e4d6");var j=new Element("div").setStyles({background:"#ffffff url("+i[d.current].get("src")+") center top no-repeat",position:"relative",margin:"20px auto 5px",width:"800px",height:"30px","padding-top":"570px","text-align":"center",color:"#464646"}).set("html","<strong>"+f.collection.name+", "+h.get("title")+"</strong><br />"+(d.current+1)+" / "+(d.last+1)).inject(c);new Element("a",{href:"javascript:void(null);"}).addClass("previous").addEvent("click",function(k){k.stop();if(d.current-1>=0){if(d.current==d.last){this.getNext("a").setStyle("opacity",1)}j.setStyle("background","#ffffff url("+i[--d.current].get("src")+") center top no-repeat");j.set("html","<strong>"+f.collection.name+", "+g[d.current].getParent("a").get("title")+"</strong><br />"+(d.current+1)+" / "+(d.last+1));if(d.current==0){this.setStyle("opacity",0.2)}}}).setStyle("opacity",d.current==0?0.2:1).inject(c);new Element("a",{href:"javascript:void(null);"}).addClass("next").addEvent("click",function(k){k.stop();if(d.current+1<=d.last){if(d.current==0){this.getPrevious("a").setStyle("opacity",1)}j.setStyle("background","#ffffff url("+i[++d.current].get("src")+") center top no-repeat");j.set("html","<strong>"+f.collection.name+", "+g[d.current].getParent("a").get("title")+"</strong><br />"+(d.current+1)+" / "+(d.last+1));if(d.current==d.last){this.setStyle("opacity",0.2)}}}).setStyle("opacity",d.current==d.last?0.2:1).inject(c);new Element("a",{href:"javascript:void(null)"}).addClass("products-close").addEvent("click",function(k){k.stop();c.destroy();$("products-overlay").destroy()}).inject(c)})}})},infos_insert:function(e){var c=this.infos,d="";for(var b in e.assignments){d+=(d?", ":"")+e.assignments[b]}new Element("div",{html:this.locale.assignment+": <strong>"+d+"</strong>","class":"info-container"}).addClass("a").inject(c);new Element("div",{html:(e.wipe.key.toInt()==6?this.locale.wipe.b:this.locale.wipe.a)+": <strong>"+e.wipe.value+"</strong>","class":"info-container"}).addClass("w").inject(c);return this},container:function(d){var c=d.getCoordinates(),b=new Element("div",{id:"products-overlay"}).setStyles({height:window.getScrollSize().y,background:"#313131"}).setOpacity(0.5).inject($(document.body)),a=new Element("div",{id:"products-zoom"}).setStyles({position:"absolute",left:c.left+3,top:c.top+3,width:c.width-6,height:c.height-6,background:"#e3e4d6 url("+this.loaders[1].src+") center center no-repeat",opacity:0.6}).inject($(document.body));return a},my_choice_add:function(a,b){if(this.getParent("a").retrieve("selected")){this.getParent("a").store("selected",0);this.destroy();return false}b.data=$merge(b.data,{el:b.data.type=="decor"?this.getParent().get("rel").split(":")[1]:this.getParent().get("ref"),token:b.$this.settings.token});b.$this.my_choice_request(b.data);this.getParent("a").store("selected",1);this.setStyle("background","url(/Module/Products/Page/images/choice_added.gif) no-repeat");return false},my_choice_request:function(b){var a=this;if(this.choice_request===null){this.choice_request=new Request.JSON({async:false,method:"post",url:"/pl/products/choiceadd",data:{},onComplete:function(c,d){if(d){a.settings.token=d}}})}this.choice_request.options.data=b;this.choice_request.get()}});