

;(function (jQuery, undefined) {
'use strict';
if (typeof(Wicket) === 'undefined') {
window.Wicket = {};
}
if (typeof(Wicket.Event) === 'object') {
return;
}
jQuery.extend(true, Wicket, {
Browser: {
_isKHTML: null,
isKHTML: function () {
var wb = Wicket.Browser;
if (wb._isKHTML === null) {
wb._isKHTML = (/Konqueror|KHTML/).test(window.navigator.userAgent) && !/Apple/.test(window.navigator.userAgent);
}
return wb._isKHTML;
},
_isSafari: null,
isSafari: function () {
var wb = Wicket.Browser;
if (wb._isSafari === null) {
wb._isSafari = !/Chrome/.test(window.navigator.userAgent) && /KHTML/.test(window.navigator.userAgent) && /Apple/.test(window.navigator.userAgent);
}
return wb._isSafari;
},
_isChrome: null,
isChrome: function () {
var wb = Wicket.Browser;
if (wb._isChrome === null) {
wb._isChrome = (/KHTML/).test(window.navigator.userAgent) && /Apple/.test(window.navigator.userAgent) && /Chrome/.test(window.navigator.userAgent);
}
return wb._isChrome;
},
_isOpera: null,
isOpera: function () {
var wb = Wicket.Browser;
if (wb._isOpera === null) {
wb._isOpera = !Wicket.Browser.isSafari() && typeof(window.opera) !== "undefined";
}
return wb._isOpera;
},
_isIE: null,
isIE: function () {
var wb = Wicket.Browser;
if (wb._isIE === null) {
wb._isIE = !Wicket.Browser.isSafari() && (typeof(document.all) !== "undefined" || window.navigator.userAgent.indexOf("Trident/")>-1) && typeof(window.opera) === "undefined";
}
return wb._isIE;
},
_isIEQuirks: null,
isIEQuirks: function () {
var wb = Wicket.Browser;
if (wb._isIEQuirks === null) {

 wb._isIEQuirks = Wicket.Browser.isIE() && window.document.documentElement.clientHeight === 0;
}
return wb._isIEQuirks;
},
_isIELessThan9: null,
isIELessThan9: function () {
var wb = Wicket.Browser;
if (wb._isIELessThan9 === null) {
var index = window.navigator.userAgent.indexOf("MSIE");
var version = parseFloat(window.navigator.userAgent.substring(index + 5));
wb._isIELessThan9 = Wicket.Browser.isIE() && version < 9;
}
return wb._isIELessThan9;
},
_isIELessThan11: null,
isIELessThan11: function () {
var wb = Wicket.Browser;
if (wb._isIELessThan11 === null) {
wb._isIELessThan11 = !Wicket.Browser.isSafari() && typeof(document.all) !== "undefined" && typeof(window.opera) === "undefined";
}
return wb._isIELessThan11;
},
_isIE11: null,
isIE11: function () {
var wb = Wicket.Browser;
if (wb._isIE11 === null) {
var userAgent = window.navigator.userAgent;
var isTrident = userAgent.indexOf("Trident") > -1;
var is11 = userAgent.indexOf("rv:11") > -1;
wb._isIE11 = isTrident && is11;
}
return wb._isIE11;
},
_isGecko: null,
isGecko: function () {
var wb = Wicket.Browser;
if (wb._isGecko === null) {
wb._isGecko = (/Gecko/).test(window.navigator.userAgent) && !Wicket.Browser.isSafari();
}
return wb._isGecko;
}
},

Event: {
idCounter: 0,
getId: function (element) {
var $el = jQuery(element),
id = $el.prop("id");
if (typeof(id) === "string" && id.length > 0) {
return id;
} else {
id = "wicket-generated-id-" + Wicket.Event.idCounter++;
$el.prop("id", id);
return id;
}
},
keyCode: function (evt) {
return Wicket.Event.fix(evt).keyCode;
},

stop: function (evt, immediate) {
evt = Wicket.Event.fix(evt);
if (immediate) {
evt.stopImmediatePropagation();
} else {
evt.stopPropagation();
}
return evt;
},

fix: function (evt) {
return jQuery.event.fix(evt || window.event);
},
fire: function (element, event) {
event = (event === 'mousewheel' && Wicket.Browser.isGecko()) ? 'DOMMouseScroll' : event;
jQuery(element).trigger(event);
},

add: function (element, type, fn, data, selector) {
if (type === 'domready') {
jQuery(fn);
} else if (type === 'load' && element === window) {
jQuery(window).on('load', function() {
jQuery(fn);
});
} else {
type = (type === 'mousewheel' && Wicket.Browser.isGecko()) ? 'DOMMouseScroll' : type;
var el = element;
if (typeof(element) === 'string') {
el = document.getElementById(element);
}
if (!el && Wicket.Log) {
Wicket.Log.error('Cannot bind a listener for event "' + type +
'" on element "' + element + '" because the element is not in the DOM');
}
jQuery(el).on(type, selector, data, fn);
}
return element;
},

remove: function (element, type, fn) {
jQuery(element).off(type, fn);
},

subscribe: function (topic, subscriber) {
if (topic) {
jQuery(document).on(topic, subscriber);
}
},

unsubscribe: function(topic, subscriber) {
if (topic) {
if (subscriber) {
jQuery(document).off(topic, subscriber);
} else {
jQuery(document).off(topic);
}
} else {
jQuery(document).off();
}
},

publish: function (topic) {
if (topic) {

 var args = Array.prototype.slice.call(arguments).slice(1);
jQuery(document).triggerHandler(topic, args);
jQuery(document).triggerHandler('*', args);
}
},

Topic: {
DOM_NODE_REMOVING : '/dom/node/removing',
DOM_NODE_ADDED : '/dom/node/added',
AJAX_CALL_INIT : '/ajax/call/init',
AJAX_CALL_BEFORE : '/ajax/call/before',
AJAX_CALL_PRECONDITION : '/ajax/call/precondition',
AJAX_CALL_BEFORE_SEND : '/ajax/call/beforeSend',
AJAX_CALL_SUCCESS : '/ajax/call/success',
AJAX_CALL_COMPLETE : '/ajax/call/complete',
AJAX_CALL_AFTER : '/ajax/call/after',
AJAX_CALL_FAILURE : '/ajax/call/failure',
AJAX_CALL_DONE : '/ajax/call/done',
AJAX_HANDLERS_BOUND : '/ajax/handlers/bound'
}
}
});
})(jQuery);
