// JavaScript Document
//Drop downs
	$(document).ready(function() {
	
		//On Hover Over
		function megaHoverOver(){
			$(this).find(".sub").stop().fadeTo(100, 1).show(); //Find sub and fade it in
			//$(this).find(".sub").stop().css('opacity', 1);
			(function($) {
				//Function to calculate total width of all ul's
				jQuery.fn.calcSubWidth = function() {
					rowWidth = 0;
					//Calculate row
					$(this).find("ul").each(function() { //for each ul...
						rowWidth += $(this).width(); //Add each ul's width together
					});
				};
			})(jQuery); 
		
			if ( $(this).find(".row").length > 0 ) { //If row exists...
		
				var biggestRow = 0;	
		
				$(this).find(".row").each(function() {	//for each row...
					$(this).calcSubWidth(); //Call function to calculate width of all ul's
					//Find biggest row
					if(rowWidth > biggestRow) {
						biggestRow = rowWidth;
					}
				});
		
				$(this).find(".sub").css({'width' :biggestRow}); //Set width
				$(this).find(".row:last").css({'margin':'0'});  //Kill last row's margin
		
			} else { //If row does not exist...
		
				$(this).calcSubWidth();  //Call function to calculate width of all ul's
				$(this).find(".sub").css({'width' : rowWidth}); //Set Width
		
			}
		}
		//On Hover Out
		function megaHoverOut(){
		  $(this).find(".sub").stop().fadeTo(100, 0, function() { //Fade to 0 opactiy
			  $(this).hide();  //after fading, hide it
		  });
		  /*
		  $(this).find(".sub").css('opacity', 0).hide();
		  */
		}
		
		//Set custom configurations
		var config = {
			 sensitivity: 2, // number = sensitivity threshold (must be 1 or higher)
			 interval: 100, // number = milliseconds for onMouseOver polling interval
			 over: megaHoverOver, // function = onMouseOver callback (REQUIRED)
			 timeout: 100, // number = milliseconds delay before onMouseOut
			 out: megaHoverOut // function = onMouseOut callback (REQUIRED)
		};
		
		$("ul#topnav li .sub").css({'opacity':'0'}); //Fade sub nav to 0 opacity on default
		$("ul#topnav li").hoverIntent(config); //Trigger Hover intent with custom configurations
	
	});
 
 //BOTTOM BUTTONS
 /*
 $(document).ready(function(){
	$(".eco").hover(function() {
		$(this).attr("src","/img/buttons/eco-2.png");
			}, function() {
		$(this).attr("src","/img/buttons/eco.png");
	});
	
	$(".apply").hover(function() {
		$(this).attr("src","/img/buttons/apply-2.png");
			}, function() {
		$(this).attr("src","/img/buttons/apply.png");
	});
	
	$(".facebook").hover(function() {
		$(this).attr("src","/img/buttons/facebook-2.png");
			}, function() {
		$(this).attr("src","/img/buttons/facebook.png");
	});
});
*/


/**
 * Update the current floorplan image based on which level is currently selected and what options are currently selected. 
 */
function updateFpImage(id) {
	var slug = $('#fp_level_lower').attr('checked') ? 'lower' : 'upper';
	var slug2 = slug == 'lower' ? 'upper' : 'lower';
	$('.fp_'+slug+'_group').fadeIn();
	$('.fp_'+slug2+'_group').fadeOut();
	if (id && id.substr(0, 10) == 'fp_option_' && $('#'+id).attr('checked')) {
		$('.fp_level_grouping INPUT').attr('checked', false);
		$('#' + id).attr('checked', true);
	} else {
		// Fallback to parent image
		id = 'fp_level_' + slug;	
		// Deselect any existing options
		$('.fp_level_grouping INPUT').attr('checked', false);
	}
	//$('#' + id).css('display', 'block');
	$('.fp-photo').css('display', 'none');
	$('#fp_image_' + id).css('display', 'block');  //slideDown();
}
$(function() {
	if ($('#fp_image_container').length > 0) { // not on pages that don't have the floorplans
		// Update update
		updateFpImage();
		// Check for clicks on floorplan selector
		$('#fp_form INPUT').click(function() {
			updateFpImage($(this).attr('id'));
		});
		// Initialize colorbox
		$('.fp-photo').colorbox({transition: "fade"});
	}
});

 
 //COLORBOX PHOTOGALLERY
 $(document).ready(function(){
	if ($("a[rel='echo-photo']").length > 0) {
		$("a[rel='echo-photo']").colorbox({transition:"fade"});
		$("a[rel='feat-lux-img']").colorbox({transition:"fade"});
	}
	if ($("A.colorboxed").length > 0) {
		$("A.colorboxed").colorbox({transition: 'fade'});
	}
});


$(document).ready(function() {
 if ($('.accordionContent').length > 0) {
//ACCORDION BUTTON ACTION (ON CLICK DO THE FOLLOWING)
$('.accordionButton').click(function() {

	//REMOVE THE ON CLASS FROM ALL BUTTONS
	
	$('.accordionButton').removeClass('on');
	  
	//NO MATTER WHAT WE CLOSE ALL OPEN SLIDES
	// Nah, makes it hard to read long entries
	//$('.accordionContent').slideUp('2000');

	//IF THE NEXT SLIDE WASN'T OPEN THEN OPEN IT
	if($(this).next().is(':hidden') == true) {
		
		//ADD THE ON CLASS TO THE BUTTON
		$(this).addClass('on');
		  
		//OPEN THE SLIDE
		$(this).next().slideDown('2000');
	 } else {
		 $(this).removeClass('on');
		$(this).next().slideUp('2000'); 
	 }
	  
 });

/********************************************************************************************************************
CLOSES ALL S ON PAGE LOAD
********************************************************************************************************************/	
$('.accordionContent').hide();

 }

});


