$(function(){
	$("#ppp").change(function(){
		location.hash = $('option[value='+$('#ppp').val()+']').attr('lang');
	});
});
hashChange();
function hashChange()
{
    hash = location.hash;
    $.getJSON('/cat.php', {'hash':hash}, function(d){
        $('#func_in .selector').html(d['p']);
        $('#workarea').html(d['d']);

        $('#nov').attr('href', '#sort=' + d['sort'] + '&ns=new&ppp=' + d['ppp']);
        $('#act').attr('href', '#sort=' + d['sort'] + '&ns=act&ppp=' + d['ppp']);
        $('#tagarea a').each(function(){
            $(this).attr('href', '#sort=' + d['sort'] + '&ns=' + $(this).attr('coords') + '&ppp=' + d['ppp']);
        });
        if (d['sort'] == 'asc')
            $('.price_sort a').attr('href', '#sort=desc&ns=' + d['ns'] + '&ppp=' + d['ppp']);
        else
            $('.price_sort a').attr('href', '#sort=asc&ns=' + d['ns'] + '&ppp=' + d['ppp']);

		$('#ppp option').each(function(){
			$(this).attr('lang', 'sort=' + d['sort'] + '&ns=' + d['ns'] + '&ppp=' + $(this).val());
		});
		$('#ppp').val(d['ppp']);
    });
}
if("addEventListener" in window) {
   window.addEventListener("hashchange", hashChange, false);
} else if ("attachEvent" in window) {
   window.attachEvent( "onhashchange", hashChange);
}
