;/*
 *  @author yangzeming
 *  @desc   常用方法扩展
 */

/*
 *  @desc  类继承
 */

/*
 *  @desc  事件分发机制
 */
var _ = _ || {};
$.extend(_, (function () {

    /**
     * 消息中心
     * @type {{eventPool: (*|jQuery|HTMLElement), observe: Function, fire: Function, stopObserving: Function}}
     */
    var MessageManager = {
        debug: false,
        eventPool: $({}),

        on: function () {
            this.eventPool.bind.apply(this.eventPool, arguments);
        },

        fire: function () {
            this.eventPool.trigger.apply(this.eventPool, arguments);
        },

        stopObserving: function () {
            this.eventPool.unbind.apply(this.eventPool, arguments);
        }
    };

    /***
	 * @desc 用于生成类的函数
	 * @param {Object} properties 类的成员属性和方法集
	 * @return JS类对象
	 */
    var Class = function (properties) {
        if (!properties.hasOwnProperty('initial') || !$.isFunction(properties.initial)) {
            properties.initial = new Function();
        }
        var _getProperties = function (properties) {
            var result = {
                'noMethod': {},
                'method': {},
                'extend': null
            };
            for (var i in properties) {
                if (i == 'prototype') continue;

                if ($.isFunction(properties[i])) {
                    result.method[i] = properties[i];
                } else if ($.isArray(properties[i])) {
                    result.noMethod[i] = Array.prototype.slice.call(properties[i], 0);
                } else if ($.isPlainObject(properties[i])) {
                    result.noMethod[i] = $.extend({}, properties[i]);
                } else {
                    result.noMethod[i] = properties[i];
                }
            }
            return result;
        };
        var _propObj = _getProperties(properties);
        var _class = function () {
            $.extend(this, _propObj.noMethod);
            if (_class.prototype.initial && $.isFunction(_class.prototype.initial)) {
                _class.prototype.initial.apply(this, arguments);
            }
        };
        /***
		 * @desc 类继承方法
		 * @param {Object} prop 新类的成员属性集合
		 * @return 新的类对象
		 */
        _class.extend = function (prop) {
            var _prototype = _class.prototype;
            var __prop = {};
            $.extend(__prop, _prototype, prop);
            var _newClass = Class(__prop);
            $.extend(_newClass.prototype, {
                "__parent__": function (propName) {
                    var self = this;
                    if (!_prototype.hasOwnProperty(propName)) return;
                    return ($.isFunction(_prototype[propName])) ? function () { _prototype[propName].apply(self, arguments); } : _prototype[propName];
                },
                "__super__": function () {
                    //alert(this.parent('initial'));
                    return this.__parent__('initial').apply(this, arguments);
                }
            });
            return _newClass;
        };
        if (!properties["noDispatcher"]) {
            var tmp = $.extend(true, {}, Dispatcher);
            $.extend(_class.prototype, tmp);
        }
        $.extend(_class.prototype, properties, { 'prototype': _class.prototype });

        //if()
        return _class;
    };
    /***
	 * @class 事件类
	 */

    var Event = Class({
        type: '',		//事件类型
        target: null,	//目标对象
        /**
		 * @desc 构造函数
		 * @param {String} 事件类型
		 * @param {Object} 事件目标
		 */
        initial: function (eventType, target) {
            this.type = eventType;
            this.target = target;
        }
    });
    /***
	 * @class 事件分发类
	 */
    var Dispatcher = {
        _eventStack: {},
        /***
		 * @desc 绑定事件
		 * @param {String} eventType		事件类型
		 * @param {Function} eventHandler		事件处理函数
		 * @param {Object} context
		 */
        bind: function (eventType, eventHandler, context) {
            if (!this._eventStack.hasOwnProperty(eventType)) {
                this._eventStack[eventType] = [];
            }
            this._eventStack[eventType].push({
                'handler': eventHandler,
                'context': context
            });
        },
        /***
		 * @desc 绑定事件
		 * @param {String} eventType		事件类型
		 * @param {Function} eventHandler		事件处理函数
		 */
        unbind: function (eventType, eventHandler) {
            if (!this._eventStack.hasOwnProperty(eventType)) {
                return;
            }
            //如果没有传入具体的事件处理函数 则删除所有该eventType绑定
            if (!eventHandler || !$.isFunction(eventHandler)) {
                delete this._eventStack[eventType];
                return;
            }
            var _eventStack = this._eventStack[eventType];
            for (var i = 0, len = _eventStack.length; i < len; i++) {
                if (_eventStack[i]['handler'] == eventHandler) {
                    _eventStack.splice(i, 1);
                    break;
                }
            }
        },
        /***
		 * @desc 事件分发
		 * @param {String} eventType 事件类型
		 */
        trigger: function (eventType) {
            if (!this._eventStack.hasOwnProperty(eventType) || !this._eventStack[eventType].length)
                return;

            var _evt = new Event(eventType, this);
            var _args = Array.prototype.slice.call(arguments, 0),
				_tempStack = [];
            _args.shift();
            _args = [_evt].concat(_args);

            if (this._eventStack[eventType]) {
                _tempStack = Array.prototype.slice.call(this._eventStack[eventType]);
            }

            for (var i = 0, stack = _tempStack, len = _tempStack.length; i < len; i++) {
                if (!stack || !stack[i]) {
                    continue;
                }
                var obj = stack[i],
					fn = obj['handler'],
					ctx = obj['context'] || null;
                if (fn && $.isFunction(fn)) {
                    fn.apply(ctx, _args);
                }
            }
        },

        observe: function () {
            MessageManager.observe.apply(MessageManager, arguments);
        },

        stopObserving: function () {
            MessageManager.stopObserving.apply(MessageManager, arguments);
        },

        fire: function () {
            MessageManager.fire.apply(MessageManager, arguments);
        }
    };
    return {
        Class: Class,
        Dispatcher: Class(Dispatcher),
        MessageManager: MessageManager

    };
})()
);
/*! Copyright (c) 2011 Brandon Aaron (http://brandonaaron.net)
 * Licensed under the MIT License (LICENSE.txt).
 *
 * Thanks to: http://adomas.org/javascript-mouse-wheel/ for some pointers.
 * Thanks to: Mathias Bank(http://www.mathias-bank.de) for a scope bug fix.
 * Thanks to: Seamus Leahy for adding deltaX and deltaY
 *
 * Version: 3.0.6
 * 
 * Requires: 1.2.2+
 */

