/* Ajax error */
$(document).ajaxError(function (request,settings,e) {
    alert('Error requesting URL: '+e.url);
});
/* URL router */
var Router = function (route,params) {
    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(){
    
    $('#portfolio-logos div').hide().fadeIn(400);
    $('#portfolio-logos div').hover(function () {
        $('img',this).animate({
            width: '160px',
            height: '150px',
            top: '0px',
            left: '0px'
        }, {
            duration: 200
        });
    },function () {
        $('img',this).animate({
            width: '120px',
            height: '112px',
            top: '19px',
            left: '20px'
        }, {
            duration: 200
        });
    });
    
    $('#mainMenu > li').hover(
        function(){
            var ulChild = $(this).find('ul');
            if(ulChild.is(':hidden')){
                var uls = $('#mainMenu li ul:visible');
                if(ulChild != undefined){
                    ulChild.css('opacity',0.9).slideDown(300,function(){ if(uls != undefined){ uls.hide(); } });
                }
            }
        }
       ,function(){
           $(this).find('ul:visible').slideUp(150);
       }
    );
});

function fadeInImage(index,images){
    if(index < images.length){
        $(images[index]).fadeIn(600,function(){
            fadeInImage(index + 1,images);
        });
    }
};