/* 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();;
});

$(function(){
    var animationImages = $('#sloganAnimationImages').val();
    if (animationImages){
        eval('animationImages = ' + animationImages + ';');
        var ul = $('<ul></ul>').attr('id','sloganAnimation');
        $.each(animationImages,function (idx,imgsrc){
				ul.append('<li><img src="' + imgsrc + '" alt=""></img></li>');
        });
        $('#sloganAnimationImages').after(ul);
        ul.innerfade({
            animationtype: 'fade',
            speed: 'slow',
            timeout: 4000
        });
    }
});

$(function(){
  /*
    $('a#message').click(function(){
        if(!$('div#messageContainer').length){
            var message = $('<div>').attr('id','messageContainer').hide();
            $('ul#kontextMenu').after(message);
            
            message.load(LANGROOT + '/ask/',function(){
                message.fadeIn();
                    $('form#message').submit(function(){
                    $.post(this.action,$(this).serialize(),function(response){
                        eval('var r = '+response+';');
                        $('div.report',message).remove();
                        if (r.status == 'OK') {
                            message.prepend('<div class="report report_INFO"><span class="ico ico_INFO">&nbsp;</span>'+r.message+'</div>');
                            window.setTimeout(function(){
                                message.fadeOut(function(){
                                    $(this).remove();
                                });
                            },1500);
                        } else {
                            message.prepend('<div class="report report_ERROR"><span class="ico ico_ERROR">&nbsp;</span>'+r.message+'</div>');
                        }
                    });
                    return false;
                });
            });
            
        } else{
            $('div#messageContainer').fadeOut(function(){
                $(this).remove();
            });
        }
    }); */
});
