
/*!
 * jQuery Smart Banner
 * Copyright (c) 2012 Arnold Daniels <arnold@jasny.net>
 * Based on 'jQuery Smart Web App Banner' by Kurt Zenisek @ kzeni.com
 */
(function(root, factory) {
  if (typeof define == 'function' && define.amd) {
    define(['jquery'], factory);
  } else {
    factory(root.jQuery);
  }
})(this, function($) {
  var UA = navigator.userAgent;
  var isEdge = /Edge/i.test(UA);

  var SmartBanner = function(options) {
    // Get the original margin-top of the HTML element so we can take that into account.
    this.origHtmlMargin = parseFloat($('html').css('margin-top'));
    this.options = $.extend({}, $.smartbanner.defaults, options);

    // Check if it's already a standalone web app or running within a webui view of an app (not mobile safari).
    var standalone = navigator.standalone;

    // Detect banner type (iOS or Android).
    if (this.options.force) {
      this.type = this.options.force;
    }
    else if (UA.match(/Windows Phone/i) !== null && UA.match(/Edge|Touch/i) !== null) {
      this.type = 'windows';
    }
    else if (UA.match(/iPhone|iPod/i) !== null || (UA.match(/iPad/) && this.options.iOSUniversalApp)) {
      if (UA.match(/Safari/i) !== null &&
          (UA.match(/CriOS/i) !== null ||
           UA.match(/FxiOS/i) != null ||
            window.Number(UA.substr(UA.indexOf('OS ') + 3, 3).replace('_', '.')) < 6)) {
        // Check webview and native smart banner support (iOS 6+).
        this.type = 'ios';
      }
    }
    else if (UA.match(/\bSilk\/(.*\bMobile Safari\b)?/) || UA.match(/\bKF\w/) || UA.match('Kindle Fire')) {
      this.type = 'kindle';
    }
    else if (UA.match(/Android/i) !== null) {
      this.type = 'android';
    }
    // Don't show banner if device isn't iOS or Android, website is loaded in app or user dismissed banner.
    if (!this.type || standalone || this.getCookie('sb-closed') || this.getCookie('sb-installed')) {
      return;
    }
    // Calculate scale.
    this.scale = this.options.scale == 'auto' ? $(window).width() / window.screen.width : this.options.scale;
    if (this.scale < 1) {
      this.scale = 1;
    }
    // Get info from meta data.
    var meta = $(
      this.type == 'android'
        ? 'meta[name="google-play-app"]'
        : (this.type == 'ios'
            ? 'meta[name="apple-itunes-app"]'
            : (this.type == 'kindle'
                ? 'meta[name="kindle-fire-app"]'
                : 'meta[name="msApplication-ID"]'
              )
          )
    );

    if (!meta.length) {
      return;
    }
    // For Windows Store apps, get the PackageFamilyName for protocol launch.
    if (this.type == 'windows') {
      if (isEdge) {
        this.appId = $('meta[name="msApplication-PackageEdgeName"]').attr('content');
      }
      if (!this.appId) {
        this.appId = $('meta[name="msApplication-PackageFamilyName"]').attr('content');
      }
    }
    else {
      // Try to pull the appId out of the meta tag and store the result.
      var parsedMetaContent = /app-id=([^\s,]+)/.exec(meta.attr('content'));
      if (parsedMetaContent) {
        this.appId = parsedMetaContent[1];
      } else {
        return;
      }
    }
    this.title = this.options.title
      ? this.options.title
      : (meta.data('title') || $('title').text().replace(/\s*[|\-·].*$/, ''));

    this.author = this.options.author
      ? this.options.author
      : (meta.data('author') || ($('meta[name="author"]').length ? $('meta[name="author"]').attr('content') : window.location.hostname));

    this.iconUrl = meta.data('icon-url');
    this.price = meta.data('price');

    // Set default onInstall callback if not set in options.
    if (typeof this.options.onInstall == 'function') {
      this.options.onInstall = this.options.onInstall;
    } else {
      this.options.onInstall = function() {};
    }
    // Set default onClose callback if not set in options.
    if (typeof this.options.onClose == 'function') {
      this.options.onClose = this.options.onClose;
    } else {
      this.options.onClose = function() {};
    }
    // Create banner.
    this.create();
    this.show();
    this.listen();
  };

  SmartBanner.prototype = {

    constructor: SmartBanner,

    create: function() {
      var iconURL;
      var price = this.price || this.options.price;

      var link = this.options.url || (function() {
        switch (this.type) {
          case 'android':
            return 'market://details?id=';
          case 'kindle':
            return 'amzn://apps/android?asin=';
          case 'windows':
            return isEdge
              ? 'ms-windows-store://pdp/?productid='
              : 'ms-windows-store:navigate?appid=';
        }
        return 'https://itunes.apple.com/' + this.options.appStoreLanguage + '/app/id';
      }.call(this) + this.appId);

      var inStore = !price ? '' : (function() {
        var result = price + ' - ';
        switch (this.type) {
          case 'android':
            return result + this.options.inGooglePlay;
          case 'kindle':
            return result + this.options.inAmazonAppStore;
          case 'windows':
            return result + this.options.inWindowsStore;
        }
        return result + this.options.inAppStore
      }.call(this));

      var gloss = this.options.iconGloss == null
        ? (this.type=='ios')
        : this.options.iconGloss;

      if (this.type == 'android' && this.options.GooglePlayParams) {
        link += '&referrer=' + this.options.GooglePlayParams;
      }
      var banner = (
        '<div id="smartbanner" class="' + this.type + '">' +
          '<div class="sb-container">' +
            '<a href="#" class="sb-close">&times;</a>' +
            '<span class="sb-icon"></span>' +
            '<div class="sb-info">' +
              '<strong>' + this.title + '</strong>' +
              '<span>' + this.author + '</span>' +
              '<span>' + inStore + '</span>' +
            '</div>' +
            '<a href="' + link + '" class="sb-button">' +
              '<span>' + this.options.button + '</span>' +
            '</a>' +
          '</div>' +
        '</div>'
      );
      if (this.options.layer) {
        $(this.options.appendToSelector).append(banner);
      } else {
        $(this.options.appendToSelector).prepend(banner);
      }
      if (this.options.icon) {
        iconURL = this.options.icon;
      } else if(this.iconUrl) {
        iconURL = this.iconUrl;
      } else if ($('link[rel="apple-touch-icon-precomposed"]').length > 0) {
        iconURL = $('link[rel="apple-touch-icon-precomposed"]').attr('href');
        if (this.options.iconGloss == null) {
          gloss = false;
        }
      } else if ($('link[rel="apple-touch-icon"]').length > 0) {
        iconURL = $('link[rel="apple-touch-icon"]').attr('href');
      } else if ($('meta[name="msApplication-TileImage"]').length > 0) {
        iconURL = $('meta[name="msApplication-TileImage"]').attr('content');
      } else if ($('meta[name="msapplication-TileImage"]').length > 0) {
        // Redundant because ms docs show two case usages.
        iconURL = $('meta[name="msapplication-TileImage"]').attr('content');
      }
      if (iconURL) {
        $('#smartbanner .sb-icon').css('background-image', 'url(' + iconURL + ')');
        if (gloss) {
          $('#smartbanner .sb-icon').addClass('gloss');
        }
      } else{
        $('#smartbanner').addClass('no-icon');
      }
      this.bannerHeight = $('#smartbanner').outerHeight() + 2;

      if (this.scale > 1) {
        $('#smartbanner')
          .css('top', parseFloat($('#smartbanner').css('top')) * this.scale)
          .css('height', parseFloat($('#smartbanner').css('height')) * this.scale)
          .hide();
        $('#smartbanner .sb-container')
          .css('-webkit-transform', 'scale(' + this.scale + ')')
          .css('-msie-transform', 'scale(' + this.scale + ')')
          .css('-moz-transform', 'scale(' + this.scale + ')')
          .css('width', $(window).width() / this.scale);
      }
      $('#smartbanner')
        .css('position', this.options.layer ? 'absolute' : 'static');
    },

    listen: function() {
      $('#smartbanner .sb-close').on('click', $.proxy(this.close, this));
      $('#smartbanner .sb-button').on('click', $.proxy(this.install, this));
    },

    show: function(callback) {
      var banner = $('#smartbanner');
      banner.stop();

      if (this.options.layer) {
        banner
          .animate({ top: 0, display: 'block' }, this.options.speedIn)
          .addClass('shown')
          .show();
        $(this.pushSelector)
          .animate({
            paddingTop: this.origHtmlMargin + (this.bannerHeight * this.scale)
          }, this.options.speedIn, 'swing', callback);
      }
      else {
        if ($.support.transition) {
          banner.animate({ top: 0 }, this.options.speedIn).addClass('shown');
          var transitionCallback = function() {
            $('html').removeClass('sb-animation');
            if (callback) {
              callback();
            }
          };
          $(this.pushSelector)
            .addClass('sb-animation')
            .one($.support.transition.end, transitionCallback)
            .emulateTransitionEnd(this.options.speedIn)
            .css('margin-top', this.origHtmlMargin + (this.bannerHeight * this.scale));
        }
        else {
          banner
            .slideDown(this.options.speedIn)
            .addClass('shown');
        }
      }
    },

    hide: function(callback) {
      var banner = $('#smartbanner');
      banner.stop();

      if (this.options.layer) {
        banner.animate({
          top: -1 * this.bannerHeight * this.scale,
          display: 'block'
        }, this.options.speedIn)
        .removeClass('shown');

        $(this.pushSelector)
          .animate({
            paddingTop: this.origHtmlMargin
          }, this.options.speedIn, 'swing', callback);
      }
      else {
        if ($.support.transition) {
          if (this.type !== 'android') {
            banner
              .css('top', -1 * this.bannerHeight * this.scale)
              .removeClass('shown');
          }
          else {
            banner
              .css({display:'none'})
              .removeClass('shown');
          }
          var transitionCallback = function() {
            $('html').removeClass('sb-animation');
            if (callback) {
              callback();
            }
          };
          $(this.pushSelector)
            .addClass('sb-animation')
            .one($.support.transition.end, transitionCallback)
            .emulateTransitionEnd(this.options.speedOut)
            .css('margin-top', this.origHtmlMargin);
        }
        else {
          banner.slideUp(this.options.speedOut).removeClass('shown');
        }
      }
    },

    close: function(e) {
      e.preventDefault();
      this.hide();
      this.setCookie('sb-closed', 'true', this.options.daysHidden);
      this.options.onClose(e);
    },

    install: function(e) {
      if (this.options.hideOnInstall) {
        this.hide();
      }
      this.setCookie('sb-installed', 'true', this.options.daysReminder);
      this.options.onInstall(e);
    },

    setCookie: function(name, value, exdays) {
      var exdate = new Date();
      exdate.setDate(exdate.getDate() + exdays);
      value = encodeURI(value) + ((exdays == null) ? '' : '; expires=' + exdate.toUTCString());
      document.cookie = name + '=' + value + '; path=/;';
    },

    getCookie: function(name) {
      var i, x, y, ARRcookies = document.cookie.split(';');
      for (i = 0; i < ARRcookies.length; i++) {
        x = ARRcookies[i].substr(0, ARRcookies[i].indexOf('='));
        y = ARRcookies[i].substr(ARRcookies[i].indexOf('=') + 1);
        x = x.replace(/^\s+|\s+$/g, '');
        if (x == name) {
          return decodeURI(y);
        }
      }
      return null;
    },

    // Demo only.
    switchType: function() {
      var that = this;

      this.hide(function() {
        that.type = that.type == 'android' ? 'ios' : 'android';
        var meta = $(that.type == 'android' ? 'meta[name="google-play-app"]' : 'meta[name="apple-itunes-app"]').attr('content');
        that.appId = /app-id=([^\s,]+)/.exec(meta)[1];

        $('#smartbanner').detach();
        that.create();
        that.show();
      });
    }
  };

  $.smartbanner = function(option) {
    var $window = $(window);
    var data = $window.data('smartbanner');
    var options = typeof option == 'object' && option;
    if (!data) {
      $window.data('smartbanner', (data = new SmartBanner(options)));
    }
    if (typeof option == 'string') {
      data[option]();
    }
  };

  // override these globally if you like (they are all optional)
  $.smartbanner.defaults = {
    title: null, // What the title of the app should be in the banner (defaults to <title>)
    author: null, // What the author of the app should be in the banner (defaults to <meta name="author"> or hostname)
    price: 'FREE', // Price of the app
    appStoreLanguage: 'us', // Language code for App Store
    inAppStore: 'On the App Store', // Text of price for iOS
    inGooglePlay: 'In Google Play', // Text of price for Android
    inAmazonAppStore: 'In the Amazon Appstore',
    inWindowsStore: 'In the Windows Store', //Text of price for Windows
    GooglePlayParams: null, // Aditional parameters for the market
    icon: null, // The URL of the icon (defaults to <meta name="apple-touch-icon">)
    iconGloss: null, // Force gloss effect for iOS even for precomposed
    button: 'VIEW', // Text for the install button
    url: null, // The URL for the button. Keep null if you want the button to link to the app store.
    scale: 'auto', // Scale based on viewport size (set to 1 to disable)
    speedIn: 300, // Show animation speed of the banner
    speedOut: 400, // Close animation speed of the banner
    daysHidden: 15, // Duration to hide the banner after being closed (0 = always show banner)
    daysReminder: 90, // Duration to hide the banner after "VIEW" is clicked *separate from when the close button is clicked* (0 = always show banner)
    force: null, // Choose 'ios', 'android' or 'windows'. Don't do a browser check, just always show this banner
    hideOnInstall: true, // Hide the banner after "VIEW" is clicked.
    layer: false, // Display as overlay layer or slide down the page
    iOSUniversalApp: true, // If the iOS App is a universal app for both iPad and iPhone, display Smart Banner to iPad users, too.
    appendToSelector: 'body', //Append the banner to a specific selector
    pushSelector: 'html' // What element is going to push the site content down; this is where the banner append animation will start.
  };

  $.smartbanner.Constructor = SmartBanner;

  // ============================================================
  // Bootstrap transition
  // Copyright 2011-2014 Twitter, Inc.
  // Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)

  function transitionEnd () {
    var el = document.createElement('smartbanner');

    var transEndEventNames = {
      WebkitTransition: 'webkitTransitionEnd',
      MozTransition: 'transitionend',
      OTransition: 'oTransitionEnd otransitionend',
      transition: 'transitionend'
    };

    for (var name in transEndEventNames) {
      if (el.style[name] !== undefined) {
        return {end: transEndEventNames[name]};
      }
    }
    // Explicit for ie8.
    return false;
  }
  if ($.support.transition !== undefined) {
    // Prevent conflict with Twitter Bootstrap.
    return;
  }

  // http://blog.alexmaccaw.com/css-transitions
  $.fn.emulateTransitionEnd = function(duration) {
    var called = false, $el = this;
    $(this).one($.support.transition.end, function() {
      called = true;
    });
    var callback = function() {
      if (!called) {
        $($el).trigger($.support.transition.end);
      }
    };
    setTimeout(callback, duration);
    return this;
  };

  $(function() {
    $.support.transition = transitionEnd();
  });
  // ============================================================
});

