/**************
/js/jquery.cookie.js
/js/imagelist.js
/js/dropdownmenu.js
**************/



jQuery.cookie=function(name,value,options){if(typeof value!='undefined'){options=options||{};if(value===null){value='';options.expires=-1;}
var expires='';if(options.expires&&(typeof options.expires=='number'||options.expires.toUTCString)){var date;if(typeof options.expires=='number'){date=new Date();date.setTime(date.getTime()+(options.expires*24*60*60*1000));}else{date=options.expires;}
expires='; expires='+date.toUTCString();}
var path=options.path?'; path='+(options.path):'';var domain=options.domain?'; domain='+(options.domain):'';var secure=options.secure?'; secure':'';document.cookie=[name,'=',encodeURIComponent(value),expires,path,domain,secure].join('');}else{var cookieValue=null;if(document.cookie&&document.cookie!=''){var cookies=document.cookie.split(';');for(var i=0;i<cookies.length;i++){var cookie=jQuery.trim(cookies[i]);if(cookie.substring(0,name.length+1)==(name+'=')){cookieValue=decodeURIComponent(cookie.substring(name.length+1));break;}}}
return cookieValue;}};;(function($){$(function(){var qs=parseQueryString(window.location.search);if(typeof sort_modes!="undefined"&&sort_modes){var sortAction=function(mode){return function(){var qs=parseQueryString(window.location.search);if(mode==default_sort_mode)delete qs.sort;else qs.sort=mode;delete qs.page;window.location.search="?"+makeQueryString(qs);};};var sortMenu=[];$.each(sort_modes,function(k,v){sortMenu.push({text:v,onclick:sortAction(k)});});if(sortMenu.length>0){$("#sort-para").show();if(typeof qs.sort=="undefined"||typeof sort_modes[qs.sort]=="undefined"){$("#sort-by").text("Сортировка "+sort_modes[default_sort_mode]+"\u25bc");}else{$("#sort-by").text("Сортировка "+sort_modes[qs.sort]+"\u25bc");}
$("#sort-by").css("cursor","pointer").hoverClass("hl").click(function(event){showDropDownMenu(event.pageX+8,event.pageY+8,sortMenu);return false;});}}
function setListSize(n){return function(){var p=parseQueryString(window.location.search);if(typeof p.page=="undefined")p.page=1;$("form[name='PageImagelistSetSizeForm']").find(":input[name='listSize']").val(n).end().find(":input[name='page']").val(p.page).end().submit();};}
$("#image-list-size").attachDropdownMenu([{text:"по 12 шт.",onclick:setListSize(12)},{text:"по 24 шт.",onclick:setListSize(24)},{text:"по 36 шт.",onclick:setListSize(36)},{text:"по 48 шт.",onclick:setListSize(48)}]);$("div.image-table div.th-block").hoverClass("hover");$("div.image-table .tollbtn").ajaxStop(function(){$(this).removeClass("in-process");});$("div.image-table a.add-to-cart").click(function(){var self=this;self.blur();if($(self).hasClass("in-process"))return false;$(self).addClass("in-process");$.post($(self).hasClass("in-cart")?"/ajax-service/remove-from-cart":"/ajax-service/add-to-cart",{image_id:$(self).parents(".th-block:first").attr("id").substr("image".length)},function(result){$(self).removeClass("in-process");if(typeof result=="string"){alert(result);}else{if($(self).hasClass("in-cart")){$(self).addClass("autohide").removeClass("in-cart").attr("hint","Добавить в корзину");$(document).trigger("cartCountChanged",[-1]);}else{GA_track('/!events/cart-add/from-imagelist');$(self).removeClass("autohide").addClass("in-cart").attr("hint","В корзине (удалить)");$(document).trigger("cartCountChanged",[+1]);}}},"json");return false;});$("div.image-table a.add-to-album").click(function(event){this.blur();var imageId=$(this).parents(".th-block:first").attr("id").substr("image".length);loadScriptOnDemand("/js/albums-lib.js",function(){return typeof AlbumsLib!="undefined"},function(){AlbumsLib.showMenuAtImageListPage(imageId,event);});return false;});var muteBy=function(param,value){return function(){var qs=parseQueryString(location.search);if(typeof qs[param]=='undefined')qs[param]=value;else qs[param]+=','+value;location.search=makeQueryString(qs);}};$("div.image-table .mute-this").live('click',function(event){var cell=$(this).parents(".th-block:first");var imageId=cell.attr("id").substr("image".length);var author=cell.attr("author");var models=$.trim(cell.attr("models"));var menu=[];menu.push({html:"Убрать из результатов поиска<br>изображения:"});menu.push({separator:true});menu.push({text:"Похожие на данное",onclick:muteBy('like',-imageId)});menu.push({text:"Данного автора",onclick:muteBy('author','-'+author)});if(models!='')
menu.push({text:"С данной моделью",onclick:muteBy('model','-'+models.replace(' ',',-'))});showDropDownMenu(event.pageX+8,event.pageY+8,menu);});$('.is_muted .pseudolink').click(function(){var qs=parseQueryString(location.search);$.each(['like','author','model'],function(){if(typeof qs[this]=='undefined')return;qs[this]=qs[this].replace(/,?-[^,]+/g,'');if(qs[this]=='')delete qs[this];});location.search=makeQueryString(qs);});var maWin=null;$("#mass-action").click(function(){this.blur();if(!maWin)maWin=$('<div class="jqmWindow"></div>').appendTo(document.body).jqm({modal:true});maWin.load("/ajax-service/img-list-mass-action").html("Загрузка…").jqmShow();return false;});$("div.image-table div.th-block div.charity").each(function(){$(this).css("left",($(this).siblings(".thumbnail").width()+12)+"px").show();});$("div.image-table div.th-block div.br_icons").each(function(){var th=$(this).siblings(".thumbnail");var bl=$(this).parent();$(this).css({top:(th.height()-9)+"px",right:(bl.width()-th.width()+11)+"px"}).show();});$("div.image-table div.th-block .tollbtn.right").each(function(){var th=$(this).siblings(".thumbnail");$(this).css({left:(th.width()+24)+"px"});});var has_overflow=function(e){e.scrollTop=5;if(e.scrollTop>0){e.scrollTop=0;return true;}else{return false;}};$("a.img-title").each(function(){if(!has_overflow(this))return;var htext=htmlsafe($(this).text());var t=htext;do{t=t.replace(/[\s,.-]\S+$/,'')+'<span>[…]</span>';$(this).html(t);}while(has_overflow(this));$('span',this).attr('hint','<div style="width: 250px;">'+htext+'</div>');});if(!$.browser.msie||parseFloat($.browser.version)>=7.0){var imgTable=$("div.image-table>table");var curCells=$("tr:first>td",imgTable).length;var totalCells=$("td",imgTable).length;$(window).bind("load resize",function(){var nCells=Math.floor((document.documentElement.clientWidth-300)/190);if(nCells>6)nCells=6;else if(nCells>4)nCells=4;else if(nCells<2)nCells=2;if(nCells==curCells)return;var nRows=totalCells/nCells;var t=document.createElement("table");for(var j=0;j<nRows;j++){var r=t.insertRow(-1);for(var i=0;i<nCells;i++){var d=imgTable.find("div.th-block:first").get(0);var c=r.insertCell(-1);if(d)c.appendChild(d);}}
imgTable.replaceWith(t).remove();imgTable=$(t);curCells=nCells;$.cookie('imglist_cells',nCells,{path:'/'});});}});})(jQuery);;window.showDropDownMenu=null;(function(){var Menu=null;$(function(){Menu=document.createElement("UL");Menu.className="DropDownMenu";document.body.appendChild(Menu);$(document.body).click(function(){$(Menu).hide();});window.showDropDownMenu=function(x,y,items){$(Menu).empty();$.each(items,function(i,item){var li=$("<li></li>").appendTo(Menu);if(typeof item.text!="undefined")li.text(item.text);if(typeof item.html!="undefined")li.html(item.html);if(typeof item.checked!="undefined")li.addClass(item.checked?"check on":"check off");if(typeof item.onclick!="undefined"){li.click(item.onclick).hover(function(){$(this).addClass("hl");},function(){$(this).removeClass("hl");});}else if(typeof item.url!="undefined"){li.click(function(){window.location=item.url;}).hover(function(){$(this).addClass("hl");},function(){$(this).removeClass("hl");});}else if(typeof item.separator!="undefined"){li.addClass("separator");}else{li.addClass("static");}});$(Menu).css({left:x+"px",top:y+"px"}).show("fast",function(){if(x+$(Menu).width()>$(window).width())
$(Menu).css({left:($(window).width()-$(Menu).width()-4)+"px"})});};});jQuery.fn.attachDropdownMenu=function(menu){return this.css("cursor","pointer").hover(function(){$(this).addClass("yellow-highlight");},function(){$(this).removeClass("yellow-highlight");}).click(function(event){showDropDownMenu(event.pageX+8,event.pageY+8,menu);return false;});};})();;