/* 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();
	
    $('#menu li').hover(
        function(){ $(this).addClass('hover'); }
       ,function(){ $(this).removeClass('hover'); }
    );
    
    $('div.list-item').hover(
        function(){ $(this).addClass('list-item-hover'); }
       ,function(){ $(this).removeClass('list-item-hover'); }
    );
    
    $('div.lightbox img').hover(
        function(){ $(this).addClass('hover'); }
       ,function(){ $(this).removeClass('hover'); }
    );
    
    $('area').click(function() {
        $.mapSrc = '/public/themes/images/mapa/' + $(this).attr('alt') + '.gif';
        $("#mapa").attr('src',$.mapSrc);
        
        $('.dealer').hide();
        $('#'+ $(this).attr('alt')).slideDown(500);
        
        return false;
    }).hover(
         function(){
             $.mapSrc = $("#mapa").attr('src');
             $("#mapa").attr('src','/public/themes/images/mapa/' + $(this).attr('alt') + '.gif');
         }
        ,function(){
            $("#mapa").attr('src',$.mapSrc);
        }
    );
    
    $('area[alt=ke]').trigger('click');
    
});