jQuery.smartbanner({
	title: 'ABA Mobile App',
	author: 'The Bank is wherever you are',
	button: 'INSTALL',
	icon: 'https://www.ababank.com/typo3conf/ext/boxmodel/Configuration/TypoScript/custom/addon/smart_app_banner/logo/aba-bank.png'
});

/*! enscroll - v0.6.2 - 2016-03-24
 * Copyright (c) 2016 ; Licensed  */
! function(a, b, c, d) {
	var e = {
			verticalScrolling: !0,
			horizontalScrolling: !1,
			verticalScrollerSide: "right",
			showOnHover: !1,
			scrollIncrement: 20,
			minScrollbarLength: 40,
			pollChanges: !0,
			drawCorner: !0,
			drawScrollButtons: !1,
			clickTrackToScroll: !0,
			easingDuration: 500,
			propagateWheelEvent: !0,
			verticalTrackClass: "vertical-track",
			horizontalTrackClass: "horizontal-track",
			horizontalHandleClass: "horizontal-handle",
			verticalHandleClass: "vertical-handle",
			scrollUpButtonClass: "scroll-up-btn",
			scrollDownButtonClass: "scroll-down-btn",
			scrollLeftButtonClass: "scroll-left-btn",
			scrollRightButtonClass: "scroll-right-btn",
			cornerClass: "scrollbar-corner",
			zIndex: 1,
			addPaddingToPane: !0,
			horizontalHandleHTML: '<div class="left"></div><div class="right"></div>',
			verticalHandleHTML: '<div class="top"></div><div class="bottom"></div>'
		},
		f = function(a) {
			a.preventDefault ? a.preventDefault() : a.returnValue = !1, a.stopPropagation ? a.stopPropagation() : a.cancelBubble = !0
		},
		g = b.requestAnimationFrame || b.mozRequestAnimationFrame || b.webkitRequestAnimationFrame || b.oRequestAnimationFrame || b.msRequestAnimationFrame || function(a) {
				setTimeout(a, 17)
			},
		h = function(b, c) {
			var d = a(b).css(c),
				e = /^-?\d+/.exec(d);
			return e ? +e[0] : 0
		},
		i = function(a) {
			var b, c, d = {
					width: "5px",
					height: "1px",
					overflow: "hidden",
					padding: "8px 0",
					visibility: "hidden",
					whiteSpace: "pre-line",
					font: "10px/1 serif"
				},
				e = document.createElement(a),
				f = document.createTextNode("a\na");
			for (c in d) e.style[c] = d[c];
			return e.appendChild(f), document.body.appendChild(e), b = e.scrollHeight < 28, document.body.removeChild(e), b
		},
		j = .5 * Math.PI,
		k = 10 * Math.log(2),
		l = function(a, b, c) {
			var d = j / b,
				e = a * d;
			return Math.round(e * Math.cos(d * c))
		},
		m = function(a, b, c) {
			return Math.round(a * k * Math.pow(2, -10 * c / b + 1) / b)
		},
		n = function(a, b, c, d) {
			return 2 * c / Math.PI * Math.asin((d - a) / b)
		},
		o = function(b) {
			var c = a(this).data("enscroll"),
				d = this,
				e = c.settings,
				f = function() {
					var b = a(this).data("enscroll"),
						c = b.settings;
					b && c.showOnHover && (c.verticalScrolling && a(b.verticalTrackWrapper).is(":visible") && a(b.verticalTrackWrapper).stop().fadeTo(275, 0), c.horizontalScrolling && a(b.horizontalTrackWrapper).is(":visible") && a(b.horizontalTrackWrapper).stop().fadeTo(275, 0), b._fadeTimer = null)
				};
			c && e.showOnHover && (c._fadeTimer ? clearTimeout(c._fadeTimer) : (e.verticalScrolling && a(c.verticalTrackWrapper).is(":visible") && a(c.verticalTrackWrapper).stop().fadeTo(275, 1), e.horizontalScrolling && a(c.horizontalTrackWrapper).is(":visible") && a(c.horizontalTrackWrapper).stop().fadeTo(275, 1)), b !== !1 && (c._fadeTimer = setTimeout(function() {
				f.call(d)
			}, 1750)))
		},
		p = function(b, c) {
			var d = a(b),
				e = d.data("enscroll"),
				f = d.scrollTop();
			e && e.settings.verticalScrolling && (d.scrollTop(f + c), e.settings.showOnHover && o.call(b))
		},
		q = function(b, c) {
			var d = a(b),
				e = d.data("enscroll"),
				f = d.scrollLeft();
			e && e.settings.horizontalScrolling && (d.scrollLeft(f + c), e.settings.showOnHover && o.call(b))
		},
		r = function(b) {
			if (1 === b.which) {
				var d, e, f, h, i, j, k, l, m, n = b.data.pane,
					p = a(n),
					q = p.data("enscroll"),
					r = !0,
					s = function() {
						r && (f !== h && (q._scrollingY || (q._scrollingY = !0, q._startY = p.scrollTop(), g(function() {
							t(p)
						})), e.style.top = f + "px", q._endY = f * m / l, h = f), g(s), q.settings.showOnHover && o.call(n))
					},
					u = function(a) {
						return r && (f = a.clientY - j - i, f = Math.min(0 > f ? 0 : f, l)), !1
					},
					v = function() {
						return r = !1, c.body.style.cursor = k, this.style.cursor = "", d.removeClass("dragging"), a(c.body).off("mousemove.enscroll.vertical").off("mouseup.enscroll.vertical"), a(c).off("mouseout.enscroll.vertical"), p.on("scroll.enscroll.pane", function(a) {
							x.call(this, a)
						}), !1
					};
				return d = a(q.verticalTrackWrapper).find(".enscroll-track"), e = d.children().first()[0], f = parseInt(e.style.top, 10), m = n.scrollHeight - (q._scrollHeightNoPadding ? a(n).height() : a(n).innerHeight()), i = b.clientY - a(e).offset().top, l = d.height() - a(e).outerHeight(), j = d.offset().top, p.off("scroll.enscroll.pane"), a(c.body).on({
					"mousemove.enscroll.vertical": u,
					"mouseup.enscroll.vertical": function(a) {
						v.call(e, a)
					}
				}), a(c).on("mouseout.enscroll.vertical", function(a) {
					a.target.nodeName && "HTML" === a.target.nodeName.toUpperCase() && v.call(e, a)
				}), d.hasClass("dragging") || (d.addClass("dragging"), k = a(c.body).css("cursor"), this.style.cursor = c.body.style.cursor = "ns-resize"), g(s), !1
			}
		},
		s = function(b) {
			if (1 === b.which) {
				var d, e, f, h, i, j, k, l, m, n = b.data.pane,
					p = a(n),
					q = a(n).data("enscroll"),
					r = !0,
					s = function() {
						r && (f !== h && (q._scrollingX || (q._scrollingX = !0, q._startX = p.scrollLeft(), g(function() {
							t(p)
						})), e.style.left = f + "px", q._endX = f * i / m, h = f), g(s), q.settings.showOnHover && o.call(n))
					},
					u = function(a) {
						return r && (f = a.clientX - k - j, f = Math.min(0 > f ? 0 : f, m)), !1
					},
					v = function() {
						return r = !1, d.removeClass("dragging"), c.body.style.cursor = l, this.style.cursor = "", d.removeClass("dragging"), a(c.body).off("mousemove.enscroll.horizontal").off("mouseup.enscroll.horizontal"), a(c).off("mouseout.enscroll.horizontal"), p.on("scroll.enscroll.pane", function(a) {
							x.call(this, a)
						}), !1
					};
				return d = a(q.horizontalTrackWrapper).find(".enscroll-track"), e = d.children().first()[0], f = parseInt(e.style.left, 10), i = n.scrollWidth - a(n).innerWidth(), j = b.clientX - a(e).offset().left, m = d.width() - a(e).outerWidth(), k = d.offset().left, p.off("scroll.enscroll.pane"), a(c.body).on({
					"mousemove.enscroll.horizontal": u,
					"mouseup.enscroll.horizontal": function(a) {
						v.call(e, a)
					}
				}), a(c).on("mouseout.enscroll.horizontal", function(a) {
					a.target.nodeName && "HTML" === a.target.nodeName.toUpperCase() && v.call(e, a)
				}), d.hasClass("dragging") || (d.addClass("dragging"), l = a("body").css("cursor"), this.style.cursor = c.body.style.cursor = "ew-resize"), g(s), !1
			}
		},
		t = function(a) {
			var b, c, d, e = a.data("enscroll"),
				f = e._duration;
			e._scrollingX === !0 && (b = e._endX - e._startX, 0 === b ? e._scrollingX = !1 : (c = a.scrollLeft(), d = n(e._startX, b, f, c), b > 0 ? c >= e._endX || c < e._startX ? e._scrollingX = !1 : (q(a, Math.max(1, l(b, f, d))), g(function() {
				t(a)
			})) : c <= e._endX || c > e._startX ? e._scrollingX = !1 : (q(a, Math.min(-1, l(b, f, d))), g(function() {
				t(a)
			})))), e._scrollingY === !0 && (b = e._endY - e._startY, 0 === b ? e._scrollingY = !1 : (c = a.scrollTop(), d = n(e._startY, b, f, c), b > 0 ? c >= e._endY || c < e._startY ? e._scrollingY = !1 : (p(a, Math.max(1, l(b, f, d))), g(function() {
				t(a)
			})) : c <= e._endY || c > e._startY ? e._scrollingY = !1 : (p(a, Math.min(-1, l(b, f, d))), g(function() {
				t(a)
			}))))
		},
		u = function(a, b) {
			var c = a.data("enscroll"),
				d = a.scrollLeft(),
				e = a[0].scrollWidth - a.innerWidth();
			return !c.settings.horizontalScrolling || c._scrollingY ? !1 : (c._scrollingX || (c._scrollingX = !0, c._startX = d, c._endX = c._startX, g(function() {
				t(a)
			})), c._endX = b > 0 ? Math.min(d + b, e) : Math.max(0, d + b), 0 > b && d > 0 || b > 0 && e > d)
		},
		v = function(a, b) {
			var c = a.data("enscroll"),
				d = a.scrollTop(),
				e = a[0].scrollHeight - (c._scrollHeightNoPadding ? a.height() : a.innerHeight());
			return !c.settings.verticalScrolling || c._scrollingX ? !1 : (c._scrollingY || (c._scrollingY = !0, c._startY = d, c._endY = c._startY, g(function() {
				t(a)
			})), c._endY = b > 0 ? Math.min(d + b, e) : Math.max(0, d + b), 0 > b && d > 0 || b > 0 && e > d)
		},
		w = function(b) {
			var c, d = a(this),
				e = d.data("enscroll"),
				g = e.settings.scrollIncrement,
				h = "deltaX" in b ? -b.deltaX : "wheelDeltaX" in b ? b.wheelDeltaX : 0,
				i = "deltaY" in b ? -b.deltaY : "wheelDeltaY" in b ? b.wheelDeltaY : "wheelDelta" in b ? b.wheelDelta : 0;
			Math.abs(h) > Math.abs(i) && 0 !== h ? (c = (h > 0 ? -g : g) << 2, (u(d, c) || !e.settings.propagateWheelEvent) && f(b)) : 0 !== i && (c = (i > 0 ? -g : g) << 2, (v(d, c) || !e.settings.propagateWheelEvent) && f(b))
		},
		x = function() {
			var b, c, d, e = a(this),
				f = e.data("enscroll");
			f && (f.settings.verticalScrolling && (c = a(f.verticalTrackWrapper).find(".enscroll-track")[0], b = c.firstChild, d = e.scrollTop() / (this.scrollHeight - (f._scrollHeightNoPadding ? e.height() : e.innerHeight())), d = isNaN(d) ? 0 : d, b.style.top = d * (a(c).height() - a(b).outerHeight()) + "px"), f.settings.horizontalScrolling && (c = a(f.horizontalTrackWrapper).find(".enscroll-track")[0], b = c.firstChild, d = e.scrollLeft() / (this.scrollWidth - e.innerWidth()), d = isNaN(d) ? 0 : d, b.style.left = d * (a(c).width() - a(b).innerWidth()) + "px"))
		},
		y = function(b) {
			var c, d = a(this),
				e = d.data("enscroll");
			if (!/(input)|(select)|(textarea)/i.test(this.nodeName) && b.target === this && e) {
				switch (c = e.settings.scrollIncrement, b.keyCode) {
					case 32:
					case 34:
						return v(d, d.height()), !1;
					case 33:
						return v(d, -d.height()), !1;
					case 35:
						return v(d, this.scrollHeight), !1;
					case 36:
						return v(d, -this.scrollHeight), !1;
					case 37:
						return u(d, -c), !1;
					case 38:
						return v(d, -c), !1;
					case 39:
						return u(d, c), !1;
					case 40:
						return v(d, c), !1
				}
				return !0
			}
		},
		z = function() {
			var b = this,
				d = a(b).data("enscroll").settings,
				e = !0,
				f = 0,
				h = 0,
				i = a(b).offset().top,
				j = i + a(b).outerHeight(),
				k = a(b).offset().left,
				l = k + a(b).outerWidth(),
				m = function(a) {
					var b = a.pageX,
						c = a.pageY;
					f = k > b ? b - k : b > l ? b - l : 0, h = i > c ? c - i : c > j ? c - j : 0
				},
				n = function() {
					d.horizontalScrolling && f && q(b, parseInt(f / 4, 10)), d.verticalScrolling && h && p(b, parseInt(h / 4, 10)), e && g(n)
				},
				o = function() {
					e = !1, a(c).off("mousemove.enscroll.pane").off("mouseup.enscroll.pane")
				};
			g(n), a(c).on({
				"mousemove.enscroll.pane": m,
				"mouseup.enscroll.pane": o
			})
		},
		A = function(a) {
			var b, c, e, h, i, j, k, l = this,
				n = function(a) {
					b = a.touches[0].clientX, c = a.touches[0].clientY, e || (e = c === i && b === h ? d : Math.abs(i - c) > Math.abs(h - b) ? "y" : "x"), f(a)
				},
				o = function() {
					j && ("y" === e ? (p(l, i - c), k = i - c, i = c) : "x" === e && (q(l, h - b), k = h - b, h = b), g(o))
				},
				r = function() {
					var a = 0,
						b = Math.abs(1.5 * k);
					this.removeEventListener("touchmove", n, !1), this.removeEventListener("touchend", r, !1), j = !1, g(function c() {
						var d;
						a === b || j || (d = m(k, b, a), isNaN(d) || 0 === d || (a += 1, "y" === e ? p(l, d) : q(l, d), g(c)))
					})
				};
			1 === a.touches.length && (h = a.touches[0].clientX, i = a.touches[0].clientY, j = !0, this.addEventListener("touchmove", n, !1), this.addEventListener("touchend", r, !1), g(o))
		},
		B = {
			reposition: function() {
				return this.each(function() {
					var b, c, d, e = a(this),
						f = e.data("enscroll"),
						g = function(a, b, c) {
							a.style.left = b + "px", a.style.top = c + "px"
						};
					f && (d = e.position(), b = f.corner, f.settings.verticalScrolling && (c = f.verticalTrackWrapper, g(c, "right" === f.settings.verticalScrollerSide ? d.left + e.outerWidth() - a(c).width() - h(this, "border-right-width") : d.left + h(this, "border-left-width"), d.top + h(this, "border-top-width"))), f.settings.horizontalScrolling && (c = f.horizontalTrackWrapper, g(c, d.left + h(this, "border-left-width"), d.top + e.outerHeight() - a(c).height() - h(this, "border-bottom-width"))), b && g(b, d.left + e.outerWidth() - a(b).outerWidth() - h(this, "border-right-width"), d.top + e.outerHeight() - a(b).outerHeight() - h(this, "border-bottom-width")))
				})
			},
			resize: function() {
				return this.each(function() {
					var b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r = a(this),
						s = r.data("enscroll");
					return s ? (b = s.settings, void(r.is(":visible") ? (b.verticalScrolling && (e = s.verticalTrackWrapper, c = r.innerHeight(), f = c / this.scrollHeight, g = a(e).find(".enscroll-track")[0], j = a(e).find("." + b.scrollUpButtonClass), k = a(e).find("." + b.scrollDownButtonClass), i = b.horizontalScrolling ? c - a(s.horizontalTrackWrapper).find(".enscroll-track").outerHeight() : c, i -= a(g).outerHeight() - a(g).height() + j.outerHeight() + k.outerHeight(), n = g.firstChild, p = Math.max(f * i, b.minScrollbarLength), p -= a(n).outerHeight() - a(n).height(), e.style.display = "none", g.style.height = i + "px", n.style.height = p + "px", 1 > f && (f = r.scrollTop() / (this.scrollHeight - r.height()), n.style.top = f * (i - p) + "px", e.style.display = "block")), b.horizontalScrolling && (e = s.horizontalTrackWrapper, d = r.innerWidth(), f = d / this.scrollWidth, g = a(e).find(".enscroll-track")[0], l = a(e).find("." + b.scrollLeftButtonClass), m = a(e).find("." + b.scrollRightButtonClass), h = b.verticalScrolling ? d - a(s.verticalTrackWrapper).find(".enscroll-track").outerWidth() : d, h -= a(g).outerWidth() - a(g).width() + l.outerWidth() + m.outerWidth(), n = g.firstChild, o = Math.max(f * h, b.minScrollbarLength), o -= a(n).outerWidth() - a(n).width(), e.style.display = "none", g.style.width = h + "px", n.style.width = o + "px", 1 > f && (f = r.scrollLeft() / (this.scrollWidth - r.width()), n.style.left = f * (h - o) + "px", e.style.display = "block"), s._prybar && (q = s._prybar, this.removeChild(q), b.verticalScrolling && (q.style.width = this.scrollWidth + a(s.verticalTrackWrapper).find(".enscroll-track").outerWidth() + "px", this.appendChild(q)))), s.corner && (s.corner.style.display = s.verticalTrackWrapper && s.horizontalTrackWrapper && a(s.verticalTrackWrapper).is(":visible") && a(s.horizontalTrackWrapper).is(":visible") ? "" : "none")) : (b.verticalScrolling && (s.verticalTrackWrapper.style.display = "none"), b.horizontalScrolling && (s.horizontalTrackWrapper.style.display = "none"), s.corner && (s.corner.style.display = "none")))) : !0
				})
			},
			startPolling: function() {
				return this.each(function() {
					var b, c = a(this).data("enscroll"),
						d = this,
						e = a(d),
						f = -1,
						g = -1,
						h = -1,
						i = -1,
						j = function() {
							if (c.settings.pollChanges) {
								var a = d.scrollWidth,
									k = d.scrollHeight,
									l = e.width(),
									m = e.height(),
									n = e.offset();
								(c.settings.verticalScrolling && (m !== g || k !== i) || c.settings.horizontalScrolling && (l !== f || a !== h)) && (h = a, i = k, B.resize.call(e)), (b.left !== n.left || b.top !== n.top || l !== f || m !== g) && (b = n, f = l, g = m, B.reposition.call(e)), setTimeout(j, 350)
							}
						};
					c && (c.settings.pollChanges = !0, i = d.scrollHeight, h = d.scrollWidth, b = e.offset(), j())
				})
			},
			stopPolling: function() {
				return this.each(function() {
					var b = a(this).data("enscroll");
					b && (b.settings.pollChanges = !1)
				})
			},
			destroy: function() {
				return this.each(function() {
					var c, d, e = a(this),
						f = e.data("enscroll");
					f && (B.stopPolling.call(e), d = f._mouseScrollHandler, f.settings.verticalScrolling && (c = f.verticalTrackWrapper, a(c).remove(), c = null), f.settings.horizontalScrolling && (c = f.horizontalTrackWrapper, a(c).remove(), c = null), f._fadeTimer && clearTimeout(f._fadeTimer), f.corner && a(f.corner).remove(), f._prybar && f._prybar.parentNode && f._prybar.parentNode === this && a(f._prybar).remove(), this.setAttribute("style", f._style || ""), f._hadTabIndex || e.removeAttr("tabindex"), e.off("scroll.enscroll.pane").off("keydown.enscroll.pane").off("mouseenter.enscroll.pane").off("mousedown.enscroll.pane").data("enscroll", null), this.removeEventListener ? (this.removeEventListener("wheel", d, !1), this.removeEventListener("mousewheel", d, !1), this.removeEventListener("touchstart", A, !1)) : this.detachEvent && this.detachEvent("onmousewheel", d), a(b).off("resize.enscroll.window"))
				})
			}
		};
	a.fn.enscroll = function(d) {
		var f;
		return B[d] ? B[d].call(this) : (f = a.extend({}, e, d), this.each(function() {
			if (f.verticalScrolling || f.horizontalScrolling) {
				var d, e, g, j, k, l, m, n, t, C, D, E, F, G, H, I, J, K, L = a(this),
					M = this,
					N = L.attr("style"),
					O = !0,
					P = {
						position: "absolute",
						"z-index": f.zIndex,
						margin: 0,
						padding: 0
					},
					Q = function(a) {
						w.call(M, a)
					},
					R = function(b, c) {
						"string" == typeof c ? a(b).html(c) : b.appendChild(c)
					};
				if (f.verticalScrolling) {
					e = c.createElement("div"), j = c.createElement("div"), l = c.createElement("a"), a(j).css("position", "relative").addClass("enscroll-track").addClass(f.verticalTrackClass).appendTo(e), f.drawScrollButtons && (m = c.createElement("a"), n = c.createElement("a"), a(m).css({
						display: "block",
						"text-decoration": "none"
					}).attr("href", "").html("&nbsp;").addClass(f.scrollUpButtonClass).on("click", function() {
						return p(M, -f.scrollIncrement), !1
					}).insertBefore(j), a(n).css({
						display: "block",
						"text-decoration": "none"
					}).attr("href", "").html("&nbsp;").on("click", function() {
						return p(M, f.scrollIncrement), !1
					}).addClass(f.scrollDownButtonClass).appendTo(e)), f.clickTrackToScroll && a(j).on("click", function(b) {
						b.target === this && v(L, b.pageY > a(l).offset().top ? L.height() : -L.height())
					}), a(l).css({
						position: "absolute",
						"z-index": 1
					}).attr("href", "").addClass(f.verticalHandleClass).mousedown({
						pane: this
					}, r).click(function() {
						return !1
					}).appendTo(j), R(l, f.verticalHandleHTML), a(e).css(P).insertAfter(this), f.showOnHover && a(e).css("opacity", 0).on("mouseover.enscroll.vertical", function() {
						o.call(M, !1)
					}).on("mouseout.enscroll.vertical", function() {
						o.call(M)
					}), E = a(j).outerWidth(), f.addPaddingToPane && (K = "right" === f.verticalScrollerSide ? {
						"padding-right": h(this, "padding-right") + E + "px"
					} : {
						"padding-left": h(this, "padding-left") + E + "px"
					}, L.css(a.extend({
						width: L.width() - E + "px"
					}, K)));
					try {
						I = parseInt(L.css("outline-width"), 10), 0 !== I && !isNaN(I) || "none" !== L.css("outline-style") || L.css("outline", "none")
					} catch (S) {
						L.css("outline", "none")
					}
				}
				f.horizontalScrolling && (d = c.createElement("div"), g = c.createElement("div"), k = c.createElement("a"), a(g).css({
					position: "relative",
					"z-index": 1
				}).addClass("enscroll-track").addClass(f.horizontalTrackClass).appendTo(d), f.drawScrollButtons && (t = c.createElement("a"), C = c.createElement("a"), a(t).css("display", "block").attr("href", "").on("click", function() {
					return q(M, -f.scrollIncrement), !1
				}).addClass(f.scrollLeftButtonClass).insertBefore(g), a(C).css("display", "block").attr("href", "").on("click", function() {
					return q(M, f.scrollIncrement), !1
				}).addClass(f.scrollRightButtonClass).appendTo(d)), f.clickTrackToScroll && a(g).on("click", function(b) {
					b.target === this && u(L, b.pageX > a(k).offset().left ? L.width() : -L.width())
				}), a(k).css({
					position: "absolute",
					"z-index": 1
				}).attr("href", "").addClass(f.horizontalHandleClass).click(function() {
					return !1
				}).mousedown({
					pane: this
				}, s).appendTo(g), R(k, f.horizontalHandleHTML), a(d).css(P).insertAfter(this), f.showOnHover && a(d).css("opacity", 0).on("mouseover.enscroll.horizontal", function() {
					o.call(M, !1)
				}).on("mouseout.enscroll.horizontal", function() {
					o.call(M)
				}), D = a(g).outerHeight(), f.addPaddingToPane && L.css({
					height: L.height() - D + "px",
					"padding-bottom": parseInt(L.css("padding-bottom"), 10) + D + "px"
				}), f.verticalScrolling && (J = document.createElement("div"), a(J).css({
					width: "1px",
					height: "1px",
					visibility: "hidden",
					padding: 0,
					margin: "-1px"
				}).appendTo(this))), f.verticalScrolling && f.horizontalScrolling && f.drawCorner && (F = c.createElement("div"), a(F).addClass(f.cornerClass).css(P).insertAfter(this)), H = L.attr("tabindex"), H || (L.attr("tabindex", 0), O = !1);
				try {
					G = L.css("outline"), (!G || G.length < 1) && L.css("outline", "none")
				} catch (S) {
					L.css("outline", "none")
				}
				L.on({
					"scroll.enscroll.pane": function(a) {
						x.call(this, a)
					},
					"keydown.enscroll.pane": y,
					"mousedown.enscroll.pane": z
				}).css("overflow", "hidden").data("enscroll", {
					settings: f,
					horizontalTrackWrapper: d,
					verticalTrackWrapper: e,
					corner: F,
					_prybar: J,
					_mouseScrollHandler: Q,
					_hadTabIndex: O,
					_style: N,
					_scrollingX: !1,
					_scrollingY: !1,
					_startX: 0,
					_startY: 0,
					_endX: 0,
					_endY: 0,
					_duration: parseInt(f.easingDuration / 16.66666, 10),
					_scrollHeightNoPadding: i(this.nodeName)
				}), a(b).on("resize.enscroll.window", function() {
					B.reposition.call(L)
				}), f.showOnHover && L.on("mouseenter.enscroll.pane", function() {
					o.call(this)
				}), this.addEventListener ? ("onwheel" in this || "WheelEvent" in b && navigator.userAgent.toLowerCase().indexOf("msie") >= 0 ? this.addEventListener("wheel", Q, !1) : "onmousewheel" in this && this.addEventListener("mousewheel", Q, !1), this.addEventListener("touchstart", A, !1)) : this.attachEvent && this.attachEvent("onmousewheel", Q), f.pollChanges && B.startPolling.call(L), B.resize.call(L), B.reposition.call(L)
			}
		}))
	}
}(jQuery, window, document);

