//depends hangout.js
jQuery(document).ready(function($){
    hquery.appendLoader();
    hquery.fillQueryVars();
    hquery.updateCatCount();
    $('#sort-hangout #submit').css({
        display : 'none'
    });
    $('select#location').change(function (){
        hquery.page = 1;
        hquery.fillQueryVars();
        hquery.get();
        hquery.updateCatCount();
    });
    $('#categorychecklist input:checkbox').click(function (){
        hquery.page = 1;
        hquery.fillQueryVars();
        hquery.get();
        hquery.updateCatCount();
    });
    $('#tagchecklist input:checkbox').click(function (){
        hquery.page = 1;
        hquery.fillQueryVars();
        hquery.get();
        hquery.updateCatCount();
    })
    $('a.page-numbers').live('click', function(e){
        e.preventDefault();
        var pid = $(this).attr('href');
        pid = pid.split('?')[1];
        hquery.page = pid.substr(6);
        hquery.fillQueryVars();
        hquery.get();
        return false;
    });
    //compare button
    $('.compare').css({
        display: 'block'
    });
    $('.compare input:checkbox').map(function() {
        if(jQuery(this).is(' :checked')) $(this).parent().toggleClass('compare-selected');
    } );
    hquery.updateFavCount();
    $('.compare input:checkbox').live('click', function (){
        $(this).hide();
        $('.load', $(this).parent()).show();
        $(this).parent().toggleClass('compare-selected');
        if($(this).is(' :checked')){
            favs_flush_to_text($(this).val());
            $('.viewFavs', $(this).parent()).show();
        }
        else{
           new_fav_remove_fav($(this).val());
           $('.viewFavs', $(this).parent()).hide();
        }
        hquery.updateFavCount();
        hquery.saveFavs(this);
    });
});

//helpers

function getPageSize(){
	var de = document.documentElement;
	var w = window.innerWidth || self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
	var h = window.innerHeight || self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight;
	arrayPageSize = [w,h];
	return arrayPageSize;
}