﻿(function ($, window) {
	/*
	* Library Copyright StudioForty9
	* http://www.studioforty9.com
	*/
	
	$.bank = {
		external: function (settings) {
			var hostname = window.location.hostname, options = $.extend({
				selector: 'a'
			}, settings);
			if (typeof settings === 'string') { options.selector = options; }
			hostname = hostname.replace('www.', '').toLowerCase();
			return $(options.selector).each(function () {
				if ($(this).attr('href') !== undefined) {
					var href = $(this).attr('href').toLowerCase();
					if (href.indexOf('http://') !== -1 && href.indexOf(hostname) === -1) {
						$(this).attr('target', '_blank');
						$(this).addClass('external');
					}
				}
			});
		},
		popup: function (options) {
			var defaults = {
				selector: '.popup',
				popupId: 'bank_popup',
				preloadText: 'Loading...',
				errorText: 'There has been a problem with your request, please click outside this window to close it.',
				closeText: 'Close',
				prevText: '&laquo; Previous',
				nextText: 'Next &raquo;'
			};
			if (typeof options == 'string') defaults.selector = options;
			var options = $.extend(defaults, options);
			return $(options.selector).each(function (i) {
				if ($(this).hasClass('gallery')) {
					var classNames = $(this).attr('class');
					classNames = classNames.split(' ').join('');
					$.data(this, 'gallery', classNames);
					eval('if((typeof ' + classNames + '_arr == "undefined")) ' + classNames + '_arr= new Array()');
					eval(classNames + '_arr').push($(this));
					$.data(this, 'index', eval(classNames + '_arr').length - 1)
				};
				$(this).bind('click', function (e) {
					e.preventDefault();
					if ($.browser.opera) $.support.opacity = true;
					var ie6 = $.browser.msie && $.browser.version.substr(0, 1) < 7;
					var opera95 = $.browser.opera && $.browser.version <= 9.5;
					var w = $(window).width();
					var h = $(document).height();
					var w2 = $(window).width() / 2;
					var h2 = $(window).height() / 2;
					show = function () {
						$('#' + options.popupId + 'preloader').remove();
						if (cw != 0) $('#' + options.popupId + 'content').css('width', cw + 'px');
						if (ch != 0) $('#' + options.popupId + 'content').css('height', ch + 'px');
						set($('#' + options.popupId + 'content'));
						$('#' + options.popupId + 'content').css('visibility', 'visible')
					};
					set = function (obj) {
						$(obj).css({
							'border-radius' : '7px',
							'padding': '12px',
							'background': '#fff',
							'color': '#333',
							'text-align': 'left',
							'float': 'left',
							'position': 'fixed',
							'z-index': '10001',
							'visible': 'hidden'
						});
						var left = w2 - $(obj).width() / 2;
						var top = h2 - $(obj).height() / 2;
						$(obj).css({
							'left': left,
							'top': top,
							'display': 'none'
						}).fadeIn('1000');
						if (ie6) $(obj).css({
							'position': 'absolute',
							'top': (top + $(window).scrollTop()) + 'px'
						});
						if (opera95) $(obj).css({
							'position': 'absolute',
							'top': (document.body['clientHeight'] / 2 - $(obj).height() / 2 + $(window).scrollTop()) + 'px'
						});
						$('.caption', obj).css({
							'width': $(obj).width() + 'px',
							'display': 'block'
						})
					};
					if (ie6) $('embed, object, select').css('visibility', 'hidden');
					error = function () {
						$('#' + options.popupId + 'content').text(options.errorText);
						show()
					};
					remove = function () {
						$('#' + options.popupId).remove();
						$('#' + options.popupId + 'content').remove();
						$('#' + options.popupId + 'preloader').remove();
						if (ie6) $('embed, object, select').css('visibility', 'visible')
					};
					if ($('#' + options.popupId).length == 0) {
						$('<div id="' + options.popupId + '"></div>').appendTo('body').css({
							'width': w,
							'height': h,
							'background': '#000',
							'position': 'absolute',
							'top': '0',
							'left': '0',
							'z-index': '10000',
							'opacity': .7
						}).click(function () {
							remove()
						})
					};
					var href = $(this).attr('href');
					var extension = href.substr(href.lastIndexOf('.')).toLowerCase();
					var content;
					var cw = 0;
					var ch = 0;
					var showOk = false;
					$('<div id="' + options.popupId + 'preloader">' + options.preloadText + '</div>').appendTo('body');
					set($('#' + options.popupId + 'preloader'));
					$('<div id="' + options.popupId + 'content"></div>').appendTo('body');
					$('#' + options.popupId + 'content').css({
						'visibility': 'hidden',
						'position': 'absolute',
						'top': '-10000px',
						'left': '-10000px'
					});
					if ($(this).hasClass('flash')) {
						var flash = '<object width="100%" height="100%"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="' + href + '" /><embed src="' + href + '" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="100%" height="100%"></embed></object>';
						$(flash).appendTo('#' + options.popupId + 'content');
						cw = 600;
						ch = 400;
						showOk = true
					} else {
						if (extension == '.jpg' || extension == '.jpeg' || extension == '.gif' || extension == '.png' || extension == '.bmp') {
							var img = new Image();
							$(img).error(function () {
								error()
							}).appendTo('#' + options.popupId + 'content');
							img.onload = function () {
								show();
								$imageTop = '-' + this.height/2 - 32 + 'px';
								$('.gallery-btn').css('top', $imageTop);
								$imageLeft = this.width + 17 + 'px';
								$('#gallery-next').css('left', $imageLeft);
								img.onload = function () {}
							};
							img.src = href + '?' + (new Date()).getTime() + ' =' + (new Date()).getTime()
						} else if (href.charAt(0) == '#') {
							$(href).clone().removeClass('hidden').appendTo('#' + options.popupId + 'content').show();
							$.jssp.forms('#' + options.popupId + 'content form');
							showOk = true
						} else {
							$('<iframe frameborder="0" scrolling="auto" style="width:100%;height:100%" src="' + href + '" />').appendTo('#' + options.popupId + 'content');
							cw = 900;
							ch = 500;
							showOk = true
						}
					};
					var rel = $(this).attr('rel').split(';');
					$.each(rel, function (i) {
						if (rel[i].indexOf('width') != -1) cw = rel[i].split(':')[1];
						if (rel[i].indexOf('height') != -1) ch = rel[i].split(':')[1]
					});
					if ($(this).attr('title') != '') {
						$('<span class="caption">' + $(this).attr('title') + '</span>').appendTo('#' + options.popupId + 'content').css({
							'display': 'none',
							'padding': '10px 0 0 0',
							'text-align' : 'center',
							'font-size' : '1.6em'
						})
					};
					if (showOk) show();
					$('<small>' + options.closeText + '</small>').appendTo('#' + options.popupId + 'content').css({
						'position': 'absolute',
						'float': 'left',
						'right': '-8px',
						'color': '#fff',
						'cursor': 'pointer',
						'height': '24px',
						'top' : '-14px',
						'width': '24px'
					}).click(function () {
						remove()
					});
					if ($(this).hasClass('gallery')) {
						var arr = $.data(this, 'gallery');
						arr = eval(arr + '_arr');
						var index = $.data(this, 'index');
						if (arr.length > 1) {
							$('<small>' + (index + 1) + '/' + arr.length + '</small>').appendTo('#' + options.popupId + 'content').css({
								'position': 'absolute',
								'float': 'right',
								'font-size' : '1.3em',
								'right': '10px',
								'bottom': '10px',
								'color': '#000',
								'z-index' : '10002'
							});
							$('<small id="' + options.popupId + 'gallery"></small>').appendTo('#' + options.popupId + 'content').css({
								'position': 'absolute',
								'cursor': 'pointer'
							});
							if (index != 0) {
								$('<span id="gallery-prev" class="gallery-btn">' + options.prevText + '</span>').css({
								'position': 'absolute',
								'float': 'left',
								'right': '17px'
								}).appendTo('#' + options.popupId + 'gallery').click(function () {
									$('#' + options.popupId + 'content').remove();
									var obj = arr[index - 1];
									$(obj).trigger('click')
								})
							}
							if (index < arr.length - 1) {
								$('<span id="gallery-next" class="gallery-btn">' + options.nextText + '</span>').css({
								'position': 'absolute'
								}).appendTo('#' + options.popupId + 'gallery').click(function () {
									$('#' + options.popupId + 'content').remove();
									var obj = arr[index + 1];
									$(obj).trigger('click')
								})
							}
						}
					}
				})
			})
		}
	};
}(jQuery, this));
$(document).ready(function() {
	$.bank.external();
	$.bank.popup({
		preloadText: '<img src="http://www.thebankcasino.com/wp-content/themes/bank/assets/img/ajax-loader.gif" />',
		closeText: '<img src="http://www.thebankcasino.com/wp-content/themes/bank/assets/img/bg-close.png" width="24px" height="24px" />'
	});
	$('#sidebar .facebook-comment:last').addClass('last');
	$('#main-content .facebook-comment:last').addClass('last');
	if($('body').hasClass('110')) { load();}
	
	
});