creatABALocation = function() { if(jQuery('#location-list').length) {
	/**
	 * TODO: IMPROVE THE ZOOM LEVEL OF EACH LOCATION
	 * desp: when the level zoom is more than 10 should clear Marker and setLocation
	 */
	var activeLocations = new Array(); var activeIndex = new String('');
	var atm_image = '/fileadmin/user_upload/Map_Icon/ATM.png';
	var branch_image = '/fileadmin/user_upload/Map_Icon/ABA.png';
	var cashin_image = '/fileadmin/user_upload/Map_Icon/CASH_in.png';
	var selfservice_image = '/fileadmin/user_upload/Map_Icon/24-7.png';
	var map;
	function addMessage(marker, message, index, map) {
		google.maps.event.addListener(marker, 'click', function() {
			infoWindow.setContent(message);
			infoWindow.open(map, marker);
			map.setCenter(marker.getPosition());
			map.setZoom(marker_zoom);
		});
	}
	function goToLocationCustomize(map, index, zoom){
		
		map.setZoom(zoom);
		goTop();
		setActiveMarkerLocation(activeLocations, map, false);
		activeIndex = index;
		setLocationMarker(places[activeIndex].marker);
		jQuery('#location_select_list').val(activeIndex + 1);
		jQuery('.list-all-marker').removeClass('hide');
		drawMaps();
	}
	function goToLocation(marker, map, index, zoom) {
		google.maps.event.addListener(marker, 'click', function() {
			
			map.setCenter(marker.getPosition());
			map.setZoom(zoom);
			goTop();
			// Unset Location marker.
			setActiveMarkerLocation(activeLocations, map, false);
			activeIndex = index;
			setLocationMarker(places[activeIndex].marker);
			//createRelateLinkMarker(places[activeIndex].marker, activeIndex);
			jQuery('#location_select_list').val(activeIndex + 1);
			jQuery('.list-all-marker').removeClass('hide');
			drawMaps();
		});
	}
	function scrollTop(top) {
		$('html, body').animate({ scrollTop: top }, '100');
	}
	function setMarker(name, lat, lng, image, title, map) {
		name = new google.maps.Marker({
			position : new google.maps.LatLng(lat * 1, lng * 1),
			map : map,
			icon : image,
			title : title
		});
		return name;
	}
	function drawMaps() {
		if( activeIndex instanceof String ) {
			return;
		}
		var isCashIn = jQuery("#cashin-box").prop('checked');
		var isATM = jQuery("#atm-box").prop('checked');
		var isBranch = jQuery("#branch-box").prop('checked');
		var isSelfService = jQuery("#selfservice-box").prop('checked');
		
		var locationMarkers = getATMBranch(places[activeIndex].marker);
		if ( isCashIn ) {
			setMarkerActive(locationMarkers.cashin, map);
		} else {
			clearMarkers(locationMarkers.cashin, map);
		}
		if ( isATM ) {
			setMarkerActive(locationMarkers.atm, map);
		} else {
			clearMarkers(locationMarkers.atm, map);
		}
		if ( isBranch ) {
			setMarkerActive(locationMarkers.branch, map);
		} else {
			clearMarkers(locationMarkers.branch, map);
		}
		if ( isSelfService) {
			setMarkerActive(locationMarkers.selfservice, map);
		} else {
			clearMarkers(locationMarkers.selfservice, map);
		}
		createRelateLinkMarker(getATMBranchCustomize(places[activeIndex].marker, isBranch, isATM, isCashIn, isSelfService), activeIndex);
	}
	function clearMarkers(markers, map) {
		for (var i = 0; i< markers.length; i++) {
			markers[i].title.setMap(null);
		}
	}
	function removeOption(markers, indexMap) {
		for (var i = 0; i< markers.length; i++) {
			markers[i].title.setMap(null);
		}
	}
	
	function setMarkerActive (markers, map) {
		for (var i = 0; i< markers.length; i++) {
			markers[i].title.setMap(map);
		}
	}
	function getATMBranch (markers) {
		var m = 0; var n = 0; var c = 0;var ss = 0;
		var branchs = new Array();
		var atms = new Array();
		var cashins = new Array();
		var selfservices = new Array();
		for (var i = 0; i<markers.length; i++) {
			if (markers[i]['type'] == "Branch") {
				branchs[m] = markers[i];
				m++;
			} else if (markers[i]['type'] == "ATM") {
				atms[n] = markers[i];
				n++;
			} else if (markers[i]['type'] == "SelfService") {
				selfservices[ss] = markers[i];
				ss++;
			}  else {
				cashins[c] = markers[i];
				c++;
			}
		}
		return {cashin: cashins, atm: atms, branch: branchs, selfservice: selfservices};
	}
	// editing
	function getATMBranchCustomize (markers,isBranch, isAtm, isCashIn, isSelfService) {
		var udom = new Array();
		for (var i = 0; i<markers.length; i++) {
			if (isBranch && markers[i]['type'] == "Branch") {
				udom.push(markers[i])
			} else if (isAtm && markers[i]['type'] == "ATM") {
				udom.push(markers[i])
			} else if(isCashIn && markers[i]['type'] == "Cash In") {
				udom.push(markers[i])
			} else if(isSelfService && markers[i]['type'] == "SelfService") {
				udom.push(markers[i])
			}
		}
		return udom;
	}
	function goTop() {
		scrollTop(380);
	}
	function createRelateLinkMarker(markerList, index) {
		head = '<table class="table table-hover table table-bordered"><thead><tr><th>No</th><th>Name</th><th>Address</th><th>Contact</th></tr></thead>';
		body = '';
		for ( var i = 0; i < markerList.length; i++) {
			body += '<tr index="' + i + '"><td>' + (i + 1) + '</td>';
			body += '<td>' + markerList[i].title.getTitle() + '</td>';
			body += '<td>' + markerList[i].address.replace('Address :', '') + '</td>';
			body += '<td>' + markerList[i].contact.replace('Tel :', '') + '</td></tr>';
		}
		body += '</table>';
		jQuery('#relate-marker').html(head + body);
		jQuery("#relate-marker tr").click(
			function() {
				if (jQuery(this).attr('index')) {
					marker_id = jQuery(this).attr('index') * 1;
					var marker = places[index].marker[marker_id];
					map.setCenter(marker.title.getPosition());
					map.setZoom(marker_zoom);
					showInfo(infoWindow, marker);
					goTop();
				}
		});
	}
	function showInfo(infoWindow, marker) {
		infoWindow.setContent('<span class="text-info">' + marker.title.getTitle() + '</span>.<br /><address>' + 
marker.address+'</address>'+marker.open+'<br />'+marker.contact + '<br /><a target="_blank" href="/contact-support/feedback-form/">contact</a>');
		infoWindow.open(map, marker.title);
	}
	/**
	 * SET OR Unset Location marker
	 *
	 */
	function setActiveMarkerLocation (markers, map, isTrue) {
		if(isTrue) {
			for(var i=0 ; i< markers.length; i++){
				markers[i].setMap(map);
			}
		} else {
			for(var i=0 ; i< markers.length; i++){
				markers[i].setMap(null);
			}
		}
	}
	/**
	 * SET OR Unset ATM, Branch and CashIn Markers on the Map
	 *
	 */
	function setActiveMarker( markers, map, isTrue) {
		if(isTrue) {
			for(var i=0 ; i< markers.length; i++){
				markers[i].title.setMap(map);
			}
		} else {
			for(var i=0 ; i< markers.length; i++){
				markers[i].title.setMap(null);
			}
		}
	}
	/**
	 * SET ATM, Branch and CashIn Markers on the Map
	 *
	 */
	function setLocationMarker(markers) {
		var isCashIn = jQuery("#cashin-box").prop('checked');
		var isATM = jQuery("#atm-box").prop('checked');
		var isBrnach = jQuery("#branch-box").prop('checked');
		var isSelfService = jQuery("#selfservice-box").prop('checked');
		
		if(markers[0].title instanceof Object) {
			setActiveMarker(markers, map, true);
			return;
		}
		var currentMarker = getATMBrandArray(markers);
		var cashin = currentMarker.cashin;
		var atm = currentMarker.atm;
		var branch = currentMarker.branch;
		var selfservice = currentMarker.selfservice;
		if (true) {
			for (var i=0; i < cashin.length; i++) {
				cashin[i].title = setMarker(cashin[i].title, cashin[i].lat, cashin[i].lng, cashin_image, cashin[i].title, map);
				var message = '<span class="text-info">' + cashin[i].title.title + '</span> <br /> <address>' + cashin[i].address + 
'</address>'+ cashin[i].open +'<br />'+ cashin[i].contact +'<br /><a target="_blank" href="/feedback-form/">contact</a>';
				addMessage(cashin[i].title,message, activeIndex, map);
			}
		}
		if(true) {
			for (var i=0; i < atm.length; i++) {
				atm[i].title = setMarker(atm[i].title, atm[i].lat, atm[i].lng, atm_image, atm[i].title, map);
				var message = '<span class="text-info">' + atm[i].title.title + '</span> <br /> <address>' + atm[i].address + '</address>'+ 
atm[i].open +'<br />'+ atm[i].contact +'<br /><a target="_blank" href="/feedback-form/">contact</a>';
				addMessage(atm[i].title,message, activeIndex, map);
			}
		}
		if (true) {
			for (var i=0; i < branch.length; i++) {
				branch[i].title = setMarker(branch[i].title, branch[i].lat, branch[i].lng, branch_image, branch[i].title, map);
				var message = '<span class="text-info">' + branch[i].title.title + '</span> <br /> <address>' + branch[i].address + 
'</address>'+ branch[i].open +'<br />'+ branch[i].contact +'<br /><a target="_blank" href="/feedback-form/">contact</a>';
				addMessage(branch[i].title,message, activeIndex, map);
			}
		}
		if (true) {
			for (var i=0; i < selfservice.length; i++) {
				selfservice[i].title = setMarker(selfservice[i].title, selfservice[i].lat, selfservice[i].lng, selfservice_image, selfservice[i].title, map);
				var message = '<span class="text-info">' + selfservice[i].title.title + '</span> <br /> <address>' + selfservice[i].address + 
'</address>'+ selfservice[i].open +'<br />'+ selfservice[i].contact +'<br /><a target="_blank" href="/feedback-form/">contact</a>';
				addMessage(selfservice[i].title,message, activeIndex, map);
			}
		}
	}
	/**
	 * Separate The ATM, The Branch and The CashIn
	 *
	 */
	function getATMBrandArray( markers ) {
		var cashinHours = places[places.length - 1]['Cash In'];
		var atmHours = places[places.length - 1]['ATM'];
		var branchHours = places[places.length - 1]['Branch'];
		var selfserviceHours = places[places.length -1]['SelfService'];
		var m = 0;
		var n = 0;
		var c = 0;
		var ss = 0;
		var cashins = new Array();
		var branchs = new Array();
		var atms = new Array();
		var selfservices = new Array();
		for (var i = 0; i<markers.length; i++) {
			if (markers[i]['type'] == "Branch") {
				branchs[m] = markers[i];
				m++;
			} else if (markers[i]['type'] == "ATM") {
				atms[n] = markers[i];
				n++;
			} else if (markers[i]['type'] == "SelfService") {
				selfservices[ss] = markers[i];
				ss++;
			}  else {
				cashins[c] = markers[i];
				c++;
			}
		}
		return {cashin: cashins, atm: atms, branch: branchs, selfservice: selfservices};
	}
	var zoom = 7; // Zoom Default
	var marker_zoom = 16; // zoom when click on the marker
	
	var intial_location = {
		'lat' : 12.712165,
		'lng' : 104.889518
	}; // Default Location Kampong Thom LatLng
	var cashin_markers;
	var atm_markers;
	var branch_markers;
	var selfservice_markers;
	// Globals map object to front End
	var map;
	var allmarker = [];
	var infoWindow = new google.maps.InfoWindow({
		maxWidth : 250,
		disableAutoPan : false
	});
	function initialize() {
		mapSetting = jQuery.parseJSON(jQuery('#map-setting').val());
		places = jQuery.parseJSON(jQuery("#location-list").val());
		var marker_temp = [];
		var m = 0;
		var marker_temp1 = [];
		var n = 0;
		var marker_temp2 = [];
		var c = 0;
		var marker_temp3 = [];
		var ss = 0;
		// Set From the Setting
		latlng = mapSetting.defaultLatlng.split(',');
		intial_location = {
			'lat': latlng[0] * 1,
			'lng': latlng[1] * 1
		}
	
		var defaultMapTypeId = mapSetting.mapType;
		zoom = mapSetting.defaultZoom / 1;
		marker_zoom = mapSetting.makerDefaultZoom / 1;
		cashin_markers = marker_temp2;
		atm_markers = marker_temp;
		branch_markers = marker_temp1;
		selfservice_markers = marker_temp3;
		/* _______CREATE MAP START______ */
		// Map options
		var mapOptions = {
			center : new google.maps.LatLng(intial_location['lat'],
					intial_location['lng']),
			zoom : zoom,
			scrollwheel: false,
			minZoom: 7,
			streetViewControl : true,
			overviewMapControl : true,
			styles: [
			{
				featureType : 'poi',
				elementType : 'labels',
				stylers : [ {
					visibility : 'off'
				} ]
			},
			{
				featureType : 'administrative',
				elementType : 'labels',
				stylers : [ {
					visibility : 'off'
				} ]
			}],
			mapTypeId : defaultMapTypeId
		};
	
		var map_location = document.getElementById("map-canvas"); // Map location
		map = new google.maps.Map(map_location, mapOptions); // Map Object
		path = 'uploads/tx_weaba/';
		for(j = 0; j < places.length - 1; j++) {
			var marker = places[j].name;
			img = path + places[j].icon;
			places[j].name = new google.maps.Marker({
				title: places[j].name,
				position : new google.maps.LatLng(places[j].latitude, places[j].longtitude),
				map : map,
				icon : img
			});
			activeLocations[j] = places[j].name;
			goToLocation(places[j].name, map, j, places[j].zoomLevel);
		}
	
		google.maps.event.addListener(map, 'zoom_changed', function() {
			if(map.getZoom() < 12){
				if( activeIndex instanceof String ) {
					return;
				} else {
					setActiveMarkerLocation(activeLocations, map, true);
					setActiveMarker(places[activeIndex].marker, map, false);
					activeIndex = new String('');
					return;
				}
			}
		});
	
		if ( mapSetting.hideOtherCountry * 1 ) {
			layer = new google.maps.FusionTablesLayer({
				clickable: false,
				query: {
					select: 'geometry',
					from: '17CkE8aMS47pKycdLKn0q7mc1A4yxU64PzYcCoJ4'
				},
				styles: [{
					polygonOptions: {
						fillColor: '#CACACA',
						fillOpacity: 0.6
					}
				}]
			});
			layer.setMap(map);
		}
	}
	google.maps.event.addDomListener(window, 'load', initialize); /** ---- DOCUMENT READY ---- **/ jQuery(document).ready(
	function() {
		places = jQuery.parseJSON(jQuery("#location-list").val());
		jQuery("#location_select_list").prepend("<option value='0' selected='selected'>All</option>");
		jQuery("#location_select_list").change(function() {
			// var place_index = jQuery('#location_select_list option:selected').val() * 1 ;
			// if(place_index){
			// map.setZoom(12);
			// var index = place_index - 1;
			// map.setCenter(new google.maps.LatLng(places[index].latitude * 1 , places[index].longtitude * 1));
			// setActiveMarkerLocation(activeLocations, map, true);
			// jQuery('.list-all-marker').removeClass('hide');
			// if(activeIndex instanceof String){
			// return false;
			// } else {
			// setActiveMarkerLocation(activeLocations, map, true);
			// setActiveMarker(places[activeIndex].marker, map, false);
			// activeIndex = new String('');
			// }
			// } else {
			// jQuery('#start-again').trigger('click');
			// }
			// Update By pak udom 2016-09-07
			var place_index = jQuery('#location_select_list option:selected').val() * 1 ;
			if(place_index){
				var index = place_index - 1;
				map.setCenter(new google.maps.LatLng(places[index].latitude * 1 , places[index].longtitude * 1));
				setActiveMarkerLocation(activeLocations, map, true);
				
				goToLocationCustomize(map, index, places[index].zoomLevel);
				
			} else {
				jQuery('#start-again').trigger('click');
			}
		});
		/** RESET BUTTON **/
		if (jQuery("#start-again").length) {
			jQuery('#start-again').click(
				function() {
					infoWindow.close();
					map.setCenter(new google.maps.LatLng(
						intial_location['lat'],
						intial_location['lng']));
					map.setZoom(zoom);
					goTop();
					jQuery('.list-all-marker').addClass('hide');
					jQuery('#location_select_list').val('option:selected', 0);
					
					if(activeIndex instanceof String){
						return false;
					} else {
						setActiveMarkerLocation(activeLocations, map, true);
						setActiveMarker(places[activeIndex].marker, map, false);
						activeIndex = new String('');
					}
					return false;
				}
			);
			jQuery('.list-all-marker').addClass('hide');
		}
		jQuery("#cashin-box, #atm-box, #branch-box, #selfservice-box").click(function() {
			drawMaps();
		});
		/* Set height for google map */
		var mapWidth = jQuery("#map-canvas").width();
		var mapHeight = jQuery("#map-canvas").css('height', mapWidth - 100);
	});
}
}
creatABALocation();

