function pacifichomes() {
	var paged = $('div.paged');

	if (paged.length) {
		new horizontalslide(paged);
	}
	$('div#shortlink').shortlink();
}

function horizontalslide(ele) {
	var pages = $('div.page',ele);

	if (pages.length>1) {
		this.init(ele,pages);
	}
}
horizontalslide.prototype={
init:function(ele,pages) {
	var obj = this;
	this.width=ele.width()+1;
	this.pages=pages.length;
	this.paged=ele;
	this.floater=$('div.float',ele);
	this.floater.width(this.pages*this.width) + 1;
	this.page=0;
	this.prevbtn=$('<div class="slideprev"/>').bind('mouseover',function() {
		$(this).toggleClass('prevhover',true);
	}).bind('mouseout',function() {
		$(this).toggleClass('prevhover',false);
	}).bind('click',function() {
		obj.slide(-1);
	}).appendTo('div.right div.inner');
	this.nextbtn=$('<div class="slidenext"/>').bind('mouseover',function() {
		$(this).toggleClass('nexthover',true);
	}).bind('mouseout',function() {
		$(this).toggleClass('nexthover',false);
	}).bind('click',function() {
		obj.slide(1);
	}).appendTo('div.right div.inner');
	this.navindex=$('#navindex');
	for (var x=0; x < this.pages; x++) {
		$('<span class="ni'+x+'">'+(x+1)+(x == this.pages-1?'':' • ')+'</span>').appendTo(this.navindex);
	}
	if (ret=/!page=(\d+)/.exec(document.location.hash)) {
		this.page = Number(ret[1])-1;
		this.paged.attr({
			scrollLeft:(this.page*this.width)
		});
		this.slide(0);
	} else {
		this.prevbtn.addClass('disabled');
		$('span.ni'+this.page,this.navindex).addClass('active');
	}
},
slide:function(dir) {
	this.page+=dir;
	if (this.page <= 0) {
		this.page = 0;
		this.prevbtn.addClass('disabled');
	} else {
		this.prevbtn.removeClass('disabled');
	}
	if (this.page >= this.pages - 1) {
		this.page=this.pages - 1;
		this.nextbtn.addClass('disabled');
	} else {
		this.nextbtn.removeClass('disabled');
	}
	$('span',this.navindex).removeClass('active');
	$('span.ni'+this.page,this.navindex).addClass('active');
	document.location.hash='!page='+(this.page+1);
	this.paged.stop(true,false).animate({
		scrollLeft:(this.page*this.width)
	},300);
}
}

if(typeof jQuery != "undefined") {
	jQuery(function($) {
		$.fn.extend({
			shortlink:function(options) {
				this.addClass('slconf');
				this.shortlinklabel();
				this.bind('click',function() {
					$(this).op='test';
					$(this).shortlinkclick($(this).hasClass('unchecked'));
				});
			},
			shortlinkclick:function(state) {
				var ele=this;
				$.fn.shortlink.reqstate=state;
				$.ajax({
					url:'/shortlist.nb?'+(state?'add=':'remove=')+this.attr('rel'),
					dataType:'json',
					timeout:10000,
					success:function(data,textStatus,req) {
						if ($.fn.shortlink.reqstate == state) {
							ele.toggleClass('checked',state);
							ele.toggleClass('unchecked',!state);
							ele.shortlinklabel();
							ele.updateshortlistbutton(data);
						}
					},
					error:function(req,st,err) {
						if($.fn.shortlink.reqstate == state) {
							ele.shortlinkclick(state);
						}
					}
				});
			},
			shortlinklabel:function() {
				this.html(this.hasClass('checked')?"On your shortlist":"Add to shortlist");
			},
			updateshortlistbutton:function(state) {
				var sllink=$('#shortlist');
				if (sllink.length) {
					if (state) {
						sllink.fadeIn();
					} else {
						sllink.fadeOut();
					}
				} else {
					if (state) {
						$('<div id="shortlist"><a href="/shortlist.nb">shortlist</a></div>').hide().appendTo('#header div.inner').fadeIn();
					}
				}
			}
		});
	});
}

function pacificmap(la,ln,z,m,i) {
	if (typeof m == 'undefined') {
		return;
	}

	var map = new google.maps.Map($('#map').get(0),{
		mapTypeId:google.maps.MapTypeId.ROADMAP,
		zoom:z,
		center:new google.maps.LatLng(la,ln),
		panControl:true,
		streetViewControl:false,
		zoomControlOptions:{
				style:google.maps.ZoomControlStyle.LARGE
		}
	});

	var x,ct;

	var info=new google.maps.InfoWindow();

	var sh=new google.maps.MarkerImage('/pacifichomes/map/shadow.png',new google.maps.Size(55,62),new google.maps.Point(0,0),new google.maps.Point(28,50));

	var ic={};
	for (var id in i) {
		ic[id]=new google.maps.MarkerImage('/pacifichomes/map/'+i[id],new google.maps.Size(41,50),new google.maps.Point(0,0),new google.maps.Point(21,50));
	}

	function showinfo(mrkr,m) {
		var cc=$('<div class="popup"><div class="img"><img src="/pacifichomes/map/'+i['i'+m[1]]+'" width="41" height="50" alt=""/></div><div class="text"><h1>'+m[0]+'</h1>'+(m[4]?'<address>'+m[4]+'</address>':'')+'<div><a href="http://maps.google.com/maps?q='+m[2]+','+m[3]+'" target="_blank">view this location in google maps</a></div></div></div>');
		google.maps.event.addListener(mrkr,'click',function() {
			info.setContent(cc.get(0));
			info.open(map,mrkr);
		});
	}
	for (x=0,ct=m.length; x < ct; x++) {
		var mrkr=new google.maps.Marker({
			position:new google.maps.LatLng(m[x][2],m[x][3]),
			map:map,
			title:m[x][0]+"  \n"+m[x][4],
			animation:google.maps.Animation.DROP,
			draggable:true,
			icon:ic['i'+m[x][1]],
			shadow:sh
		});
		showinfo(mrkr,m[x]);
	}
}

