/**
 * @copyright  Copyright (c) 2007 August Ash Inc. (http://www.augustash.com)
 * @version    $Id: aailib.js 21 2008-06-11 21:35:26Z jjohnson $
 */

/**
 * Filter the property results table
 * 
 * @param {String} type Module specific type
 * @param {Object} element Select menu object
 */
function filterTable(type, element)
{
    var theValue  = element.value;
    var theAction = $('#propFilter').attr('action');
    
    window.location = theAction + "&" + type + "=" + theValue;
    return false;
}

/**
 * Prepare Links - using jQuery
 * 
 * Checks the document, when ready, for all link nodes with a class
 * name "external" and opens them in a new window when clicked.
 */
$(document).ready(function(){
	$("a").filter(".external").click(function (){
		var NewWindow = new OpenWindow($(this).attr("href"));
		return NewWindow.open();
	})
    .end();
});

/**
 * OpenWindow Class
 * 
 * Creates an OpenWindow object that allows you to define the URL, 
 * window name, and features for firing a pop-up window.
 * 
 * @param {String} href
 */
function OpenWindow(href)
{
	// Set default values
	var _href     = href;
	var _name     = "external";
	var _features = "";
	
	function __construct() {
		// Define methods		
		this.getHref     = function() { return _href; }
		this.setHref     = function(href) { _href = href; }
		this.getName     = function() { return _name; }
		this.setName     = function(name) { _href = name; }
		this.getFeatures = function() { return _features; }
		this.setFeatures = function(features) { _features = features; }
		
		this.open = function() {
			window.open(_href, _name, _features);
			return false;
		}
	};
	
	return new __construct();
}

/**
 * Son of Suckerfish Drop Down Menu
 * http://www.htmldog.com/
 */
$(document).ready(function(){
	var sfEls = $("ul#nav li");
	for (var i = 0; i < sfEls.length; i++) {
		$(sfEls[i]).mouseover(function(){
			$(this).addClass("sfhover");
		});
		$(sfEls[i]).mouseout(function(){
			$(this).removeClass("sfhover");
		});
	}
});

// Toggle HOME-TABS Boxes
// toggles div#manage-box and div#acquisitions-box
// when user clicks on respective tabs
$(document).ready(function(){
	var acquistionsTab = $("h2#acquisitions a");
	var manageTab = $("h2#manage a");
	var acquisitionsBox = $("div#acquisitions-box");
	var manageBox = $("div#manage-box");
	
	acquistionsTab.click(function(){
		$(manageTab).removeClass("active");							  
		$(this).addClass("active");
		$(manageBox).hide();
		$(acquisitionsBox).show();
	});
	
	manageTab.click(function(){
		$(acquistionsTab).removeClass("active");							  
		$(this).addClass("active");
		$(acquisitionsBox).hide();
		$(manageBox).show();
	});

});


// Property Listings Links and Photos
// in HOME-TABS Boxes
$(document).ready(function(){
	var propertyList = $("ol#propertyListings");
	var propertyListItems = $("ol#propertyListings li");
	var propertyPhotos = $("ul#propertyListingsPhotos li");

	// hide all but first li element in ul#propertyListingPhotos
	$("ul#propertyListingsPhotos li:gt(0)").hide();

	// Loop over each Property Listing in ol#propertyListings
	$(propertyListItems).each( function(i) {
		
		// Bind the onclick event to display corresponding
		// image located in ul#propertyListingsPhotos
		$(this).bind(
			"click",
			function(){
				// changes default index value from 0 to 1
				var j= i + 1;	
				
				$("li#propertyPhoto" + j).siblings("li").hide();											
				$("li#propertyPhoto" + j).show();
			}
		);
	});
});


// jCarousel Lite rotator for Recent Aquisitions Tab on home page
$(document).ready(function(){
	$(".scrollMore .jCarouselLite").jCarouselLite({
		btnNext: ".scrollMore .next",
		btnPrev: ".scrollMore .prev",
		scroll: 3,
		speed: 800
	});

	// keep here other wise it will mess with
	// jCarouselLite functions
	var acquisitionsBox = $("div#acquisitions-box");
	$(acquisitionsBox).hide();
	
});


// Rotating images using JQuery Innerfade
// for reference: http://medienfreunde.com/lab/innerfade/
$(document).ready( function(){
	var marketLink = $('a#marketHousing');
	var affordableLink = $('a#affordableHousing');
	var rotate1 = $('div#rotateMe');
	var rotate2 = $('div#rotateMe_2');

	// hide the second set of rotating images ( ul.affordableHousing )
	$(rotate2).hide();
	
	// defaults ot 1st set of rotating images (div#rotateMe ul.marketHousing )
	$('.marketHousing').innerfade({
		animationtype: 'fade', 		// slide, fade
		speed: 'slow', 				// slow, fast or time in milliseconds
		timeout: 10000, 			// in milliseconds
		type: 'sequence', 			// random or sequence
		containerheight: '214px' 
	});
	
	// hide div#rotateMe and show div#rotateMe_2 when clicked
	$(affordableLink).click(function(){
		$(marketLink).removeClass('active');
		$(rotate1).hide();
		$(rotate2).show();
		$(this).addClass('active');
		$('.affordableHousing').innerfade({
			animationtype: 'fade', 		// slide, fade
			speed: 'slow', 				// slow, fast or time in milliseconds
			timeout: 10000, 			// in milliseconds
			type: 'sequence', 			// random or sequence
			containerheight: '214px' 
		});
	
	});

	// hide div#rotateMe_2 and show div#rotateMe when clicked
	$(marketLink).click(function(){
		$(affordableLink).removeClass('active');
		$(rotate2).hide();
		$(rotate1).show();
		$(this).addClass('active');
		$('.marketHousing').innerfade({
			animationtype: 'fade', 		// slide, fade
			speed: 'slow', 				// slow, fast or time in milliseconds
			timeout: 10000, 			// in milliseconds
			type: 'sequence', 			// random or sequence
			containerheight: '214px' 
		});
	
	});

});