if (navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPad/i)) {
	var viewportmeta = document.querySelector('meta[name="viewport"]');
	if (viewportmeta) {
		viewportmeta.content = 'width=device-width, minimum-scale=1.0, maximum-scale=1.0, initial-scale=1.0';
		document.body.addEventListener('gesturestart', function () {
			viewportmeta.content = 'width=device-width, minimum-scale=0.25, maximum-scale=1.6';
		}, false);
	}
}

jQuery(document).ready(function () {
	var abaIframe = $(document).find('.aba-iframe');
	if(abaIframe.length > 0){
		$.each(abaIframe, function(index, value){
			var iframe = $(value).html();
			var arrData = explode(" ", iframe);
			$(value).html('<iframe '+arrData[1]+' '+arrData[2]+' frameborder="0" allowfullscreen=""></iframe>');
		});
	}
	if (navigator.appVersion.indexOf("Mac")!=-1) {
		$('body').addClass('is-safari');
	}

	if (jQuery(window).width() < 768) {
		jQuery('div.carousel-caption').addClass('in-device');
		jQuery('#myCarousel .item').each(function () {
			image = jQuery(this).children().children('a > .hide-in-mobile');
			jQuery(this).children('a:first-child').replaceWith(image);
		});
	}

	/* ---- Start font switcher ----*/
	if (jQuery('#font-size-switcher').length > 0) {
		jQuery('#font-size-big a').click(function (e) {
			jQuery('#left_content').addClass('large-text');
			jQuery('.content').addClass('large-text');
			e.preventDefault();
		});
		jQuery('#font-size-normal a').click(function (e) {
			jQuery('#left_content').removeClass('large-text');
			jQuery('.content').removeClass('large-text');
			e.preventDefault();
		});
	}
	/* ---- End font switcher ----*/

	/* ---- Start telephone href rewriting  ----*/
	if (jQuery('#main_nav #telephone').length > 0) {
		var newHref = jQuery('#main_nav #telephone').attr('class');
		jQuery('#main_nav #telephone').attr('href', newHref);
	}
	/* ---- End telephone href rewriting ----*/

	/* ---- Start iBanking href rewriting  ----*/
	if (jQuery('#main_nav #iBanking').length > 0) {
		var iBankingHref = jQuery('#main_nav #iBanking').attr('class');
		var iBankingHrefArray = iBankingHref.split(":");
		var protocol = 'http://';
		switch (iBankingHrefArray[0]) {
			case '2':
				protocol = 'ftp://';
				break;
			case '3':
				protocol = 'mailto:';
				break;
			case '4':
				protocol = 'https://';
				break;
			default:
				break;
		}

		urlSlash = iBankingHrefArray[1].substr(iBankingHrefArray[1].length - 1);
		if (urlSlash != '/') {
			jQuery('#main_nav #iBanking').attr('href', protocol + iBankingHrefArray[1] + '/');
		} else {
			jQuery('#main_nav #iBanking').attr('href', protocol + iBankingHrefArray[1]);
		}
	}
	/* ---- End iBanking href rewriting ----*/

	/* ---- Share Start----*/
	var popupShare = false;
	if ((jQuery('#social-share').length)) {
		jQuery('#social-share').popover();
		jQuery('#social-share').click(function () {
			popupShare = true;
			jQuery(".popover-content").html("");
			var url = window.location.href;
			jQuery(".popover-content").html(jQuery("#social-content").html().replace(/{URL}/g, url));
			jQuery(".popover-content").html(jQuery(".popover-content").html().replace(/{PAGETITLE}/, jQuery('title').text()));
			return false;
		});
	}

	// Enable close popup share when anywhere outside
	jQuery('body').bind('click', function (e) {
		if (popupShare) {
			jQuery('#social-share').click();
			popupShare = false;
		}
	});
	/* ---- Share End----*/

	/* --- Carousel start --- */
	if (jQuery('#myCarousel').length) {
		/*jQuery('#myCarousel').on('slide', '', function() {
		 activeSlide = jQuery("#myCarousel div.carousel-inner div.active .container .carousel-caption").html();
		 activeSlide = jQuery.trim(activeSlide);
		 if (activeSlide == '') {
		 alert('me');
		 }
		 });*/
		jQuery("#myCarousel .carousel-inner .item").each(function (index) {
			element = index + 1;
			if (index == 0) {
				jQuery('ol.carousel-indicators').append("<li class='active' data-target='#myCarousel' data-slide-to='" + index + "'>" + "</li>");
			} else {
				jQuery('ol.carousel-indicators').append("<li data-target='#myCarousel' data-slide-to='" + index + "'>" + "</li>");
			}
			disableBox = parseInt(jQuery(this).children('div.hidden').children('.disable-box-mapping').text());
			if (disableBox) {
				jQuery(this).children('div.container').children('div.carousel-caption').addClass('disable-box');
			}
			boxAlignment = jQuery(this).children('div.hidden').children('.box-position').text();
			if (jQuery(this).children('div.container').children('div.carousel-caption').children('.hide-in-mobile').text() == '' &&
				jQuery(this).children('div.container').children('div.carousel-caption').children('.display-in-mobile').text() == '' &&
				jQuery(this).children('div.container').children('div.carousel-caption').children('.text-in-box').text() == '') {
				jQuery(this).children('div.container.whole-content').hide();
			} else {
				jQuery(this).children('div.container').children('div.carousel-caption').addClass(jQuery(this).children('div.hidden').children('.box-color').text());
			}
			jQuery(this).children('div.container').children('div.carousel-caption').css('left', boxAlignment);
			if (boxAlignment != 0) {
				jQuery(this).children('div.container').children('div.carousel-caption').addClass("box_right");
			}
		});
		jQuery("#myCarousel div.carousel-inner div.item:first").addClass("active");
		jQuery("#myCarousel").swiperight(function () {
			jQuery("#myCarousel").carousel('prev');
		});
		jQuery("#myCarousel").swipeleft(function () {
			jQuery("#myCarousel").carousel('next');
		});
		setSpeedCarousel();
		if (jQuery("#myCarousel .carousel-inner .item").length > 1) {
			jQuery('#myCarousel').hover(function (e) {
				jQuery(this).children('.carousel-control.left').css('display', 'block');
				jQuery(this).children('.carousel-control.right').css('display', 'block');
			}, function () {
				jQuery('.carousel-control.left').css('display', 'none');
				jQuery('.carousel-control.right').css('display', 'none');
			});
		}
		if (jQuery('#myCarousel .carousel-inner .item').length == 1) {
			jQuery('#myCarousel ol.carousel-indicators li').css('display', 'none');
		}
		setPositionCarouselSlideTool();
	}
	/* --- Carousel end --- */

	/* --- Tab start --- */
	jQuery("ul.nav-tabs li.active a").each(function () {
		jQuery(jQuery(this).attr('href')).addClass('active');
	});
	jQuery("div.tab-content div header.csc-header").remover;

	/* --- Searchbox start --- */
	var placeholderSearchValue = jQuery('.navbar-form #search_field').attr('placeholder');
	jQuery('.navbar-form #search_field').val(placeholderSearchValue);
	jQuery('.priority .navbar-form #search_button').addClass('icon-white');
	jQuery('.navbar-form #search_field').focus(function () {
		jQuery(this).addClass('focus-in');
		if (jQuery(this).val() == placeholderSearchValue) {
			jQuery('.navbar-form #search_field').val('');
		}
		jQuery(this).css({'background': '#fff', 'color': '#000'});
		jQuery('.navbar-form #search_button').removeClass('icon-white');
		if (jQuery(window).width() > 978) {
			jQuery(this).animate({width: '206px'}, 600);
		} else {
			jQuery(this).animate({width: '100px'}, 300);
		}
	});

	jQuery('.navbar-form #search_button[type^="button"]').click(function () {
		var rel = jQuery(this).attr('rel');
		if (rel == 'expand') {
			if (jQuery(window).width() > 978) {
				jQuery('.navbar-form #search_field').animate({width: '206px'}, 600);
			} else {
				jQuery('.navbar-form #search_field').animate({width: '100px'}, 300);
			}
			jQuery('.navbar-form #search_field').focus();
			jQuery(this).attr('rel', 'collapse');
		} else {
			var searchValue = jQuery('.navbar-form #search_field').val();
			if (searchValue.length == '' || searchValue == placeholderSearchValue) {
				if (jQuery(window).width() > 978) {
					jQuery('.navbar-form #search_field').animate({width: '50px'}, 600);
				} else {
					jQuery('.navbar-form #search_field').animate({width: '50px'}, 300);
				}
				jQuery('.navbar-form #search_field').focusout();
				jQuery(this).attr('rel', 'expand');
			}
		}
	});

	jQuery('.navbar-form #search_field').keyup(function () {
		var searchValue = jQuery(this).val();
		if (searchValue.length > 1) {
			jQuery('.navbar-form #search_button[type^="button"]').attr('type', 'submit');
			jQuery('.navbar-form #search_field').focus();
		}
	});

	jQuery('.navbar-form #search_field').focusout(function () {
		jQuery('.priority .navbar-form #search_field').css({'color': '#fff'});
		jQuery('.priority .navbar-form #search_button').addClass('icon-white');
		if (jQuery(this).val() == '') {
			jQuery(this).removeClass('focus-in');
			jQuery(this).animate({width: '50px'}, 600);
			jQuery(this).css({'background': 'none'});
			jQuery('.navbar-form #search_field').val(placeholderSearchValue);
		}
	});

	/*---------------------  Visible Searchbox in Phone  ------------------------*/
	jQuery('.phone-search').click(function () {
		if (jQuery('.pull-left.searchbox').hasClass('hidden-phone')) {
			jQuery('.pull-left.searchbox').removeClass('hidden-phone');
			jQuery('.pull-left.searchbox').hide();
		}
		if (jQuery('.pull-left.searchbox').is(':hidden')) {
			jQuery('.pull-left.searchbox').slideDown('fast');
			jQuery('.navbar .whole-content .btn-navbar').animate({top: '97px'}, 200);
		} else {
			$('.pull-left.searchbox').slideUp('fast');
			jQuery('.navbar .whole-content .btn-navbar').animate({top: '59px'}, 200);
		}
	});
	/* --- Searchbox end --- */

	/* --- Menu click/hover action start --- */

	// Prevent redirect when clicking on top level menu in responsive
	jQuery('.menu-phone #nav_main .dropdown').click(function (event) {
		event.preventDefault();
	});

	jQuery('#nav_main .dropdown-submenu a.dropdown-toggle').click(function (event) {
		event.preventDefault();
		event.stopPropagation();
	});
	/* testing button */
	jQuery("#dropdownMenuButton").hover(function(){
   	 console.log('ibanking');
 	 });

	jQuery('.main-nav .nav > li.dropdown-submenu').hover(function () {
		if ((jQuery.support.touch == false) && (jQuery(document).width() <= 979)) {
			jQuery(this).addClass('open');
			jQuery(this).nextAll('li').removeClass('open');
		}
	});

	jQuery('ul.nav-pills li a').click(function () {
		className = jQuery(this).attr('data-target');
		if (jQuery(this).parent().hasClass('dropdown')) {
			if (!jQuery(className).hasClass('in')) {
				jQuery(className).collapse('toggle');
				if (className == '.col1') {
					if (jQuery('.col2').hasClass('in')) {
						jQuery('.col2').collapse('toggle');
					}
					if (jQuery('.main-menu').hasClass('in')) {
						jQuery('.main-menu').collapse('toggle');
					}
				} else if (className == '.col2') {
					if (jQuery('.col1').hasClass('in')) {
						jQuery('.col1').collapse('toggle');
					}
					if (jQuery('.main-menu').hasClass('in')) {
						jQuery('.main-menu').collapse('toggle');
					}
				}
				return false;
			}
		}
	});
	jQuery('button.btn-navbar').click(function () {
		if (jQuery('.col1').hasClass('in')) {
			jQuery('.col1').collapse('toggle');
		}
		if (jQuery('.col2').hasClass('in')) {
			jQuery('.col2').collapse('toggle');
		}
	});
	/* --- Menu click/hover action end --- */

	/* --- Menu fix top for subpage start --- */
	if (jQuery(window).width() >= 1024) {
		jQuery(window).scroll(function () {
			if (jQuery(window).scrollTop() > 130) {
				jQuery('.subpage .main-nav').addClass('navbar-fixed-top');
			} else {
				jQuery('.subpage .main-nav').removeClass('navbar-fixed-top');
			}
		});
	}
	/* --- Menu fix top for subpage end --- */

	/* --- Arrow Change and Scroll down start --- */
	jQuery('label[data-target$="#sitemap-dropdown"]').click(function () {
		var footerBar = 95;
		jQuery('#sitemap-dropdown .whole-content').css('display', 'block');
		if (jQuery('.subpage').length) footerBar += 40;
		var height = jQuery('body').height() - footerBar;
		if (jQuery('#arrow-sitemap').attr('class') != "sitemap-arrow-up") {
			jQuery('#arrow-sitemap').attr('class', 'sitemap-arrow-up');
			jQuery('html, body').animate({scrollTop: height}, '100');
		} else {
			jQuery('#arrow-sitemap').attr('class', 'sitemap-arrow-down');
		}
		;
	});
	/* --- Arrow Change and Scroll down end --- */

	/* --- PRINT Icon start and TOP--- */
	var oldSrc = '';
	jQuery('a#footer_print').click(function () {
		oldSrc = jQuery('.visible-phone img').attr('src');
		jQuery('.visible-phone img').attr('src', jQuery('.hidden-phone img').attr('src'));
		jQuery('.visible-phone img').attr('style', '    width: 150px !important;margin-left: 20px;');
		window.print();
		setTimeout(function () {
			jQuery('.visible-phone img').attr('src', oldSrc);
			jQuery('.visible-phone img').attr('style', 'width: 150px !important;');
		}, 500);
	});
	jQuery('a#footer_gotop').click(function () {
		goTop();
		return false;
	});
	/* --- PRINT Icon and TOP end --- */

	/* --- Retina support of image tag start --- */
	Retina = function () {
		return {
			init: function () {
				// Get pixel ratio and perform retina replacement
				// Optionally, you may also check a cookie to see if the user has opted out of (or in to) retina support
				var pixelRatio = !!window.devicePixelRatio ? window.devicePixelRatio : 1;
				if (pixelRatio > 1) {
					jQuery("img").each(function (idx, el) {
						el = jQuery(el);
						if (el.attr("data-src2x")) {
							el.attr("data-src-orig", el.attr("src"));
							el.attr("src", el.attr("data-src2x"));
						}
					});
				}
			}
		};
	}();
	//Init
	Retina.init();
	/* --- Retina support of image tag end --- */

	/* --- Poll start --- */
	if (jQuery('#pollAjaxUrl').length > 0) {
		initPoll('default');
	}
	/* --- Poll end --- */

	/* --- Survey or splashscreen start --- */
	var surveyId = jQuery('#survey_invitation #surveyUid').val();
	var surveyHash = jQuery('#survey_invitation #surveyHash').val();
	if (jQuery('.modal').is('#splashscreen')) {
		if (document.cookie.indexOf('weaba[splashscreen]') < 0) {
			jQuery('#splashscreen').modal('show').css({
				'top': function () {
					var spacing = jQuery(window).height() - jQuery(this).height();
					return (spacing > 0) ? (spacing / 2) : 0;
				}
			});
		}
		jQuery('div.modal-backdrop, button.close, button.btn[data-dismiss="modal"]').click(function () {
			document.cookie = 'weaba[splashscreen] = 1234567890';
		});
	} else {
		if (jQuery('#survey_invitation').length) {
			if (surveyId && surveyHash) {
				if (document.cookie.indexOf('weaba[survey_' + surveyId + ']=' + surveyHash) < 0) {
					jQuery('#survey_invitation').modal('show').css({
						'top': function () {
							var spacing = jQuery(window).height() - jQuery(this).height();
							return (spacing > 0) ? (spacing / 2) : 0;
						}
					});
				}
				// Click outside box and close button and Later button
				jQuery('div.modal-backdrop, button.close, button.btn[data-dismiss="modal"]').click(function () {
					document.cookie = 'weaba[survey_' + surveyId + '] = ' + surveyHash;
				});
				jQuery('#survey_no').click(function () {
					var exdate = new Date();
					exdate.setDate(exdate.getDate() + 365);
					document.cookie = 'weaba[survey_' + surveyId + ']=' + surveyHash + '; expires=' + exdate.toUTCString();
				});
			}
		}
	}

	/* --- Survey end --- */

	//Splash screen no text
	if (jQuery('.modal').is('#splashscreen-noimage')) {
		if (document.cookie.indexOf('weaba[splashscreen-noimage]') < 0) {
			jQuery('#splashscreen-noimage').modal('show').css({
				'top': function () {
					var spacing = jQuery(window).height() - jQuery(this).height();
					return (spacing > 0) ? (spacing / 2) : 0;
				}
			});
		}
		jQuery('div.modal-backdrop, button.close, button.btn[data-dismiss="modal"]').click(function () {
			document.cookie = 'weaba[splashscreen-noimage] = 1234567890';
		});
	}

	/* ---- Ajax newsletter start ---- */
	if (jQuery('#newsletter').length) {
		jQuery.ajax({
			url: jQuery('#newsletter a').attr('href') + '&type=1368790593&ajax=1',
			dataType: 'html',
			success: function (data) {
				jQuery('#newsletter').html(data.replace('type=1368790593&amp;ajax=1', ''));
			}
		});
	}
	/* ---- Ajax newsletter end ---- */

	/* ---- Close window for logout Start ----*/
	jQuery(".tx-we-aba .btn-close").click(function () {
		window.close();
	});
	/* ---- Close window for logout End ----*/

	/* ---- Currency Converter Start ----*/
	if (jQuery('.tx-we-aba .amount-value').length) {
		var currency = jQuery.parseJSON(jQuery('.tx-we-aba #json-array').val()); // currency : Json of all Currency
		var selectFrom = jQuery('.tx-we-aba select.cur-from-value').html(); // default : Currency From use to restore when selecte change
		var selectTo = jQuery('.tx-we-aba select.cur-to-value').html(); // default : Currency To use to restore when selecte change

		/* ### CALCULATOR OF THE CURRENCY CONVERTOR ##*/
		jQuery('.tx-we-aba .amount-value').keyup(function (e) {
			jQuery(this).val(jQuery(this).val().replace(/[^.\d]/, ''));
			var from = jQuery('.tx-we-aba select.cur-from-value option:selected').val();
			var to = jQuery('.tx-we-aba select.cur-to-value option:selected').val();
			calculateCurrency(currency, from, to);
		});

		jQuery('.tx-we-aba .amount-value').blur(function (e) {
			jQuery(this).val(thousandSepator(jQuery(this).val()));
		});

		jQuery('.tx-we-aba .amount-value').click(function (e) {
			jQuery(this).val(jQuery(this).val().replace(/,/g, ''));
		});

		jQuery('.tx-we-aba select.cur-from-value').change(function (e) {
			var from = jQuery('.tx-we-aba select.cur-from-value option:selected').val();
			var to = jQuery('.tx-we-aba select.cur-to-value option:selected').val();
			var secondOption = '';
			for (var i = 0; i < currency.length; i++) {
				if (currency[i].sym_from == from) {
					secondOption += '<option value=' + currency[i].sym_to + '>' + currency[i].cur_to + '</option>';
				}
			}
			// REMOVE Non Depandantcy Currency
			jQuery('.tx-we-aba select.cur-to-value').children().remove();
			jQuery('.tx-we-aba select.cur-to-value').html(secondOption);
			calculateCurrency(currency, from, jQuery('.tx-we-aba select.cur-to-value option:selected').val());

			// Restore The Currency From Seleceted.
			var selected = jQuery(this).val();
			jQuery(this).html(selectFrom.replace('value="' + selected, 'selected value="' + selected));
		});

		jQuery('.tx-we-aba select.cur-to-value').change(function (e) {
			calculateCurrency(currency, jQuery('.tx-we-aba select.cur-from-value option:selected').val(), jQuery('.tx-we-aba select.cur-to-value option:selected').val());
		});
	}
	/* ---- Currency Converter End ----*/

	/* ---- Scroll to bottom when subscribe error starts ----*/
	if (jQuery('.socialbar .newsletter .help-inline').length > 0) {
		window.scroll(0, 50000);
	}
	/* ---- Scroll to bottom when subscribe error ends ----*/

	/* ---- Rates on popup ----*/
	if (jQuery('#rates-popup').length) {
		jQuery('#teaser-rate-container').click(function () {
			jQuery.colorbox({href: "#rates-popup", inline: true});
			return false;
		});

		/* ---- Add class last for last child of rate popup ----*/
		jQuery('#rates-popup .span2:last').addClass('last');
	}

	/* ---- Colorbox news caption ---- */
	var cboxTitle = jQuery('a.t3colorbox').attr('title');
	if (typeof cboxTitle != 'undefined') {
		if (cboxTitle.length == 0)
			jQuery('#cboxTitle').css('padding', '0');
		else
			jQuery('#cboxTitle').css('padding', '10px');
	}

	$('.t3colorbox').click(function () {
		if ($(this).siblings('figcaption').html()) {
			$(this).attr('title', $(this).siblings('figcaption').html());
		}
	});

	/* ---- Google plus ----*/
	/* (function () {
		var po = document.createElement('script');
		po.type = 'text/javascript';
		po.async = true;
		po.src = 'https://apis.google.com/js/plusone.js';
		var s = document.getElementsByTagName('script')[0];
		s.parentNode.insertBefore(po, s);
	})(); */
	/* ---------------job -------------*/
	if (jQuery('.news-list-view .job').length) {
		jQuery('.Tx-Formhandler').remove();
	}
	/* --------------end job ----------*/

	/* -------------- Start select box for point and Priority Merchant----------*/
	if (jQuery('.priority #myCarousel').length) {
		setMerchantBackground();
		jQuery(window).resize(function () {
			setMerchantBackground();
		});
	}

	if (jQuery('.point #merchant-list').length) {
		setMerchantBackground();
		jQuery(window).resize(function () {
			setMerchantBackground();
		});
	}

	if (jQuery('#abaLocationList').length) {
		var abaLocations = jQuery.parseJSON(jQuery('#abaLocationList').text());
		var marker_temp = [];
		var m = 0;
		var marker_temp1 = [];
		var n = 0;
		for (var i = 0; i < abaLocations.length - 1; i++) {
			var markers = abaLocations[i]['marker'];
			var zone = abaLocations[i]['name'];
			var atmHours = abaLocations[abaLocations.length - 1]['ATM'];
			var branchHours = abaLocations[abaLocations.length - 1]['Branch'];

			for (var j = 0; j < markers.length; j++) {
				markers[j]['zone'] = zone;
				if (markers[j]['type'] == 'ATM') {
					marker_temp[m] = markers[j];
					m++;
				} else {
					marker_temp1[n] = markers[j];
					n++;
				}
			}
		}

		atm_markers = marker_temp;
		branch_markers = marker_temp1;

		jQuery('.select-point ul li').click(function () {
			currentLocation = jQuery('.select-point button').attr('id');
			if (currentLocation != jQuery(this).attr('data-value')) {
				$("#merchant-filter-list").hide();
				jQuery('#merchant-filter-list').empty();
				span = '<span class="caret"></span>';
				jQuery('.select-point button').attr('id', jQuery(this).attr('data-value')).html(jQuery(this).html() + span);
				initMerchant(jQuery(this).attr('data-value'));
			}
		});

		jQuery('.span3.teaser-point').each(function (index, description) {
			if (jQuery(description).children('.item').length == 1) {
				jQuery(description).children('.arrow-top, .arrow-down').hide();
			}
		});

		jQuery('.span3.teaser-point .arrow-top').click(function () {
			moveItem(jQuery(this).siblings('.item'), true);
		});
		jQuery('.span3.teaser-point .arrow-down').click(function () {
			moveItem(jQuery(this).siblings('.item'), false);
		});
		/* -------------- Start select box for point and Priority Merchant----------*/

		activeMarker = new google.maps.Marker({
			position: new google.maps.LatLng(11.9893, 105.46342)
		});
		var contentString = '';
		infoWindow = new google.maps.InfoWindow({
			posistion: activeMarker.getPosition(),
		});
		loadMap();
	}

	/*---------------------  FCE Image teaser box  ------------------------*/
	jQuery('.body-teaser-box').each(function () {
		var des = jQuery(this).children('.description');
		var child = des.children();
		for (var i = 0; i < child.length; i++) {
			var element = jQuery(child[i]);
			if (element.hasClass('header')) {
				if (element.children('h3').text().length < 1) {
					des.css('display', 'none');
					break;
				}
			} else {
				if (element.text().length < 1) {
					des.children('.header').children('i').hide();
					des.html(des.children('.header'));
				}
			}
		}
	});
	setCarouselBoxBottom();
});
/* -------------- END merchant map----------*/

