/**
 * Namespace "Houses"
 * @class Houses
 * @desc Subclass of Base
 */
Base.Houses = function() {
	// Variables & functions defined here are private

	// fold out the choice for a neighbourhood
	function cityToggler() {
		$('.toggle-in a').click(function(){
			var sel = $(this).closest('.selector');
			$(sel).find('.btm').toggle();
			$(sel).find('.middleright ul').toggle();
			$(sel).find('.toggle-out').toggle();
			$(sel).find('.toggle-in a').toggleClass('min');
			return false;
		}),
		$('.city-selector a.close').click(function(){
			$('.toggle-in .btm').show();
			$('.toggle-out').hide();
			$('.middleright ul').toggle();
			$('.toggle-in a').removeClass('min');
			return false;
		});
	}

	// function for hovering effect on table tr with houses
	function hovering() {
		$('.clickable tbody tr, table.houses-overview th').live('mouseover', function() {
			$(this).addClass('hover');
		}).live('mouseout',function() {
			$(this).removeClass('hover');
		});
	}


	// how many checkboxes 
	function compareHouses() {
		$('table.clickable :checkbox').click( function(e) {
			e.stopPropagation();
			
			var boxesChecked = $('.houses-overview :checkbox:checked').length;
			
			switch(boxesChecked) {
				case 4:
					$('.compare-list .button').attr('disabled','disabled').css('opacity',0.5);
					$('.compare-list .error-msg').show();
				
					break;
				case 3:
					$('.compare-list .button').removeAttr('disabled').css('opacity', 1);
					$('.compare-list .error-msg').hide();
					break;
			}
		})
	};


	// function to get url from <a> on <tr> in table 
	function linkedHouses() {
		$('table.clickable tr').click(function() {
			document.location= $(this).find('a').attr('href');
		})
	}

	return {
  	// Variables & functions defined here are public
    
		/**
		 * Initialize this Class
		 */
		init: function() {
			// do something, or test:
			compareHouses() 
			cityToggler();
			hovering();
			linkedHouses();
		}
	};
}();

/* Initialize this class */
Base.register(Base.Houses.init);