(function ($) {

    var types = ['DOMMouseScroll', 'mousewheel'];

    if ($.event.fixHooks) {
        for (var i = types.length; i;) {
            $.event.fixHooks[types[--i]] = $.event.mouseHooks;
        }
    }

    $.event.special.mousewheel = {
        setup: function () {
            if (this.addEventListener) {
                for (var i = types.length; i;) {
                    this.addEventListener(types[--i], handler, false);
                }
            } else {
                this.onmousewheel = handler;
            }
        },

        teardown: function () {
            if (this.removeEventListener) {
                for (var i = types.length; i;) {
                    this.removeEventListener(types[--i], handler, false);
                }
            } else {
                this.onmousewheel = null;
            }
        }
    };

    $.fn.extend({
        mousewheel: function (fn) {
            return fn ? this.bind("mousewheel", fn) : this.trigger("mousewheel");
        },

        unmousewheel: function (fn) {
            return this.unbind("mousewheel", fn);
        }
    });


    function handler(event) {
        var orgEvent = event || window.event, args = [].slice.call(arguments, 1), delta = 0, returnValue = true, deltaX = 0, deltaY = 0;
        event = $.event.fix(orgEvent);
        event.type = "mousewheel";

        // Old school scrollwheel delta
        if (orgEvent.wheelDelta) { delta = orgEvent.wheelDelta / 120; }
        if (orgEvent.detail) { delta = -orgEvent.detail / 3; }

        // New school multidimensional scroll (touchpads) deltas
        deltaY = delta;

        // Gecko
        if (orgEvent.axis !== undefined && orgEvent.axis === orgEvent.HORIZONTAL_AXIS) {
            deltaY = 0;
            deltaX = -1 * delta;
        }

        // Webkit
        if (orgEvent.wheelDeltaY !== undefined) { deltaY = orgEvent.wheelDeltaY / 120; }
        if (orgEvent.wheelDeltaX !== undefined) { deltaX = -1 * orgEvent.wheelDeltaX / 120; }

        // Add event and delta to the front of the arguments
        args.unshift(event, delta, deltaX, deltaY);

        return ($.event.dispatch || $.event.handle).apply(this, args);
    }

})(jQuery);

/*
 *  @desc 工具箱 解析url 获取
 */