/* ============================== END DOCUMENT READY ============================== */

/* ============================== START WINDOW RESIZE ============================== */
jQuery(window).resize(function () {
	alignMenuItems();
	if (jQuery('#myCarousel').length) {
		jQuery('#myCarousel').carousel('pause');
		setPositionCarouselSlideTool();
	}
	if (jQuery('#splashscreen').length) {
		jQuery('#splashscreen').css({
			'top': function () {
				var spacing = jQuery(window).height() - jQuery('#splashscreen').height();
				return (spacing > 0) ? (spacing / 2) : 0;
			}
		});
	}
	if (jQuery('#survey_invitation').length) {
		jQuery('#survey_invitation').css({
			'top': function () {
				var spacing = jQuery(window).height() - jQuery('#survey').height();
				return (spacing > 0) ? (spacing / 2) : 0;
			}
		});
	}
	;
	if (jQuery('#myCarousel').length) {
		setSpeedCarousel();
	}

	/* ---- Start banner remove class .btn ----*/
	jQuery(window).resize(function () {
		if (jQuery(window).width() < 481) {
			jQuery('.whole-content .text-in-box a').removeClass('btn');
		} else {
			jQuery('.whole-content .text-in-box a').addClass('btn');
		}
	});
	/* ---- End banner remove class .btn ----*/
});
/* ============================== END WINDOW RESIZE ============================== */

