window.log = function() {
    if (JSTOOLS.settings.DEBUG) {
        try { 
            console.log.apply( console, Array.prototype.slice.call(arguments) ); 
        } catch(e) {
            try {
                opera.postError.apply( opera, arguments ); 
            } catch(er) { 
                  alert( Array.prototype.join.call( arguments, " " ) ); 
            }
        }
    }
};

if (JSTOOLS.settings.DEBUG) {
    $(document).ajaxError(function(e, XMLHttpRequest, textStatus, errorThrown) {
        document.write(XMLHttpRequest.responseText);
    })
}

(function($) {
    
$.easing.aino = function (x, t, b, c, d) {
    if ((t/=d/2) < 1) { 
        return c/2*t*t*t*t + b;
    }
    return -c/2 * ((t-=2)*t*t*t - 2) + b;
};

var nav = navigator.userAgent.toLowerCase();

var A = window.Aino = {
    
    ready: function(fn) {
        $(window).bind('init', function(e, scope) {
            fn.call(scope);
        });
    },
    trigger: function(type, scope) {
        $(window).trigger(type, [ scope || this ] );
    },
    activate: function(elem) {
        return $(elem).addClass('active').siblings('.active').removeClass('active');
    },
    table: function(table) {
        $(table).find('tr:odd').addClass('odd');
        Aino.anchorClass($(table).find('tr'));
    },
    anchorClass: function(elem) {
        return $(elem).hover(function() {
            $(this).addClass('hover')
        }, function() {
            $(this).removeClass('hover')
        }).mousedown(function() {
            $(this).addClass('active').removeClass('hover');
        }).mouseup(function() {
            $(this).removeClass('active hover');
        });
    },
    prototyping: function() {
        $('img[src="#"]').attr('src', JSTOOLS.settings.MEDIA_URL + 'i/blank.gif').addClass('placeholder').each(function() {
            this.width = this.width - 2;
            this.height = this.height - 2;
        });
        $('a[href="#"]').click(function(e) {
            e.preventDefault();
        });
    },
    anchors: function() {
        var loc = $.trim(window.location.hostname);
        $('a').live('mousedown', function(e) {
            e.target.blur();
            e.target.hideFocus = true;
            $(e.target).css('outline','none');
        }).live('mouseout', function(e) {
            e.target.blur();
            e.target.hideFocus = false;
            $(e.target).attr('style', e.target.style.toString().replace(/outline:[^;];/,''));
        }).filter(function() {
            try {
                return $.trim(this.hostname) != loc;
            }
            catch(e) {
                return false;
            }
        }).each(function() {
            $(this).attr({
                target: '_blank',
                title: 'Open in new window: '+ (this.protocol + this.hostname + this.pathname)
            });
        }).end().filter(function() {
            return this.title.length
        }).tooltip({ 
            track: true,
            delay: 400, 
            showURL: false, 
            showBody: " - ", 
            fade: 200
        });
    },
    IE : (function() {
        var undef, v = 3, div = document.createElement('div');
        while (
            div.innerHTML = '<!--[if gt IE '+(++v)+']><i></i><![endif]-->',
            div.getElementsByTagName('i')[0]
        );
        return v > 4 ? v : undef;
    }()),
    WEBKIT : /webkit/.test( nav ),
    SAFARI : /safari/.test( nav ),
    CHROME : /chrome/.test( nav ),
    QUIRK : (this.IE && document.compatMode && document.compatMode == "BackCompat"),
    MAC : /mac/.test(navigator.platform.toLowerCase())
}

})(jQuery);

