var RecentGoods_class=new Class({catalog:null,Class:'RecentGoods_class',options:{count_item:3,URL:'http://my.sokol.ua/recent_goods/',tpl:'',cookie_duration:183,url:'/cgi-bin/recent_goods.php'},is_updated:0,existent_goods_id:[],initialize:function(options){this.setOptions(options);if(S.checkup)this.onLoadS(S);S.addEvent('loadS',this.onLoadS.bind(this))},init:function(id){if(this._isAllow()){this.elem=$(id);if($defined(this.S)&&$defined(this.goods)){this.update()}else if(Cookie.get("recent_goods")&&!Cookie.get("sid")){this.renewS()}}},_isAllow:function(){if(!$defined(this.options.users_quota)){var is_allow=true}else if(this.options.users_quota==0){var is_allow=false}else{var uid=Cookie.get('uid');var is_allow=(uid&&!(crc32(uid)%this.options.users_quota))}return is_allow},onLoadS:function(){if($defined(S.data)&&$defined(S.data.recent_goods)){this.S=S.data.recent_goods}else if(Cookie.get("recent_goods")){this.renewS()}if(this.S){this.goods=[];with(this.S)for(var key in records){if(!$defined(this.goods[key])&&$type(records[key])=='object'){this.goods.include(records[key]);this.existent_goods_id.include(this.goods[key].id)}};this.update()}},update:function(){if($defined(this.elem)&&!this.is_updated&&this.goods){var goods=this.goods.filter(function(item,key){return key<this.options.count_item}.bind(this));var node={};node.title='Просмотренные товары';node.href='http://my.sokol.ua/recent_goods/';this.elem.setHTML(App.getHTML(this.options.tpl,{goods:goods,node:node}));this.onUpdate(goods);this.is_updated=1}},onUpdate:function(items){},add:function(id){if(id&&this._isAllow()){var cookie_str=Cookie.get("recent_goods")?Cookie.get("recent_goods"):'';var recent_goods_ids=cookie_str.split(/,/);if(!recent_goods_ids.contains(id.toString())){cookie_str=cookie_str?cookie_str+','+id:id;Cookie.set("recent_goods",cookie_str,{duration:this.options.cookie_duration,domain:'.sokol.ua',path:'/'});this.renewS()}}},renewS:function(){S.renew(this.options.url)}});RecentGoods_class.implement(new Options,new Events);var SokolRecentGoods_class=RecentGoods_class.extend({update:function(){if($defined(this.elem)&&!this.is_updated&&this.goods){var goods=this.goods.filter(function(item,key){return key<this.options.count_item}.bind(this));var node={};node.title='Просмотренные товары';node.href='http://my.sokol.ua/recent_goods/';var need_to_show_all_link=(this.goods.length>this.options.count_item);this.elem.setHTML(App.getHTML(this.options.tpl,{goods:goods,node:node,need_to_show_all_link:need_to_show_all_link}));if($defined(this.catalog)){goods.each(function(goods_record){if(goods_record.id!=undefined)this.catalog.add(goods_record.id)}.bind(this));this.fireEvent('update')}this.is_updated=1}}});var GoodsStock=new GoodsStock_class().setOptions({id:'stock-block',items_tpl:'<section class=\"named-block goods tile offer\">\r\n\t<header class=\"head\">\r\n\t\t<div class=\"container\">\r\n\t\t\t<h2>\u0420\u0430\u0441\u043f\u0440\u043e\u0434\u0430\u0436\u0430<\/h2>\r\n\t\t<\/div>\r\n\t<\/header>\r\n\t<div class=\"inner\">\r\n\t\t<div class=\"container\">\r\n\t\t   {if  !hide_all_link}\r\n\t\t   <div class=\"all\">\r\n\t\t\t\t<a href=\"{if all_link_href}${all_link_href}{else}http:\/\/www.sokol.ua\/stock\/c77838\/{\/if}\" class=\"with-arrow\">\r\n\t\t\t\t\t<span>\u0421\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0432\u0441\u0435<\/span> <span class=\"arrow\">&rarr;<\/span>\r\n\t\t\t\t<\/a>\r\n\t\t\t<\/div>\r\n\t\t   {\/if}\r\n\t\t   <table class=\"one-fouth\">\r\n\r\n\t\t\t\t{macro toImagesRow(item)}\r\n\t\t\t\t<td>\r\n\t\t\t\t\t<a href=\"${item.href}\">\r\n\t\t\t\t\t\t${item.image}\r\n\t\t\t\t\t\t<span class=\"tag-stock\"><\/span>\r\n\t\t\t\t\t<\/a>\r\n\t\t\t\t\t<\/td>\r\n\t\t\t\t{\/macro}\r\n\t\t\t\t{macro toDetailsRow(item)}\r\n\t\t\t\t<td id=\"catalog_item${item.id}\">\r\n\t\t\t\t\t\t\t\t\t\t<div class=\"title\"><a href=\"${item.href}\">${item.title}<\/a><\/div>\r\n\t\t\t\t\t<div class=\"price\"><span class=\"uah\" name=\"uah\">${item.price}<\/span> <span class=\"usd\" name=\"usd\">${item.price_usd}<\/span><\/div>\r\n\t\t\t\t\t{if item.description_defect}\r\n\t\t\t\t\t\t\t<div class=\"stock-docket\">${item.description_defect}<\/div>\r\n\t\t\t\t\t{\/if}\r\n\t\t\t\t<\/td>\r\n\t\t\t\t{\/macro}\r\n\r\n\t\t\t\t{var images=\"\"}\r\n\t\t\t\t{var details=\"\"}\r\n\t\t\t\t{var count=0}\r\n\t\t\t\t{for item in items}\r\n\t\t\t\t\t{var images = images+toImagesRow(item)}\r\n\t\t\t\t\t{var details = details+toDetailsRow(item)}\r\n\t\t\t\t\t{var count=count+1}\r\n\t\t\t\t\t{if count%4 == 0 }\r\n\t\t\t<tr class=\"images\">${images}<\/tr>\r\n\t\t\t<tr class=\"details\">${details}<\/tr>\r\n\t\t\t\t\t{var images=\"\"}\r\n\t\t\t\t\t{var details=\"\"}\r\n\t\t\t\t\t{var count=0}\r\n\t\t\t\t\t{\/if}\r\n\t\t\t\t{\/for}\r\n\r\n\t\t\t\t{if count==3}\r\n\t\t\t\t\t{var items = images+\"<td><\/td>\"}\r\n\t\t\t\t\t{var details = details+\"<td><\/td>\"}\r\n\t\t\t\t{elseif count==2}\r\n\t\t\t\t\t{var items = images+\"<td><\/td><td><\/td>\"}\r\n\t\t\t\t\t{var details = details+\"<td><\/td><td><\/td>\"}\r\n\t\t\t\t{elseif count==1}\r\n\t\t\t\t\t{var items = images+\"<td><\/td><td><\/td><td><\/td>\"}\r\n\t\t\t\t\t{var details = details+\"<td><\/td><td><\/td><td><\/td>\"}\r\n\t\t\t\t{\/if}\r\n\r\n\t\t\t\t{if images && details}\r\n\t\t\t<tr class=\"images\">${images}<\/tr>\r\n\t\t\t<tr class=\"details\">${details}<\/tr>\r\n\t\t\t\t{\/if}\r\n\r\n\t\t\t<\/table>\r\n\t\t<\/div>\r\n\t<\/div>\r\n<\/section>\r',hide_all_link:false});SokolRecentGoods_class.prototype.catalog=GoodsCatalog;var RecentGoods=new SokolRecentGoods_class().setOptions({count_item:2,tpl:'<section class=\"goods\"> <div class=\"named-block small-view\"> <header class=\"head\"> <div class=\"container\"> <h2>\u041f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u043d\u044b\u0435 \u0442\u043e\u0432\u0430\u0440\u044b<\/h2> <\/div> <\/header> <div class=\"inner\"> <div class=\"container\"> {for item in goods} {if item.id} <div class=\"item\"> <div class=\"title\"><a href=\"${item.href}\">${item.title}<\/a><\/div> <div class=\"details\"> {if item.attachments.images && item.attachments.images.mobile_small} <div class=\"image\"><a href=\"${item.href}\"> <img src=\"${item.attachments.images.mobile_small.url}\" width=\"${item.attachments.images.mobile_small.width}\" height=\"${item.attachments.images.mobile_small.height}\" alt=\"${item.title}\" \/> <\/a><\/div> {\/if} <div class=\"description\" id=\"catalog_item${item.id}\"> <div class=\"price\"><span class=\"uah\" name=\"uah\">${item.price}<\/span> <span class=\"usd\" name=\"usd\">${item.price_usd}<\/span><\/div> <\/div> <\/div> <\/div> {\/if} {\/for} {if need_to_show_all_link} <div class=\"all\"><a href=\"${node.href}\" class=\"with-arrow\"><span>\u0421\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0432\u0441\u0435<\/span> <span class=\"arrow\">&rarr;<\/span><\/a><\/div> {\/if} <\/div> <\/div> <\/div> <\/section>'});GoodsCatalog.updateBind(RecentGoods);var RecentGoodsMain=new SokolRecentGoods_class().setOptions({count_item:4,tpl:'<section class=\"goods\"> <div class=\"named-block\"> <header class=\"head\"> <div class=\"container\"> <h2>\u041f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u043d\u044b\u0435 \u0442\u043e\u0432\u0430\u0440\u044b<\/h2> <\/div> <\/header> <div class=\"inner\"> <div class=\"container recent-goods\"> {if need_to_show_all_link} <div class=\"all\"><a href=\"${node.href}\" class=\"with-arrow\"><span>\u0421\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0432\u0441\u0435<\/span> <span class=\"arrow\">&rarr;<\/span><\/a><\/div> {\/if} <table class=\"one-fouth\"><tr> {for item in goods} {if item.id} <td> {if item.attachments.images.mobile_small} <div class=\"image image50\"> <table><tr><td> <a href=\"${item.href}\"> <img src=\"${item.attachments.images.mobile_small.url}\" width=\"${item.attachments.images.mobile_small.width}\" height=\"${item.attachments.images.mobile_small.height}\" alt=\"${item.title}\" \/> <\/a> <\/td><\/tr><\/table> <\/div> {\/if} {if item.parent_title_single}<div class=\"type\">${item.parent_title_single}<\/div>{\/if} <div class=\"title\"><a href=\"${item.href}\">${item.title}<\/a><\/div> <div class=\"description\" id=\"catalog_item${item.id}\"> <div class=\"price\"><span class=\"uah\" name=\"uah\">${item.price}<\/span> <span class=\"usd\" name=\"usd\">${item.price_usd}<\/span><\/div> <\/div> <\/td> {\/if} {\/for} <\/tr><\/table> <\/div> <\/div> <\/div> <\/section>'});GoodsCatalog.updateBind(RecentGoodsMain);