/* ============================== START WINDOW LOAD ============================== */
jQuery(window).load(function () {
	alignMenuItems();
});
/* ============================== END WINDOW LOAD ============================== */

/* ============================== START ROTATION ============================== */
var interval;

window.addEventListener("orientationchange", function () {
	jQuery(".zopim").hide();
	interval = setInterval('hideChatWidget();', 1000);
}, false);
/* ============================== END ROTATION ============================== */

function hideChatWidget() {
	jQuery(".zopim").show();
	clearInterval(interval);
}
function setPositionCarouselSlideTool() {
	rightIndicators = (jQuery(document).width() - jQuery("div.row-fluid").width()) / 2;
	jQuery(".carousel-indicators").css('right', rightIndicators);
	if (jQuery(document).width() > 1024) {
		jQuery("#myCarousel .left").css('left', rightIndicators - 170);
		jQuery("#myCarousel a.right").css('right', rightIndicators - 170);
	} else if (jQuery(document).width() < 768) {
		jQuery('#myCarousel .carousel-control.left').css('left', '15px');
		jQuery('#myCarousel .carousel-control.right').css('right', '15px');
	}
}
function setSpeedCarousel() {
	if (jQuery('#myCarousel').length) {
		jQuery('#myCarousel').carousel({
			interval: jQuery('#carousel-speed').text()
		}).bind('slid', function () {
			if (jQuery(window).width() <= 767) {
				setCarouselArrowTop();
			}
		});
		if (jQuery(window).width() <= 767) {
			setCarouselArrowTop();
		}
		if (jQuery(window).width() > 767) {
			setCarouselBoxBottom();
			jQuery("#myCarousel .left").css('top', '40%');
			jQuery("#myCarousel a.right").css('top', '40%');
		}
	}
}
function setCarouselArrowTop() {
	activeSlide = jQuery("#myCarousel div.carousel-inner div.active .container .carousel-caption").html();
	imageHeight = jQuery("#myCarousel div.carousel-inner div.active img").height();
	contenerHeight = jQuery("#myCarousel div.carousel-inner div.active .container .carousel-caption").height();
	activeSlide = jQuery.trim(activeSlide);
	arrowPosition = activeSlide == '' ? (imageHeight / 2) : imageHeight + (contenerHeight / 2);
	jQuery("#myCarousel .left").css('top', arrowPosition - 10);
	jQuery("#myCarousel a.right").css('top', arrowPosition - 10);
}
function setCarouselBoxBottom() {
	haveActive = jQuery("#myCarousel div.carousel-inner div.active img").length;
	haveContent = jQuery("#myCarousel div.carousel-inner div.active .container .carousel-caption").length;
	imageHeight = 0;
	contenerHeight = 0;
	if (haveActive) {
		imageHeight = jQuery("#myCarousel div.carousel-inner div.active img").height();
	}
	if (haveContent) {
		contenerHeight = jQuery("#myCarousel div.carousel-inner div.active .container .carousel-caption").height();
		paddingTop = parseInt(jQuery("#myCarousel div.carousel-inner div.active .container .carousel-caption").css("padding-top"));
		paddingBottom = parseInt(jQuery("#myCarousel div.carousel-inner div.active .container .carousel-caption").css("padding-bottom"));
	}
	if (imageHeight > 0 & contenerHeight > 0) {
		if (jQuery(window).width() < 1024) {
			boxPosition = (imageHeight - (contenerHeight + paddingTop + paddingBottom)) / 2;
			jQuery("#myCarousel div.carousel-inner div .container .carousel-caption").css('bottom', boxPosition);
		} else {
			jQuery("#myCarousel div.carousel-inner div .container .carousel-caption").css('bottom', '50px');
		}
	}
}

