PropertyImageDlg=Class.create({
	initialize:function(id,title){
		this._width=404;this._height=304;this.width=this._width.toString()+"px";this.height=this._height.toString()+"px";
		this.top="0px";this.left="0px";this.id=id;this.title=title;this.params={id:this.id};
		this.url="/Ajax/sr_xml.php";this.imageElement;this.imageSrc;this.waitImageSrc="/images/loading.gif";
		this.overlayDiv=new Element("div",{id:"div_overlay"});var dim=this._getPageSize();
		this.overlayHeight=dim.pageHeight.toString()+"px";this.overlayWidth=dim.pageWidth.toString()+"px";
		this.overlayDivStyle=$H({position:"absolute",left:"0px",top:"0px",width:"100%",height:this.overlayHeight,backgroundColor:"#000",opacity:0.0,zIndex:999});
		this.overlayDiv.setStyle(this.overlayDivStyle.toObject());
		this.labelDiv=new Element("div").setStyle({position:"absolute",left:"2px",top:"-49px",width:"400px",height:"50px",textAlign:"center",lineHeight:"79px",fontSize:"12px",fontWeight:"bold",color:"#069",letterSpacing:"3px",wordSpacing:"4px",backgroundImage:"url(/images/label_horz.png)",fontFamily:"Verdana, Geneva, sans-serif"}).update(this.title).pngHack();
		this.topLeftVertDiv=new Element("div").setStyle({position:"absolute",left:"-8px",top:"-19px",width:"10px",height:"80px",backgroundImage:"url(/images/top_left_vert.png)"}).pngHack();
		this.topRightVertDiv=new Element("div").setStyle({position:"absolute",right:"-8px",top:"-19px",width:"10px",height:"80px",backgroundImage:"url(/images/top_right_vert.png)"}).pngHack();
		this.idDiv=new Element("div").setStyle({position:"absolute",right:"1px",top:"-19px",width:"40px",height:"20px",textAlign:"right",lineHeight:"22px",fontSize:"14px",fontWeight:"bold",color:"#6CA870"});
		this.listingDiv=new Element("div").setStyle({position:"absolute",left:"2px",bottom:"-1px",width:"400px",height:"30px",backgroundImage:"url(/images/bottom_horz.png)"});
		this.listingBtn=new Element("a",{href:""}).setStyle({position:"absolute",left:"140px",top:"0px",width:"120px",height:"30px",color:"#024",fontSize:"12px",fontWeight:"bold",lineHeight:"28px",textAlign:"center",textDecoration:"none",background:"url(/images/listing_btn.png) no-repeat top left"}).update("Go to Listing");
		this.closeBtn=new Element("div").setStyle({position:"absolute",right:"0px",top:"0px",width:"40px",height:"30px",color:"#024",fontSize:"11px",fontWeight:"bold",lineHeight:"30px",textAlign:"center",cursor:"pointer",background:"url(/images/close_btn.png) no-repeat top left",paddingRight:"10px"}).update("Close");
		this.listingDiv.insert(this.listingBtn);this.listingDiv.insert(this.closeBtn);
		this.bottomLeftVertDiv=new Element("div").setStyle({position:"absolute",left:"-8px",bottom:"-1px",width:"10px",height:"80px",backgroundImage:"url(/images/bottom_left_vert.png)"}).pngHack();
		this.bottomRightVertDiv=new Element("div").setStyle({position:"absolute",right:"-8px",bottom:"-1px",width:"10px",height:"80px",backgroundImage:"url(/images/bottom_right_vert.png)"}).pngHack();
		this.viewportDim;this.setDialogPos();
		this.containerDivStyle=$H({position:this._isOldIE()?"absolute":"fixed",top:this.top,left:this.left,width:this.width,height:this.height,opacity:1.0,textAlign:"center",cursor:"default",zIndex:1000});
		this.containerDiv=new Element("div",{id:"image_dialog"});
		this.containerDiv.setStyle(this.containerDivStyle.toObject());
		this.waitImage=new Element("img",{src:this.waitImageSrc,"width":"32","height":"32"});
		this.waitDiv=new Element("div").setStyle({position:"absolute",left:"184px",top:"134px",width:"32px",height:"32px"}).insert(this.waitImage);
		this.containerDiv.insert(this.waitDiv);this.showOverlay();this.showContainer();
		this.positionHandler=this.rePosition.bind(this);Event.observe(window,"resize",this.positionHandler);
		this.imageCloseHandler=this.fadeDiv.bind(this);this.closeDivHoverHandler=this.closeDivHover.bind(this);
		this.closeDivOutHandler=this.closeDivOut.bind(this);this.gotoListingHoverHandler=this.listingHover.bind(this);
		this.gotoListingOutHandler=this.listingOut.bind(this);this.gotoListingClickHandler=this.listingClick.bind(this);
		this.getImage();},
	listingClick:function(){this.fadeDiv();},
	closeDivHover:function(){this.closeBtn.setStyle({background:"url(/images/close_btn.png) no-repeat bottom left",color:"#F00",textDecoration:"underline"});},
	closeDivOut:function(){this.closeBtn.setStyle({background:"url(/images/close_btn.png) no-repeat top left",color:"#024",textDecoration:"none"});},
	listingHover:function(){this.listingBtn.setStyle({background:"url(/images/listing_btn.png) no-repeat bottom left",color:"#069",textDecoration:"underline"});},
	listingOut:function(){this.listingBtn.setStyle({background:"url(/images/listing_btn.png) no-repeat top left",color:"#024",textDecoration:"none"});},
	getImage:function(){new Ajax.Request(this.url,{parameters:this.params,onSuccess:this.loadXMLData.bindAsEventListener(this)});},
	loadXMLData:function(xhr){var xmlDoc=xhr.responseXML;		//alert(xhr.responseText);
		this.imageSrc=xmlDoc.getElementsByTagName("image")[0].firstChild.nodeValue;
		this.properTitle=xmlDoc.getElementsByTagName("proper_title")[0].firstChild.nodeValue;
		this.listingBtn.writeAttribute("href","http://www.cannes-property-rentals.com/"+this.id+"-"+this.properTitle+".html");
		this.image=new Element("img",{src:this.imageSrc,"width":"400","height":"300","alt":this.id+" - "+this.title,title:"Click to close",id:"prop_image"});
		this.image.setStyle({opacity:0.0,border:"1px solid #002244",cursor:"pointer"});
		this.containerDiv.insert(this.image);new Effect.Fade(this.waitDiv,{duration:0.2});
		new Effect.Appear(this.image,{duration:0.7});this.containerDiv.insert(this.labelDiv);
		this.containerDiv.insert(this.topLeftVertDiv);this.containerDiv.insert(this.bottomLeftVertDiv);
		this.containerDiv.insert(this.bottomRightVertDiv);this.containerDiv.insert(this.topRightVertDiv);
		this.containerDiv.insert(this.idDiv);this.containerDiv.insert(this.listingDiv);
		this.idDiv.update("#"+this.id);this.containerDiv.insert(this.bottomLeftVertDiv);this.startObservers();},
	showOverlay:function(){document.getElementsByTagName("body")[0].appendChild(this.overlayDiv);
		new Effect.Opacity(this.overlayDiv,{duration:0.5,from:0.0,to:0.7});
		document.getElementsByTagName("body")[0].style.cursor="wait";},
	showContainer:function(){document.getElementsByTagName("body")[0].appendChild(this.containerDiv);},
	startObservers:function(){
		this.image.observe("click",this.imageCloseHandler);this.closeBtn.observe("click",this.imageCloseHandler);
		this.closeBtn.observe("mouseover",this.closeDivHoverHandler);this.closeBtn.observe("mouseout",this.closeDivOutHandler);
		this.listingBtn.observe("mouseover",this.gotoListingHoverHandler);
		this.listingBtn.observe("mouseout",this.gotoListingOutHandler);
		this.listingBtn.observe("click",this.gotoListingClickHandler);},
	stopObservers:function(){
		Event.stopObserving(window,"resize",this.positionHandler);this.image.stopObserving("click",this.imageCloseHandler);
		this.closeBtn.stopObserving("click",this.imageCloseHandler);this.closeBtn.stopObserving("mouseover",this.closeDivHoverHandler);
		this.closeBtn.stopObserving("mouseout",this.closeDivOutHandler);
		this.listingBtn.stopObserving("mouseover",this.gotoListingHoverHandler);
		this.listingBtn.stopObserving("mouseout",this.gotoListingOutHandler);
		this.listingBtn.stopObserving("click",this.gotoListingClickHandler);},
	setDialogPos:function(){
		this.viewportDim=this._getPageSize();this.left=((this.viewportDim.windowWidth/2)-(this._width/2)).toString()+"px";
		if(this._isOldIE()){var dso=document.viewport.getScrollOffsets();
			this.top=((this.viewportDim.windowHeight/2)-(this._height/2)+dso.top).toString()+"px";
		}else this.top=((this.viewportDim.windowHeight/2)-(this._height/2)).toString()+"px";},
	rePosition:function(){this.setDialogPos();this.containerDiv.setStyle({left:this.left,top:this.top});},
	fadeDiv:function(){new Effect.Fade(this.containerDiv,{duration:0.5,afterFinish:this.removeDiv.bind(this)});},
	removeDiv:function(){this.stopObservers();this.containerDiv.remove();this.fadeOverlay();},
	fadeOverlay:function(){
		new Effect.Opacity(this.overlayDiv,{duration:0.5,from:0.7,to:0.0,afterFinish:this.removeOverlay.bind(this)});},
	removeOverlay:function(){document.getElementsByTagName("body")[0].style.cursor="default";this.overlayDiv.remove();},
	_isOldIE:function(){return(Prototype.Browser.IE&&parseFloat(navigator.appVersion.split(';')[1].strip().split(' ')[1])<=6)?true:false;},
	_getBrowserSize:function(){var browserWidth,browserHeight;
		if(Prototype.Browser.IE){browserHeight=document.documentElement.clientHeight;browserWidth=document.documentElement.clientWidth;   		}else{browserHeight=window.innerHeight;browserWidth=document.width||document.body.offsetWidth;}
		return{browserWidth:browserWidth,browserHeight:browserHeight};},
	_getPageSize:function(){var windowWidth,windowHeight,pageHeight,pageWidth,xScroll,yScroll;
		if(window.innerHeight&&window.scrollMaxY){xScroll=document.body.scrollWidth;yScroll=window.innerHeight+window.scrollMaxY;
		}else if(document.body.scrollHeight>document.body.offsetHeight){
			xScroll=document.body.scrollWidth;yScroll=document.body.scrollHeight;
		}else{xScroll=document.body.offsetWidth;yScroll=document.body.offsetHeight;}
		if(self.innerHeight){windowWidth=self.innerWidth;windowHeight=self.innerHeight;
		}else if(document.documentElement && document.documentElement.clientHeight){
			windowWidth=document.documentElement.clientWidth;windowHeight=document.documentElement.clientHeight;
		}else if(document.body){windowWidth=document.body.clientWidth;windowHeight=document.body.clientHeight;}  
		if(yScroll<windowHeight)pageHeight=windowHeight;else pageHeight=yScroll;
		if(xScroll<windowWidth)pageWidth=windowWidth;else pageWidth=xScroll;	
		return {pageWidth:pageWidth,pageHeight:pageHeight,windowWidth:windowWidth,windowHeight:windowHeight};}
});
SearchResultsManager=Class.create({		// Isn't it Geeky?
	initialize:function(){this.srDivsArray=$$("div.cpr_sr_div");var rx=new RegExp("(cpr_sr_div_)","g"),pid=0,ptitle="";
		for(var i=0,l=this.srDivsArray.length;i<l;i++){pid=this.srDivsArray[i].readAttribute("id").replace(rx,"");
			ptitle=this.srDivsArray[i].down("div.title_frame").down("a.idtitle_hlink").firstChild.nodeValue;
			this.srDivsArray[i].down("div.button_pdf").down("a.sr_btn_pdf").observe("click",this.pdfClick.bindAsEventListener(this));;
			this.srDivsArray[i].down("a.enlarge_hlink").observe("click",this.enlargeClick.bindAsEventListener(this,pid,ptitle));
			this.srDivsArray[i].down("img.thumb").observe("click",this.enlargeClick.bindAsEventListener(this,pid,ptitle));
			this.srDivsArray[i].down("div.button_details").observe("mouseover",this.enterButtons.bindAsEventListener(this,this.srDivsArray[i],"details"));
			this.srDivsArray[i].down("div.button_pdf").observe("mouseover",this.enterButtons.bindAsEventListener(this,this.srDivsArray[i],"pdf"));
			this.srDivsArray[i].down("div.button_book").observe("mouseover",this.enterButtons.bindAsEventListener(this,this.srDivsArray[i],"book"));
			this.srDivsArray[i].down("img.thumb").observe("mouseover",this.enterButtons.bindAsEventListener(this,this.srDivsArray[i],"enlarge"));
			this.srDivsArray[i].down("div.title_frame").down("a.idtitle_hlink").observe("mouseover",this.enterButtons.bindAsEventListener(this,this.srDivsArray[i],"details"));
			this.srDivsArray[i].down("div.button_details").observe("mouseout",this.leaveButtons.bindAsEventListener(this,this.srDivsArray[i]));
			this.srDivsArray[i].down("div.button_pdf").observe("mouseout",this.leaveButtons.bindAsEventListener(this,this.srDivsArray[i]));
			this.srDivsArray[i].down("div.button_book").observe("mouseout",this.leaveButtons.bindAsEventListener(this,this.srDivsArray[i]));
			this.srDivsArray[i].down("img.thumb").observe("mouseout",this.leaveButtons.bindAsEventListener(this,this.srDivsArray[i]));
			this.srDivsArray[i].down("div.title_frame").down("a.idtitle_hlink").observe("mouseout",this.leaveButtons.bindAsEventListener(this,this.srDivsArray[i]));
		}},
	pdfClick:function(e){e.stop();window.open(e.element().readAttribute("href"));},
	enlargeClick:function(e){e.stop();new PropertyImageDlg(arguments[1],arguments[2]);},
	enterButtons:function(e){var params=$A(arguments),infoFrame=params[1].down("div.info_frame"),el=e.element();
		infoFrame.setOpacity(0.0);
		if(params[2]=="pdf"){infoFrame.update("Open this property's PDF brochure in a new window");
			new Effect.Opacity(infoFrame,{duration:0.2,from:0.0,to:1.0});
		}else if(params[2]=="details"){infoFrame.update("View Listing - more details on this property");
			new Effect.Opacity(infoFrame,{duration:0.2,from:0.0,to:1.0});
		}else if(params[2]=="book"){infoFrame.update("Inquire for this property's availability, rates and further details...");
			new Effect.Opacity(infoFrame,{duration:0.2,from:0.0,to:1.0});
		}else if(params[2]=="enlarge"){infoFrame.update("Enlarge this property's image");
			new Effect.Opacity(infoFrame,{duration:0.2,from:0.0,to:1.0});
		}e.stop();},
	leaveButtons:function(e){arguments[1].down("div.info_frame").update("");}
});
PrevNextNavigation=Class.create({
	initialize:function(){this.bPrev=this.bNext=false;
		if($$("#sr_top_prev a").length>0){this.bPrev=true;this.preva=$$("#sr_top_prev a")[0];this.prevLink=this.preva.readAttribute("href");}
		if($$("#sr_top_next a").length>0){this.bNext=true;this.nexta=$$("#sr_top_next a")[0];this.nextLink=this.nexta.readAttribute("href");}
		this.keyboardHandler=this.keyboardAction.bindAsEventListener(this);document.observe("keydown",this.keyboardHandler); 
	},
	moveToPrevious:function(){if(this.bPrev)window.location.href=this.prevLink;},moveToNext:function(){if(this.bNext)window.location.href=this.nextLink;},
	keyboardAction:function(event){var keycode=event.keyCode,key=String.fromCharCode(keycode).toLowerCase();
		if((key=='p')||(keycode==37))this.moveToPrevious();else if((key=='n')||(keycode==39))this.moveToNext();}
});
VillaPopupSubMenu=Class.create({
	initialize:function(){this.tc=0;this.vb=$("villa_hlink");this.vp=$("villa_popup");this.vpLinks=$$("a.vp_links");
		for(var i=0,l=this.vpLinks.length;i<l;++i){this.vpLinks[i].observe("click",this.hvp.bind(this));}
		this.vb.observe("mouseover",this.ch.bind(this,true));this.vb.observe("mouseout",this.ch.bind(this,false));
		this.vp.observe("mouseover",this.ch.bind(this,true));this.vp.observe("mouseout",this.ch.bind(this,false));},
	ch:function(s){if(s){
			this.vp.setStyle({display:"block",visibility:"visible",zIndex:7777});if(this.tc>0)window.clearTimeout(this.tc);
		}else this.tc=this.hvp.bind(this).delay(0.7);},
	hvp:function(){this.vp.setStyle({display:"none",visibility:"hidden",zIndex:0});}
});
Event.observe(document,"dom:loaded",function(){									 
	new XDEV.textColorFx(document.getElementsByTagName("h2")[0],"#00F","#069","#060","#024",4,4);
	new PrevNextNavigation();
	new SearchResultsManager();
	new VillaPopupSubMenu();
});
