$(document).ready(function() {
    $('#categoryJump').change(function() {
        if($(this).val()) {
            window.location.href = "/"+$('#townJump').val()+"/"+$(this).val();
        }
    });
    
    $('#townJump').change(function() {
        if($(this).val()) {
            window.location.href = "/"+$(this).val()+($('#categoryJump').val() ? '/'+$('#categoryJump').val() : '');
        }
    });
    
    $('ul.advertList.public li a[target=_blank]:not(.moreLink)').click(function() {
        var parts = $(this).parents('li.advertContainer').attr('id').split('-');
        var id = parts[1];
        
        $.get("/ajax/hit?id="+id);
    });
    
    $('ul.advertList div.advertToolbar a').parents().children('div.advertContentContainer').css('top','0px');
    
    $('ul.advertList div.advertToolbar a').each(function() {
        if($(this).parents().children('div.advertContentContainer').height() <= 200) {
            $(this).hide();
        }
    });
    
    $('ul.advertList div.advertToolbar a').click(function() {
        var container = $(this).parents().children('div.advertContentContainer');
        if(container.height() > 200) {
            if(container.css('top') !== '0px') {
                container.animate({top: '0'}, 1500);
                $(this).html('More');
            } else {
                var pos = (Number(container.height() - 202) * -1) + 'px';
                container.animate({top: pos}, 1500);
                $(this).html('Top');
            }
        }
        return false;
    });
    
/*     $('ul.advertList').sortable({placeholder: 'placeholder', handle: 'div.advertToolbar a'}); */
});