(function ($) {
    /**
     * @namespace
     */
    $.easyUtil = $.easyUtil || {};

    /**
    * 返回字符串的字节长度
    * @param s 目标字符串
    * @return {Number}
    */
    $.easyUtil.getByteLength = function (s) {
        return (s + '').replace(/[^\x00-\xff]/g, "mm").length;
    };
    /**
	 * 缩放图片
	 * @param {Image|Object} o 目标图片标签
	 * @param {Number} Mw 最大宽度
	 * @param {Number} Mh 最大高度
	 * @param {Boolean} need_margin 是否需要设置margin使图片居中
	 *
	 * @example
	 * // 追加一个图片缩放并添加到dom上。
	 * var img = $('<img>').load(function () {
	 *     $.tb.resizePic(this, 100, 100, true, 'width');
	 * }).attr('src', 'http://www.baidu.com/img/baidu_sylogo1.gif').appendTo($('body'));
	 */
    $.easyUtil.resizePic = function (o, mw, mh, need_margin, by) {
        var w = o.width, h = o.height,
		width = w, height = h;
        if (w === 0 || h === 0) {
            return;
        }
        if (typeof need_margin === 'string') {
            by = need_margin;
            need_margin = false;
        }
        // 
        width = mw;
        height = Math.round((mw * h) / w);
        if (height < mh) {
            height = mh;
            width = Math.round((mh * w) / h);

        }
        /*
         * if( w/h >= mw/mh){
            if (w > mw) {
                width = mw;
                height = Math.round((mw*h)/w);
            }
            
        }else{
            
            if (h > mh) {
                height = mh;
                width = Math.round((mh*w)/h);
            }
        }
         * if (by === 'width' || (by !== 'height' && w/h >= mw/mh)) {
            if (w > mw) {
                width = mw;
                height = Math.round((mw*h)/w);
            }
        } else {
            if (h > mh) {
                height = mh;
                width = Math.round((mh*w)/h);
            }
        }*/

        if (need_margin) {
            //if (width < mw) {
            o.style.marginLeft = Math.floor((mw - width) / 2) + 'px';
            //}
            //if (height < mh) {
            o.style.marginTop = Math.floor((mh - height) / 2) + 'px';
            //}
        }

        o.width = width;
        o.height = height;

    };
    $.easyUtil.gw = function (money, n) {
        var m = money + "",
            money=money+"",
            n1 = 3;
        var setDf = function (mm) {
            if (mm.length <= n1) return mm;
            var len = mm.length - n1;
            var hm = mm.slice(len, mm.length),
                ym = setDf(mm.slice(0, len));
            var jm = ym + "," + hm;
            return jm;
        };
        if (m.indexOf(".") == -1) {
            if (m.length > n1) {
                //var len = m.length - n1;

                // m = m.slice(0, len) + "," + m.slice(len, m.length);
                m = setDf(m);
            }
            m =m +".00"
        } else {
            var mj = m.slice(0, money.indexOf(".")),
                xj = m.slice(money.indexOf("."),m.length);
          //  if (mj.length > n1) {
            //    var len = mj.length - n1;

            m = setDf(mj) + xj;//mj.slice(0, len) + "," + mj.slice(len, mj.length) + xj;
           // }

        }
        return m;
    }
    $.easyUtil.cdata = function (money, h, n) {
        var m = Number(money),
            j = n || 10000,
            dw = "万";
        // 获取单位
        switch (j) {
            case 10: dw = "十"; break;
            case 100: dw = "百"; break;
            case 1000: dw = "千"; break;
            case 10000: dw = "万"; break;
            case 100000: dw = "十万"; break;
            case 1000000: dw = "百万"; break;
            case 10000000: dw = "千万"; break;
            case 100000000: dw = "亿"; break;

        }
        // 先判断是否那么多位
        var org = m / j;
        if (org < 1) {
            return m.toFixed(h);
        } else {
            return org.toFixed(h) + dw;

        }
    }
    /**
     * 字符串截断
     * @param {String} s 目标字符串
     * @param {Number} n 超过多少个字节进行截断
     * @param {String} [text="..."]  截断后的字符串, 默认为"...", 如果不需截断则直接返回;如果超出长度则出str
     * @return {String}
     */
    $.easyUtil.subByte = function (s, n, text) {
        if ($.easyUtil.getByteLength(s) <= n) {
            return s;
        }
        text = text === undefined ? '...' : String(text);

        n -= $.easyUtil.getByteLength(text);
        for (var i = Math.floor(n / 2), l = $.easyUtil.getByteLength(s) ; i < l ; i++) {
            var sub = s.substring(0, i),
				len = $.easyUtil.getByteLength(sub);
            if (len == n) {
                return sub + text;
            } else if (len > n) {
                return s.substring(0, i - 1) + text;
            }
        }
        return s;

    };
    $.easyUtil.Storage = (function () {
        var _guid = 'easyUI',
		_status = {//状态说明
		    SUCCESS: 0,
		    FAILURE: 1,
		    OVERFLOW: 2
		};
        function _getKey(key) {
            //escape spaces in name，单下划线替换为双下划线，空格替换为_s
            return key.replace(/[_\s]/g, function (matcher) {
                return matcher == '_' ? '__' : '_s';
            });
        }

        function _getElement() {
            return document.getElementById(_guid + '-storage');
        }

        function isDate(o) {
            return {}.toString.call(o) === "[object Date]" && o.toString() !== 'Invalid Date' && !isNaN(o);
        }

        function _getInstance() {
            var _storage;
            if (window.localStorage) {
                _storage = _createLocalStorage();
            } else if (window.ActiveXObject) {
                _storage = _createUserData();
            }
            return _storage;
        }

        /**
		 * 将userData进行包装并返回一个只包含三个方法的对象
		 * @return {Object} 一个对象，包括set, get, del接口.
		 * @private
		 */
        function _createUserData() {
            var holder = document.createElement('div');
            holder.style.display = 'none';
            holder.id = _guid + '-storage';
            document.body.appendChild(holder);

            _getElement().addBehavior('#default#userData');
            return {
                //            size: 64 * 1024,
                set: function (key, value, expires) {
                    var status = _status.SUCCESS,
                    ele = _getElement(),
                    newKey = _getKey(key),
                    time = expires ? expires
                        : new Date().getTime() + 365 * 24 * 60 * 60 * 1000;//默认保存一年时间
                    isDate(time) && (time = time.getTime());

                    ele.expires = new Date(time).toUTCString();
                    try {
                        ele.setAttribute(newKey, value);
                        ele.save(newKey);
                    } catch (e) {
                        status = _status.OVERFLOW;//存储时抛出异常认为是溢出
                    }
                    ele = null;
                    return status;
                },
                get: function (key) {
                    var ele = _getElement(),
                    newKey = _getKey(key),
                    val = null;
                    try {
                        ele.load(newKey);
                        val = ele.getAttribute(newKey);//若过期则返回null
                        return val;
                    } catch (e) {
                        throw e.message;
                    }

                },
                del: function (key) {
                    var ele = _getElement(),
                    newKey = _getKey(key),
                    val;
                    try {
                        ele.load(newKey);
                        val = ele.getAttribute(newKey);
                        if (val) {
                            //315532799000 是格林威治时间1979年12月31日23时59分59秒。这是删除UserData的最靠前的一个有效expires时间了，再往前一毫秒，expires = new Date(315532798999).toUTCString(); 就删不掉userdata了，可以认为是IE的一个bug
                            ele.removeAttribute(newKey);
                            ele.expires = new Date(315532799000).toUTCString();
                            ele.save(newKey);
                            return true;
                        } else {
                            return false;
                        }
                    } catch (e) {
                        return false;
                    }
                }
            };
        }

        /**
		 * 将localstorage进行包装并返回一个只包含三个方法的对象
		 * @return {Object} 一个对象，包括set, get, del接口.
		 * @private
		 */
        function _createLocalStorage() {
            return {
                //            size: 10 * 1024 * 1024,
                set: function (key, value, expires) {
                    var status = _status.SUCCESS,
						storage = window.localStorage,
						newKey = _getKey(key),
						time = expires ? expires : new Date().getTime() + 365 * 24 * 60 * 60 * 1000;//默认保存一年时间;
                    isDate(time) && (time = time.getTime());
                    try {
                        storage.setItem(newKey, time + '|' + value);
                    } catch (e) {
                        status = _status.OVERFLOW;//存储时抛出异常认为是溢出
                    }
                    return status;
                },
                get: function (key) {
                    var storage = window.localStorage,
                    newKey = _getKey(key),
                    val = null,
                    index,
                    time;
                    try {
                        val = storage.getItem(newKey);
                    } catch (e) {
                        return null;
                    }
                    if (val) {
                        index = val.indexOf('|');
                        time = parseInt(val.substring(0, index), 10);
                        if (new Date(time).getTime() > new Date().getTime()
							|| time == 0) {
                            val = val.substring(index + 1, val.length);
                            return val;
                        } else {
                            val = null;
                            this.del(key);
                            return null;
                        }
                    } else {
                        return null;
                    }

                },
                del: function (key) {
                    var storage = window.localStorage,
                    newKey = _getKey(key),
                    val = null;
                    try {
                        val = storage.getItem(newKey);
                    } catch (e) {
                        return false;
                    }
                    if (val) {
                        val = val.substring(val.indexOf('|') + 1, val.length);
                        val && storage.removeItem(newKey);
                        return true;
                    } else {
                        return false;
                    }
                }
            };
        }

        return /** @lends $.tb.Storage */ {
            /**
			 * 将一个键值对存入到本地存储中
			 * @param {String} key 一个键名.
			 * @param {String} value 一个值.
			 * @param {Date|Number} expires 设置一个过期时间，值的类型必须是一个Date对象或是一个毫秒数
             * @return 各状码表示{0: 成功, 1: 失败, 2: 溢出}
			 */
            set: function (key, value, expires) {
                var me = this;
                !me._storage && (me._storage = _getInstance());
                return me._storage.set.apply(me._storage, arguments);
            },

            /**
			 * 依据一个键名称来取得本地存储中的值
			 * @param {String} key 一个键名称.
			 * @return null表示key不存在
			 */
            get: function (key) {
                var me = this;
                !me._storage && (me._storage = _getInstance());
                return me._storage.get.apply(me._storage, arguments);
            },

            /**
			 * 根据一个键名称来删除在本地存储中的值
			 * @param {String} key 一个键名称.
			 */
            remove: function (key) {
                var me = this;
                !me._storage && (me._storage = _getInstance());
                return me._storage.del.apply(me._storage, arguments);
            },
            /**
             * 检查浏览器是否支持本地存储特性
             * @return {boolean} true表示支持，false表示不支持
             */
            isSupport: function () {
                return !!(window.localStorage || window.ActiveXObject);
            }
        };
    })();
	
	$(document).ajaxStart(function (jqXHR) {
        $('body').append('<div class="ajaxloading" style="position:absolute;left:45%;top:30%;width:130px;height:130px;z-index:3000000;"><img src="'+url+'/images/nloding.gif"></div>');
    });
    $(document).ajaxComplete(function (jqXHR) {
       $(".ajaxloading").remove();
    });
})(jQuery);

