

$(document).ready(function() {
	
		// Homes for Sale Prev and Next
		$(".homes-for-sale a").show();


		/* Build Navigation*/
		/*
		var buttons = '';

		$(".pictures li").each(function (id) {
			var active = $(this).hasClass('show') ? ' class="active"' : '';
			buttons += '<li' + active + '>' + ++id + '</li>';
		});

		$("#featured-homes-nav").append('<ul class="buttons">' + buttons + '</ul>');
		*/
		/* Make Navigation Work*/
		/*
		$(".buttons li").click(function() {
			var id = $(this).text() - 1;
			$(".buttons li").removeClass("active");
			$(this).addClass("active");
			$(".pictures li").removeClass("show");
			$(".pictures li:eq(" + id + ")").addClass("show");
		});
		*/


		/* Rotator */
		function image_rotate() {
			this.image_count = $(".homes-for-sale .container").size();
			this.next_image = 0;
			this.paused = false;
			this.time = 8 * 1000;

			function updateNextImage() {
				this.next_image = (parseInt($(".homes-for-sale .show").attr("id")) + 1 ) % this.image_count;
			}

			function pause() {
				clearInterval(this.image_interval);
				this.paused = true;
			}

			function unpause() {
				this.image_interval = setInterval("this.rotate();",this.time);
			}

			this.rotate = function() {
				if (!this.paused) {
			  		updateNextImage();

					$(".homes-for-sale .container").removeClass("show");
					$(".homes-for-sale .container:eq(" + this.next_image + ")").addClass("show");
			  		//$('#debug').html('Cycling. Value of Pause: ' + this.paused);
				} else {
					this.paused = false;
					//$('#debug').html('Reset. Skipped Value of Pause: ' + this.paused);
				}

				this.paused = false;
			}

			this.image_interval  = setInterval("this.rotate();",time);

			/* Make Navigation Work*/
			$(".homes-for-sale .nav a").click(function (e) {
				e.preventDefault();
				var id = $(this).attr("href");
				id = parseInt(id.substring(20, id.lastIndexOf("/"))) - 1;
				$(".homes-for-sale .container").removeClass("show");
				$(".homes-for-sale .container:eq(" + id + ")").addClass("show");
				this.paused = true;
				return false;
			});

			$('.homes-for-sale').hover(function() {
				pause();
			}, function() {
				unpause();
			});

		}

		image_rotate();
});

/*
 * jQuery popup v1.1 - A jQuery popup plugin.
 * By Jordan Thomas - http://labs.wondergroup.com
 * Licensed under the do whatever you want to license.
 * If you like, keep this message intact so 
 * someone else can find the origin.
*/
jQuery.fn.popup=function(options){var defaults={width:screen.width/2,height:screen.height/2,titlebar:true,status:true,resizable:true,toolbar:true,scrollbars:true,menubar:true};var options=jQuery.extend(defaults,options);Boolean.prototype.setProperty=function(){if(this==true){return"yes";}else{return"no";}};return this.each(function(){jQuery(this).click(function(){var target=this.target;var href=this.href;var posY=(parseInt(screen.height/2))-(parseInt(options.height/2));var posX=(parseInt(screen.width/2))-(parseInt(options.width/2));var win=window.open(href,target,'titlebar='+options.titlebar.setProperty()+', screenX='+posX+', screenY='+posY+', left='+posX+', top='+posY+', status='+options.status.setProperty()+', resizable='+options.resizable.setProperty()+', toolbar='+options.toolbar.setProperty()+', scrollbars='+options.scrollbars.setProperty()+', menubar='+options.menubar.setProperty()+', width='+options.width+', height='+options.height);win.focus();return false;});});};

$(document).ready(function() {
	$(".popup").popup({
	    width: 640,
	    height: 480,
	    titlebar: true,
	    status: false,
	    resizable: true,
	    toolbar: false,
	    scrollbars: true,
	    menubar: false
	});
});