/**
 * Function for AJAX call
 */
function initPoll(action, pollAnswer, message) {
	var param = '';
	var actionPath = '';
	if (action != 'default') {
		actionPath = '&tx_weaba_poll[action]=' + action;
		if (action == 'ajaxAnswer') {
			if (pollAnswer > 0) {
				param = '&tx_weaba_poll[pollAnswer]=' + pollAnswer;
			} else {
				actionPath = '';
				var validation = false;
			}
		} else if (action == 'ajaxAdditionalAnswer') {
			param = pollAnswer;
			actionPath = '&tx_weaba_poll[action]=ajaxAnswer';
		}
	}

	jQuery.ajax({
		url: jQuery('#pollAjaxUrl a').attr('href') + '&type=1368790591' + actionPath + param,
		dataType: 'html',
		success: function (data) {
			jQuery('section#poll').html(data);

			// Display message on validation error
			if (validation == false) {
				alertContent = '<div class="alert alert-error"><button type="button" class="close" data-dismiss="alert">×</button>' + message + '</div>';
				jQuery(alertContent).insertAfter('.tx-we-aba div.modal-header');
				jQuery('.tx-we-aba .modal-footer #btnPollSubmit').attr('disabled', 'disabled');
			}

			// Call available actions
			initPollActions();
		}
	});
}
/*--------------- Merchant ---------------*/
/**
 * Merchant Location
 */
function initMerchant(city) {
	//jQuery('#merchant-filter-list').removeClass('hidden');
	$("#merchant-filter-list").fadeIn();
	jQuery('#merchant-list .span3').each(function (index) {
		merchantCity = jQuery(this).children('div.hidden').text();

		if (city == '0') {
			jQuery(this).removeClass('hidden');
			jQuery(this).addClass('merchants-active');
		} else {
			if (merchantCity == city) {
				jQuery(this).removeClass('hidden');
				jQuery(this).addClass('merchants-active');
			} else {
				jQuery(this).addClass('hidden');
				jQuery(this).removeClass('merchants-active');
			}
		}
	});
	jQuery('#merchant-list .merchants-active').each(function (index) {
		if (index % 4 == 0) {
			var rowFluid = document.createElement("div");
			rowFluid.setAttribute("class", "row-fluid");
			jQuery('#merchant-filter-list').append(rowFluid);
		}
		jQuery(this).clone().appendTo('#merchant-filter-list .row-fluid:last');
	});
	jQuery('#merchant-list').addClass("hidden");
	jQuery('.arrow-top').click(function () {
		moveItem(jQuery(this).siblings('.item'), true);
	});
	jQuery('.arrow-down').click(function () {
		moveItem(jQuery(this).siblings('.item'), false);
	});
	clickSeeOnMap();
}

function initPollActions() {
	// Onload disable the button and when an answer is chosen, enable the button and remove any alert message
	jQuery('.tx-we-aba input[name="tx_weaba_poll[pollAnswer][answerOption][__identity]"]').change(function () {
		jQuery('.tx-we-aba .modal-footer #btnPollSubmit').removeAttr('disabled');
		jQuery('.tx-we-aba .modal .alert-error').remove();
	});

	// Set radio for other option is checked whenever textarea is on focus
	jQuery('.tx-we-aba textarea#AdditionalAnswer').focus(function () {
		if (!jQuery('.tx-we-aba input#freeAnswer').is(':checked')) {
			jQuery('.tx-we-aba input#freeAnswer').trigger('click');
		}

		if ($.trim(jQuery(this).val()).length > 0) {
			jQuery('.tx-we-aba .modal-footer #btnPollSubmit').removeAttr('disabled');
			jQuery('.tx-we-aba .modal .alert-error').remove();
		} else {
			jQuery('.tx-we-aba .modal-footer #btnPollSubmit').attr('disabled', 'disabled');
		}

		jQuery(this).on('keyup', function () {
			if ($.trim(jQuery(this).val()).length > 0) {
				jQuery('.tx-we-aba .modal-footer #btnPollSubmit').removeAttr('disabled');
				jQuery('.tx-we-aba .modal .alert-error').remove();
			} else {
				jQuery('.tx-we-aba .modal-footer #btnPollSubmit').attr('disabled', 'disabled');
			}
		});
	});

	jQuery('.tx-we-aba label.radio.freetext, .tx-we-aba label.radio.freetext input[name="tx_weaba_poll[pollAnswer][answerOption][__identity]"]').on('click', function () {
		if ($.trim(jQuery('#poll .tx-we-aba textarea#AdditionalAnswer').val()).length > 0) {
			jQuery('.tx-we-aba .modal-footer #btnPollSubmit').removeAttr('disabled');
		} else {
			jQuery('.tx-we-aba .modal-footer #btnPollSubmit').attr('disabled', 'disabled');
		}
	});

	// Onclick on the submit button, call the ajax function to submit the answer
	jQuery('.tx-we-aba .modal-footer #btnPollSubmit').click(function () {
		jQuery(this).button('loading');
		/**
		 * @TODO this ajax submit should be re-factored for next improvement
		 */
		jQuery('.tx-we-aba input[name="tx_weaba_poll[pollAnswer][answerOption][__identity]"]:checked').each(function () {
			var value = jQuery(this).val();
			var action = 'ajaxAnswer';
			if (typeof jQuery(this).attr('id') !== 'undefined') {
				value = '&tx_weaba_poll[pollAdditionalAnswer]=' + $.trim(jQuery('.tx-we-aba textarea#AdditionalAnswer').val());
				action = 'ajaxAdditionalAnswer';
			}
			initPoll(
				action,
				value,
				jQuery('.tx-we-aba .modal-footer #message').text()
			);
		});
		return false;
	});

	// Onclick on the view result button, call the ajax function to view the result
	jQuery('.tx-we-aba .modal-footer #btnPollViewResults').click(function () {
		jQuery(this).button('loading');
		initPoll('showResults');
		return false;
	});

	// Onclick on the return button, call the ajax function to return to the poll
	jQuery('.tx-we-aba .modal-footer #btnPollReturn').click(function () {
		jQuery(this).button('loading');
		initPoll('show');
		return false;
	});
}

/*### Scroll Top ###*/
function goTop() {
	jQuery('html, body').animate({scrollTop: 30}, '200');
}

/* ### CALCULATOR OF THE CURRENCY CONVERTOR ##*/
function calculateCurrency(currency, from, to) {
	var amount = ((jQuery('.tx-we-aba .amount-value').val() == '') || (jQuery('.tx-we-aba .amount-value').val() == '.')) ? 0 : parseFloat(jQuery('.tx-we-aba .amount-value').val());
	var result = '0';
	var name = '';
	var rate1 = '';
	var rate2 = '';
	for (var i = 0; i < currency.length; i++) {
		if ((currency[i].sym_from == from) && (currency[i].sym_to == to)) {
			result = currency[i].cur_avg * amount;
			rate1 = 'Rate: <span>' + 1 + currency[i].sym_from + ' => ';
			rate2 = thousandSepator(currency[i].cur_avg) + currency[i].sym_to + '</span>';
		}
	}
	jQuery('.result-value').attr('value', thousandSepator((Math.round(result * 100) / 100).toFixed(2)));
	rateValue(rate1, rate2);
	return;
}

function thousandSepator(nStr) {
	nStr += '';
	nStr.replace(/[^.\d]/, '');
	var x = nStr.split('.');
	var x1 = x[0];
	var x2 = (x.length > 1) ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}

/* ### RATE OF CURRENCY ##*/
function rateValue(val1, val2) {
	jQuery('.tx-we-aba form p.text-success').html(val1 + val2);
	return;
}

/* ### Slide show news  */
if (jQuery("#myCarousel_teaser").length) {
	jQuery('#myCarousel_teaser').carousel({
		interval: jQuery('#latest-slideshow-speed').text()
	});
	jQuery('#myCarousel_teaser .description p').hide();
	if (jQuery.support.touch) {
		var device = navigator.userAgent.toLowerCase();
		if (!device.match(/android/)) {
			jQuery('#myCarousel_teaser .item').hover(function () {
				window.location = jQuery(this).children('a').attr('href');
			});
		}
	} else {
		jQuery('#myCarousel_teaser .item').hover(
			function () {
				description = jQuery(this).children('.description');
				description.children('p').slideDown();
				description.children(".header").children('i').removeClass('box-arrow-up');
				description.children(".header").children('i').addClass('box-arrow-down');
			}, function () {
				description = jQuery(this).children('.description');
				description.children('p').stop().slideUp();
				description.children(".header").children('i').removeClass('box-arrow-down');
				description.children(".header").children('i').addClass('box-arrow-up');
			});
	}

	jQuery('#myCarousel_teaser .item').click(
		function () {
			document.location.href = jQuery(this).children('#link-to-detail').attr('href');
		}
	);
	if (jQuery("#myCarousel_teaser .carousel-inner .item").length > 1) {
		jQuery('#myCarousel_teaser').hover(function (e) {
			jQuery(this).children('.carousel-control.left').css('display', 'block');
			jQuery(this).children('.carousel-control.right').css('display', 'block');
		}, function () {
			jQuery('.carousel-control.left').css('display', 'none');
			jQuery('.carousel-control.right').css('display', 'none');
		});
	}
}

/* ### Teaser Box Home Page*/
if (jQuery('.body-teaser-box').length) {
	jQuery('.body-teaser-box').click(function () {
		if (jQuery(this).children('span.hidden').length) {
			window.location = jQuery(this).children('span.hidden').children('a').attr('href');
		}
	});
}

if (jQuery('.body-teaser-box .description').size() > 0) {
	jQuery('.body-teaser-box .description p').hide();
	if (!jQuery.support.touch) {
		jQuery('.body-teaser-box ').hover(
			function () {
				description = jQuery(this).children('.description');
				description.children('p').slideDown();
				description.children(".header").children('i').removeClass('box-arrow-up');
				description.children(".header").children('i').addClass('box-arrow-down');
			}, function () {
				description = jQuery(this).children('.description');
				description.children('p').stop().slideUp();
				description.children(".header").children('i').removeClass('box-arrow-down');
				description.children(".header").children('i').addClass('box-arrow-up');
			}
		);
	}
}
/* ### Teaser Box Home Page END*/

/* align menu */
function alignMenuItems() {
	var totEltWidth = 0;
	var menuWidth = $('#main_nav')[0].offsetWidth;
	var availableWidth = 0;
	var space = 0;

	var elts = $('#main_nav > li > a');
	elts.each(function (inx, elt) {
		// reset paddding to 0 to get correct offsetwidth
		$(elt).css('padding-left', '0px');
		$(elt).css('padding-right', '0px');

		totEltWidth += elt.offsetWidth;
	});
	availableWidth = menuWidth - totEltWidth;
	space = Math.floor(availableWidth / (elts.length * 2));
	var space_mod = availableWidth % (elts.length * 2);

	elts.each(function (inx, elt) {
		if (space_mod > 0) {
			jQuery(elt).css('padding-left', space - 1 + 'px');
			space_mod = space_mod - 1;
		} else {
			jQuery(elt).css('padding-left', space - 2 + 'px');
		}
		if (space_mod > 0) {
			jQuery(elt).css('padding-right', space - 1 + 'px');
			space_mod = space_mod - 1;
		} else {
			jQuery(elt).css('padding-right', space - 2 + 'px');
		}
	});

	var url =  $(location).attr('href');
	var arUrl = url.split('/');
	if(arUrl.length > 3 && arUrl[3] == 'km'){
		elts.each(function (inx, elt) {
			$(elt).css('padding-left', '28px');
			$(elt).css('padding-right', '28px');
		});
	}else{
		elts.each(function (inx, elt) {
			$(elt).css('padding-left', '23px');
			$(elt).css('padding-right', '23px');
		});
	}
}