/**
 * Cookie plugin
 * 
 * Copyright (c) 2006 Klaus Hartl (stilbuero.de) Dual licensed under the MIT and
 * GPL licenses: http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 * 
 */

/**
 * 通过给定的名称和值创建一个cookie, 并且可以配置cookie的其它一些参数，如果没有提供value, 将返回对应名称的值
 * @param {String} name cookie的名称
 * @param {String} [value] cookie的值
 * @param {Object} [options] 配置参数
 * @param {Number|Date} options.Number 指明过期日期距离当天的天数;Date:过期时间
 * @param {String} options.path 有权限读取该 cookie的路径(默认为创建本cookie所在的路径)
 * @param {String} options.domain 有权限读取该 cookier的路径(默认为创建本cookie所在的域)
 * @param {Boolean} options.secure 当置为true时，表示创建的 cookie 只能在 HTTPS 连接中被浏览器传递到服务器端进行会话验证，如果是 HTTP 连接则不会传递该信息
 * @return {String|void} 如果没有提供value, 将返回对应名称的值
 *
 * @example
 * //设置cookie值
 * $.cookie('the_cookie', 'the_value');
 *
 * //设置一个cookie，带上所有可用的配置参数
 * $.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secure: true });
 *
 * //删除一个cookie
 * $.cookie('the_cookie', null);
 */
