function getRadioGroupValue(radioGroupObj) {
    for (var i=0; i < radioGroupObj.length; i++)
	if (radioGroupObj[i].checked) return radioGroupObj[i].value;
    return null;
}

$(function() {
    // Заглушка для браузеров без консоли отладки (уходи прочь IE)
    if (!("console" in window)) {
	var methods = ["log", "debug", "info",
		       "warn", "error", "assert",
		       "dir", "dirxml", "trace",
		       "group", "groupCollapsed",
		       "groupEnd", "time", "timeEnd",
		       "profile", "profileEnd", "count",
		       "exception", "table"
	];
        window.console = {};
	for (var method in methods) {
	    if (!(methods[method] in window.console)) {
		window.console[methods[method]] = function(){};
	    }
	}
    }
    
    // Сворачивание/разворачивание списков
    if ($().collapsorz) {
		$("ul.collapsorz,ol.collapsorz").collapsorz({
			minimum: 10,
			showText: "Развернуть",
			hideText: "Свернуть",
			wrapLink: '<div class="sidebar-left-item-more">'
		});
				$(".crcentr ul").collapsorz({
			minimum: 16,
			showText: "Показать все",
			hideText: "Свернуть",
			wrapLink: '<p class="more" style="text-align:right; z-index:20; position:relative; right:18px; zoom:1;">'
		});
		$(".firmrubric ul").collapsorz({
			minimum: 4,
			showText: '<span style="float:right; margin-top:3px; cursor:pointer;">Показать все</span>',
			hideText: '<span style="float:right; margin-top:3px; cursor:pointer;">Свернуть</span>',
			wrapLink: '<p class="more" style="z-index:20; border-bottom:1px solid #e7e7e7; width:100%; zoom:1; position:relative; padding-bottom:20px; background:#fff; //padding-bottom:2px;">'
		});
	}
    $('a.pseudo_link').click(function(e) {
        e.preventDefault();
        $('#' + $(this).attr('rel')).slideToggle().toggleClass('hidden');
    });
    // Календарь
    if (jQuery().datePicker) {
	$('#datepicker-wrap').datePicker({
		inline:true,
		startDate: '01/01/1970'
	})
	.bind('dateSelected', function(event, date, $td, status) {
		day = date.getDate();
		month = date.getMonth() + 1;
		//month = date.getMonth();
		year = date.getFullYear();
		document.location.href = '?module=articles&action=list&day='+day+'&month='+month+'&year='+year;
	});
    }
    
    // Подгрузка фото при прокрутке страницы
    if (jQuery().lazyload) {
	$('.img').lazyload({
	    effect:'fadeIn',
	    placeholder:'images/banner.gif'
	});
    }
    
    if (jQuery().selectBox) {
	$('select').selectBox();
    }
    $('#nyear').change(function() {
	var yearObj = $(this);
	var yearVal = yearObj.val();
	var numberObj = $('#issue');
	
	$.ajax({
	    url: "?module=number&action=getnumbers&id="+yearVal,
	    dataType: "json",
            success: function (data, status, request) {
                if (status == "success") { //console.log(data);
                    var len = data.id.length;
                    if (len > 0) {
			numberObj.empty();
			numberObj.selectBox('destroy');
			numberObj.append('<option value="">Номер</option>');
                        for(i = 0; i < len;i++) {		
			    numberObj.append('<option value="'+data.id[i]+'">'+data.name[i]+'</option>');
			    
                        }
			numberObj.selectBox();
                    }
                }
            }
        });
    });
    $('#issue').change(function() {
	$(this).parent().submit();
    });
    
    // Всплвающая гелерея для фото
    if (jQuery().lightBox) {
	$('a[href$=gif],a[href$=png],a[href$=jpg],a[href$=jpeg]').lightBox({
	    overlayBgColor: '#000',
	    overlayOpacity: 0.6,
	    //fixedNavigation: true,
	    imageLoading: 'images/lytebox/lightbox-ico-loading.gif',
	    imageBtnClose: 'images/lytebox/lightbox-btn-close.gif',
	    imageBtnPrev: 'images/lytebox/lightbox-btn-prev.gif',
	    imageBtnNext: 'images/lytebox/lightbox-btn-next.gif',
	    imageBlank: 'images/lytebox/lightbox-blank.gif',
	    containerResizeSpeed: 350,
	    containerBorderSize: 0,
	    txtImage: 'Фото',
	    txtOf: 'из'
	});
    }
    
    /*if (jQuery().rating) {
	// Установим текущий рейтинг
	$('#rating-answer-3').attr('checked', true);
	$('#rating-count > span').text(4);
	$('#rating-form > input:radio').rating({
	    required: false,
	    readOnly: false,
	    callback: function (value) {
		$.get(
		    $('#rating-form').attr('action'),
		    {value: value},
		    function (data) {
			// Блокируем
			$('#rating-form > input:radio').rating('disable');
			$('#rating-form').animate({opacity: "hide" }, 500);
			$('#rating-form').animate({opacity: "show" }, 500);
			$('#rating-message').text(data).animate({opacity: "hide" }, 6000);			
			$('#rating-count > span').text(parseInt($('#rating-count > span').text()) + 1);
			
		    }
		);
	    }
	});
    }*/
    
});
