/**
* xlightbox Plugin
* 
* Copyright (c) 2016 Zul Zolkaffly
* Version: 1.0.0 (01/11/2015) (DD/MM/YYYY)
* Minimum Requirement:
*		-	jQuery v1.12.1
* ----------------------------------------------------------------------
* FILE		   	: xlightbox.js
* VERSION     : 1.0.0
* DATE				: 2015-11-01 (YYYY-MM-DD)
* AUTHOR      : Zul Zolkaffly
* CONTACT			: mohammad.zulfadhli.zolkaffly@gmail.com
* LICENSE     : GNU-LGPL v3 (http:*www.gnu.org/copyleft/lesser.html)
* ----------------------------------------------------------------------
* Copyright (C) 2015 [ ZUL ZOLKAFFLY ]
* ----------------------------------------------------------------------
*
* xlightbox is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* xlightbox is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with xlightbox.  If not, see <http:*www.gnu.org/licenses/>.
* ----------------------------------------------------------------------
* DISCLAIMER:
*  XLIGHTBOX IS A JQUERY PLUGIN FOR IMAGE GALLERY LIGHTBOX
*  THIS FILE, ALONG WITH REST OF XLIGHTBOX PROJECT FILES ARE A PART OF
*  THE INTELLECTUAL PROPERTIES OF ZUL ZOLKAFFLY.
*  ANY USE OF THIS FILE AND ANY FILE FROM THE PROJECT XLIGHTBOX IS WITHIN
*  YOUR OWN CONSENT. ANY MISCONDUCT, MISUSE, HARMS, INJURIES
*  AND ANY KIND OF UNDESIRABLE SITUATION, IN ANY TYPES AND WAYS
*  SHOULD NOT BE REFERRED TO THE ORIGINAL AUTHOR, AND THE ORIGINAL AUTHOR
*	 SHOULD NOT BE HELD RESPONSIBLE FOR IT, IN ANY LEGAL OR ILLEGAL CONSEQUENCES
*  OR ACTIONS, FINANCIALLY, PHYSICALLY OR ANY OTHER WAYS MEANT FOR
*  DIRECT OR INDIRECT PUNISHMENTS OR PAYMENTS FOR AND TO THE
*  ORIGINAL AUTHOR. ANY USE OF THIS FILE AND ANY FILE
*  FROM THE PROJECT XLIGHTBOX SHOULD ALWAYS INCLUDE A FILE NAMED
*  <XLIGHTBOX_LICENSE_AND_DISCLAIMER.txt>. YOU MAY MODIFY ANY PART OF
*  THIS FILE OR ANY FILE FROM THE PROJECT XLIGHTBOX ACCORDING TO YOUR
*  REQUIREMENTS AND NEEDS. HOWEVER, THIS FILE AND ANY FILE FROM
*  THE PROJECT SHOULD NOT BE CLAIMED AS BELONG TO YOU, YOUR TEAM,
*  ORGANIZATION OR ANY PARTY OTHER THAN THE ORIGINAL AUTHOR AND
*  HIS TEAM. ANY CLAIM OF OWNAGE OTHER THAN THE ORIGINAL AUTHOR
*  IS A SERIOUS OFFENSE OF HUMAN RIGHTS AND RESPECT.
* ----------------------------------------------------------------------
*/

function XLightbox_Init(options) {
	$('[data-toggle="xlightbox"]').off('click').on('click',function() {
		$(this).xlightbox(options);
	});
}

