$(document).ready(function(){ 
    $(document).pngFix();
});

Registry = function() {};
Registry.prototype._hash = Array();
Registry.prototype.set = function(key, value) {
    if (this._hash[key] != undefined) return false;
    this._hash[key] = value;
}
Registry.prototype.get = function(key) {
    if (this._hash[key] != undefined) return this._hash[key];
    return null;
}
var registry = new Registry();
registry.pageRatings = new Registry();

function toggleElm(elm) { $(elm).css('display', ($(elm).css('display') == 'none' ? '' : 'none')); }
function animToggleElm(elm) { $(elm).slideToggle('slow'); }

function request(dataToSend, successHandler, failHandler, method) {
    //dataToSend.hash = makeHash(dataToSend);
    var _url = base;
    if (dataToSend.url != undefined) {
    	_url = dataToSend.url;
    	if (method == undefined || method == 'GET')
    		dataToSend = {};
    }
    
    $.ajax({
        type:(method != undefined) ? method : 'GET',
        url:_url,
        dataType:'json',
        data:dataToSend,
        //contentType:"application/x-www-form-urlencoded",
        //beforeSend:onBeforeSend(dataToSend),
        success:function(data) { successHandler(data); },
        error:failHandler
    });
}

function failure() {
	$.jGrowl("Ошибка при получении данных от сервера!", { theme: 'error', life: 5000 });
}

function changeCaptcha(captchaImg, prefix) {
	var newCaptcha = base + 'utils/captcha/' + prefix + '/';
	newCaptcha += Math.random();
	$('#'+captchaImg).attr('src', newCaptcha);
}

function showTimedMessage(elt, message, time) {
	if (time == undefined) time = 3;

	$(elt).html(message);
	$.timer(1000*time, function(timer) {
		$(elt).html('');
		timer.stop();
	});
}