$.cookie = function (name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime()
						+ (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires
            // attribute,
            // max-age is not
            // supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path,
				domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie
							.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};
(function ($, undefined) {
    /**
     * 获取全局zIndex值,基数为10005
     * @return {Number}
     * @author yangzeming
     * @version 2012.11.19
     */
    $.getcurzIndex = function () {
        $.curzIndex = ($.curzIndex || 10005);
        return $.curzIndex++;
    }
    /**
     * 获取全局zIndex值,基数为50000
     * @return {Number}
     */
    $.getzIndex = function () {
        $.zIndex = ($.zIndex || 50000);
        return $.zIndex++;
    },
    /**
    * 获取全局zIndex值,基数为50000
    * @return {Number}
    */
	    $.getInerzIndex = function () {
	        $.inerzIndex = ($.inerzIndex || 1000);
	        return $.inerzIndex++;
	    }
})(jQuery);
;/*! jQuery UI - v1.10.4 - 2014-02-13
* http://jqueryui.com
* Includes: jquery.ui.position.js, jquery.ui.effect.js, jquery.ui.effect-blind.js, jquery.ui.effect-bounce.js, jquery.ui.effect-clip.js, jquery.ui.effect-drop.js, jquery.ui.effect-explode.js, jquery.ui.effect-fade.js, jquery.ui.effect-fold.js, jquery.ui.effect-highlight.js, jquery.ui.effect-pulsate.js, jquery.ui.effect-scale.js, jquery.ui.effect-shake.js, jquery.ui.effect-slide.js, jquery.ui.effect-transfer.js
* Copyright 2014 jQuery Foundation and other contributors; Licensed MIT */

(function ($, undefined) {

    $.ui = $.ui || {};

    var cachedScrollbarWidth,
        max = Math.max,
        abs = Math.abs,
        round = Math.round,
        rhorizontal = /left|center|right/,
        rvertical = /top|center|bottom/,
        roffset = /[\+\-]\d+(\.[\d]+)?%?/,
        rposition = /^\w+/,
        rpercent = /%$/,
        _position = $.fn.position;

    function getOffsets(offsets, width, height) {
        return [
            parseFloat(offsets[0]) * (rpercent.test(offsets[0]) ? width / 100 : 1),
            parseFloat(offsets[1]) * (rpercent.test(offsets[1]) ? height / 100 : 1)
        ];
    }

    function parseCss(element, property) {
        return parseInt($.css(element, property), 10) || 0;
    }

    function getDimensions(elem) {
        var raw = elem[0];
        if (raw.nodeType === 9) {
            return {
                width: elem.width(),
                height: elem.height(),
                offset: { top: 0, left: 0 }
            };
        }
        if ($.isWindow(raw)) {
            return {
                width: elem.width(),
                height: elem.height(),
                offset: { top: elem.scrollTop(), left: elem.scrollLeft() }
            };
        }
        if (raw.preventDefault) {
            return {
                width: 0,
                height: 0,
                offset: { top: raw.pageY, left: raw.pageX }
            };
        }
        return {
            width: elem.outerWidth(),
            height: elem.outerHeight(),
            offset: elem.offset()
        };
    }

    $.position = {
        scrollbarWidth: function () {
            if (cachedScrollbarWidth !== undefined) {
                return cachedScrollbarWidth;
            }
            var w1, w2,
                div = $("<div style='display:block;position:absolute;width:50px;height:50px;overflow:hidden;'><div style='height:100px;width:auto;'></div></div>"),
                innerDiv = div.children()[0];

            $("body").append(div);
            w1 = innerDiv.offsetWidth;
            div.css("overflow", "scroll");

            w2 = innerDiv.offsetWidth;

            if (w1 === w2) {
                w2 = div[0].clientWidth;
            }

            div.remove();

            return (cachedScrollbarWidth = w1 - w2);
        },
        getScrollInfo: function (within) {
            var overflowX = within.isWindow || within.isDocument ? "" :
                    within.element.css("overflow-x"),
                overflowY = within.isWindow || within.isDocument ? "" :
                    within.element.css("overflow-y"),
                hasOverflowX = overflowX === "scroll" ||
                    (overflowX === "auto" && within.width < within.element[0].scrollWidth),
                hasOverflowY = overflowY === "scroll" ||
                    (overflowY === "auto" && within.height < within.element[0].scrollHeight);
            return {
                width: hasOverflowY ? $.position.scrollbarWidth() : 0,
                height: hasOverflowX ? $.position.scrollbarWidth() : 0
            };
        },
        getWithinInfo: function (element) {
            var withinElement = $(element || window),
                isWindow = $.isWindow(withinElement[0]),
                isDocument = !!withinElement[0] && withinElement[0].nodeType === 9;
            return {
                element: withinElement,
                isWindow: isWindow,
                isDocument: isDocument,
                offset: withinElement.offset() || { left: 0, top: 0 },
                scrollLeft: withinElement.scrollLeft(),
                scrollTop: withinElement.scrollTop(),
                width: isWindow ? withinElement.width() : withinElement.outerWidth(),
                height: isWindow ? withinElement.height() : withinElement.outerHeight()
            };
        }
    };

    $.fn.position = function (options) {
        if (!options || !options.of) {
            return _position.apply(this, arguments);
        }

        // make a copy, we don't want to modify arguments
        options = $.extend({}, options);

        var atOffset, targetWidth, targetHeight, targetOffset, basePosition, dimensions,
            target = $(options.of),
            within = $.position.getWithinInfo(options.within),
            scrollInfo = $.position.getScrollInfo(within),
            collision = (options.collision || "flip").split(" "),
            offsets = {};

        dimensions = getDimensions(target);
        if (target[0].preventDefault) {
            // force left top to allow flipping
            options.at = "left top";
        }
        targetWidth = dimensions.width;
        targetHeight = dimensions.height;
        targetOffset = dimensions.offset;
        // clone to reuse original targetOffset later
        basePosition = $.extend({}, targetOffset);

        // force my and at to have valid horizontal and vertical positions
        // if a value is missing or invalid, it will be converted to center
        $.each(["my", "at"], function () {
            var pos = (options[this] || "").split(" "),
                horizontalOffset,
                verticalOffset;

            if (pos.length === 1) {
                pos = rhorizontal.test(pos[0]) ?
                    pos.concat(["center"]) :
                    rvertical.test(pos[0]) ?
                        ["center"].concat(pos) :
                        ["center", "center"];
            }
            pos[0] = rhorizontal.test(pos[0]) ? pos[0] : "center";
            pos[1] = rvertical.test(pos[1]) ? pos[1] : "center";

            // calculate offsets
            horizontalOffset = roffset.exec(pos[0]);
            verticalOffset = roffset.exec(pos[1]);
            offsets[this] = [
                horizontalOffset ? horizontalOffset[0] : 0,
                verticalOffset ? verticalOffset[0] : 0
            ];

            // reduce to just the positions without the offsets
            options[this] = [
                rposition.exec(pos[0])[0],
                rposition.exec(pos[1])[0]
            ];
        });

        // normalize collision option
        if (collision.length === 1) {
            collision[1] = collision[0];
        }

        if (options.at[0] === "right") {
            basePosition.left += targetWidth;
        } else if (options.at[0] === "center") {
            basePosition.left += targetWidth / 2;
        }

        if (options.at[1] === "bottom") {
            basePosition.top += targetHeight;
        } else if (options.at[1] === "center") {
            basePosition.top += targetHeight / 2;
        }

        atOffset = getOffsets(offsets.at, targetWidth, targetHeight);
        basePosition.left += atOffset[0];
        basePosition.top += atOffset[1];

        return this.each(function () {
            var collisionPosition, using,
                elem = $(this),
                elemWidth = elem.outerWidth(),
                elemHeight = elem.outerHeight(),
                marginLeft = parseCss(this, "marginLeft"),
                marginTop = parseCss(this, "marginTop"),
                collisionWidth = elemWidth + marginLeft + parseCss(this, "marginRight") + scrollInfo.width,
                collisionHeight = elemHeight + marginTop + parseCss(this, "marginBottom") + scrollInfo.height,
                position = $.extend({}, basePosition),
                myOffset = getOffsets(offsets.my, elem.outerWidth(), elem.outerHeight());

            if (options.my[0] === "right") {
                position.left -= elemWidth;
            } else if (options.my[0] === "center") {
                position.left -= elemWidth / 2;
            }

            if (options.my[1] === "bottom") {
                position.top -= elemHeight;
            } else if (options.my[1] === "center") {
                position.top -= elemHeight / 2;
            }

            position.left += myOffset[0];
            position.top += myOffset[1];

            // if the browser doesn't support fractions, then round for consistent results
            if (!$.support.offsetFractions) {
                position.left = round(position.left);
                position.top = round(position.top);
            }

            collisionPosition = {
                marginLeft: marginLeft,
                marginTop: marginTop
            };

            $.each(["left", "top"], function (i, dir) {
                if ($.ui.position[collision[i]]) {
                    $.ui.position[collision[i]][dir](position, {
                        targetWidth: targetWidth,
                        targetHeight: targetHeight,
                        elemWidth: elemWidth,
                        elemHeight: elemHeight,
                        collisionPosition: collisionPosition,
                        collisionWidth: collisionWidth,
                        collisionHeight: collisionHeight,
                        offset: [atOffset[0] + myOffset[0], atOffset[1] + myOffset[1]],
                        my: options.my,
                        at: options.at,
                        within: within,
                        elem: elem
                    });
                }
            });

            if (options.using) {
                // adds feedback as second argument to using callback, if present
                using = function (props) {
                    var left = targetOffset.left - position.left,
                        right = left + targetWidth - elemWidth,
                        top = targetOffset.top - position.top,
                        bottom = top + targetHeight - elemHeight,
                        feedback = {
                            target: {
                                element: target,
                                left: targetOffset.left,
                                top: targetOffset.top,
                                width: targetWidth,
                                height: targetHeight
                            },
                            element: {
                                element: elem,
                                left: position.left,
                                top: position.top,
                                width: elemWidth,
                                height: elemHeight
                            },
                            horizontal: right < 0 ? "left" : left > 0 ? "right" : "center",
                            vertical: bottom < 0 ? "top" : top > 0 ? "bottom" : "middle"
                        };
                    if (targetWidth < elemWidth && abs(left + right) < targetWidth) {
                        feedback.horizontal = "center";
                    }
                    if (targetHeight < elemHeight && abs(top + bottom) < targetHeight) {
                        feedback.vertical = "middle";
                    }
                    if (max(abs(left), abs(right)) > max(abs(top), abs(bottom))) {
                        feedback.important = "horizontal";
                    } else {
                        feedback.important = "vertical";
                    }
                    options.using.call(this, props, feedback);
                };
            }

            elem.offset($.extend(position, { using: using }));
        });
    };

    $.ui.position = {
        fit: {
            left: function (position, data) {
                var within = data.within,
                    withinOffset = within.isWindow ? within.scrollLeft : within.offset.left,
                    outerWidth = within.width,
                    collisionPosLeft = position.left - data.collisionPosition.marginLeft,
                    overLeft = withinOffset - collisionPosLeft,
                    overRight = collisionPosLeft + data.collisionWidth - outerWidth - withinOffset,
                    newOverRight;

                // element is wider than within
                if (data.collisionWidth > outerWidth) {
                    // element is initially over the left side of within
                    if (overLeft > 0 && overRight <= 0) {
                        newOverRight = position.left + overLeft + data.collisionWidth - outerWidth - withinOffset;
                        position.left += overLeft - newOverRight;
                        // element is initially over right side of within
                    } else if (overRight > 0 && overLeft <= 0) {
                        position.left = withinOffset;
                        // element is initially over both left and right sides of within
                    } else {
                        if (overLeft > overRight) {
                            position.left = withinOffset + outerWidth - data.collisionWidth;
                        } else {
                            position.left = withinOffset;
                        }
                    }
                    // too far left -> align with left edge
                } else if (overLeft > 0) {
                    position.left += overLeft;
                    // too far right -> align with right edge
                } else if (overRight > 0) {
                    position.left -= overRight;
                    // adjust based on position and margin
                } else {
                    position.left = max(position.left - collisionPosLeft, position.left);
                }
            },
            top: function (position, data) {
                var within = data.within,
                    withinOffset = within.isWindow ? within.scrollTop : within.offset.top,
                    outerHeight = data.within.height,
                    collisionPosTop = position.top - data.collisionPosition.marginTop,
                    overTop = withinOffset - collisionPosTop,
                    overBottom = collisionPosTop + data.collisionHeight - outerHeight - withinOffset,
                    newOverBottom;

                // element is taller than within
                if (data.collisionHeight > outerHeight) {
                    // element is initially over the top of within
                    if (overTop > 0 && overBottom <= 0) {
                        newOverBottom = position.top + overTop + data.collisionHeight - outerHeight - withinOffset;
                        position.top += overTop - newOverBottom;
                        // element is initially over bottom of within
                    } else if (overBottom > 0 && overTop <= 0) {
                        position.top = withinOffset;
                        // element is initially over both top and bottom of within
                    } else {
                        if (overTop > overBottom) {
                            position.top = withinOffset + outerHeight - data.collisionHeight;
                        } else {
                            position.top = withinOffset;
                        }
                    }
                    // too far up -> align with top
                } else if (overTop > 0) {
                    position.top += overTop;
                    // too far down -> align with bottom edge
                } else if (overBottom > 0) {
                    position.top -= overBottom;
                    // adjust based on position and margin
                } else {
                    position.top = max(position.top - collisionPosTop, position.top);
                }
            }
        },
        flip: {
            left: function (position, data) {
                var within = data.within,
                    withinOffset = within.offset.left + within.scrollLeft,
                    outerWidth = within.width,
                    offsetLeft = within.isWindow ? within.scrollLeft : within.offset.left,
                    collisionPosLeft = position.left - data.collisionPosition.marginLeft,
                    overLeft = collisionPosLeft - offsetLeft,
                    overRight = collisionPosLeft + data.collisionWidth - outerWidth - offsetLeft,
                    myOffset = data.my[0] === "left" ?
                        -data.elemWidth :
                        data.my[0] === "right" ?
                            data.elemWidth :
                            0,
                    atOffset = data.at[0] === "left" ?
                        data.targetWidth :
                        data.at[0] === "right" ?
                            -data.targetWidth :
                            0,
                    offset = -2 * data.offset[0],
                    newOverRight,
                    newOverLeft;

                if (overLeft < 0) {
                    newOverRight = position.left + myOffset + atOffset + offset + data.collisionWidth - outerWidth - withinOffset;
                    if (newOverRight < 0 || newOverRight < abs(overLeft)) {
                        position.left += myOffset + atOffset + offset;
                    }
                }
                else if (overRight > 0) {
                    newOverLeft = position.left - data.collisionPosition.marginLeft + myOffset + atOffset + offset - offsetLeft;
                    if (newOverLeft > 0 || abs(newOverLeft) < overRight) {
                        position.left += myOffset + atOffset + offset;
                    }
                }
            },
            top: function (position, data) {
                var within = data.within,
                    withinOffset = within.offset.top + within.scrollTop,
                    outerHeight = within.height,
                    offsetTop = within.isWindow ? within.scrollTop : within.offset.top,
                    collisionPosTop = position.top - data.collisionPosition.marginTop,
                    overTop = collisionPosTop - offsetTop,
                    overBottom = collisionPosTop + data.collisionHeight - outerHeight - offsetTop,
                    top = data.my[1] === "top",
                    myOffset = top ?
                        -data.elemHeight :
                        data.my[1] === "bottom" ?
                            data.elemHeight :
                            0,
                    atOffset = data.at[1] === "top" ?
                        data.targetHeight :
                        data.at[1] === "bottom" ?
                            -data.targetHeight :
                            0,
                    offset = -2 * data.offset[1],
                    newOverTop,
                    newOverBottom;
                if (overTop < 0) {
                    newOverBottom = position.top + myOffset + atOffset + offset + data.collisionHeight - outerHeight - withinOffset;
                    if ((position.top + myOffset + atOffset + offset) > overTop && (newOverBottom < 0 || newOverBottom < abs(overTop))) {
                        position.top += myOffset + atOffset + offset;
                    }
                }
                else if (overBottom > 0) {
                    newOverTop = position.top - data.collisionPosition.marginTop + myOffset + atOffset + offset - offsetTop;
                    if ((position.top + myOffset + atOffset + offset) > overBottom && (newOverTop > 0 || abs(newOverTop) < overBottom)) {
                        position.top += myOffset + atOffset + offset;
                    }
                }
            }
        },
        flipfit: {
            left: function () {
                $.ui.position.flip.left.apply(this, arguments);
                $.ui.position.fit.left.apply(this, arguments);
            },
            top: function () {
                $.ui.position.flip.top.apply(this, arguments);
                $.ui.position.fit.top.apply(this, arguments);
            }
        }
    };

    // fraction support test
    (function () {
        var testElement, testElementParent, testElementStyle, offsetLeft, i,
            body = document.getElementsByTagName("body")[0],
            div = document.createElement("div");

        //Create a "fake body" for testing based on method used in jQuery.support
        testElement = document.createElement(body ? "div" : "body");
        testElementStyle = {
            visibility: "hidden",
            width: 0,
            height: 0,
            border: 0,
            margin: 0,
            background: "none"
        };
        if (body) {
            $.extend(testElementStyle, {
                position: "absolute",
                left: "-1000px",
                top: "-1000px"
            });
        }
        for (i in testElementStyle) {
            testElement.style[i] = testElementStyle[i];
        }
        testElement.appendChild(div);
        testElementParent = body || document.documentElement;
        testElementParent.insertBefore(testElement, testElementParent.firstChild);

        div.style.cssText = "position: absolute; left: 10.7432222px;";

        offsetLeft = $(div).offset().left;
        $.support.offsetFractions = offsetLeft > 10 && offsetLeft < 11;

        testElement.innerHTML = "";
        testElementParent.removeChild(testElement);
    })();

}(jQuery));

; (function (global, undefined) {

    var slice = [].slice,
        subscriptions = {};

    var amplify = global.amplify = {
        publish: function (topic) {
            if (typeof topic !== "string") {
                throw new Error("You must provide a valid topic to publish.");
            }

            var args = slice.call(arguments, 1),
                topicSubscriptions,
                subscription,
                length,
                i = 0,
                ret;

            if (!subscriptions[topic]) {
                return true;
            }

            topicSubscriptions = subscriptions[topic].slice();
            for (length = topicSubscriptions.length; i < length; i++) {
                subscription = topicSubscriptions[i];
                ret = subscription.callback.apply(subscription.context, args);
                if (ret === false) {
                    break;
                }
            }
            return ret !== false;
        },

        subscribe: function (topic, context, callback, priority) {
            if (typeof topic !== "string") {
                throw new Error("You must provide a valid topic to create a subscription.");
            }

            if (arguments.length === 3 && typeof callback === "number") {
                priority = callback;
                callback = context;
                context = null;
            }
            if (arguments.length === 2) {
                callback = context;
                context = null;
            }
            priority = priority || 10;

            var topicIndex = 0,
                topics = topic.split(/\s/),
                topicLength = topics.length,
                added;
            for (; topicIndex < topicLength; topicIndex++) {
                topic = topics[topicIndex];
                added = false;
                if (!subscriptions[topic]) {
                    subscriptions[topic] = [];
                }

                var i = subscriptions[topic].length - 1,
                    subscriptionInfo = {
                        callback: callback,
                        context: context,
                        priority: priority
                    };

                for (; i >= 0; i--) {
                    if (subscriptions[topic][i].priority <= priority) {
                        subscriptions[topic].splice(i + 1, 0, subscriptionInfo);
                        added = true;
                        break;
                    }
                }

                if (!added) {
                    subscriptions[topic].unshift(subscriptionInfo);
                }
            }

            return callback;
        },

        unsubscribe: function (topic, context, callback) {
            if (typeof topic !== "string") {
                throw new Error("You must provide a valid topic to remove a subscription.");
            }

            if (arguments.length === 2) {
                callback = context;
                context = null;
            }

            if (!subscriptions[topic]) {
                return;
            }

            var length = subscriptions[topic].length,
                i = 0;

            for (; i < length; i++) {
                if (subscriptions[topic][i].callback === callback) {
                    if (!context || subscriptions[topic][i].context === context) {
                        subscriptions[topic].splice(i, 1);

                        // Adjust counter and length for removed item
                        i--;
                        length--;
                    }
                }
            }
        }
    };

}(this));
;/*
 * Lazy Load - jQuery plugin for lazy loading images
 *
 * Copyright (c) 2007-2013 Mika Tuupola
 *
 * Licensed under the MIT license:
 *   http://www.opensource.org/licenses/mit-license.php
 *
 * Project home:
 *   http://www.appelsiini.net/projects/lazyload
 *
 * Version:  1.9.3
 *
 */

(function ($, window, document, undefined) {
    var $window = $(window);

    $.fn.lazyload = function (options) {
        var elements = this;
        var $container;
        var settings = {
            threshold: 0,
            failure_limit: 0,
            event: "scroll",
            effect: "show",
            container: window,
            data_attribute: "original",
            skip_invisible: true,
            appear: null,
            load: null,
            placeholder: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB/AAffA0nNPuCLAAAAAElFTkSuQmCC"
        };

        function update() {
            var counter = 0;

            elements.each(function () {
                var $this = $(this);
                if (settings.skip_invisible && !$this.is(":visible")) {
                    return;
                }
                if ($.abovethetop(this, settings) ||
                    $.leftofbegin(this, settings)) {
                    /* Nothing. */
                } else if (!$.belowthefold(this, settings) &&
                    !$.rightoffold(this, settings)) {
                    $this.trigger("appear");
                    /* if we found an image we'll load, reset the counter */
                    counter = 0;
                } else {
                    if (++counter > settings.failure_limit) {
                        return false;
                    }
                }
            });

        }

        if (options) {
            /* Maintain BC for a couple of versions. */
            if (undefined !== options.failurelimit) {
                options.failure_limit = options.failurelimit;
                delete options.failurelimit;
            }
            if (undefined !== options.effectspeed) {
                options.effect_speed = options.effectspeed;
                delete options.effectspeed;
            }

            $.extend(settings, options);
        }

        /* Cache container as jQuery as object. */
        $container = (settings.container === undefined ||
                      settings.container === window) ? $window : $(settings.container);

        /* Fire one scroll event per scroll. Not one scroll event per image. */
        if (0 === settings.event.indexOf("scroll")) {
            $container.bind(settings.event, function () {
                return update();
            });
        }

        this.each(function () {
            var self = this;
            var $self = $(self);

            self.loaded = false;

            /* If no src attribute given use data:uri. */
            if ($self.attr("src") === undefined || $self.attr("src") === false) {
                if ($self.is("img")) {
                    $self.attr("src", settings.placeholder);
                }
            }

            /* When appear is triggered load original image. */
            $self.one("appear", function () {
                if (!this.loaded) {
                    if (settings.appear) {
                        var elements_left = elements.length;
                        settings.appear.call(self, elements_left, settings);
                    }
                    $("<img />")
                        .bind("load", function () {

                            var original = $self.attr("data-" + settings.data_attribute);
                            $self.hide();
                            if ($self.is("img")) {
                                $self.attr("src", original);
                            } else {
                                $self.css("background-image", "url('" + original + "')");
                            }
                            $self[settings.effect](settings.effect_speed);

                            self.loaded = true;

                            /* Remove image from array so it is not looped next time. */
                            var temp = $.grep(elements, function (element) {
                                return !element.loaded;
                            });
                            elements = $(temp);

                            if (settings.load) {
                                var elements_left = elements.length;
                                settings.load.call(self, elements_left, settings);
                            }
                        })
                        .attr("src", $self.attr("data-" + settings.data_attribute));
                }
            });

            /* When wanted event is triggered load original image */
            /* by triggering appear.                              */
            if (0 !== settings.event.indexOf("scroll")) {
                $self.bind(settings.event, function () {
                    if (!self.loaded) {
                        $self.trigger("appear");
                    }
                });
            }
        });

        /* Check if something appears when window is resized. */
        $window.bind("resize", function () {
            update();
        });

        /* With IOS5 force loading images when navigating with back button. */
        /* Non optimal workaround. */
        if ((/(?:iphone|ipod|ipad).*os 5/gi).test(navigator.appVersion)) {
            $window.bind("pageshow", function (event) {
                if (event.originalEvent && event.originalEvent.persisted) {
                    elements.each(function () {
                        $(this).trigger("appear");
                    });
                }
            });
        }

        /* Force initial check if images should appear. */
        $(document).ready(function () {
            update();
        });

        return this;
    };

    /* Convenience methods in jQuery namespace.           */
    /* Use as  $.belowthefold(element, {threshold : 100, container : window}) */

    $.belowthefold = function (element, settings) {
        var fold;

        if (settings.container === undefined || settings.container === window) {
            fold = (window.innerHeight ? window.innerHeight : $window.height()) + $window.scrollTop();
        } else {
            fold = $(settings.container).offset().top + $(settings.container).height();
        }

        return fold <= $(element).offset().top - settings.threshold;
    };

    $.rightoffold = function (element, settings) {
        var fold;

        if (settings.container === undefined || settings.container === window) {
            fold = $window.width() + $window.scrollLeft();
        } else {
            fold = $(settings.container).offset().left + $(settings.container).width();
        }

        return fold <= $(element).offset().left - settings.threshold;
    };

    $.abovethetop = function (element, settings) {
        var fold;

        if (settings.container === undefined || settings.container === window) {
            fold = $window.scrollTop();
        } else {
            fold = $(settings.container).offset().top;
        }

        return fold >= $(element).offset().top + settings.threshold + $(element).height();
    };

    $.leftofbegin = function (element, settings) {
        var fold;

        if (settings.container === undefined || settings.container === window) {
            fold = $window.scrollLeft();
        } else {
            fold = $(settings.container).offset().left;
        }

        return fold >= $(element).offset().left + settings.threshold + $(element).width();
    };

    $.inviewport = function (element, settings) {
        return !$.rightoffold(element, settings) && !$.leftofbegin(element, settings) &&
               !$.belowthefold(element, settings) && !$.abovethetop(element, settings);
    };

    /* Custom selectors for your convenience.   */
    /* Use as $("img:below-the-fold").something() or */
    /* $("img").filter(":below-the-fold").something() which is faster */

    $.extend($.expr[":"], {
        "below-the-fold": function (a) { return $.belowthefold(a, { threshold: 0 }); },
        "above-the-top": function (a) { return !$.belowthefold(a, { threshold: 0 }); },
        "right-of-screen": function (a) { return $.rightoffold(a, { threshold: 0 }); },
        "left-of-screen": function (a) { return !$.rightoffold(a, { threshold: 0 }); },
        "in-viewport": function (a) { return $.inviewport(a, { threshold: 0 }); },
        /* Maintain BC for couple of versions. */
        "above-the-fold": function (a) { return !$.belowthefold(a, { threshold: 0 }); },
        "right-of-fold": function (a) { return $.rightoffold(a, { threshold: 0 }); },
        "left-of-fold": function (a) { return !$.rightoffold(a, { threshold: 0 }); }
    });

})(jQuery, window, document);

