$().ready(function(){
	
	
	$('#nav li').hover(function(){
		$(this).addClass('hover');
	},function(){
		$(this).removeClass('hover');
	});
	
	$('.sidebar.hoverable').hover(function() {
		$(this).addClass('hover');
	}, function(){
		$(this).removeClass('hover');
	});
	

	var strHideText = 'hide bio';
	var strShowText = 'read bio';

	$('.employee_bio .expand-collapse').click(function() {
		var myDisplay = $(this).parent().find('.bio').css('display');
		$('.bio').slideUp('medium');
		if ($(this).parent().find('.bio').css('display') == 'none') {
			$(this).text(strHideText);
			$(this).parent().find('.expand').css('display', 'none');
			$(this).parent().find('.collapse').css('display', 'inline');
		} else {
			$(this).text(strShowText);
			$(this).parent().find('.expand').css('display', 'inline');
			$(this).parent().find('.collapse').css('display', 'none');
		}
		
		if (myDisplay != 'block') {
			$(this).parent().find('.bio').slideToggle("medium");
		}

	});

	$("hr").wrap('<div class="hr2"></div>');
	
	$(".local_market_button").click(function() {
		$(".local_market_offices_box").slideToggle("medium");
		
		$(this).find('span span').toggleClass('open');
		
	});
});

function resetForm()
{
	
	var oForm = $('#property_form').get(0);
	
	var elements = oForm.elements;
	
	//oFrom.reset();
	
	for(i=0; i<elements.length; i++) {
	
		field_type = elements[i].type.toLowerCase();
		
		switch(field_type) {
	
			case "text":
			case "password":
			case "textarea":
			case "hidden":
				elements[i].value = "";
				break;
	
			case "radio":
			case "checkbox":
				if (elements[i].checked) {
					elements[i].checked = false;
					elements[i].onchange();
				}
				break;
	
			case "select-one":
			case "select-multi":
				elements[i].selectedIndex = 0;
				elements[i].onchange();
				break;
	
			default:
				break;
			
		}
		
	
	}
	$("#select-footage-range").slider("values", 0, 0);
	$("#select-footage-range").slider("values", 1, 1500000);
	$("#select-footage-min").val($("#select-footage-range").slider("values", 0));
	$("#select-footage-max").val($("#select-footage-range").slider("values", 1));
	$('#select-footage-display').text($("#select-footage-range").slider("values", 0) + ' - ' + $("#select-footage-range").slider("values", 1) + ' sq ft');

	
	
	return false;
	
}

function resetEmployeeSearchForm()
{
	
	var oForm = $('#people_search_form').get(0);
	
	var elements = oForm.elements;
	
	//oFrom.reset();
	
	for(i=0; i<elements.length; i++) {
	
		field_type = elements[i].type.toLowerCase();
		
		switch(field_type) {
	
			case "text":
			case "password":
			case "textarea":
			case "hidden":
				elements[i].value = "";
				break;
	
			case "radio":
			case "checkbox":
				if (elements[i].checked) {
					elements[i].checked = false;
					elements[i].onchange();
				}
				break;
	
			case "select-one":
			case "select-multi":
				elements[i].selectedIndex = 0;
				elements[i].onchange();
				break;
	
			default:
				break;
			
		}
		
	
	}
	
	return false;
	
}


$().ready(function(){
	
	$('#property_form').submit(function(){
		
		return true;
		
		/*******************************************************
		 * we no longer check for property type to be selected
		 * keeping for rollback
		 *******************************************************
		var sel = false;
		
		if($('#building_inventory').attr('checked')) {
			sel = true;
		}
		
		if($('#land_sites').attr('checked')) {
			sel = true;
		}
	
		if(sel) {
			return true;
		}else{
			alert('Please select a property category.');
			$('.property_types_long').css('padding','5px 0 5px 5px');
			$('.property_types_long').css('border','2px solid #fff7d9');
			$('.property_types_long').effect("highlight", {}, 3000);
			
			$('.property_types_tall').css('padding','5px 0 0 5px');
			$('.property_types_tall').css('border','1px solid #fff7d9');
			$('.property_types_tall').effect("highlight", {}, 3000);
			return false;
		}
		*/
	});

	
	$('.property_image_small').click(function (event) {

		event.preventDefault();
				
		smallImageWidth = 110;
		smallImageHeight = 70;
		largeImageWidth = 525;
		largeImageHeight = 334;
		
		newLargeImageHeight = $(this).attr('height')/$(this).attr('width') * largeImageWidth;
		
		largeImage = $('.property_image_large');
		largeImageSrc = largeImage.attr('src');
		newSmallImageTitle = largeImage.attr('title');

		largeImage.attr('height', '0');
		
		newLargeImageSrc = $(this).attr('src');
		newLargeImageTitle = $(this).attr('title');
		
		newLargeImageSrc = newLargeImageSrc.replace(/w=[0-9]*/, 'w=' + largeImageWidth);
		newLargeImageSrc = newLargeImageSrc.replace(/width=[0-9]*/, 'width=' + largeImageWidth);
		newLargeImageSrc = newLargeImageSrc.replace(/height=[0-9]*/, 'height=' + largeImageHeight);

		newSmallImageSrc = largeImageSrc.replace(/w=[0-9]*/, 'w=' + smallImageWidth);
		newSmallImageSrc = newSmallImageSrc.replace(/width=[0-9]*/, 'width=' + smallImageWidth);
		newSmallImageSrc = newSmallImageSrc.replace(/height=[0-9]*/, 'height=' + smallImageHeight);
		
		largeImage.attr('src', '');

		$('#property_image_large_container').css('height', newLargeImageHeight);
		largeImage.attr('height', newLargeImageHeight);
		
		largeImage.attr('src', newLargeImageSrc);
		largeImage.attr('title', newLargeImageTitle);
		
		$(this).attr('src', newSmallImageSrc);
		$(this).attr('title', newSmallImageTitle);
		$(this).siblings('span').text(newSmallImageTitle);
		
	});
	
	
	$('#property_advanced_search_drop_down').click(function() {
		
		searchBar = $('#property_advanced_search_bar');
		
		if (searchBar.css('display') == 'block') {
			
			searchBar.hide();
			$(this).find('span').text('Show');
			$(this).find('img').attr('src', '/img/sidebar-icons/sidebar-double-down-arrow.png');
			
		} else {
			
			searchBar.show();
			$(this).find('span').text('Hide');
			$(this).find('img').attr('src', '/img/sidebar-icons/sidebar-double-up-arrow.png');
			
		}

		return false;
	});
});

YUI({gallery:'gallery-2010.06.16-19-51'}).use('gallery-effects',function(Y){
Y.on('domready',function() {
	Y.all('.collapsable .trigger').each(function(o){
		// set initial state to content areas
		o.ancestor().all('.content').setStyles({'overflow':'hidden','height':0}).removeClass('opening');
		
		// bind clicks to triggers
		o.on('click',function(e){
			var cont = e.currentTarget.ancestor().one('.content');
			if(cont.hasClass('opening')) {
				// hide it
				cont.morph({to:{height:0}});
				cont.removeClass('opening');
			}else{
				// close it
				var oldH = cont.getStyle('height');
				var newH = oldH;
				if(oldH !== 'auto') {
					oldH = parseInt(oldH,10);
					cont.setStyle('height','');
					newH = cont.get('offsetHeight');
					cont.setStyle('height',oldH);
					cont.morph({to:{height:newH}});
				}
				cont.addClass('opening');
			}
		});
	});
});});
