/*
* Turtle skin libraries
*
* Copyright (c) 2008 - 2013 Lazaworx
* http://www.lazaworx.com
* Author: Laszlo Molnar
*
* Dual licensed under the MIT and GPL licenses.
* - http://www.opensource.org/licenses/mit-license.php
* - http://www.gnu.org/copyleft/gpl.html
* Bound to jAlbum licensing terms
* - http://jalbum.net/en/terms-and-conditions
*
*/
/* Verified using http://www.jshint.com/ */
/*jshint smarttabs:true, eqnull:true, eqeqeq:false, scripturl:true, unused:false */
/*global jQuery:true, google:true, gapi:true, FOTOMOTO:true, Search:true, _jaShowAds:true */
var VER = '4.2.2',
DEBUG = true,
UNDEF = 'undefined',
NOLINK = 'javascript:void(0)',
LOCAL = location.protocol.indexOf('file:') === 0,
LOCALSTORAGE = (function(){
try {
localStorage.setItem('_t', VER);
localStorage.removeItem('_t');
return true;
} catch(e) {
return false;
}
}());
/*
* Extending String object with new methods
*/
String.prototype.trim = function() {
return this.replace(/^\s+|\s+$/g,'');
};
String.prototype.trunc = function( n ) {
if (this.length <= n) {
return this.toString();
}
var s = this.substring(0, n - 1), i = s.lastIndexOf(' ');
return ((i > 6 && (s.length - i) < 20)? s.substring(0, i) : s) + '...';
};
String.prototype.startsWith = function( s ) {
return this.indexOf( s ) === 0;
};
String.prototype.endsWith = function( s ) {
return this.substring(this.length - s.length) === s;
};
String.prototype.getExt = function() {
var i = this.lastIndexOf('.');
return (i <= 0 || i >= this.length - 1)? '' : this.substring(i + 1).toLowerCase();
};
String.prototype.replaceExt = function( s ) {
var i = this.lastIndexOf('.');
return (i <= 0)? this : (this.substring(0, i + 1) + s);
};
String.prototype.fixExtension = function() {
return this.replace(/.gif$/gi, '.png').replace(/.tif+$/gi, '.jpg');
};
String.prototype.getDir = function() {
var u = this.split('#')[0];
return u.substring(0, u.lastIndexOf('/') + 1);
};
String.prototype.getFile = function() {
var u = this.split('#')[0];
return u.substring(u.lastIndexOf('/') + 1);
};
String.prototype.fixUrl = function() {
var i, j, s = this + '';
while ( (i = s.indexOf('../')) > 0) {
if ( i === 1 || (j = s.lastIndexOf('/', i - 2)) === -1 ) {
return s.substring(i + 3);
}
s = s.substring(0, j) + s.substring(i + 2);
}
return s;
};
String.prototype.fullUrl = function() {
var s = this + '';
if ( !s.match(/^(http|ftp|file)/) ) {
s = window.location.href.getDir() + s;
}
return s.fixUrl();
};
String.prototype.cleanupHTML = function() {
var htmlregex = [
[ /
/gi, '\n' ],
[ /\&/gi, '&' ],
[ /\</gi, '<' ],
[ /\>/gi, '>' ],
[ /\&(m|n)dash;/gi , '-' ],
[ /\'/gi, '\'' ],
[ /\"/gi, '"' ]
];
var s = this;
for ( var i = htmlregex.length - 1; i >= 0; i--) {
s = s.replace( htmlregex[i][0], htmlregex[i][1] );
}
return s;
};
String.prototype.stripHTML = function() {
return this.replace(/<\/?[^>]+>/gi, '');
};
String.prototype.stripQuote = function() {
return this.replace(/\"/gi, '"');
};
String.prototype.appendSep = function(s, sep) {
return (this.length? (this + (sep || ' · ')) : '') + s;
};
String.prototype.rgb2hex = function() {
if (this.charAt(0) === '#' || this === 'transparent') {
return this;
}
var n, r = this.match(/\d+/g), h = '';
for ( var i = 0; i < r.length && i < 3; i++ ) {
n = parseInt( r[i], 10 ).toString(16);
h += ((n.length < 2)? '0' : '') + n;
}
return '#' + h;
};
String.prototype.template = function( t ) {
if ( !t ) {
return this;
}
var s = this;
for ( var i = 0; i < t.length; i++ ) {
s = s.replace( new RegExp('\\{' + i + '\\}', 'gi'), t[i] );
}
return s;
};
Math.minMax = function(a, b, c) {
b = (isNaN(b))? parseFloat(b) : b;
return (b < a)? a : ((b > c)? c : b);
};
/*
* Getting coordinates of a touch event
*/
var getCoords = function( e ) {
if ( e.touches && e.touches.length > 0 ) {
return {
x: Math.round(e.touches[0].clientX),
y: Math.round(e.touches[0].clientY)
};
} else if ( e.clientX !== null ) {
return {
x: Math.round(e.clientX),
y: Math.round(e.clientY)
};
}
return {
x: UNDEF,
y: UNDEF
};
};
/*
* Dummy function to avoid further events
*/
var noAction = function(e) {
e.stopPropagation();
e.preventDefault();
return false;
};
/*
* Removing the extra parameters from url in order Facebook can display
* the comments belonging to a page. Can be called before jQuery.
*/
var fixFbComments = function( pageName ) {
var u = window.location.href;
if (u.indexOf('?fb_comment_id=') === -1) {
u = u.split('#')[0];
if (pageName && u[u.length-1] === '/') {
u += pageName;
}
} else {
u = u.split('?')[0];
}
document.getElementById('fb-comments').setAttribute('data-href', u);
};
/*
* Debugging functions
*/
var log = function() {};
(function($) {
// log: logging function
var _logel, _logover = false, _lastlog, _lastcnt = 1;
log = function(c) {
if ( !DEBUG || _logover ) {
return;
}
if ( !_logel ) {
_logel = $('