(function(b){var a;a=b.fn.galleria=function(e){if(!a.hasCSS()){return false}b.historyInit(a.onPageLoad);var k={insert:".galleria_container",history:true,clickNext:true,onImage:function(m,l,i){},onThumb:function(i){}};var f=b.extend(k,e);for(var j in f){if(j){b.galleria[j]=f[j]}}var d=(b(f.insert).is(f.insert))?b(f.insert):jQuery(document.createElement("div")).insertBefore(this);var c=b(document.createElement("div")).addClass("galleria_wrapper");var h=b(document.createElement("span")).addClass("caption");var g=b(document.createElement("b")).addClass("image-next");d.addClass("galleria_container").append(c).append(h).append(g);return this.each(function(){b(this).addClass("galleria");b(this).children("li").each(function(r){var n=b(this);var l=b.meta?b.extend({},f,n.data()):f;l.clickNext=b(this).is(":only-child")?false:l.clickNext;var q=b(this).find("a").is("a")?b(this).find("a"):false;var m=b(this).children("img").css("display","none");var s=q?q.attr("href"):m.attr("src");var p=q?q.attr("title"):m.attr("title");var o=new Image();if(l.history&&(window.location.hash&&window.location.hash.replace(/\#/,"")==s)){n.siblings(".active").removeClass("active");n.addClass("active")}b(o).load(function(){b(this).attr("alt",m.attr("alt"));var u=q?q.find("img").addClass("thumb noscale").css("display","none"):m.clone(true).addClass("thumb").css("display","none");if(q){q.replaceWith(u)}if(!u.hasClass("noscale")){var i=Math.ceil(m.width()/m.height()*n.height());var t=Math.ceil(m.height()/m.width()*n.width());if(i<t){u.css({height:"auto",width:n.width(),marginTop:-(t-n.height())/2})}else{u.css({width:"auto",height:n.height(),marginLeft:-(i-n.width())/2})}}else{window.setTimeout(function(){u.css({marginLeft:-(u.width()-n.width())/2,marginTop:-(u.height()-n.height())/2})},1)}u.attr("rel",s);u.attr("title",p);u.click(function(){b.galleria.activate(s)});u.hover(function(){b(this).addClass("hover")},function(){b(this).removeClass("hover")});n.hover(function(){n.addClass("hover")},function(){n.removeClass("hover")});n.prepend(u);u.css("display","block");l.onThumb(jQuery(u));if(n.hasClass("active")){b.galleria.activate(s)}m.remove()}).error(function(){n.html('<span style="color: red;">Картинка недоступна: '+s+"</span>")}).attr("src",s)})})};a.nextSelector=function(c){return b(c).is(":last-child")?b(c).siblings(":first-child"):b(c).next()};a.previousSelector=function(c){return b(c).is(":first-child")?b(c).siblings(":last-child"):b(c).prev()};a.hasCSS=function(){b("body").append(b(document.createElement("div")).attr("id","css_test").css({width:"1px",height:"1px",display:"none"}));var c=(b("#css_test").width()!=1)?false:true;b("#css_test").remove();return c};a.onPageLoad=function(f){var d=b(".galleria_wrapper");var e=b('.galleria img[@rel="'+f+'"]');if(f){if(b.galleria.history){window.location=window.location.href.replace(/\#.*/,"")+"#"+f}e.parents("li").siblings(".active").removeClass("active");e.parents("li").addClass("active");var c=b(new Image()).attr("src",f).addClass("replaced");d.empty().append(c);d.siblings(".caption").html('<a href="/zakaz-taksi-kazan/">Заказать авто</a>'+e.attr("title"));d.siblings(".image-next").html('<a href="#" title="Следующее авто &raquo;" onclick="$.galleria.next(); return false;"><b></b></a>');b.galleria.onImage(c,d.siblings(".caption"),e)}else{d.siblings().andSelf().empty();b(".galleria li.active").removeClass("active")}b.galleria.current=f};b.extend({galleria:{current:"",onImage:function(){},activate:function(c){if(b.galleria.history){b.historyLoad(c)}else{a.onPageLoad(c)}},next:function(){var c=b(a.nextSelector(b('.galleria img[@rel="'+b.galleria.current+'"]').parents("li"))).find("img").attr("rel");b.galleria.activate(c)},prev:function(){var c=b(a.previousSelector(b('.galleria img[@rel="'+b.galleria.current+'"]').parents("li"))).find("img").attr("rel");b.galleria.activate(c)}}})})(jQuery);jQuery.extend({historyCurrentHash:undefined,historyCallback:undefined,historyInit:function(d){jQuery.historyCallback=d;var c=location.hash;jQuery.historyCurrentHash=c;if(jQuery.browser.msie){if(jQuery.historyCurrentHash===""){jQuery.historyCurrentHash="#"}$("body").prepend('<iframe id="jQuery_history" style="display: none;"></iframe>');var a=$("#jQuery_history")[0];var b=a.contentWindow.document;b.open();b.close();b.location.hash=c}else{if($.browser.safari){jQuery.historyBackStack=[];jQuery.historyBackStack.length=history.length;jQuery.historyForwardStack=[];jQuery.isFirst=true}}jQuery.historyCallback(c.replace(/^#/,""));setInterval(jQuery.historyCheck,100)},historyAddHistory:function(a){jQuery.historyBackStack.push(a);jQuery.historyForwardStack.length=0;this.isFirst=true},historyCheck:function(){if(jQuery.browser.msie){var a=$("#jQuery_history")[0];var d=a.contentDocument||a.contentWindow.document;var f=d.location.hash;if(f!=jQuery.historyCurrentHash){location.hash=f;jQuery.historyCurrentHash=f;jQuery.historyCallback(f.replace(/^#/,""))}}else{if($.browser.safari){if(!jQuery.dontCheck){var b=history.length-jQuery.historyBackStack.length;if(b){jQuery.isFirst=false;var c;if(b<0){for(c=0;c<Math.abs(b);c++){jQuery.historyForwardStack.unshift(jQuery.historyBackStack.pop())}}else{for(c=0;c<b;c++){jQuery.historyBackStack.push(jQuery.historyForwardStack.shift())}}var e=jQuery.historyBackStack[jQuery.historyBackStack.length-1];if(e!==undefined){jQuery.historyCurrentHash=location.hash;jQuery.historyCallback(e)}}else{if(jQuery.historyBackStack[jQuery.historyBackStack.length-1]===undefined&&!jQuery.isFirst){if(document.URL.indexOf("#")>=0){jQuery.historyCallback(document.URL.split("#")[1])}else{f=location.hash;jQuery.historyCallback("")}jQuery.isFirst=true}}}}else{f=location.hash;if(f!=jQuery.historyCurrentHash){jQuery.historyCurrentHash=f;jQuery.historyCallback(f.replace(/^#/,""))}}}},historyLoad:function(d){var e;if(jQuery.browser.safari){e=d}else{e="#"+d;location.hash=e}jQuery.historyCurrentHash=e;if(jQuery.browser.msie){var a=$("#jQuery_history")[0];var c=a.contentWindow.document;c.open();c.close();c.location.hash=e;jQuery.historyCallback(d)}else{if(jQuery.browser.safari){jQuery.dontCheck=true;this.historyAddHistory(d);var b=function(){jQuery.dontCheck=false};window.setTimeout(b,200);jQuery.historyCallback(d);location.hash=e}else{jQuery.historyCallback(d)}}}});
$(function(){$(".gallery").galleria({history:true,clickNext:true,insert:"#main_image",onImage:function(d,b,a){d.css("display","none").fadeIn(1000);b.css("display","none").fadeIn(1500);var c=a.parents("li");c.siblings().children("img.selected").fadeTo(500,1);a.fadeTo("fast",0.3).addClass("selected")},onThumb:function(a){var c=a.parents("li");var b=c.is(".active")?"0.3":"1";a.css({display:"none",opacity:b}).fadeIn(1500);a.hover(function(){a.fadeTo("fast",0.3)},function(){c.not(".active").children("img").fadeTo("fast",1)})}})});
$(function(){$(".image-next").fadeTo("fast",0);$(".image-next").hover(function(){$(this).fadeTo("normal",1)},function(){$(this).fadeTo("fast",0)})});
