$(document).ready(function(){
	
	//focus clear fields
	$('.default').each(function(){
		$(this).css({'color' : '#666'});
		var _default = $(this)[0].defaultValue;//document.getElementById($(this).attr('id')).defaultValue;
		$(this).focus(function(){
			$(this).css({'color' : '#000'});
			if($(this).val() == _default){
				$(this).val('');	
			}
		});
		$(this).blur(function(){
			if($(this).val() == ''){
				$(this).val(_default);	
				$(this).css({'color' : '#666'});
			}
		});						
	});
	//end of clear focus
	
	
	//textarea simple autoexpand
	$('textarea').each(function(){
		$(this).css({overflow: 'hidden'});
		$(this).each(function(){
			if($(this)[0].scrollHeight > $(this).height())	$(this).css({height: $(this)[0].scrollHeight + 50});
		});
		$(this).keyup(expandTextarea);
	});
	
	function expandTextarea(){
		if($(this)[0].scrollHeight > $(this).height()){
			$(this).animate({height: $(this)[0].scrollHeight + 50}, {duration:200, queue:false});
		}
	}
	//end of autoexpand
	

	//generic toggler
	$('.toggler').each(function(){
		$(this).next().hide();
		if($(this).hasClass('selected')){
			$(this).next().animate({height: 'toggle', opacity: 1}, 300);
		}
	});
	$('.toggler').click(function(){	
		var _h = parseInt($(this).next().css('height'));//height();
		if(_h > 0 || _h == NaN){
			$(this).removeClass('selected');
		}else{
			$(this).addClass('selected');
		}
		$(this).next().animate({height: 'toggle', opacity: 1}, 300);
		if($(this).children('a').text() == '[-]'){
			$(this).children('a').text('[+]');
		}else{
			$(this).children('a').text('[-]');
		}
		return false;
	});
	$('.toggler_close').click(function(){
		obj = $(this);
		while($(obj).prev('.toggler').length == 0){
			obj = $(obj).parent();	
		}
		$(obj).prev().trigger('click');
		return false;
	});
	//end of generic toggler
	
	
	//simple alert
	$(".alert").animate({opacity: 1}, 3000).animate({opacity: 0 }, {duration: 600, easing: 'easeInQuad'}).animate({height: 0, paddingTop: 0, paddingBottom: 0, borderWidth: 0, marginBottom: 0, marginTop: 0}, {duration: 500, easing: 'easeInQuad', complete: 
		function(){$(this).remove();}
	});
	//end of alert
	
	//floorplans
	var flr_width = ($('#floorplans #details .floorplan').length * 640);
	$('#details_contents').css({width: flr_width});
	
	$('#floorplan_links a').click(function(){
		var offset = $('#floorplan_links a').index($(this));
		$('#details_contents').animate({marginLeft: offset * -640}, {duration: 600, easing: 'easeInOutBack'});
		return false;
	});
	//end of floorplans
});