(function($){
	function XLightbox() {
		// DEFAULT OPTIONS
		_defaults = {
			info: {
				show: true,
				title: true,
				caption: true,
				ajax: false,
				url: null
			},
			thumb: {
				show: false,
				createforvideo: false,
				location: 'none'
			},
			theme: {
				file: null,
				name: null
			},
			preSelect: $.noop(),
			onSelect: $.noop()
		};
		
		var self = this;
		var target = null;
		var inst = null;
		var detail = null;
		
		_reinit = function($target, setting) {			
			_closeBox();
			
			inst = _createInstance($target, setting);
			target = $target;
			detail = _getItemInfo(target);			
			target.data('_xlb_inst', inst);
			
			_callback(target,'pre');	
			
			_createBox(target);	
			_initTheme(target);	
			_insertContent(target, detail);
			_attachHandler(target);		
			
			if(detail['gallery']) _navVisibility(detail['count'], detail['index']);
				
			_showBox(target);
			
			_callback(target);			
			
			return self;
		};		
		
		_createInstance = function($target, setting) {
			var seq = (_xlb_inst.length)+1;
				_xlb_inst.push(seq);	
				
			var s = $.extend({}, _defaults||{}, setting||{});
					s = _validateOptions($target, s);
					
			var inst = {
				seq: seq,
				setting: s
			};
			
			return inst;
		};
		
		_validateOptions = function($target, setting) {
			return setting;
		};
						
		_getItemInfo = function ($target) {
			var $title = $target.find('.xlightbox-title'),
					$src = $target.find('.xlightbox-src'),
					$caption = $target.find('.xlightbox-caption');
					
			var id = $.trim($target.attr('id'));
				if(!id) {
					id = this._createRandomID();
					$target.attr('id',id);
				}					
			var gallery = $.trim($target.data('gallery'));
					gallery = (!gallery) ? null : gallery;					
			var src = $.trim($src.attr('src'));
					src = (!src) ? null : src;	
			var title = $.trim($title.html());
					title = (!title) ? $.trim($title.val()) : title;
					title = (!title) ? null : title;
			var caption = $.trim($caption.html());
					caption = (!caption) ? $.trim($caption.val()) : caption;
					caption = (!caption) ? null : caption;
		
			var count = $('[data-toggle="xlightbox"][data-gallery="'+gallery+'"]').length;
			var index = $target.index('[data-toggle="xlightbox"][data-gallery="'+gallery+'"]');
					
			return {
				id : id,
				gallery : gallery,
				src : src,
				title : title,
				caption : caption,
				count : count,
				index : index
			};
		};
		
		_createRandomID = function() {
			var id = "";
			
			var getid = function() {
				var an = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
				var id = "";
				for( var i=0; i < 5; i++ ) id += an.charAt(Math.floor(Math.random() * an.length));
				return id;
			}
			
			var exists = false;
			do {
				id = getid();
				
				var $e = $('body').find('#'+id);
				if($e.length) exists = true;
				
			} while (exists == true);

			return id;
		};
		
		_createBox = function($target) {
			var data = $target.data();
			var setting = $target.data('_xlb_inst').setting;
			
			var $box = $('<div />',{ 'class' : 'xlightbox', 'id' : 'xlightbox' });	
			var $dialog = $('<div />',{ 'class' : 'box-dialog' });	
			var $content = $('<div />',{ 'class' : 'box-content' });
			
			var $media = $('<div />',{ 'class' : 'box-media' });
			var $navleft = $('<button />', { 'class' : 'box-nav-left hidden' });
			var $navarrowleft = $('<div />',{ 'class' : 'box-arrow' }).html('<span></span><span></span>');
			var $navright = $('<button />', { 'class' : 'box-nav-right hidden' });		
			var $navarrowright = $('<div />',{ 'class' : 'box-arrow' }).html('<span></span><span></span>');
			
			var $info = $('<div />',{ 'class' : 'box-info' });
			var $title = $('<h4 />',{ 'class' : 'box-title' });
			var $caption = $('<p />',{ 'class' : 'box-caption' });
			var $other = $('<p />',{ 'class' : 'box-other' });
			
			var $close = $('<button />', { 'class' : 'box-close' }).html('<span></span><span></span>');	
			
			var showinfo = (data.hasOwnProperty('infoShow')) ? data.infoShow : setting.info.show;
			if(!showinfo) {
				$info.addClass('hidden');
				$media.addClass('full');
				$content.css('height','auto');
			}
			var capt = (data.hasOwnProperty('infoCaption')) ? data.infoCaption : setting.info.caption;
			var title = (data.hasOwnProperty('infoTitle')) ? data.infoTitle : setting.info.title;
			if(!capt) $caption.addClass('hidden');
			if(!title) $title.addClass('hidden');
			
			var thumbShow = (data.hasOwnProperty('thumbShow')) ? data.thumbShow : setting.thumb.show;
			var thumbLoc = (thumbShow) ? (data.hasOwnProperty('thumbLocation')) ? $.trim(data.thumbLocation.charAt(0).toUpperCase()) : $.trim(setting.thumb.location.chartAt(0).toUpperCase()) : 'N';
			
			var $thumb = $('<div />', { 'class' : 'box-thumb '+ thumbLoc.toLowerCase() });
			if(thumbLoc != 'N') $dialog.addClass('thumb-'+(thumbLoc.toLowerCase()));
			if(thumbLoc == 'T' || thumbLoc == 'L') $thumb.appendTo($dialog);
						
			$navleft.append($navarrowleft).appendTo($media);
			$navright.append($navarrowright).appendTo($media);
			$media.appendTo($content);
			
			$title.appendTo($info);
			$caption.appendTo($info);
			$other.appendTo($info);
			$info.appendTo($content);
			
			$content.appendTo($dialog);
			if(thumbLoc == 'B' || thumbLoc == 'R') $thumb.appendTo($dialog);
			
			$dialog.appendTo($box);
			$close.appendTo($box);
			$box.appendTo('body');
		};
		
		_initTheme = function($target) {
			var data = $target.data();
			var setting = $target.data('_xlb_inst').setting;
			
			var themeFile = (data.hasOwnProperty('themeFile')) ? data.themeFile : ((setting.theme && setting.theme.file) ? setting.theme.file : null);			
			if(themeFile) {
				if (!$("link[href='"+themeFile+"']").length) {
					$("<link/>", { 'rel': "stylesheet", 'type': "text/css", 'href': themeFile, 'data-for':'xlightbox' }).appendTo("head");
				}
			}
			
			if(data.hasOwnProperty('themeName')) {
				$('#xlightbox.xlightbox').addClass(data.themeName);
			} else if(setting.theme && setting.theme.name) {
				$('#xlightbox.xlightbox').addClass(setting.theme.name);
			}
		},
		
		_attachHandler = function($target) {
			var setting = $target.data('_xlb_inst').setting;
			
			$('#xlightbox.xlightbox .box-close').off('click').on('click', function (e) { _closeBox(); });

			$('#xlightbox.xlightbox, #xlightbox.xlightbox .box-dialog').off('click').on('click', function (e) {
				if (e.target !== this) return;
				_closeBox();
			});
			
			$(document).off('keyup').on('keyup',{target:$target},function(e) {
				var $target = e.data.target;
				
				if (e.keyCode == 27) _closeBox();		
				if (e.keyCode == 37 || e.keyCode == 38) _switch($target,'prev');
				if (e.keyCode == 39 || e.keyCode == 40) _switch($target,'next');
			});
			
			$('#xlightbox.xlightbox .box-nav-left').off('click').on('click',{target:$target},function(e) {
				var $target = e.data.target;
				_switch($target,'prev');
			});
			
			$('#xlightbox.xlightbox .box-nav-right').off('click').on('click',{target:$target},function(e) {
				var $target = e.data.target;
				_switch($target,'next');
			});
			
			$('#xlightbox.xlightbox .box-media img').off('load').on('load', function() {
				var w = this.naturalWidth;
				var h = this.naturalHeight;
				
				var $p = $(this).parent('.box-media');
				
				var mode = 'tall';
				if(w > h) mode = 'wide';
				
				$p.removeClass('wide').removeClass('tall').addClass(mode);
				
				if(mode == 'wide') {
					var pH = $p.outerHeight();
					var sH = $(this).outerHeight();
					var dH = (pH - sH) / 2;
					
					$(this).css('margin-top',dH+'px');
				}
			});	
			
			$('#xlightbox.xlightbox .box-media video').off('loadedmetadata').on('loadedmetadata', function() {
				var w = this.videoWidth;
				var h = this.videoHeight;
				
				var $p = $(this).parent('.box-media');
				
				var mode = 'tall';
				if(w > h) mode = 'wide';
				
				$p.removeClass('wide').removeClass('tall').addClass(mode);
				
				if(mode == 'wide') {
					var pH = $p.outerHeight();
					var sH = $(this).outerHeight();
					var dH = (pH - sH) / 2;
					
					$(this).css('margin-top',dH+'px');
				}
			});
			
			$('#xlightbox.xlightbox .thumb-item').off('click').on('click',{target:$target},function(e) {				
				var $target = e.data.target;
				var index = $(this).data('index');
				_goThumb($target, index);
			});
			
			$target.off('destroyed').on('destroyed',_destroy);
		};
		
		_showBox = function($target) {				
			$('[data-toggle="xlightbox"].in').removeClass('in');
			$target.addClass('in');
			
			$('#xlightbox.xlightbox').addClass('in');
		};
		
		_closeBox = function() {			
			$('[data-toggle="xlightbox"].in').removeClass('in');
			$('#xlightbox.xlightbox').remove();
			
			if ($('link[data-for="xlightbox"]').length) $('link[data-for="xlightbox"]').remove();
		};
		
		_insertContent = function($target, detail) {
			var data = $target.data();
			var setting = $target.data('_xlb_inst').setting;
			var $box = $('#xlightbox.xlightbox');		
		
			if(detail['src']) {				
				var ext = detail['src'].substr( (detail['src'].lastIndexOf('.') +1) ).toLowerCase();
				
				if($.inArray(ext, ['ogg','ogv','avi','mpe?g','mov','wmv','flv','mp4']) >= 0) {					
					var $src = $('<video />',{ 'class' : 'box-src-item' });
							$src.prop('controls',1);
							$src.html('<source src="'+detail['src']+'" type="video/'+ext+'">Your browser does not support the video tag.');	
				} else if(_isUrl(detail['src'])) {					
					var $src = $('<iframe />',{ 'width' : '100%', 'height' : '80vh', 'frameborder' : '0', 'allowfullscreen' : 'false' }).attr('src',detail['src']);
					var source = $.trim(detail['src']);
					if(source !== "") {
						var code = null;
						if(	source.indexOf('https://youtu.be/') >= 0 ) {
							code = source.replace('https://youtu.be/','');
						}
						if(	source.indexOf('https://www.youtube.com/watch?') >= 0 ) {
							parts = _parseUrl(source);
							code = parts['searchObject']['v'];
						}
						
						if($.trim(	code	) !== "") {
							$src = $('<iframe />',{ 'width' : '100%', 'height' : '80vh', 'frameborder' : '0', 'allowfullscreen' : 'false' }).attr('src','https://www.youtube.com/embed/'+code);
						}
					}					
				} else {
					var $src = $('<img />',{ 'class' : 'box-src-item' }).attr('src',detail['src']);
				}
				
				$box.find('.box-media').append($src);							
			}
			
			var capt = (data.hasOwnProperty('infoCaption')) ? data.infoCaption : setting.info.caption;
			var title = (data.hasOwnProperty('infoTitle')) ? data.infoTitle : setting.info.title;
			
			if(title && detail['title']) $box.find('.box-title').html(detail['title']);
			if(capt && detail['caption']) $box.find('.box-caption').html(detail['caption']);
			
			var ajax = (data.hasOwnProperty('infoAjax')) ? data.infoAjax : setting.info.ajax;
			var url = (data.hasOwnProperty('infoUrl')) ? $.trim(data.infoUrl) : $.trim(setting.info.url);
		
			if(ajax && url) {
				$box.find('.box-other').html('<img src="img/loader.gif" />');	
				$.ajax({
					url: url,
					type: 'POST',
					data: detail,
					success: function(result) {
						$box.find('.box-other').html(result);
					}
				});
			}
			
			var thumbCreate = (data.hasOwnProperty('thumbCreateforvideo')) ? data.thumbCreateforvideo : setting.thumb.createforvideo;
			var thumbShow = (data.hasOwnProperty('thumbShow')) ? data.thumbShow : setting.thumb.show;
			var thumbLoc = (thumbShow) ? (data.hasOwnProperty('thumbLocation')) ? $.trim(data.thumbLocation.charAt(0).toUpperCase()) : $.trim(setting.thumb.location.chartAt(0).toUpperCase()) : 'N';
			if(thumbShow && thumbLoc != 'N' && detail['gallery']) {
				var i = 0;
				var $thumb = $('.xlightbox#xlightbox .box-thumb');
				
				var videos = [];
				$('[data-toggle="xlightbox"][data-gallery="'+detail['gallery']+'"]').each(function(k,v) {
					var src = $(this).find('.xlightbox-src').attr('src');						
					var ext = src.substr( (src.lastIndexOf('.') +1) ).toLowerCase();
					
					var $item = $('<div />',{ 'class' : 'thumb-item' }).attr('data-index',i);
				
					if((i+1) < Number(detail['index'])) {
						if(thumbLoc == 'T' || thumbLoc == 'B') $item.css('margin-left',-10+'%');
						if(thumbLoc == 'L' || thumbLoc == 'R') $item.css('margin-top',-100+'%');
					}
					if(i == detail['index']) $item.addClass('active');
				
					if($.inArray(ext, ['ogg','ogv','avi','mpe?g','mov','wmv','flv','mp4']) >= 0) videos.push(i);
					
					var $thumbsrc = $('<img />',{ 'src' : src });		
					$thumbsrc.appendTo($item);	
					$item.appendTo($thumb);
					
					$(this).attr('data-index',i);
					
					i++;
				});
				
				if(thumbCreate && videos.length) {
					var t = videos.length;
					var v = 0;
					var intvl = setInterval(function() {
						var src = $('[data-toggle="xlightbox"][data-gallery="'+detail['gallery']+'"][data-index="'+videos[v]+'"]').find('.xlightbox-src').attr('src');
						var ext = src.substr( (src.lastIndexOf('.') +1) ).toLowerCase();
						
						$tmp = $('<div />',{ 'class' : 'xlightbox-tmp-vid', 'data-index' : v }).css('display','none');						
						$vid = $('<video />').html('<source src="'+src+'" type="video/'+ext+'">Your browser does not support the video tag.');	
						$can = $('<canvas />');
						
						$vid.appendTo($tmp);
						$can.appendTo($tmp);
						$('body').append($tmp);
					
						$('.xlightbox-tmp-vid[data-index="'+v+'"] video')[0].play();						
						setTimeout(function() {
							var video = $('.xlightbox-tmp-vid[data-index="'+(v-1)+'"] video')[0];
							var canvas = $('.xlightbox-tmp-vid[data-index="'+(v-1)+'"] canvas')[0];
							
							var ctx = canvas.getContext("2d");
							var videoHeight = video.videoHeight; 
							var videoWidth = video.videoWidth;
							canvas.width = videoWidth;
							canvas.height = videoHeight;
							$('.xlightbox-tmp-vid[data-index="'+(v-1)+'"] video')[0].pause();		
							
							ctx.drawImage(video, 0, 0, videoWidth, videoHeight);
							var data = canvas.toDataURL("image/png");
							
							$box.find('.thumb-item[data-index="'+videos[(v-1)]+'"] img').attr('src',data);							
							
							$('.xlightbox-tmp-vid[data-index="'+(v-1)+'"]').remove();
						}, 100);			
						
						v++;
						if(v == t) clearInterval(intvl);
					},500);
				}
			}
			
		};
				
		_navVisibility = function(count, index) {
			var $box = $('#xlightbox.xlightbox');
			if(count > 0) {
				if(index > 0) {
					$box.find('.box-nav-left').removeClass('hidden');
				} else {
					$box.find('.box-nav-left').addClass('hidden');
				}
				
				if(index > -1 && index < (count - 1)) {
					$box.find('.box-nav-right').removeClass('hidden');
				} else {
					$box.find('.box-nav-right').addClass('hidden');
				}
			} else {
				$box.find('.box-nav-left').addClass('hidden');
				$box.find('.box-nav-right').addClass('hidden');
			}
		};
	
		_switch = function($target, type) {
			var setting = $target.data('_xlb_inst').setting;
				
			var $active = $('[data-toggle="xlightbox"].in');
			var gallery = $.trim($active.data('gallery'));
					gallery = (!gallery) ? null : gallery;		
			
			if(gallery === null) return null;		
					
			var $elem = (type == 'prev') ?
										$active.prev('[data-toggle="xlightbox"][data-gallery="'+gallery+'"]') :
										$active.next('[data-toggle="xlightbox"][data-gallery="'+gallery+'"]');
			
			if(!$elem.length) return null;
			
			_destroy();			
			_reinit($elem, setting);
		};
		
		_goThumb = function($target, index) {		
			var setting = $target.data('_xlb_inst').setting;
			var $elem = null;
			
			$('[data-toggle="xlightbox"][data-gallery="'+detail['gallery']+'"]').each(function(k,v) {
				if(k == index) $elem = $(this);
			});
			
			if(!$elem) return;
			
			_destroy();			
			_reinit($elem, setting);
		};
		
    _destroy = function() {			
			target.off("destroyed", this._teardown);
			target.removeData('_xlb_inst');			
			target.removeClass('in');
			
			$('body').children().filter(".xlightbox-tmp-vid").each(function(){
				$(this).find('video').get(0).pause();
				delete this;
				$(this).remove();
			});
			
			target = null;
			
			_xlb_inst = [];
    };
		
		_callback = function($target, type) {
			var data = $target.data();
			var setting = $target.data('_xlb_inst').setting;	
			
			var cb = null;
			var prop = type+'select';
			if(type == 'pre') {				
				if(data.hasOwnProperty('preselect')) {
					cb = data.preselect;
				} else if(setting.preSelect) {
					cb = setting.preSelect;
				}
			} else {		
				if(data.hasOwnProperty('onselect')) {
					cb = data.onselect;
				} else if(setting.onSelect) {
					cb = setting.onSelect;
				}
			}
			
			if(cb && typeof cb !== "undefined") {
				if($.isFunction(cb)) {
					return cb(self);
				} else {
					return _callfunc(cb, window, self);
				}
			} else {
				return null;
			}
		};
	
		_callfunc = function (name, context /*, args */) {
			/*http://stackoverflow.com/a/359910*/
			var args = [].slice.call(arguments).splice(2);
			var namespaces = name.split(".");
			var func = namespaces.pop();
			for(var i = 0; i < namespaces.length; i++) {
				context = context[namespaces[i]];
			}
			return context[func].apply(context, args);
		};
	
		_getDetail = function() { return detail; },
		
		_setDetail = function(type, value) { detail[type] = value; }
		
		_getSetting = function() { return inst.setting; }
		
		_isUrl = function(s) {
			var regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
			return regexp.test(s);
		}
	
		_parseUrl = function(url) {
			/*https://www.abeautifulsite.net/parsing-urls-in-javascript*/
			var parser = document.createElement('a'), searchObject = {}, queries, split, i;
			parser.href = url;
			queries = parser.search.replace(/^\?/, '').split('&');
			for( i = 0; i < queries.length; i++ ) {
				split = queries[i].split('=');
				searchObject[split[0]] = split[1];
			}
			return {
					protocol: parser.protocol,
					host: parser.host,
					hostname: parser.hostname,
					port: parser.port,
					pathname: parser.pathname,
					search: parser.search,
					searchObject: searchObject,
					hash: parser.hash
			};
		}

		_fileExists = function(path) {
			/*http://stackoverflow.com/a/3646923*/
			var http = new XMLHttpRequest();
			http.open('HEAD', path, false);
			http.send();
			return http.status!=404;
		}
		
		return this;
	};
	
	$.extend(XLightbox.prototype, {		
		_init: function(target, setting) {
			var $target = $(target);
			
			return _reinit($target, setting);
		},
		
		getActive: function() {
			return $('[data-toggle="xlightbox"].in');
		},
		
		getPrev: function() {				
			var $active = $('[data-toggle="xlightbox"].in');
			var gallery = $.trim($active.data('gallery'));
					gallery = (!gallery) ? null : gallery;		
			
			if(gallery === null) return null;					
			return $active.prev('[data-toggle="xlightbox"][data-gallery="'+gallery+'"]');
		},
		
		getNext: function() {				
			var $active = $('[data-toggle="xlightbox"].in');
			var gallery = $.trim($active.data('gallery'));
					gallery = (!gallery) ? null : gallery;		
			
			if(gallery === null) return null;					
			return $active.next('[data-toggle="xlightbox"][data-gallery="'+gallery+'"]');
		},
	
		getDetail: function() { return _getDetail(); },
		
		setDetail: function(type, value) { return _setDetail(type, value); },
		
		getCaption: function() { var det = _getDetail(); return det.caption; },
		
		getCount: function() { var det = _getDetail(); return det.count; },
		
		getGallery: function() { var det = _getDetail(); return det.gallery; },
		
		getId: function() { var det = _getDetail(); return det.id; },
		
		getImage: function() { var det = _getDetail(); return det.img; },
		
		getIndex: function() { var det = _getDetail(); return det.index; },
		
		getTitle: function() { var det = _getDetail(); return det.title; },
		
		getSetting: function() { return _getSetting(); },
	});	

	var _xlb_inst = [];
	$.xlightbox = new XLightbox();
	$.fn.xlightbox = function(options){
		if (this.length) {
			return this.each(function(){
				var xlb = $.xlightbox._init(this, options);
			});
		}
	};
})(jQuery);