function moveItem(element, up) {
	length = element.length;
	if (up) {
		for (var i = 0; i < length; i++) {
			if (jQuery(element[i]).hasClass('active')) {
				if (i > 0) {
					jQuery(element[i - 1]).addClass('active');
				} else {
					jQuery(element[length - 1]).addClass('active');
				}
				jQuery(element[i]).removeClass('active');
				break;
			}
		}
		;
	} else {
		for (var i = 0; i < length; i++) {
			if (jQuery(element[i]).hasClass('active')) {
				if (i == (length - 1)) {
					jQuery(element[i]).removeClass('active');
					jQuery(element[0]).addClass('active');
				} else {
					jQuery(element[i]).removeClass('active');
					jQuery(element[i + 1]).addClass('active');
				}
				break;
			}
		}
		;
	}
}

var maps;
var activeMarker;
var infoWindow;
/* LOAD THE MAP*/
function loadMap() {
	function initialize() {
		var mapOptions = {
			zoom: 17,
			center: new google.maps.LatLng(11.9893, 105.46342),
			disableDefaultUI: true,
			mapTypeId: google.maps.MapTypeId.ROADMAP
		};
		maps = new google.maps.Map(document.getElementById('merchantMap'), mapOptions);
		maps.set('styles', [{
			featureType: 'road',
			elementType: 'labels',
			stylers: [{
				visibility: 'off'
			}]
		}, {
			featureType: 'road.local',
			elementType: 'labels',
			stylers: [{
				visibility: 'on'
			}]
		}, {
			featureType: 'road.highway',
			elementType: 'labels',
			stylers: [{
				visibility: 'on'
			}]
		},
			{
				featureType: 'poi',
				elementType: 'labels',
				stylers: [{
					visibility: 'off'
				}]
			}]);

		clickSeeOnMap();

		var img_atm = '../typo3conf/ext/boxmodel/Resources/Private/Templates/ABA/images/atm-marker.png';
		var img_branch = '../typo3conf/ext/boxmodel/Resources/Private/Templates/ABA/images/aba-marker.png';
		setMarkerArray(atm_markers, img_atm, maps);
		setMarkerArray(branch_markers, img_branch, maps);
	}

	jQuery('#merchantMap').css({height: innerHeight - 60, width: innerWidth - 60});
	google.maps.event.addDomListener(window, 'load', initialize);
	jQuery(window).resize(function () {
		jQuery('#merchantMap').css({height: innerHeight - 60, width: innerWidth - 60});
		google.maps.event.addDomListener(window, 'load', initialize);
	});
}

/* SEE ON THE CLICK ACTION SETTING ON COLOR BOX */
function clickSeeOnMap() {
	jQuery('.tx-we-aba .footer span').click(function () {
		var latlng = jQuery(this).parent().siblings('.active').attr('data-latlng').split(',');
		var icon = jQuery(this).parent().siblings('.title').attr('data-logo');
		var contentData = jQuery(this).parent().parent();
		header = '';
		if (contentData.children('.header').length) {
			header = '<div class="header">' + contentData.children('.header').html() + '</div>'
		}
		var content = '<div class="teaser-point">' + header + '<div class="title">' + contentData.children('.title').html() + '</div><div class="description item active">' + contentData.children('.active').html() + '</div></div>';
		activeMarker.setMap(null);
		var position = new google.maps.LatLng(latlng[0] * 1, latlng[1] * 1);
		marker = new google.maps.Marker({
			position: position,
			icon: '/uploads/tx_weaba/' + icon,
			map: maps
		});

		google.maps.event.addListener(marker, 'click', function () {
			infoWindow.setOptions({content: content, position: position, maxWidth: contentData.width()});
			infoWindow.open(maps, marker);
			maps.setZoom(17);
			maps.setCenter(marker.getPosition());
		});
		activeMarker = marker;
		height = jQuery('#merchantMap').height();
		width = jQuery('#merchantMap').width();
		jQuery.colorbox({
			href: "#merchantMap",
			inline: true,
			width: width + 15,
			height: height,
			scrolling: false,
			onComplete: function () {
				maps.setCenter(position);
				maps.setZoom(17);
				infoWindow.setOptions({content: content, position: position, maxWidth: contentData.width()});
				infoWindow.open(maps, activeMarker);
			}
		});
	});
}

function setMarkerArray(markers, image, map) {
	var title;
	var temp;
	for (var i = 0; i < markers.length; i++) {
		title = markers[i]['title'];
		markers[i]['title'] = setMarker(markers[i]['title'], markers[i]['lat'],
			markers[i]['lng'], image, title, map);
		addMessage(markers[i]['title'], '<span class="text-info">' + markers[i]['title'].title + '</span>.<br /><address>' + markers[i]['address'] + '</address>' + markers[i]['open'] + '<br />' + markers[i]['contact'] + '<br /><a target="_blank" href="/contact-support/feedback-form/">contact</a>',
			markers[i]['zone'], map);
	}
}

function setMarker(name, lat, lng, image, title, map) {
	name = new google.maps.Marker({
		position: new google.maps.LatLng(lat, lng),
		map: map,
		icon: image,
		title: title
	});
	return name;
}

function addMessage(marker, message, zone, map) {
	google.maps.event.addListener(marker, 'click', function () {
		infoWindow.setContent(message);
		infoWindow.open(map, marker);
		map.setCenter(marker.getPosition());
		map.setZoom(17);
	});
}

function setMerchantBackground() {
	image = jQuery('body').css('backgroundImage');
	color = jQuery('body').css('backgroundColor');
	height = 'no-repeat center ' + (jQuery('#myCarousel .item.active').height() + jQuery('.navbar.navbar-inverse').height()) + 'px';
	jQuery('body').css('background', color + ' ' + image + height);
}

$(function () {

	var id = $('#accordion li ul li.current').attr('id');
	$('#accordion li ul#child' + id).addClass('in');

	$('#accordion').on('show.bs.collapse', function () {
		$('#accordion .in').collapse('hide');
	});
	// crop text in mobile
	if (window.screen.availWidth <= 480) {
		$('.item .text-in-box').each(function () {
			var p = $(this).contents().first().text();
			$(this).contents().first().text(p.substring(0, 110));
		});
		$('.item .text-in-box a').removeAttr('class');
	}

	// Formhandler
	$('#selectTypeOfFeedback').change(function () {
		if ($(this).val() == 'Complaint') {
			$('#branch-hidden').removeClass('branch-hidden');
		} else {
			$('#branch-hidden').addClass('branch-hidden');
			$('#selectWhichBranch').val(0);
		}
	});

	if ($('#selectTypeOfFeedback').val() == 'Complaint') {
		$('#branch-hidden').removeClass('branch-hidden');
	}

	//@TODO: update pop up message
	$('.btn-popup-link').on('click', function () {
		//var url = window.location;
		//console.log(url.parseQuery);
		//var fullUrl = url.protocol + "//" + url.host + $(this).attr('href');
		if ($(this).attr('href') != '') {
			$.ajax({
				url: $(this).attr('href'),
				type: 'GET',
				dataType: 'html',
				beforeSend: function () {
					$('body').append('<div class="loading-overlay"></div><div class="loader"></div>');
				},
				success: function (data) {
					var html = '';
					if (data != '') {
						var height = $(window).height() - 2;
						//$('#popup_card_type').height(height);
						//$('#popup_card_type .modal-body').height((height - 72));
						$('.modal-card-type .modal-body').css("height","auto");
						var temp = $(data);
						html = temp.find('#left_content > div').html();
						var title = temp.find('#left_content > h1').html();
						$('#myModalLabel').html(title);
						$('#popup_card_type .modal-body').html(html);
						$('.tab-pane').eq(0).addClass('active');
						$('#popup_card_type').modal('show');
						$('body').addClass('fixed-position');
					}
				},
				complete: function () {
					$('body').find('.loader').remove();
					$('.loading-overlay').animate({opacity: 0});
				},
				error: function () {
					$('body').find('.loader').remove();
					$('.loading-overlay').animate({opacity: 0});
				}
			});
		}
		return false;
	});
	/*$('#popup_card_type .modal-body').enscroll({
	 showOnHover: false,
	 verticalTrackClass: 'track3',
	 verticalHandleClass: 'handle3',
	 zIndex: 1,
	 scrollIncrement: 100
	 });*/
	$('#popup_card_type').on('hide.bs.modal', function (e) {
		$('.loading-overlay').remove();
		$('body').removeClass('fixed-position');
	});

	// open account popupfunction
	function getOpaoAgreeTerm() {
		if ($('input[type="radio"].with-gap.aba-classic-radio:checked').val() == "on") {
			return true;
		}
		else {
			return false;
		}
	}

	function setOpaoButtonBg() {
		if (!getOpaoAgreeTerm()) {
			$('.modal.modal-legibility.no-padding .row.no-margin.no-padding a.btn.waves-effect.btn-open-account.get-start').addClass("opao-disable-btn");
		}
		else {
			$('.modal.modal-legibility.no-padding .row.no-margin.no-padding a.btn.waves-effect.btn-open-account.get-start').removeClass("opao-disable-btn");
		}
	}


	$('input[type="radio"].with-gap.aba-classic-radio').click(function () {
		setOpaoButtonBg();
	});

	$("#opao_header_btn.header-btn-action, #opao_header_btn_bt.header-btn-action").click(function () {
		$(".modal.modal-legibility.no-padding").fadeIn("fast");
		$("body").css("overflow", "hidden");
		$("<span><span class='opao-rd-inside'></span></span>").insertBefore(".fixed-height.user-accept-condition label p");
		setOpaoButtonBg();
	});

	$('.modal.modal-legibility.no-padding .row.no-margin.no-padding a.btn.waves-effect.btn-open-account.get-start').click(function (e) {
		if (!getOpaoAgreeTerm()) {
			e.preventDefault();
		}
	});

	$(".modal.modal-legibility.no-padding .row.no-margin.no-padding .close-button.image-red.modal-close").click(function () {
		$("body").css("overflow", "auto");
		$(".modal.modal-legibility.no-padding").fadeOut("fast");
		$(".fixed-height.user-accept-condition label span").remove();
	});
	// End open account popup


});
function modalAnim(x) {
	$('.modal .modal-dialog').attr('class', 'modal-dialog  ' + x + '  animated');
};
$(document).ready(function () {
	/*if( navigator.userAgent.toLowerCase().indexOf('firefox') > -1 && navigator.userAgent.toLowerCase().indexOf('chrome') > -1){
		$('.modal-card-type .modal-header>.close').css({
			'padding':'5px 15px 1px 15px !important',
			'line-height':'34px'
		});
	}else{

	}*/
	var url = window.location.href;
	var href = url.split('#');
	if (href.length == 2) {
		setTimeout(function () {
			$.each($('a[href="#' + href[1] + '"]').parent().parent().children(), function (index, value) {
				$(this).removeClass('active');
			});
			$.each($('#' + href[1]).parent().children(), function () {
				$(this).removeClass('in active');
			});
			$('a[href="#' + href[1] + '"]').parent().addClass('active');
			$('#' + href[1]).addClass('in active');
		}, 1000);
		setTimeout(function () {
			var height = 0;
			if(typeof $('.video-container').position() != 'undefined'){
				height = $('.video-container').outerHeight() + 70;
			}
			if(typeof $('a[href="#' + href[1] + '"]').parent().parent().position() != 'undefined'){
				$('body,html').animate({
					scrollTop: $('a[href="#' + href[1] + '"]').parent().parent().position().top + height
				}, 1000);
			}
		}, 1500);
	}
});

function explode (delimiter, string, limit) {
	//  discuss at: http://locutus.io/php/explode/
	// original by: Kevin van Zonneveld (http://kvz.io)
	//   example 1: explode(' ', 'Kevin van Zonneveld')
	//   returns 1: [ 'Kevin', 'van', 'Zonneveld' ]

	if (arguments.length < 2 ||
		typeof delimiter === 'undefined' ||
		typeof string === 'undefined') {
		return null
	}
	if (delimiter === '' ||
		delimiter === false ||
		delimiter === null) {
		return false
	}
	if (typeof delimiter === 'function' ||
		typeof delimiter === 'object' ||
		typeof string === 'function' ||
		typeof string === 'object') {
		return {
			0: ''
		}
	}
	if (delimiter === true) {
		delimiter = '1'
	}

	// Here we go...
	delimiter += ''
	string += ''

	var s = string.split(delimiter)

	if (typeof limit === 'undefined') return s

	// Support for limit
	if (limit === 0) limit = 1

	// Positive limit
	if (limit > 0) {
		if (limit >= s.length) {
			return s
		}
		return s
			.slice(0, limit - 1)
			.concat([s.slice(limit - 1)
				.join(delimiter)
			])
	}

	// Negative limit
	if (-limit >= s.length) {
		return []
	}

	s.splice(s.length + limit)
	return s
}


jQuery('head').prepend("<!-- Google Tag Manager --><script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],"+
						"j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src="+
						"'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);"+
						"})(window,document,'script','dataLayer','GTM-NGX6JMQ');</script><!-- End Google Tag Manager -->");

jQuery('body').prepend('<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-NGX6JMQ"'+
+'height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>');

jQuery(document).ready(function() {
	/* ---- Start main navigation scrolling ---- */
	if (jQuery(window).width() >= 1024) {
		var scrolling = false;
		jQuery('.navbar .logo-scrolling').addClass('hidden');
		jQuery(window).scroll(function(){
			var height = jQuery(window).scrollTop();
			if (height >= 125) {
				scrolling = true;
				jQuery('.main-nav').addClass('navbar-fixed-top');
				jQuery('.main-nav li.initial').removeClass('first');
				jQuery('.main-nav .hidden-scrolling').hide();
				jQuery('.main-nav .nav-meta').hide();
				jQuery('.main-nav .logo-scrolling').stop().animate({
					opacity: 1,
					marginLeft: 0,
				}, 600).removeClass('hidden');
			} else {
				if (scrolling) {
					if (jQuery('.main-nav').hasClass('navbar-fixed-top')) {
						jQuery('.main-nav').removeClass('navbar-fixed-top');
					}
					jQuery('.main-nav .logo-scrolling').stop().animate({
						opacity: 0,
						marginLeft: -155
					},{
						duration: 0,
						complete: function() {
							jQuery(this).addClass('hidden');
							jQuery('.main-nav li.initial').addClass('first');
							jQuery('.main-nav .nav-meta').show();
							jQuery('.main-nav .hidden-scrolling').show();
						}
					});
				}
			}
		});
	}
});

jQuery('.t3colorbox').colorbox({opacity:false,current:"{current} of {total}",previous:"previous",next:"next",close:"close",slideshowStart:"Start Slideshow",slideshowStop:"Stop Slideshow",slideshowAuto:false,maxWidth:"95%",maxHeight:"95%",rel:"t3colorbox",})