// Unchecking abstraction
function uncheck(checkboxes){
    $.each( checkboxes, function( i ){
        $(checkboxes[i]).attr('checked', false);
    });
}
// Price slider - standard jQueryUI api stuff
$(function() {
    var max, min;
    max = maxp == '' ? 1000 : parseInt(maxp)
    min = minp == '' ? 0 : parseInt(minp)
    $("#slider-range").slider({
	range: true,
	min: 0,
	max: 2000,
	values: [min, max],
	slide: function(event, ui) {
	    $("#amount").val('\u00A3' + ui.values[0] + ' - \u00A3' + ui.values[1]);
	},
        change: function(event, ui){
            $( "#min" ).val(ui.values[0]);
            $( "#max" ).val(ui.values[1]);
			//console.log(ui);
			var range = ui.value[0] - ui.values
			//alert($('#min').val());
           	$( "#column_form" ).submit();
        }
    });
    // Unicodes for Pound signs - can't be bothered to sort encoding
    $("#amount").val('\u00A3' + $("#slider-range").slider("values", 0) + ' - \u00A3' + $("#slider-range").slider("values", 1));
});
$( document ).ready( function(){
    // Submits the LHCOL form on change
    $( "#column_form input" ).change(function(){
        var inputs;
        // Solar overrides everything else for no good reason
        if($(this).attr('name') == '108' && !SOLARPOSTED && !$(this).attr('checked')){
            uncheck($("input:checkbox"));
            $(this).attr('checked', true);
            $( "#column_form" ).submit();
        }
        $inp = $(this);
        checked = $(this).parent('li').siblings().children('input:checked');
        if(checked.length >= 1){
            inputs = $(this).parent('li').siblings().children('input');
            uncheck(inputs)        
            if(!$(this).attr('name') == '108'){
                $($inp).attr('checked', true);
            }
        }
		if(!$inp.is(':checked')) {
			var name = $inp.attr('name');
			$('#column_form input[name="'+name+'"]').attr('checked',false);
		}
        $( "#column_form" ).submit();
    });
    // Keeping this here because Ian will probably decide he wants
    // a clear all options checkbox/link
    $( ".none" ).click( function(e){
        e.preventDefault();
        $("#column_form input:checked").attr('checked', false);
        return false;
    });
    // // Make sure that split results get posted appropriately
    // // in the split_page_results.php output controls
    // $("a.pageResults").click(function(event){
    //     if(window.location.href.search('-c-') == -1){
    //         event.preventDefault();
    //         $( "#column_form" ).attr('action', $(this).attr('href') );
    //         $( "#column_form" ).submit();
    //     }
    // });
    
    // View all is a checkbox. At last, a proper understanding of HCI paradigms,
    // brought to bear on this very website in our time.
    $("input#all").change(function(event){
        if($(this).attr('checked')){
           window.location = 'http://'+window.location.host+'/?cPath=4&view_all=check';
        }else{
            return false;
        }
    });    
});
