$(document).ready(function(){	
	$(function() {
		$('#nav').droppy({speed: 1});
	});
	
	$("a[rel='external']").attr('target','blank');
	
	
    $('#shape_all').change(function(){
    	var v = $(this).attr('checked');
    	if(v == true){
    		$(this).parent().find("input").not(this).attr('disabled','disabled');
    		$(this).parent().find("input").not(this).attr('checked','');
    	}else{
    		$(this).parent().find("input").not(this).attr('disabled','');
    	}
    });
    
     $('#grading_all').change(function(){
    	var v = $(this).attr('checked');
    	if(v == true){
    		$(this).parent().find("input").not(this).attr('disabled','disabled');
    		$(this).parent().find("input").not(this).attr('checked','');
    	}else{
    		$(this).parent().find("input").not(this).attr('disabled','');
    	}
    });
    
    
	$('#advanced_search').hide();
	
	$('#advanced_search_toggle').toggle(
		function(){
			$('#advanced_search').slideDown();
			$('#advanced_search_toggle').addClass('current');
			$('#advanced_search_toggle span').text('(Hide)');
		},
		function(){
			$('#advanced_search').slideUp();
			$('#advanced_search_toggle').removeClass('current');
			$('#advanced_search_toggle span').text('(Show)');
		}
	);
	
	
	
	// highlight table rows
	$('#searchresults tr').mouseover(function(){
		$(this).children('td').addClass('hl');
	});
	
	$('#searchresults tr').mouseout(function(){
		$(this).children('td').removeClass('hl');
	});
	
	// compare functionality
	$('#searchresults td').not('.compare').click(function(){
		var selected = $(this).parent().find('input').attr('checked');
		if(!selected){
			$(this).parent().children('td').addClass('hl_force');
			$(this).parent().find('input').attr('checked','checked');
		}else{
			$(this).parent().children('td').removeClass('hl_force');
			$(this).parent().find('input').attr('checked','');
		}
	});
	
	$('#searchresults td input').click(function(){
		var selected = $(this).attr('checked');

		if(selected){
			$(this).parent().parent().children('td').addClass('hl_force');
		}else{
			$(this).parent().parent().children('td').removeClass('hl_force');
		}
	});
	
	var comparing = false;
	$('#compare_selected').click(function(){
		if(comparing == true){
			$('#searchresults td input').not(':checked').parent().parent().show();
			$('#compare_selected').text('Compare Selected');
			comparing = false;
		}else{
			$('#searchresults td input').not(':checked').parent().parent().hide();
			$('#compare_selected').text('Show All');
			comparing = true;
		}
		return false;
	});
	
	
	if(typeof eval(jQuery.fn.lightBox) == "function"){
    	$('#searchresults a').lightBox();
    }
    
    
    
    
    $('#markup_price_range').hide();
    $('#show_markup_price_range').click(function(){
    	$('#markup_price_range').fadeIn();
    	$('#markup_flat').hide();
    	return false;
    });
     $('#show_markup_flat').click(function(){
    	$('#markup_flat').fadeIn();
    	$('#markup_price_range').hide();
    	return false;
    });
    
   
});