onDomReady(function(){if($('key_search')){addEvent($('key_search'),'click',function(){this.style.backgroundImage='none'});addEvent($('key_search'),'keyup',function(){this.style.backgroundImage='none'
if(this.value){var ajax=new ajaxRequest("xml.php?file=key_search&key="+this.value);ajax.callBack(function(data){$('set_key').innerHTML='';var xmlData=data.responseXML;var properties=xmlData.getElementsByTagName('result');var propertiesValues=xmlData.getElementsByTagName('value');if(properties.length>0){$('set_key').style.display='block';for(var i=0,l=properties.length;i<l;i++){var propertiesList=addElement('li',{'styles':{'cursor':'pointer'}});var propertyValue=propertiesValues[i].firstChild.nodeValue;propertiesList.innerHTML=properties[i].firstChild.nodeValue;addEvent(propertiesList,'click',function(event,propertyValue){$('key_search').value=propertyValue;$('set_key').style.display='none';},propertyValue);$('set_key').appendChild(propertiesList);}}else{$('set_key').style.display='none';}});ajax.get();}});}
$css('span.email').forEach(function(item){var email=item.firstChild.nodeValue.replace('[at]','@');;item.innerHTML='<a href="mailto:'+email+'">'+email+'</a>';});if($('select_operation')){addEvent($('select_operation'),'change',function(){var selected=this.options[this.selectedIndex];var selectShow=(selected.value=='2')?$('select_rent'):$('select_buy');var selectHide=(selected.value=='2')?$('select_buy'):$('select_rent');selectHide.style.display='none';selectHide.removeAttribute('name');selectShow.style.display='inline';selectShow.name='price';selectShow.options[0].selected='selected';});}
if($('display_contact')){addEvent($('display_contact'),'click',function(event){stopEvent(event);if(hasClass(this,'nav_hide')){reverseClass(this,'nav_hide','nav_show');reverseClass($('display_images'),'nav_hide','nav_show');}
$('property_images').style.display='none';$('property_contact').style.display='block';});addEvent($('display_images'),'click',function(event){stopEvent(event);if(hasClass(this,'nav_hide')){reverseClass(this,'nav_hide','nav_show');reverseClass($('display_contact'),'nav_hide','nav_show');}
$('property_contact').style.display='none';$('property_images').style.display='block';});}});function slideShow(){var cOpacity=1,nOpacity=0,current=0,nIndex=1,imgs=[];this.options={step:3000,duration:700,align:['center','middle']};this.ajax=function(xml){var ajax=new ajaxRequest(xml);ajax.callBack(function(data,fnc){var photos=[],tagPhoto=data.responseXML.getElementsByTagName('photo');for(var i=0,l=tagPhoto.length;i<l;i++){photos.push(tagPhoto[i].firstChild.nodeValue);};fnc.setImages(photos);},this)
ajax.get();};this.initialize=function(el,options){this.box=$(el);for(var property in options)this.options[property]=options[property];this.box.position='relative';imgs[0]=$el(this.box,'img')[0];setStyles(imgs[0],{'position':'absolute'});};this.setImages=function(photos){for(var i=0,l=photos.length;i<l;i++){imgs[i+1]=addElement('img',{src:photos[i],styles:{display:'none',position:'absolute',opacity:0}});this.box.appendChild(imgs[i+1]);}
if(photos.length>0)this.nextImage(1);};this.nextImage=function(numIm){nIndex=imgs[current+1]?current+1:0;var nextImage=new Image();addEvent(nextImage,'load',function(event,fnc){fnc.play(numIm);},this);nextImage.src=imgs[numIm].src;};this.play=function(numIm){imgs[numIm].style.display='block';var fx=new Fx;fx.initialize([imgs[current],imgs[nIndex]],{duration:this.options.duration,curve:['cos']});setTimeout(function(fnc){return function(){fx.start({0:{'opacity':[1,0]},1:{'opacity':[0,1]}},function(){imgs[current].style.display='none';current=nIndex;nextLoad=imgs[nIndex+1]?nIndex+1:0;fnc.nextImage(nextLoad);});}}(this),this.options.step);};}
function ajaxGallery(xml){if($('gallery')){slideDiapo();var ajax=new ajaxRequest(xml);ajax.callBack(function getGallery(data){var pictureGallery=new gallery(data.responseXML)
pictureGallery.loader();});ajax.get();}};function gallery(data){$('gallery_menu').style.overflow='hidden';var photo=$('gallery_image');var photoBox=$('gallery_box');var photoDescription=$('gallery_description');var loadingImg=$('loading');var preLoader=[];var galleryMenu=$el($('gallery_menu'),'a');addEvents(galleryMenu,'click',function(event,fnc){galleryMenu.forEach(function(img,i){preLoader[i].src='';});fnc.displayImage(this.id.replace('diapo_',''));stopEvent(event);},this);this.loader=function(){galleryMenu.forEach(function(item,index){preLoader[index]=new Image();preLoader[index].src=data.getElementsByTagName('photo_'+item.id.replace('diapo_',''))[0].getElementsByTagName('src')[0].firstChild.nodeValue;});},this.displayImage=function(numIm){photo.style.display='none';loadingImg.style.display='inline';var xmlPhoto=Xml(data).tag('photo_'+numIm).first;var srcPhoto=Xml(xmlPhoto).tag('src').value;var descPhoto=Xml(xmlPhoto).tag('description').value;var widthPhoto=Xml(xmlPhoto).tag('width').value;var heightPhoto=Xml(xmlPhoto).tag('height').value;var imagesLoader=new Image();addEvent(imagesLoader,'load',function(event,fnc){setTimeout(function(){var fx=new Fx;fx.initialize(photo,{duration:800,curve:['cos']});loadingImg.style.display='none';photoDescription.innerHTML=(descPhoto)?descPhoto:'';setStyles(photo,{'width':widthPhoto+'px','height':heightPhoto+'px','display':'inline','opacity':0})
photo.id='gallery_image';photo.src=srcPhoto;fx.start({'opacity':[0,1]});fnc.loader();},100);},this);imagesLoader.src=srcPhoto;}}
function slideDiapo(){var galleryMenu=$('gallery_menu');var gallerySlide=$('gallery_slide');var leftArrow=$('left_arrow');var rightArrow=$('right_arrow');var leftPosition=findPos(gallerySlide).left;setStyles(galleryMenu,{'position':'relative'});setStyles(gallerySlide,{'overflow':'hidden'});var scrollFx=new scrollBox();this.set=function(){leftArrow.style.display=(gallerySlide.scrollWidth>(gallerySlide.offsetWidth+10))?'block':'none';rightArrow.style.display=(gallerySlide.scrollWidth>(gallerySlide.offsetWidth+10))?'block':'none';scrollFx.set(gallerySlide);}
addEvent(window,'resize',function(event,fnc){fnc.set()},this);this.set();addEvent(gallerySlide,'mousemove',function(event){if(!hasClass(gallerySlide,'sliding')){cursorRatio=(Cursor(event).page.x-(leftPosition+(gallerySlide.offsetWidth/2)))/80;scrollFx.init({'Left':cursorRatio});}});addEvent(gallerySlide,'mouseleave',function(event){scrollFx.stop()});addEvent(leftArrow,'mouseover',function(event){scrollFx.init({'Left':-3})});addEvent(leftArrow,'mouseout',function(event){scrollFx.stop()});addEvent(rightArrow,'mouseover',function(event){addClass(gallerySlide,'sliding');scrollFx.init({'Left':3});});addEvent(rightArrow,'mouseout',function(event){removeClass(gallerySlide,'sliding');scrollFx.stop()});}
function scrollBox(){this.set=function(el){this.el=el;this.timer=false;this.limit={'Top':(el.scrollHeight)-(el.offsetHeight),'Left':(el.scrollWidth)-(el.offsetWidth)}};this.init=function(move){this.slide=[];this.increase=[];for(var pos in move){this.increase[pos]=move[pos];this.slide[pos]=this.el["scroll"+pos];}
if(!this.timer){this.timer=setInterval(function(fnc){return function(){for(var pos in move)fnc.move(pos);}}(this),30);}};this.move=function(pos){if(this.slide[pos]+this.increase[pos]<0){this.stop();this.el['scroll'+pos]=0;this.slide[pos]=0;}else if(this.slide[pos]+this.increase[pos]>this.limit[pos]){this.stop();this.slide[pos]=this.limit[pos];this.el['scroll'+pos]=this.limit[pos];}else{this.slide[pos]+=this.increase[pos];this.el['scroll'+pos]=this.slide[pos];}}
this.stop=function(){clearInterval(this.timer);this.timer=false;}}
