/* AJAX ERROR */
$(document).ajaxError(function (request,settings,e) {
    alert('Error requesting URL: '+e.url);
});
/* URL ROUTER */
var Router = function (route,params) {
    //parametre
    if (typeof(params) == 'object') {
        var p = '';
        $.each(params,function (name,value) {
            if (p != '') {
                p += '&';
            }
            p += escape(name)+'='+escape(value);
        });
        return Router(route)+'?'+p;
    }
    else {
        return '/' + route;
    }
};
Router.route = function (route,params) {
    var url = Router(route,params);
    location.href = url;
}

/* Plugin na input hint */
jQuery.fn.inputHint = function () {
    this.each(function () {
        var self = $(this);
        if (self.is('input[type=text]')) {
            jQuery.inputHintShow(self);
            self.focus(function () {
                jQuery.inputHintHide(this);
            }).blur(function () {
                jQuery.inputHintShow(this);
            }).closest('form').submit(function () {
                jQuery.inputHintHide(self);
                return true;
            });
        }
    });
    return this;
};
jQuery.inputHintShow = function (inpt) {
    inpt = jQuery(inpt);
    if (inpt.val() == inpt.attr('title') || inpt.val() == '') {
        inpt.addClass('hint').val(inpt.attr('title'));
    }
}
jQuery.inputHintHide = function (inpt) {
    inpt = jQuery(inpt);
    inpt.removeClass('hint');
    if (inpt.val() == inpt.attr('title')) {
        inpt.val('');
    }
}

$(function(){
	//hinty vo formularoch
	$('input.hint').inputHint();;
	$('select.sselect').sSelect({
        ddMaxHeight: 150,
        minListWidth: 100
	});
	//zobrazenie a prepinanie vyhladavaca
	$('#show-pneu').click(function () {
        $('#form-pneu').show();
        $('#form-disc').hide();
        $('#show-pneu').parent().addClass('active');
        $('#show-disc').parent().removeClass('active');
    });
    $('#show-disc').click(function () {
        $('#form-disc').show();
        $('#form-pneu').hide();
        $('#show-disc').parent().addClass('active');
        $('#show-pneu').parent().removeClass('active');
    });
    //stylish select vo vyhladavaci
	$('#typeSelector select').sSelect({
        width:110,
        ddMaxHeight: 150,
        minListWidth: 140
	});
});
