$(document).ready(function(){$pelena=$('.pelena');$loader=$('.loader');$popup=$('.popup');$popupCache=null;$effectTime=300;getPopup=function($itemIndex){$galleryCurrentItem=$itemIndex;htmlHeight=parseInt($(document).height());if($.browser.msie&&$.browser.version==6){$pelena.css({"height":htmlHeight});}
$pelena.fadeIn($effectTime,function(){loaderHeight=$(document).scrollTop()+(($(window).height()-$loader.height()-40)*0.5);loaderWidth=$(document).scrollLeft()+(($(window).width()-$loader.width())*0.5);$loader.css({"top":loaderHeight,"left":loaderWidth});$loader.show();if($popupCache==null){$popup.load(document.location.href,{galleryPopup:1},function(a,b,c){$popupCache=$popup.html();showPopup();});}
else
{$popup.html($popupCache);showPopup();}});}
showPopup=function(){$popup.css({minWidth:0,minHeight:0});popupHeight=$(document).scrollTop()+(($(window).height()-$popup.height()-25)*0.5);popupWidth=$(document).scrollLeft()+(($(window).width()-$popup.width())*0.5);if(popupHeight<5){popupHeight=5;}
$popup.css({"top":popupHeight,"left":popupWidth});$popup.find('a.close').click(function(){closePelena();return false;});showGallery();$popup.fadeIn($effectTime);$loader.hide();}
closePelena=function(){if($pelena.css('display')!='none'){$loader.hide();$popup.fadeOut($effectTime,function(){$popup.html('');$pelena.fadeOut($effectTime);});}}
$(document).keyup(function(e){if(e.keyCode==27){closePelena();}});$pelena.click(function(){closePelena();return false;});$loader.click(function(){closePelena();return false;});});;$(document).ready(function(){$gallerySlider=null;$galleryAllItems=0;$galleryCurrentItem=1;$galleryAnimateBig=false;$galleryAnimateSmall=false;$galleryWidthBig=660;$galleryWidthSmall=125;$galleryOnLineSmall=6;showGallery=function(){$gallerySlider=$('.slider');$galleryAllItems=$gallerySlider.find('.small-imgs a').size();$galleryAnimate=false;$gallerySlider.find('.big-imgs img').preload({placeholder:'/images/preloaders/gallery-popup-big-placeholder.png',notFound:'/images/preloaders/gallery-popup-big-notfound.png'});$gallerySlider.find('.small-imgs img').preload({placeholder:'/images/preloaders/gallery-popup-list-placeholder.png',notFound:'/images/preloaders/gallery-popup-list-notfound.png'});$gallerySlider.find('.big-imgs').width($galleryAllItems*$galleryWidthBig);$gallerySlider.find('.small-imgs').width($galleryAllItems*$galleryWidthSmall);$gallerySlider.find('a.arrow-left').click(function(){if(!$galleryAnimateBig&&!$galleryAnimateSmall)
{$galleryAnimateBig=true;$galleryAnimateSmall=true;if($galleryCurrentItem==1)
{$galleryCurrentItem=$galleryAllItems;}
else
{$galleryCurrentItem=$galleryCurrentItem-1;}
animateGallery();}
return false;});$gallerySlider.find('a.arrow-right, .big-imgs').click(function(){if(!$galleryAnimateBig&&!$galleryAnimateSmall)
{$galleryAnimateBig=true;$galleryAnimateSmall=true;if($galleryCurrentItem==$galleryAllItems)
{$galleryCurrentItem=1;}
else
{$galleryCurrentItem=$galleryCurrentItem+1;}
animateGallery();}
return false;});$gallerySlider.find('.small-imgs a').click(function(){if(!$galleryAnimateBig&&!$galleryAnimateSmall)
{$galleryAnimateBig=true;$galleryAnimateSmall=true;$galleryCurrentItem=$gallerySlider.find('.small-imgs a').index(this)+1;animateGallery();}
return false;});animateGallery();}
animateGallery=function(){bigAnimate=($galleryCurrentItem-1)*$galleryWidthBig;$gallerySlider.find('.big-imgs').animate({marginLeft:'-'+bigAnimate+'px'},600,function(){$galleryAnimateBig=false;});$gallerySlider.find('h1').fadeOut(300,function(){$(this).html($gallerySlider.find('.small-imgs img:eq('+($galleryCurrentItem-1)+')').attr('alt')).fadeIn(300);})
$gallerySlider.find('.small-imgs img.active').removeClass('active');if(($galleryAllItems-$galleryCurrentItem)<($galleryOnLineSmall)&&($galleryAllItems>$galleryOnLineSmall))
{smallAnimate=($galleryAllItems-$galleryOnLineSmall)*$galleryWidthSmall;}
else
{smallAnimate=($galleryCurrentItem-1)*$galleryWidthSmall;}
$gallerySlider.find('.small-imgs').animate({marginLeft:'-'+smallAnimate+'px'},600,function(){$gallerySlider.find('.small-imgs img:eq('+($galleryCurrentItem-1)+')').addClass('active');$galleryAnimateSmall=false;});}});;;(function($){var $preload=$.preload=function(original,settings){if(original.split)
original=$(original);settings=$.extend({},$preload.defaults,settings);var sources=$.map(original,function(source){if(!source)
return;if(source.split)
return settings.base+source+settings.ext;var url=source.src||source.href;if(typeof settings.placeholder=='string'&&source.src)
source.src=settings.placeholder;if(url&&settings.find)
url=url.replace(settings.find,settings.replace);return url||null;});var data={loaded:0,failed:0,next:0,done:0,total:sources.length};if(!data.total)
return finish();var imgs=$(Array(settings.threshold+1).join('<img/>')).load(handler).error(handler).bind('abort',handler).each(fetch);function handler(e){data.element=this;data.found=e.type=='load';data.image=this.src;data.index=this.index;var orig=data.original=original[this.index];data[data.found?'loaded':'failed']++;data.done++;if(settings.enforceCache)
$preload.cache.push($('<img/>').attr('src',data.image)[0]);if(settings.placeholder&&orig.src){$(orig).hide();orig.src=data.found?data.image:settings.notFound||orig.src;$(orig).fadeIn(500);}
if(settings.onComplete)
settings.onComplete(data);if(data.done<data.total)
fetch(0,this);else{if(imgs&&imgs.unbind)
imgs.unbind('load').unbind('error').unbind('abort');imgs=null;finish();}};function fetch(i,img,retry){if(img.attachEvent&&data.next&&data.next%$preload.gap==0&&!retry){setTimeout(function(){fetch(i,img,true);},0);return false;}
if(data.next==data.total)return false;img.index=data.next;img.src=sources[data.next++];if(settings.onRequest){data.index=img.index;data.element=img;data.image=img.src;data.original=original[data.next-1];settings.onRequest(data);}};function finish(){if(settings.onFinish)
settings.onFinish(data);};};$preload.gap=14;$preload.cache=[];$preload.defaults={threshold:2,base:'',ext:'',replace:'',enforceCache:true};$.fn.preload=function(settings){$preload(this,settings);return this;};})(jQuery);;(function($){$.fn.toggleVal=function(theOptions){if(!theOptions||typeof theOptions=='object'){theOptions=$.extend({},$.fn.toggleVal.defaults,theOptions);}
else if(typeof theOptions=='string'&&theOptions.toLowerCase()=='destroy'){var destroy=true;}
return this.each(function(){if(destroy){$(this).unbind('focus.toggleval').unbind('blur.toggleval').removeData('defText');return false;}
var defText='';switch(theOptions.populateFrom){case'title':if($(this).attr('title')){defText=$(this).attr('title');$(this).val(defText);}
break;case'label':if($(this).attr('id')){defText=$('label[for="'+$(this).attr('id')+'"]').text();$(this).val(defText);}
break;case'custom':defText=theOptions.text;$(this).val(defText);break;default:defText=$(this).val();}
$(this).addClass('toggleval').data('defText',defText);if(theOptions.removeLabels==true&&$(this).attr('id')){$('label[for="'+$(this).attr('id')+'"]').remove();}
$(this).bind('focus.toggleval',function(){if($(this).val()==$(this).data('defText')){$(this).val('');}
$(this).addClass(theOptions.focusClass);}).bind('blur.toggleval',function(){if($(this).val()==''&&!theOptions.sticky){$(this).val($(this).data('defText'));}
$(this).removeClass(theOptions.focusClass);if($(this).val()!=''&&$(this).val()!=$(this).data('defText')){$(this).addClass(theOptions.changedClass);}
else{$(this).removeClass(theOptions.changedClass);}});});};$.fn.toggleVal.defaults={focusClass:'tv-focused',changedClass:'tv-changed',populateFrom:'default',text:null,removeLabels:false,sticky:false};$.extend($.expr[':'],{toggleval:function(elem){return $(elem).data('defText')||false;},changed:function(elem){if($(elem).data('defText')&&$(elem).val()!=$(elem).data('defText')){return true;}
return false;}});})(jQuery);
