if (navigator.userAgent.match(/iPad/i) || navigator.userAgent.match(/iPhone/i)) {
    document.write('<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"><meta name="apple-mobile-web-app-capable" content="yes"><meta name="apple-mobile-web-app-status-bar-style" content="black">')
} else if (navigator.userAgent.match(/Android/i)) {
    document.write('<meta content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0; target-densitydpi=device-dpi" name="viewport"/>')
}
var svCoreURL = (function() {
    var a;
    var b;
    var c = document.getElementsByTagName('script');
    for (var i = 0; i < c.length; i++) {
        b = c[i].src.toLowerCase().indexOf('simpleviewer.js');
        if (b >= 0) {
            a = c[i].src;
            break
        }
    }
    if (a.toLowerCase().indexOf('js/simpleviewer.js') == 0) return '';
    return a.replace(/\/[^\/]*$/, "").replace(/\/[^\/]*$/, "") + '/'
})();
document.write('<script type="text/javascript" src="' + svCoreURL + 'js/jquery-1.4.4.min.js"></script>');
document.write('<script type="text/javascript" src="' + svCoreURL + 'js/swfobject.js"></script>');
document.write('<link rel="stylesheet" href="' + svCoreURL + 'css/simpleviewer.css" type="text/css">');
var SV = SV ? SV: {};
SV.simpleviewer = {};
SV.simpleviewer.idx = 0;
SV.simpleviewer.insobjs = [];
SV.simpleviewer.load = function(a, b, c, d, e, f, g, h, i) {
    var j = new SV.simpleviewer.instance();
    j.load('svcp-' + SV.simpleviewer.idx + '-', a, b, c, d, e, f, g, h, i);
    SV.simpleviewer.idx++;
    SV.simpleviewer.insobjs.push(j)
};
SV.simpleviewer.saveCurrentPage = function() {
    for (var i = 0; i < SV.simpleviewer.insobjs.length; i++) {
        SV.simpleviewer.insobjs[i].saveCrntPg()
    }
};
SV.simpleviewer.instance = function() {
    var M = false;
    var N = false;
    var O = "";
    var P = {
        randomId: O + 'sv' + (new Date()).getTime(),
        maxItemCount: 100
    };
    var Q = 0;
    var R;
    var S = (isIpad() ? 1 : 2);
    var T = 25;
    var U = 10;
    var V;
    var W, winWidth;
    var X = {
        width: 0,
        height: 0,
        widthRatio: 0,
        heightRatio: 0
    };
    var Y = {
        width: 0,
        height: 0,
        showOverlay: true
    };
    var Z = {
        width: 0,
        height: 0,
        maxRowCount: 4,
        maxColCount: 3,
        navListIndex: 0,
        thumbCountPerPage: 0,
        totalPage: 0
    };
    var ba, svHeight, backgroundColor, svContainer, svContainerId;
    var bb = {};
    var bc = {
        displayMode: '',
        panelMode: 'both'
    };
    var bd = '9.0.124';
    var be, params, attributes;
    var bf = screen.availHeight && screen.availHeight > 500 ? 14 : 11;
    var bg = 1;
    var bh = null;
    var bi;
    var bj = '';
    function getOptionValue(a, b, c, d) {
        if (a && a[b]) {
            if (d == 'bool') {
                if (a[b] === 'false') return false;
                if (a[b] === 'true') return true
            }
            if (d == 'int') return parseInt(a[b]);
            return a[b]
        }
        if (!V) return c;
        if (typeof V[b] == 'undefined') return c;
        if (d == 'int') return parseInt(V[b]);
        return V[b]
    };
    var bk = "showopenbutton,showfullscreenbutton,useflickr,mobileshowcaption,mobileshownav,";
    var bl = "preseturl,firstimageindex,baseurl,flickrusername,flickrtags,flickruserid,flickrsetid,flickrgroupid,flickrgagmode,flickrsort,flickrimagecount,flickrimagesize,flickrextraparams,imagepath,thumbpath,galleryurl,preseturl,embedurl,title,";
    function parseXML(f, g) {
        var h = {};
        var j = bh(bh.browser.msie ? f.childNodes[1].attributes: f.childNodes[0].attributes);
        j.each(function(i, n) {
            if (bk.indexOf(n.nodeName.toLowerCase() + ",") >= 0) {
                h[n.nodeName.toLowerCase()] = n.nodeValue.toLowerCase()
            }
            if (bl.indexOf(n.nodeName.toLowerCase() + ",") >= 0) {
                h[n.nodeName.toLowerCase()] = n.nodeValue
            }
        });
        try {
            var k = bh(f).find('simpleviewergallery,simpleviewerGallery');
            bb = {
                'showopenbutton': getOptionValue(h, 'showopenbutton', true, 'bool'),
                'showfullscreenbutton': getOptionValue(h, 'showfullscreenbutton', true, 'bool'),
                'useflickr': getOptionValue(h, 'useflickr', false, 'bool'),
                'mobileshowcaption': getOptionValue(h, 'mobileshowcaption', true, 'bool'),
                'mobileshownav': getOptionValue(h, 'mobileshownav', true, 'bool'),
                'preseturl': getOptionValue(h, 'preseturl', ''),
                'firstimageindex': getOptionValue(h, 'firstimageindex', -1, 'int'),
                'flickrusername': getOptionValue(h, 'flickrusername', ''),
                'flickrtags': getOptionValue(h, 'flickrtags', ''),
                'flickruserid': getOptionValue(h, 'flickruserid', ''),
                'flickrsetid': getOptionValue(h, 'flickrsetid', ''),
                'flickrgroupid': getOptionValue(h, 'flickrgroupid', ''),
                'flickrgagmode': getOptionValue(h, 'flickrgagmode', 'ALL'),
                'flickrsort': getOptionValue(h, 'flickrsort', 'DATE-POSTED-DESC'),
                'flickrimagecount': getOptionValue(h, 'flickrimagecount', '50'),
                'flickrimagesize': getOptionValue(h, 'flickrimagesize', 'LARGE'),
                'flickrextraparams': getOptionValue(h, 'flickrextraparams', ''),
                'imagepath': getOptionValue(h, 'imagepath', ''),
                'thumbpath': getOptionValue(h, 'thumbpath', ''),
                'title': getOptionValue(h, 'title', ''),
                'images': []
            };
            if (M) {
                if (bb.useflickr) {
                    Q = parseInt(bb.flickrimagecount)
                } else {
                    Q = k.find('image').length
                }
            } else {
                if (bb.useflickr) {
                    Q = Math.min(P.maxItemCount, parseInt(bb.flickrimagecount))
                } else {
                    Q = Math.min(P.maxItemCount, k.find('image').length)
                }
                delete bb.preseturl;
                delete bb.flickruserid;
                delete bb.flickrsetid;
                delete bb.flickrgroupid;
                delete bb.flickrextraparams
            }
            if (V) return bb;
            var l = function(a, b) {
                if (typeof a !== 'undefined' && typeof b !== 'undefined' && b.indexOf("://") < 0) return ((bm(a, '/') || a.length == 0) ? a: a + '/') + b;
                return b
            };
            k.find('image').each(function() {
                if (bb.images.length >= Q) return;
                var a;
                var b = (g ? g: ((typeof svGalleryPath !== 'undefined') ? svGalleryPath: ''));
                var c = bh(this).attr('imageURL');
                var d = bh(this).attr('thumbURL');
                var e = bh(this).attr('linkURL');
                if (!c && !d && !e) {
                    c = bh(this).find('filename').text();
                    d = c;
                    if (T > 12) T -= 12
                }
                a = {
                    imageURL: l(b, c),
                    thumbURL: l(b, d),
                    imageFullURL: l(b, e) || l(b, c),
                    linkTarget: bh(this).attr('linkTarget') || '_blank',
                    caption: '',
                    description: '',
                    preloadedImage: null,
                    preloaded: false
                };
                if (bh(this).find('caption').length > 0) {
                    a.description = bh(this).find('caption:first').text()
                }
                bb.images.push(a)
            })
        } catch(e) {
            errorMessage('Cannot Parse Gallery XML.')
        }
        return bb
    };
    var bm = function(a, b) {
        if (!a || !b) return false;
        if (a[a.length - 1] == b) return true;
        return false
    };
    function cvtObjectAttrLowerCase(a) {
        var b = {};
        if (!a) return b;
        var c;
        for (var d in a) {
            c = d.toLowerCase();
            if (bk.indexOf(d.toLowerCase() + ",") >= 0) {
                b[c] = (a[d] === true ? true: (a[d] === false ? false: a[d].toLowerCase()));
                continue
            }
            if (bl.indexOf(d.toLowerCase() + ",") >= 0) {
                b[c] = a[d];
                continue
            }
            b[d] = a[d]
        }
        return b
    };
    function setPanelSize() {
        calculateMvSize();
        if (Y.width < Y.height) {
            bh('#' + O + 'sv-mobile').removeClass('sv-horizental');
            bh('#' + O + 'sv-mobile').addClass('sv-vertical')
        } else {
            bh('#' + O + 'sv-mobile').removeClass('sv-vertical');
            bh('#' + O + 'sv-mobile').addClass('sv-horizental')
        }
        if (bc.panelMode == 'navigation') {
            Z.width = Y.width;
            Z.height = Y.height
        } else {
            Z.width = 270;
            Z.height = 320
        }
    };
    function setGridScale() {
        Z.maxRowCount = 4;
        if (separateNavPanel()) {
            Z.maxRowCount = parseInt((Z.height) / 80);
            Z.maxColCount = parseInt((Z.width) / 80);
            Z.maxRowCount--;
            if (isAndroid()) {
                if (Z.width > Z.height && Z.maxRowCount <= 1) {
                    Z.maxRowCount++
                }
                if (Z.width < Z.height) {
                    if (Z.maxRowCount <= 3) {
                        Z.maxRowCount++
                    }
                }
                if (getAndroidVer() < 2.3 && Z.maxRowCount >= 3) Z.maxRowCount--
            }
            Z.maxColCount--;
            if (Z.maxRowCount > Z.maxColCount) {
                if (Z.maxRowCount > 10) Z.maxRowCount = 10;
                if (Z.maxColCount > 7) Z.maxColCount = 7
            } else {
                if (Z.maxRowCount > 7) Z.maxRowCount = 7;
                if (Z.maxColCount > 10) Z.maxColCount = 10
            }
            var a = getThumbnailGridSize();
            var b = parseInt((Z.width - a.width) / 2);
            if (b < 59 && Z.maxColCount > 1) Z.maxColCount--;
            if (Z.maxColCount * Z.maxRowCount > V.images.length && V.images.length > 0) {
                var c = parseInt(V.images.length / Z.maxColCount);
                if (V.images.length % Z.maxColCount > 0) c++;
                Z.maxRowCount = c
            }
        } else {
            Z.maxColCount = 3
        }
    };
    function setNavPnlCalculatedValues() {
        Z.thumbCountPerPage = Z.maxRowCount * Z.maxColCount;
        Z.totalPage = parseInt(Q / Z.thumbCountPerPage) + (Q % Z.thumbCountPerPage == 0 ? 0 : 1)
    };
    function setPanelsScale() {
        setPanelSize();
        setGridScale();
        Z.navListIndex = 0;
        setNavPnlCalculatedValues()
    };
    function onSwiping(d, a, b, c, e) {
        var f = 0;
        if (d.direction != "left2right") {
            f -= d.distance
        } else if (d.direction != "right2left") {
            f = d.distance
        }
        if (f == 0) return;
        var g = getThumbnailGridSize();
        var h = e ? g.width: (Y.width + U);
        b.style.webkitTransitionDuration = '0';
        b.style.webkitTransform = 'translate3d(' + f + 'px, 0px, 0px)';
        if (a) {
            a.style.webkitTransitionDuration = '0';
            if (f > 0) {
                a.style.webkitTransform = 'translate3d(-' + (h - f) + 'px, 0px, 0px)'
            } else {
                a.style.webkitTransform = 'translate3d(-' + (h) + 'px, 0px, 0px)'
            }
        }
        if (c) {
            c.style.webkitTransitionDuration = '0';
            if (f < 0) {
                c.style.webkitTransform = 'translate3d(' + (h + f) + 'px, 0px, 0px)'
            } else {
                c.style.webkitTransform = 'translate3d(' + (h) + 'px, 0px, 0px)'
            }
        }
    };
    function afterSwiping(a, b, d, c, e, f, g) {
        var h = false;
        var i = 0.1;
        var j = getThumbnailGridSize();
        var k = g ? j.width: (Y.width + U);
        e.style.webkitTransitionDuration = b.d + 'ms';
        if (d.direction == "left2right") {
            if (a <= 0) h = true;
            if (d.distance > i * k && !h) {
                if (g) {
                    Z.navListIndex--;
                    move2NavListPnl(a, Z.navListIndex, b.d)
                } else {
                    bg--;
                    move2Photo(bg, bg - 1, true, b.d, d.distance)
                }
            } else {
                e.style.webkitTransform = '';
                if (c) {
                    c.style.webkitTransitionDuration = b.d + 'ms';
                    c.style.webkitTransform = 'translate3d(-' + k + 'px, 0px, 0px)'
                }
            }
        } else if (d.direction == "right2left") {
            if ((g && a >= Z.totalPage - 1) || (!g && a >= Q - 1)) h = true;
            if (d.distance > i * k && !h) {
                if (g) {
                    Z.navListIndex++;
                    move2NavListPnl(a, Z.navListIndex, b.d)
                } else {
                    bg++;
                    move2Photo(bg - 2, bg - 1, true, b.d, d.distance)
                }
            } else {
                e.style.webkitTransform = '';
                if (f) {
                    f.style.webkitTransitionDuration = b.d + 'ms';
                    f.style.webkitTransform = 'translate3d(' + k + 'px, 0px, 0px)'
                }
            }
        }
    };
    function getDurationWithSwipeSpeed(d, a) {
        var b = parseInt(d.timerValue * a / d.distance);
        if (b > 3000) b = 3000;
        return b
    };
    function setNavControls(e, f) {
        if (e + 1 >= Z.totalPage) {
            bh('#' + O + 'sv-nav-page-next').hide()
        } else {
            bh('#' + O + 'sv-nav-page-next').show()
        }
        if (e <= 0) {
            bh('#' + O + 'sv-nav-page-prev').hide()
        } else {
            bh('#' + O + 'sv-nav-page-prev').show()
        }
        bh('#' + O + 'sv-nav-page-label').html('page ' + (parseInt(e) + 1) + ' of ' + Z.totalPage);
        bh('#' + O + 'sv-nav-page-caption').html(V.title);
        bh('#' + O + 'sv-next-photo').show();
        bh('#' + O + 'sv-prev-photo').show();
        if (Y.showOverlay && V.mobileshownav && f < V.images.length - 1) {
            bh('#' + O + 'sv-next-photo span').show()
        } else {
            bh('#' + O + 'sv-next-photo span').hide()
        }
        if (Y.showOverlay && V.mobileshownav && f > 0) {
            bh('#' + O + 'sv-prev-photo span').show()
        } else {
            bh('#' + O + 'sv-prev-photo span').hide()
        }
        Z.navListIndex = e;
        if (typeof f != 'undefined') bg = f + 1;
        var g = bh('#' + O + '-nav-lst-' + e + ' a');
        g.unbind();
        g.click(function() {
            var b = bh(this);
            var c = parseInt(b.attr('id').replace(O + 'nav-pht-lnks-', ''));
            if (bc.panelMode == 'navigation') {
                var d = bh('#' + O + 'sv-photo-navigation');
                d.fadeOut(250,
                function() {
                    d.hide();
                    var a = bh('#' + O + 'sv-photo-detail');
                    a.show();
                    move2Photo(bg - 1, c, 'calledfromnav', 0);
                    a.fadeIn(250)
                })
            } else {
                move2Photo(bg - 1, c)
            }
            return false
        });
        if (!isSwipable() || Z.totalPage <= 1) return;
        var h = getThumbnailGridSize();
        var i = getSlideDuration();
        var j = document.getElementById(O + '-nav-lst-' + (e - 1));
        var k = document.getElementById(O + '-nav-lst-' + e);
        var l = document.getElementById(O + '-nav-lst-' + (e + 1));
        var m = bh('#' + O + '-nav-lst-' + e + ' img, #' + O + '-nav-lst-' + e + ' .sv-nav-empty-thumbnail');
        m.unbind();
        m.detectFlicks({
            axis: 'x',
            threshold: 5,
            flickMove: function(d) {
                onSwiping(d, j, k, l, true)
            },
            flickEvent: function(d) {
                i.d = getDurationWithSwipeSpeed(d, h.width);
                afterSwiping(e, i, d, j, k, l, true)
            }
        })
    };
    function populatePhotoList(a) {
        var b = '';
        var c = getThumbnailGridSize().width;
        var d = supportWebkitAnim() ? '-webkit-transform:translateX(-' + c + 'px);': 'left:' + ( - c) + 'px;';
        var e = supportWebkitAnim() ? '-webkit-transform:translateX(' + c + 'px);': 'left:' + c + 'px;';
        if (a > 0) b += getPhotoListHtml(a - 1, d);
        b += getPhotoListHtml(a);
        if (a < Q - 1) b += getPhotoListHtml(a + 1, e);
        bh('#' + O + 'sv-nav-photo-list').html(b);
        setNavControls(a, bg - 1);
        setCurrentPohot(bg - 1)
    };
    function getNavBoundary(a) {
        return {
            lowbdry: Z.thumbCountPerPage * a,
            highbdry: Z.thumbCountPerPage * (parseInt(a) + 1)
        }
    };
    function getThumbnailGridSize() {
        return {
            width: Z.maxColCount * 80,
            height: Z.maxRowCount * 80
        }
    };
    function getPhotoListHtml(a, b) {
        if (a < 0 || a >= Q - 1) return '';
        var c = getNavBoundary(a);
        var d = c.lowbdry;
        var e, visited, current;
        e = '<table id="' + O + '-nav-lst-' + a + '" border="0" cellpadding="0" cellspacing="0" style="width:' + getThumbnailGridSize().width + 'px;' + (b ? b: '') + '">';
        for (var i = 0; i < Z.maxRowCount; i++) {
            e += '<tr>';
            for (var j = 0; j < Z.maxColCount; j++) {
                if (d < c.highbdry && d >= 0 && d < V.images.length && d < Q) {
                    e += '<td>';
                    if (V.images[d].visited) {
                        visited = 'visited'
                    } else {
                        visited = ''
                    }
                    if (d == bg - 1) {
                        current = 'current'
                    } else {
                        current = ''
                    }
                    e += '<a id="' + O + 'nav-pht-lnks-' + d + '" href="#" onclick="" class="' + visited + ' ' + current + '"><img src="' + V.images[d].thumbURL + '"/></a>';
                    d++
                } else {
                    e += '<td class="sv-nav-empty-thumbnail">'
                }
                e += '</td>'
            }
            e += '</tr>'
        }
        e += '';
        e += '';
        e += '</table>';
        return e
    };
    function getDeviceClass() {
        if (isIphone()) return 'sv-cls-4-iphone';
        if (isIpad()) return 'sv-cls-4-ipad';
        if (isAndroid()) return 'sv-cls-4-android';
        if (bh.browser.msie) {
            if (jQuery.browser.version < 9) {
                return 'sv-cls-4-msie8'
            } else {
                return 'sv-cls-4-msie9'
            }
        }
        return 'sv-generic-device'
    };
   function getLogo4Nav() {
       if (M) return '';
       return '<a href="http://render.kz" target="_blank" class="sv-nav-logo"></a>'
   };
    function generateSVHtml() {
        var a;
        a = '<div id="' + O + 'sv-mobile" class="simpleviewer cls-mobile ' + getDeviceClass() + '" style="background: ' + formatColor(backgroundColor) + ';">';
        a += '<div id="' + O + 'sv-photo-navigation" class="sv-photo-nav">';
        a += '<div id="' + O + 'sv-nav-photo-list" class="sv-nav-photo-list">';
        a += '</div>';
        a += '<span id="' + O + 'sv-nav-page-caption" class="sv-nav-page-caption"></span>';
        a += '<span id="' + O + 'sv-nav-page-prev" class="sv-nav-page-prev"></span>';
        a += '<span id="' + O + 'sv-nav-page-label" class="sv-nav-page-label"></span>';
        a += '<span id="' + O + 'sv-nav-page-next" class="sv-nav-page-next"></span>';
        //a += getLogo4Nav();
        a += '<div id="' + O + 'sv-nav-topmenu" class="cls-topmenu"><div id="' + O + 'sv-nav-topmenu-right" class="cls-topmenu-right"></div><div id="' + O + 'sv-nav-topmenu-links" class="cls-topmenu-links">';
        a += '<a href="" id="' + O + 'sv-nav-go-fullscreen" class="cls-go-fullscreen" title="Go Fullscreen"><span>Go Fullscreen</span></a>';
        a += '</div><div id="' + O + 'sv-nav-topmenu-left" class="cls-topmenu-left"></div></div>';
        a += '</div>';
        a += '<div id="' + O + 'sv-photo-detail" class="sv-photo-detail">';
        a += '<div id="' + O + 'sv-photos" class="cls-photos"></div>';
        a += '<div id="' + O + 'sv-prev-photo" class="cls-prev-photo"><span></span></div>';
        a += '<div id="' + O + 'sv-next-photo" class="cls-next-photo"><span></span></div>';
        //if (!M) a += '<a href="" id="' + P.randomId + '" class="sv-photo-logo"></a>';
        a += '<div id="' + O + 'sv-topmenu" class="cls-topmenu"><div id="' + O + 'sv-topmenu-right" class="cls-topmenu-right"></div><div id="' + O + 'sv-topmenu-links" class="cls-topmenu-links">';
        a += '<a href="" id="' + O + 'sv-open-window" class="cls-open-window" target="_blank" title="Open Image in New Window"><span>Open Image in New Window</span></a>';
        a += '<a href="" id="' + O + 'sv-go-fullscreen" class="cls-go-fullscreen" title="Go Fullscreen"><span>Go Fullscreen</span></a>';
        a += '<a href="#" id="' + O + 'sv-go-nav-panel" class="cls-go-nav-panel" title="View Thumbnails"><span>View Thumbnails</span></a>';
        a += '</div><div id="' + O + 'sv-topmenu-left" class="cls-topmenu-left"></div></div>';
        a += '</div>';
        a += '</div>';
        return a
    };
    function generateSVFlashHtml() {
        var a;
        a = '<div id="' + O + 'sv-mobile-flash" class="cls-mobile-flash">';
        a += '<div id="' + O + 'sv-mobile-flash-swf" class="cls-mobile-flash-swf"></div>';
        a += '</div>';
        return a
    };
    function setBodySize(a, b) {
        if (bc.displayMode !== 'fullscreen') return;
        var c = isAndroid() ? (getAndroidVer() >= 2.3 ? 1.3 * a + 'px': '110%') : 100 * getiPhoneAdjRatio(a, b) + '%';
        bh('body, html').css({
            'overflow': isAndroid() ? 'auto': 'hidden',
            'height': c,
            'margin': '0',
            'padding': '0'
        })
    };
    function checkForResize() {
        var a = getWindowWidth();
        var b = adjustHeight4Devices(getWindowHeight(), a);
        if (isAndroid()) {
            if (bc.displayMode == 'fullscreen' && (b !== W || a !== winWidth)) {
                setBodySize(b, a)
            } else {
                hideUrlBar.InTimer()
            }
        }
        if (Q > 1 && bh('#' + O + 'sv-photo-detail:visible').length > 0 && bh('#' + O + 'sv-next-photo:visible').length == 0 && bh('#' + O + 'sv-prev-photo:visible').length == 0) {
            resizeViewer()
        }
    };
    function showOverlayControlsAnim(a) {
        var b = getSlideDuration();
        if (a) {
            bh('#' + O + 'sv-topmenu').fadeIn(b.od)
        } else {
            bh('#' + O + 'sv-topmenu').fadeOut(b.od)
        }
        if (V.mobileshowcaption) {
            if (a) {
                bh('#' + O + 'sv-photos .sv-photo .sv-caption').fadeIn(b.od)
            } else {
                bh('#' + O + 'sv-photos .sv-photo .sv-caption').fadeOut(b.od)
            }
        }
        if (V.mobileshownav) {
            if (a) {
                if (V.mobileshownav && bg > 1) bh('#' + O + 'sv-prev-photo span').fadeIn(b.od);
                if (V.mobileshownav && bg < V.images.length) bh('#' + O + 'sv-next-photo span').fadeIn(b.od)
            } else {
                if (V.mobileshownav && bg > 1) bh('#' + O + 'sv-prev-photo span').fadeOut(b.od);
                if (V.mobileshownav && bg < V.images.length) bh('#' + O + 'sv-next-photo span').fadeOut(b.od)
            }
        }
    };
    function showOverlayControls(a) {
        bh('#' + O + 'sv-topmenu').hide();
        bh('#' + O + 'sv-photos .sv-photo .sv-caption').hide();
        bh('#' + O + 'sv-prev-photo span').hide();
        bh('#' + O + 'sv-next-photo span').hide();
        if (!a) return;
        bh('#' + O + 'sv-topmenu').show();
        if (V.mobileshowcaption) {
            bh('#' + O + 'sv-photos .sv-photo .sv-caption').show()
        }
        if (V.mobileshownav) {
            if (V.mobileshownav && bg > 1) bh('#' + O + 'sv-prev-photo span').show();
            if (V.mobileshownav && bg < V.images.length) bh('#' + O + 'sv-next-photo span').show()
        }
    };
    function getVisiblePhotoFramesCount() {
        return Math.min(2 * S + 1, Q)
    };
    function getCurntPhotoFramesOffset() {
        var a = parseInt(bh('#' + O + 'sv-photos .photo-frame').first().attr('id').replace(O + 'sv-photo-', ''));
        return bg - a
    };
    function getWindowWidth() {
        var w = bh(window).width();
        if (isAndroid() & w > screen.width) {
            return screen.width - 6
        }
        return w
    };
    function getWindowHeight() {
        var h = bh(window).height();
        if (isAndroid()) {
            if (h > screen.height || bc.displayMode === 'fullscreen') {
                return screen.height
            }
        }
        return h
    };
    function calculateMvSize() {
        winWidth = getWindowWidth();
        W = adjustHeight4Devices(getWindowHeight(), winWidth);
        if (bc.displayMode === 'fullscreen') {
            Y.width = winWidth;
            Y.height = W
        } else {
            if (ba.indexOf('%') > -1) {
                if (!isPercentage(svContainer.attr("style"), "width")) {
                    X.width = getContainerWidth(svContainer);
                    Y.width = Math.floor((ba.replace('%', '') / 100) * X.width)
                } else {
                    if (X.widthRatio) {
                        Y.width = Math.floor((ba.replace('%', '') / 100) * X.widthRatio * winWidth);
                        if (Y.width - 20 < parseInt(winWidth) && Y.width > parseInt(winWidth) - 20) Y.width -= 20
                    } else {
                        Y.width = Math.floor((ba.replace('%', '') / 100) * X.width)
                    }
                }
            } else {
                Y.width = parseInt(ba)
            }
            if (svHeight.indexOf('%') > -1) {
                if (!isPercentage(svContainer.attr("style"), "height")) {
                    X.height = getContainerHeight(svContainer);
                    Y.height = Math.floor((svHeight.replace('%', '') / 100) * X.height)
                } else {
                    if (X.heightRatio) {
                        Y.height = Math.floor((svHeight.replace('%', '') / 100) * X.heightRatio * W);
                        if (Y.height - 20 < parseInt(W) && Y.height > parseInt(W) - 20) Y.height -= 20
                    } else {
                        Y.height = Math.floor((svHeight.replace('%', '') / 100) * X.height)
                    }
                }
            } else {
                Y.height = parseInt(svHeight)
            }
        }
        if (bc.panelMode == 'both') {
            Y.width -= Z.width
        }
    };
    function setMvSize() {
        bh('#' + O + 'sv-photo-detail, ' + '#' + O + 'sv-photo-detail .photo-frame').width(Y.width);
        var a = O + 'sv-photo-' + (bg - 2);
        var b = O + 'sv-photo-' + (bg);
        if (supportWebkitAnim()) {
            var c = document.getElementById(a);
            var d = document.getElementById(b);
            if (c) {
                c.style.webkitTransitionProperty = '-webkit-transform';
                c.style.webkitTransitionTimingFunction = 'cubic-bezier(0.09,0.34,0.06,1)';
                c.style.webkitTransitionDuration = '0';
                c.style.webkitTransform = 'translate3d(-' + Y.width + 'px, 0px, 0px)'
            }
            if (d) {
                d.style.webkitTransitionProperty = '-webkit-transform';
                d.style.webkitTransitionTimingFunction = 'cubic-bezier(0.09,0.34,0.06,1)';
                d.style.webkitTransitionDuration = '0';
                d.style.webkitTransform = 'translate3d(' + Y.width + 'px, 0px, 0px)'
            }
        } else {
            bh('#' + a).css('left', -Y.width);
            bh('#' + b).css('left', Y.width)
        }
        var e = bh('#' + O + 'sv-photos .sv-photo.photo-frame img');
        e.css('max-width', Y.width);
        bh('#' + O + 'sv-photo-detail, #' + O + 'sv-photos, #' + O + 'sv-photos .sv-photo, #' + O + 'sv-prev-photo, #' + O + 'sv-next-photo').height(Y.height);
        var f = bh('#' + O + 'sv-photo-navigation');
        f.height(Y.height);
        f.width(Z.width);
        if (bc.panelMode == 'both') {
            bh('#' + O + 'sv-mobile').width(Y.width + Z.width).height(Y.height)
        } else if (bc.panelMode == 'navigation') {
            bh('#' + O + 'sv-mobile').width(Y.width).height(Y.height)
        }
        var g, mglft, btrgt;
        var h = getThumbnailGridSize();
        if (bc.panelMode == 'both') {
            g = parseInt((Y.height - 400) / 2);
            mglft = 0;
            btrgt = 27
        } else {
            g = parseInt((Z.height - h.height) / 2);
            mglft = parseInt((Z.width - h.width) / 2);
            if (mglft < 60) {
                btrgt = 3
            } else {
                btrgt = parseInt(mglft / 2 - 27)
            }
        }
        bh('#' + O + 'sv-nav-photo-list').css('margin-top', g).css('margin-left', mglft).height(h.height).width(h.width);
        bh('#' + O + 'sv-nav-page-label').css('left', parseInt(mglft + h.width / 2) - 20).css('top', g + h.height + 10);
        bh('#' + O + 'sv-nav-page-caption').css('left', mglft).css('top', g - 28);
        bh('#' + O + 'sv-nav-page-prev').css('left', btrgt);
        bh('#' + O + 'sv-nav-page-next').css('right', btrgt + 5);
        resizeImages()
    };
    function convertNavPnlIndex(a, b) {
        var c = a.rowCount * a.colCount;
        var d = b.rowCount * b.colCount;
        var e = c * a.crntPnlIndex;
        var f = (c + 1) * a.crntPnlIndex - 1;
        var g = e;
        if (a.imgIndex >= e && a.imgIndex <= f) {
            g = a.imgIndex
        }
        var h = parseInt(g / d);
        return {
            pnlIndex: h,
            pnlImgOnPageIdx: (g % d),
            thumbnailPerPage: d
        }
    };
    function repopuateNavPanel() {
        if (!separateNavPanel()) return;
        var a = {
            colCount: Z.maxColCount,
            rowCount: Z.maxRowCount,
            crntPnlIndex: Z.navListIndex,
            imgIndex: (bg - 1)
        };
        var b;
        setGridScale();
        b = convertNavPnlIndex(a, {
            colCount: Z.maxColCount,
            rowCount: Z.maxRowCount
        });
        Z.navListIndex = b.pnlIndex;
        setNavPnlCalculatedValues();
        removeExtraNavList(a.crntPnlIndex);
        populatePhotoList(Z.navListIndex)
    };
    hideUrlBar = {
        AfterIni: function() {
            if (bc.displayMode !== 'fullscreen') return;
            if (isIphone()) {
                window.scrollTo(0, 1)
            } else if (isAndroid()) {
                window.scrollTo(0, 1)
            }
        },
        InTimer: function() {
            if (bc.displayMode !== 'fullscreen') return;
            if (isAndroid() && getAndroidVer() >= 2.3) {
                window.scrollTo(0, 1)
            }
        },
        hidingTimer: 0,
        hidingTimer2: 0,
        AfterResizing: function() {
            if (bc.displayMode !== 'fullscreen') return;
            if (isIphone()) {
                window.scrollTo(0, 1)
            } else if (isAndroid()) {
                if (hideUrlBar.hidingTimer) window.clearTimeout(hideUrlBar.hidingTimer);
                hideUrlBar.hidingTimer = window.setTimeout(function() {
                    hideUrlBar.hidingTimer = 0;
                    window.scrollTo(0, 1);
                    if (hideUrlBar.hidingTimer2) window.clearTimeout(hideUrlBar.hidingTimer2);
                    hideUrlBar.hidingTimer2 = window.setTimeout(function() {
                        hideUrlBar.hidingTimer2 = 0;
                        bh('.cls-prev-photo, .sv-nav-page-label').hide();
                        window.setTimeout(function() {
                            bh('.cls-prev-photo, .sv-nav-page-label').show()
                        },
                        100)
                    },
                    500)
                },
                2000)
            }
        }
    };
    function resizeViewer() {
        if (hideUrlBar.hidingTimer) window.clearTimeout(hideUrlBar.hidingTimer);
        if (hideUrlBar.hidingTimer2) window.clearTimeout(hideUrlBar.hidingTimer2);
        hideUrlBar.hidingTimer = 0;
        hideUrlBar.hidingTimer2 = 0;
        setPanelSize();
        repopuateNavPanel(true);
        setMvSize();
        hideUrlBar.AfterResizing()
    };
    function resizeImages() {
        bh('#' + O + 'sv-photos .sv-photo.photo-frame').each(function() {
            if (!bh(this).hasClass('loading')) {
                resizeImage(parseInt(bh(this).attr('id').replace(O + 'sv-photo-', '')))
            }
        })
    };
    function resizePhoto(a, b, c) {
        var d, origH, targetW, targetH, ration, xRatio, yRatio;
        var e, newSvHeight;
        d = b;
        origH = c;
        e = Y.width;
        newSvHeight = Y.height;
        xRatio = e / d;
        yRatio = newSvHeight / origH;
        ratio = Math.min(xRatio, yRatio);
        if (xRatio > yRatio) {
            bh('#' + O + 'sv-photo-' + a + ' img').css({
                'height': newSvHeight + 'px',
                'width': 'auto',
                'marginTop': '0'
            })
        } else {
            var f = parseInt(origH * xRatio);
            bh('#' + O + 'sv-photo-' + a + ' img').css({
                'width': e + 'px',
                'height': 'auto',
                'marginTop': parseInt((newSvHeight - f) / 2) + 'px'
            })
        }
    };
    function resizeImage(a) {
        if (!V.images[a].preloadSet) {
            window.setTimeout(function() {
                preloadImages(a, 1)
            },
            250);
            return
        }
        if (!V.images[a].preloaded || !V.images[a].preloadedImage || !V.images[a].preloadedImage.height) {
            window.setTimeout(function() {
                resizeImage(a)
            },
            250);
            return
        }
        resizePhoto(a, V.images[a].preloadedImage.width, V.images[a].preloadedImage.height)
    };
    function resizeFlashViewer() {
        W = getWindowHeight();
        winWidth = getWindowWidth();
        if (bc.displayMode === 'fullscreen') {
            svContainer.css('position', 'static');
            bh('#' + O + 'sv-mobile-flash').width(winWidth);
            bh('#' + O + 'sv-mobile-flash').height(W)
        } else {
            if (ba.indexOf('%') === -1) {
                Y.width = parseInt(ba || X.width || winWidth)
            } else {
                if (!isPercentage(svContainer.attr("style"), "width")) {
                    X.width = getContainerWidth(svContainer);
                    Y.width = Math.floor((ba.replace('%', '') / 100) * X.width)
                } else {
                    if (X.widthRatio) {
                        Y.width = Math.floor((ba.replace('%', '') / 100) * X.widthRatio * winWidth);
                        if (Y.width - 20 < parseInt(winWidth) && Y.width > parseInt(winWidth) - 20) Y.width -= 20
                    } else {
                        Y.width = parseInt((parseInt(ba) / 100) * (X.width || winWidth))
                    }
                }
            }
            if (svHeight.indexOf('%') === -1) {
                Y.height = parseInt(svHeight || X.height || W)
            } else {
                if (!isPercentage(svContainer.attr("style"), "height")) {
                    X.height = getContainerHeight(svContainer);
                    Y.height = Math.floor((svHeight.replace('%', '') / 100) * X.height)
                } else {
                    if (X.heightRatio) {
                        Y.height = Math.floor((svHeight.replace('%', '') / 100) * X.heightRatio * W);
                        if (Y.height - 20 < parseInt(W) && Y.height > parseInt(W) - 20) Y.height -= 20
                    } else {
                        Y.height = parseInt((parseInt(svHeight) / 100) * (X.height || W))
                    }
                }
            }
            bh('#' + O + 'sv-mobile-flash').width(Y.width).children().width(Y.width);
            bh('#' + O + 'sv-mobile-flash').height(Y.height).children().height(Y.height)
        }
    };
    function preloadImages(b, c) {
        var i, end;
        if (b < 0) b = 0;
        end = ((b - 1 + c) > V.images.length - 1) ? V.images.length - 1 : (b - 1 + c);
        for (i = b; i <= end; i += 1) {
            if (needPageReload() && N) {
                bh('#' + O + 'sv-photo-' + i + ' img').attr('src', V.images[i].imageURL);
                bh('#' + O + 'sv-photo-' + i).removeClass('loading');
                var d = bh('#' + O + 'sv-photo-' + i + ' img');
                resizePhoto(i, d.width(), d.height())
            } else if (!V.images[i].preloadSet) {
                V.images[i].preloadedImage = new Image();
                V.images[i].preloadedImage.onload = function(a) {
                    return function() {
                        V.images[a].preloaded = true;
                        bh('#' + O + 'sv-photo-' + a + ' img').attr('src', V.images[a].imageURL);
                        bh('#' + O + 'sv-photo-' + a).removeClass('loading');
                        resizeImage(a)
                    }
                } (i);
                V.images[i].preloadedImage.src = V.images[i].imageURL;
                V.images[i].preloadSet = true
            } else {
                bh('#' + O + 'sv-photo-' + i + ' img').attr('src', V.images[i].imageURL);
                bh('#' + O + 'sv-photo-' + i).removeClass('loading');
                resizeImage(i)
            }
            if (!V.images[i].imageLoaded) {
                V.images[i].imageLoaded = true;
                if (!V.loadedCount) V.loadedCount = 0;
                V.loadedCount++
            }
        }
    };
    function toggleFullscreenMode(a) {
        if (bc.displayMode === 'fullscreen') {
            bc.displayMode = 'embed';
            bh(document.body).css('overflow', 'auto')
        } else {
            bc.displayMode = 'fullscreen';
            bh(document.body).css('overflow', 'hidden')
        }
        resizeViewer();
        a.preventDefault();
        a.stopPropagation()
    };
    function isInIframe() {
        if (top && top.location != location) {
            return true
        }
        return false
    };
    function errorMessage(a) {
        var b, newH;
        if (ba.indexOf('%') > -1) {
            b = Math.floor((ba.replace('%', '') / 100) * X.width)
        } else {
            b = parseInt(ba)
        }
        if (svHeight.indexOf('%') > -1) {
            newH = Math.floor((svHeight.replace('%', '') / 100) * (X.height || W))
        } else {
            newH = parseInt(svHeight)
        }
        setPanelSize();
        setMvSize();
        bh('#' + O + 'sv-mobile').html('<div id="' + O + 'sv-error" class="sv-cls-error" style=""><div id="' + O + 'sv-error-text" class="sv-cls-error-text">' + a + '</div><div id="' + O + 'sv-error-bg" class="sv-cls-error-bg"></div></div>');
        bh('#' + O + 'sv-error').css({
            'width': bh('#' + O + 'sv-error-text').outerWidth() + 'px',
            'height': bh('#' + O + 'sv-error-text').outerHeight() + 'px',
            'top': (newH / 2) - (bh('#' + O + 'sv-error-text').outerHeight() / 2) + 'px',
            'left': (b / 2) - (bh('#' + O + 'sv-error-text').outerWidth() / 2) + 'px'
        });
        bh('#' + O + 'sv-error-bg').css({
            'height': bh('#' + O + 'sv-error-text').outerHeight() + 'px'
        })
    };
    function getImageHtmlContent(i) {
        var a = '<img src="' + svCoreURL + 'img/empty-pixel.png" alt="">';
        if (V.images[i].preloadSet) a = '<img src="' + V.images[i].imageURL + '" alt="">';
        a += '<div class="sv-caption clearfix" style="font-size: ' + bf + 'px;' + (Y.showOverlay && V.mobileshowcaption ? '': 'display:none;') + '">';
        a += '<div class="sv-paging">' + (i + 1) + '/' + Q + '</div>';
        a += V.images[i].caption ? '<div class="sv-title">' + V.images[i].caption + '</div>': '';
        a += '<div class="sv-description">' + V.images[i].description + '</div>';
        a += '</div>';
        return a
    };
    function getImageHtml(i, a) {
        if (i < 0 || i >= V.images.length) return '';
        var b = (V.images[i] && V.images[i].preloaded) ? '': 'loading';
        var c = '<div class="sv-photo ' + b + ' photo-frame" id="' + O + 'sv-photo-' + i + '" style="' + (a ? a: '') + '">';
        c += getImageHtmlContent(i);
        c += '</div>';
        return c
    };
    function populatePhotoFrame(a) {
        var b = '';
        var c = supportWebkitAnim() ? '-webkit-transform:translateX(-' + (Y.width + U) + 'px);': 'left:' + ( - Y.width) + 'px;';
        var d = supportWebkitAnim() ? '-webkit-transform:translateX(' + (Y.width + U) + 'px);': 'left:' + Y.width + 'px;';
        if (a > 0) {
            b += getImageHtml(a - 1, c)
        }
        b += getImageHtml(a);
        if (a < Q - 1) {
            b += getImageHtml(a + 1, d)
        }
        bh('#' + O + 'sv-photos').html(b);
        if (a > 0) {
            preloadImages(a - 1, 1)
        }
        preloadImages(a, 1);
        if (a < Q - 1) {
            preloadImages(a + 1, 1)
        }
        setMvSize()
    };
    function adjCurrentIndex(a) {
        if (a > V.images.length) a = V.images.length;
        if (a <= 0) a = 1;
        return a
    };
    function removeExtraNavList(a) {
        if (a < 0 || a >= Q - 1) return;
        if (supportWebkitAnim()) {
            var b = document.getElementById(O + '-nav-lst-' + a);
            b.style.webkitTransitionTimingFunction = 'cubic-bezier(0.09,0.34,0.06,1)';
            b.style.webkitTransitionDuration = '0';
            b.style.webkitTransform = '';
            if (needPageReload()) {
                bh('#' + O + '-nav-lst-' + a + ' img').attr('src', '')
            }
        }
        bh('#' + O + '-nav-lst-' + a).remove()
    };
    function move2NavListPnl(a, b, c) {
        if (a < 0 || a > Z.totalPage || b < 0 || b > Z.totalPage) return;
        var d = 0;
        if (a > b) {
            d = 1
        } else if (b > a) {
            d = -1
        }
        if (d == 0) return;
        if (Math.abs(b - a) > 1) {
            removeExtraNavList(a + d);
            removeExtraNavList(a);
            populatePhotoList(b);
            return
        }
        removeExtraNavList(a + d);
        var e = getSlideDuration();
        if (!supportWebkitAnim()) {
            bh('#' + O + '-nav-lst-' + a).animate({
                left: (d * getThumbnailGridSize().width) + 'px'
            },
            {
                specialEasing: {
                    left: 'easeOutQuart'
                },
                duration: e.d
            });
            bh('#' + O + '-nav-lst-' + b).animate({
                left: '0'
            },
            {
                specialEasing: {
                    left: 'easeOutQuart'
                },
                duration: e.d,
                complete: function() {
                    populatePhotoList(b)
                }
            });
            return
        }
        var f = bh('#' + O + '-nav-lst-' + a);
        var g = getPhotoListHtml(b - d, '-webkit-animation-duration:0;-webkit-transform:translateX(' + ( - d * getThumbnailGridSize().width) + 'px);');
        if (d < 0) {
            bh('#' + O + 'sv-nav-photo-list').append(g)
        } else {
            bh(g).insertBefore('#' + O + '-nav-lst-' + b)
        }
        setNavControls(Z.navListIndex, bg - 1);
        var h = document.getElementById(O + '-nav-lst-' + a);
        var i = document.getElementById(O + '-nav-lst-' + b);
        h.style.webkitTransitionProperty = '-webkit-transform';
        i.style.webkitTransitionProperty = '-webkit-transform';
        if (c) {
            h.style.webkitTransitionTimingFunction = 'cubic-bezier(0.45,0.37,0.62,1)';
            h.style.webkitTransitionDuration = c + 'ms';
            i.style.webkitTransitionTimingFunction = 'cubic-bezier(0.45,0.37,0.62,1)';
            i.style.webkitTransitionDuration = c + 'ms'
        } else {
            h.style.webkitTransitionTimingFunction = 'cubic-bezier(0.09,0.34,0.06,1)';
            h.style.webkitTransitionDuration = e.d + 'ms';
            i.style.webkitTransitionTimingFunction = 'cubic-bezier(0.09,0.34,0.06,1)';
            i.style.webkitTransitionDuration = e.d + 'ms'
        }
        h.style.webkitTransform = 'translate3d(' + (d * 100) + '%, 0px, 0px)';
        i.style.webkitTransform = 'translate3d(0px, 0px, 0px)'
    };
    function resizeCurrentImg() {
        if (! (needPageReload() && N)) return;
        var a = bh('#' + O + 'sv-photo-' + (bg - 1) + ' img');
        resizePhoto(bg - 1, a.width(), a.height())
    };
    function getSlideDuration() {
        if (isIpad() || isAndroid() || isIphone()) return {
            d: 500,
            glcls: "anim-go2left-ipad",
            grcls: "anim-go2right-ipad"
        };
        return {
            od: 200,
            d: 500,
            glcls: "anim-go2left",
            grcls: "anim-go2right"
        }
    };
    function removeExtraPhoto(a) {
        if (supportWebkitAnim()) {
            var b = document.getElementById(O + 'sv-photo-' + a);
            if (b) {
                b.style.webkitTransitionDuration = '0';
                b.style.webkitTransform = ''
            }
            if (needPageReload()) {
                bh('#' + O + 'sv-photo-' + a + ' img').attr('src', '')
            }
        }
        bh('#' + O + 'sv-photo-' + a).remove()
    };
    var bn = '';
    function removeExtraPhotos(a, b) {
        if (b > a) {
            if (a - 1 >= 0) removeExtraPhoto(a - 1);
            if (a + 1 < b - 1) removeExtraPhoto(a + 1)
        } else {
            if (a + 1 < Q - 1) removeExtraPhoto(a + 1);
            if (a - 1 > b + 1) removeExtraPhoto(a - 1)
        }
        var c = bn.split(',');
        var d;
        for (var i = 0; i < c.length; i++) {
            d = parseInt(c[i]);
            if (d != a && Math.abs(d - b) > 1) removeExtraPhoto(d)
        }
        bn = ''
    };
    function setCurrentPohot(a) {
        bh('#' + O + 'nav-pht-lnks-' + a).addClass('current').addClass('visited')
    };
    function setNavStyle(a, b) {
        bh('#' + O + 'nav-pht-lnks-' + a).removeClass('current');
        setCurrentPohot(b)
    };
    var bo = null;
    var bp = null;
    function cancelUnfinishedAnima() {
        if (bo) bo.stop();
        if (bp) bp.stop();
        bo = null;
        bp = null
    };
    var bq = 0;
    function move2Photo(a, b, c, d, e) {
        if (a < 0 || a > Q || b < 0 || b > Q || a == b) return;
        var f = 0;
        if (a > b) {
            f = 1
        } else if (b > a) {
            f = -1
        }
        if (b >= 0 && b < Q) {
            V.images[b].visited = true
        }
        var g = parseInt(b / Z.thumbCountPerPage);
        var h = Z.navListIndex;
        Z.navListIndex = g;
        if (needPageReload() && !N && V.loadedCount >= T + 2) {
            bg = b + 1;
            SV.simpleviewer.saveCurrentPage();
            bh('#' + O + 'sv-photo-detail').hide();
            reloadPhotoSlid();
            return
        }
        move2NavListPnl(h, Z.navListIndex);
        setNavControls(Z.navListIndex, b);
        removeExtraPhotos(a, b);
        bh('#' + O + 'sv-open-window').attr('href', V.images[b].imageFullURL).attr('target', V.images[b].linkTarget);
        var i = 'width:' + Y.width + 'px;height:' + Y.height + 'px;';
        if (Math.abs(a - b) > 1) {
            var j;
            if (supportWebkitAnim()) {
                j = getImageHtml(b, '-webkit-animation-duration:0;-webkit-transform:translateX(' + ( - f * (Y.width + U)) + 'px);' + i)
            } else {
                j = getImageHtml(b, 'left:' + ( - f * (Y.width + U)) + 'px;' + i)
            }
            if (f < 0) {
                bh('#' + O + 'sv-photos').append(j)
            } else {
                bh(j).insertBefore('#' + O + 'sv-photo-' + a)
            }
            preloadImages(b, 1)
        }
        if (c == 'calledfromnav') {
            populatePhotoFrame(b)
        } else {
            var k = getSlideDuration();
            if (!supportWebkitAnim()) {
                var l = bh('#' + O + 'sv-photo-' + b);
                if (l.length <= 0) {
                    populatePhotoFrame(b);
                    setNavStyle(a, b);
                    return
                }
                cancelUnfinishedAnima();
                bp = bh('#' + O + 'sv-photo-' + a);
                bp.animate({
                    left: (f * (Y.width + U)) + 'px'
                },
                k.d, 'easeOutQuart',
                function() {
                    bp = null
                });
                bo = l;
                l.animate({
                    left: '0'
                },
                k.d, 'easeOutQuart',
                function() {
                    cancelUnfinishedAnima();
                    if (parseInt(bh('#' + O + 'sv-photo-' + b).css('left')) == 0) {
                        populatePhotoFrame(b)
                    }
                    bo = null
                });
                setNavStyle(a, b);
                return
            }
            var m = bh('#' + O + 'sv-photo-' + a);
            var n = getImageHtml(b - f, '-webkit-animation-duration:0;-webkit-transform:translateX(' + ( - f * (Y.width + U)) + 'px);' + i);
            var o;
            if (f < 0) {
                bh('#' + O + 'sv-photos').append(n);
                if (b - a > 1) {
                    o = getImageHtml(b - 1, '-webkit-animation-duration:0;-webkit-transform:translateX(' + ( - f * (Y.width + U)) + 'px);' + i);
                    bh(o).insertBefore('#' + O + 'sv-photo-' + b);
                    preloadImages(b - 1, 1)
                }
            } else {
                bh(n).insertBefore('#' + O + 'sv-photo-' + b);
                if (a - b > 1) {
                    o = getImageHtml(b + 1, '-webkit-animation-duration:0;-webkit-transform:translateX(' + ( - f * (Y.width + U)) + 'px);' + i);
                    bh('#' + O + 'sv-photos').append(o);
                    preloadImages(b + 1, 1)
                }
            }
            preloadImages(b - f, 1);
            setNavStyle(a, b);
            var p = document.getElementById(O + 'sv-photo-' + a);
            var q = document.getElementById(O + 'sv-photo-' + b);
            p.style.webkitTransitionProperty = '-webkit-transform';
            q.style.webkitTransitionProperty = '-webkit-transform';
            if (d) {
                p.style.webkitTransitionTimingFunction = 'cubic-bezier(0.45,0.37,0.62,1)';
                p.style.webkitTransitionDuration = d + 'ms';
                q.style.webkitTransitionTimingFunction = 'cubic-bezier(0.45,0.37,0.62,1)';
                q.style.webkitTransitionDuration = d + 'ms'
            } else {
                p.style.webkitTransitionTimingFunction = 'cubic-bezier(0.09,0.34,0.06,1)';
                p.style.webkitTransitionDuration = k.d + 'ms';
                q.style.webkitTransitionTimingFunction = 'cubic-bezier(0.09,0.34,0.06,1)';
                q.style.webkitTransitionDuration = k.d + 'ms'
            }
            if (!separateNavPanel()) {
                if (bq) {
                    window.clearTimeout(bq);
                    bq = 0
                }
                bq = window.setTimeout(function() {
                    p.style.webkitTransform = 'translate3d(' + (f * Y.width) + 'px, 0px, 0px)';
                    q.style.webkitTransform = 'translate3d(0px, 0px, 0px)';
                    bq = 0
                },
                100)
            } else {
                p.style.webkitTransform = 'translate3d(' + (f * (Y.width + U)) + 'px, 0px, 0px)';
                q.style.webkitTransform = 'translate3d(0px, 0px, 0px)';
                bq = 0
            }
        }
        setNavStyle(a, b);
        bn += a + ','
    };
    function isIpad() {
        if (navigator.userAgent.match(/iPad/i)) return true;
        return false
    };
    function separateNavPanel() {
        return true
    };
    function toggleOverlay() {
        if (Y.showOverlay) {
            Y.showOverlay = false
        } else {
            Y.showOverlay = true
        }
    };
    function useClickableOverlay() {
        if (isIpad() || isAndroid() || isIphone()) return true;
        return false
    };
    function needPageReload() {
        if (navigator.userAgent.match(/iPad/i)) return true;
        if (navigator.userAgent.match(/iPhone/i)) return true;
        return false
    };
    function isWindowsPhone7IE() {
        return false;
        if (navigator.userAgent.match(/Windows Phone OS 7/i) && navigator.userAgent.match(/MSIE/i)) return true;
        return false
    };
    function isAndroid() {
        if (navigator.userAgent.match(/Android/i)) return true;
        return false
    };
    function getAndroidVer() {
        var a = navigator.userAgent.indexOf('Android');
        if (a < 0) return 0;
        var b = navigator.userAgent.indexOf(';', a);
        if (b <= a) return 0;
        var c = navigator.userAgent.substring(a, b);
        var d = c.split(' ');
        if (d.length != 2) return 0;
        return parseFloat(d[1])
    };
    function isIphone() {
        if (navigator.userAgent.match(/iPhone/i)) return true;
        return false
    };
    function isSwipable() {
        if (isAndroid() || isIpad() || isIphone()) return true;
        return false
    };
    function supportWebkitAnim() {
        if (navigator.userAgent.match(/AppleWebKit/i)) return true;
        return false
    };
    function formatColor(a) {
        if (a && a.toLowerCase() == 'transparent') {
            return a
        }
        return "#" + a
    };
    function getContainerHeightRatio2Win(a) {
        return getContainerSizeRatio2Win(a, getInlineCssHeight)
    };
    function getContainerHeight(a) {
        return getContainerSize(a, getContainerPxHeight, W, "height")
    };
    function getContainerPxHeight(a) {
        var b;
        if (bh.browser.msie && bh.browser.version == '6.0') {
            b = getInlineCssHeight(a.attr("style"));
            if (parseInt(b) > 0 && b.indexOf("%") < 0) return parseInt(b)
        } else {
            b = a.height()
        }
        if (bh.browser.msie && bh.browser.version < 8) {
            var c = bh('body').height();
            if (c == 0) {
                return 0
            } else if (c < 0.7 * W) {
                return W - c
            }
        }
        if (b && !(bh.browser.msie && bh.browser.version < 7 && a.height() < 0.5 * a.width())) return b;
        var c = bh('body').height();
        if (c == 0) {
            return 0
        }
        var d = a.parent();
        while (d && d.length > 0) {
            if (d.height()) return d.height();
            d = d.parent()
        }
        return 0
    };
    function getInlineCssWidth(a) {
        var w = getInlineStyleValue(a, "width");
        if (parseInt(w) == 0) return 0;
        return w
    };
    function getInlineCssHeight(a) {
        var h = getInlineStyleValue(a, "height");
        if (parseInt(h) == 0) return 0;
        return h
    };
    function getInlineStyleValue(a, k) {
        if (!a) return '';
        if (!k) return '';
        var b = a.split(';');
        var c, itm, vk, vv;
        for (var i = 0; i < b.length; i++) {
            itm = bh.trim(b[i]);
            if (!itm) continue;
            c = itm.split(':');
            if (c.length != 2) continue;
            vk = bh.trim(c[0]);
            vv = bh.trim(c[1]);
            if (!vk) continue;
            if (vk.toLowerCase() == k.toLowerCase()) {
                return vv
            }
        }
        return ''
    };
    function isPercentage(a, b) {
        var c = getInlineStyleValue(a, b);
        if (c.indexOf('%') < 0 && parseInt(c)) return false;
        return true
    };
    function getContainerSizeRatio2Win(c, d) {
        var e = 1;
        var f = 0;
        var g;
        c.parents().each(function(i, n) {
            var a = n.nodeName.toUpperCase();
            if (a == "HTML" || a == "BODY") return;
            g = bh(n).attr("style");
            var b = d(g);
            if (b.toLowerCase().indexOf('%') < 0 && parseInt(b) > 0) {
                f = parseInt(b)
            }
            if (!b) return;
            if (f > 0) return;
            if (b.indexOf("%") > 0) {
                e *= (parseInt(b) / 100)
            }
        });
        if (f > 0) return 0;
        g = c.attr("style");
        var h = d(g);
        if (h.indexOf("%") > 0) {
            e *= (parseInt(h) / 100)
        } else if (parseInt(h) > 0) {
            return 0
        }
        return e
    };
    function getContainerWidthRatio2Win(a) {
        return getContainerSizeRatio2Win(a, getInlineCssWidth)
    };
    function getContainerSize(c, d, e, f) {
        var g = d(c);
        if (g) return g;
        if (!c.css(f) && !c.parents().css(f)) return 0;
        var h = 1;
        var j = 0;
        c.parents().each(function(i, n) {
            var a = n.nodeName.toUpperCase();
            if (a == "HTML" || a == "BODY") return;
            var b = bh(n).css(f);
            if (!b) return;
            if (j > 0) return;
            if (b.indexOf("%") > 0) {
                h *= (parseInt(b) / 100)
            } else {
                j = parseInt(b)
            }
        });
        var k = c.css(f);
        if (k.indexOf("%") > 0) {
            return (parseInt(k) / 100) * h * (j || e)
        } else if (parseInt(k) == 0) {
            return h * (j || e)
        }
        return parseInt(k)
    };
    function getContainerWidth(a) {
        return getContainerSize(a, getContainerPxWidth, winWidth, "width")
    };
    function getContainerPxWidth(a) {
        if (bh.browser.msie && bh.browser.version == '6.0') {
            var b = getInlineCssWidth(a.attr("style"));
            if (parseInt(b) > 0 && b.indexOf("%") < 0) return parseInt(b)
        }
        if (a.width()) return a.width();
        var c = bh('body').width();
        if (c == 0) return 0;
        var d = a.parent();
        while (d && d.length > 0) {
            if (d.width()) return d.width();
            d = d.parent()
        }
        return 0
    };
    function getPresetUrlOptions(d, e, f) {
        bh.ajax({
            type: 'GET',
            url: (d.indexOf('http') == 0 ? d: (e.baseurl ? e.baseurl + (bm(e.baseurl, '/') ? '': '/') + d: d)),
            dataType: (bh.browser.msie) ? 'text': 'xml',
            success: function(a) {
                var b;
                if (typeof a === 'string') {
                    b = new ActiveXObject("Microsoft.XMLDOM");
                    b.async = false;
                    b.loadXML(a)
                } else {
                    b = a
                }
                var c = parseXML(b, e.baseurl);
                c = bh.extend(c, e);
                delete c.images;
                V = bh.extend(false, V, c);
                Q = V.images.length;
                f()
            },
            error: function(a, b, c) {
                if (navigator.userAgent.indexOf('Chrome') > -1 && (window.location.href.indexOf('http://') === -1 && window.location.href.indexOf('https://') === -1)) {
                    errorMessage('SimpleViewer does not display locally in Google Chrome.')
                } else {
                    errorMessage('Gallery XML Not Found.')
                }
            }
        })
    };
    function parseBool(a, b) {
        if (typeof(a) == 'undefined') return b;
        if (typeof(a) != 'string') return a;
        if (a.toLowerCase() == "false") return false;
        if (a.toLowerCase() == "true") return true;
        return a
    };
    function setCookie(a, b, c) {
        var d = new Date();
        d.setDate(d.getDate() + c);
        document.cookie = a + "=" + escape(b) + ((c == null) ? "": ";expires=" + d.toUTCString())
    };
    function getCookie(a) {
        if (document.cookie.length > 0) {
            c_start = document.cookie.indexOf(a + "=");
            if (c_start != -1) {
                c_start = c_start + a.length + 1;
                c_end = document.cookie.indexOf(";", c_start);
                if (c_end == -1) c_end = document.cookie.length;
                return unescape(document.cookie.substring(c_start, c_end))
            }
        }
        return ""
    };
    function getCrntImgIdxKey() {
        return O + "svcrntimgi"
    };
    function getCrntNavIdxKey() {
        return O + "svcrntnavi"
    };
    function getSvReLoadedFlag() {
        return O + "svcrntimgi_lf"
    };
    function getCrntDisplayedPanelKey() {
        return O + "svcrntpanel"
    };
    function getVisitedPhotoKey() {
        return O + "svvisitedphotos"
    };
    function getIfShowOverlay() {
        return O + "svckifshowoverlay"
    };
    function getCurrentPageBoundary(a) {
        return getBoundaryByIndex(a, T)
    };
    function getBoundaryByIndex(a, b) {
        var r = a % b;
        var l = 0;
        if (r === 0) {
            if (a / b > 1) {
                l = a - b
            }
        } else {
            if (a / b > 1) {
                l = b * parseInt(a / b)
            }
        }
        l++;
        return {
            lowbdry: l,
            highbdry: l + b
        }
    };
    function getCurrentImgIdxFromCookie() {
        if (!getCookie(getSvReLoadedFlag())) return null;
        var a = parseInt(getCookie(getCrntImgIdxKey()));
        setCookie(getSvReLoadedFlag(), '', null);
        var b = parseInt(getCookie(getCrntNavIdxKey()));
        var c = parseBool(getCookie(getIfShowOverlay()));
        var d = parseInt(getCookie(getCrntDisplayedPanelKey())) > 0 ? true: false;
        var e = getCookie(getVisitedPhotoKey());
        return {
            crntImgIdx: a,
            crntNavIdx: b,
            navPnlVisible: d,
            visitedImages: e,
            showOverlay: c
        }
    };
    function setCurrentImgIdxCookie(a) {
        setCookie(getCrntImgIdxKey(), a, null);
        setCookie(getCrntNavIdxKey(), Z.navListIndex);
        setCookie(getSvReLoadedFlag(), '1', null);
        setCookie(getIfShowOverlay(), Y.showOverlay);
        var t = bh('#' + O + 'sv-photo-navigation:visible').length;
        setCookie(getCrntDisplayedPanelKey(), t);
        var b = '';
        for (var i = 0; i < V.images.length; i++) {
            if (!V.images[i].visited) continue;
            b += (i + ',')
        }
        setCookie(getVisitedPhotoKey(), b)
    };
    function reloadPhotoSlid() {
        location.reload(true)
    };
    function getiPhoneAdjRatio(a, b) {
        if (!isIphone()) return 1;
        return (a > b) ? 1.20 : 1.30
    };
    function adjustHeight4Devices(a, b) {
        if (isIphone()) {
            return a * getiPhoneAdjRatio(a, b)
        } else if (isAndroid()) {
            if (getAndroidVer() >= 2.3) {
                return a + 1
            } else {
                return a - 24
            }
        }
        return a + 1
    };
    function initializePhotoFrameObjs() {
        bi = document.getElementById(O + 'sv-photos');
        bi.style.webkitTransitionProperty = '-webkit-transform';
        bi.style.webkitTransitionTimingFunction = 'cubic-bezier(0.09,0.34,0.06,1)';
        var a = getSlideDuration();
        bj = a.d + 'ms';
        bi.style.webkitTransitionDuration = bj
    };
    var br = 0;
    function resetDuration() {
        if (br) {
            window.clearTimeout(br)
        }
        br = window.setTimeout(function() {
            bi.style.webkitTransitionDuration = bj
        },
        100)
    };
    R = {
        load: function(u, v, w, y, z, A, B, C, D, E) {
            O = u;
            if (bh === null) bh = jQuery.noConflict();
            if (!bh.easing.easeOutQuart) {
                bh.extend(bh.easing, {
                    easeOutQuart: function(x, t, b, c, d) {
                        return - c * ((t = t / d - 1) * t * t * t - 1) + b
                    }
                })
            }
            var F;
            winWidth = getWindowWidth();
            W = adjustHeight4Devices(getWindowHeight(), winWidth);
            w = w.replace('px', '');
            y = y.replace('px', '');
            svContainerId = v;
            svContainer = bh('#' + v);
            svContainer.html('');
            X.width = getContainerWidth(svContainer);
            X.height = getContainerHeight(svContainer);
            X.widthRatio = getContainerWidthRatio2Win(svContainer);
            X.heightRatio = getContainerHeightRatio2Win(svContainer);
            ba = w;
            svHeight = y;
            if (w === '100%' && y === '100%' && svContainer.width() === bh('body').width() && (!X.height || X.height == W)) {
                bc.displayMode = 'fullscreen';
                setBodySize(W, winWidth)
            } else {
                bc.displayMode = 'embed';
                if (!X.height && y.indexOf('%') === -1) {
                    svContainer.css({
                        'height': y + 'px'
                    })
                }
            }
            backgroundColor = (z ? z.replace('#', '') : '');
            be = B || {};
            params = C || {};
            attributes = D || {};
            var G = M && (E === null || typeof E === 'undefined' || (typeof E !== 'undefined' && E));
            if (!isAndroid() && typeof swfobject !== 'undefined' && swfobject.hasFlashPlayerVersion(bd) && (typeof A === 'undefined' || (typeof A !== 'undefined' && A))) {
                var H;
                if (swfobject.hasFlashPlayerVersion('10.0.0') && G) {
                    H = svCoreURL + 'swf/simpleviewer_icc.swf'
                } else {
                    H = svCoreURL + 'swf/simpleviewer.swf'
                }
                F = parseInt(X.height || W);
                svContainer.html(generateSVFlashHtml());
                bh('#' + O + 'sv-mobile-flash').height(F);
                params.allowfullscreen = true;
                params.allowscriptaccess = 'always';
                if (!z || z.toLowerCase() === 'transparent') {
                    params.wmode = 'transparent';
                    params.bgcolor = params.bgcolor || "#222222"
                } else {
                    params.bgcolor = params.bgcolor || z
                }
                be.embedurl = window.location.href;
                swfobject.embedSWF(H, O + 'sv-mobile-flash-swf', w, y, bd, false, be, params, attributes);
                bh(window).bind('resize', resizeFlashViewer);
                window.setTimeout(resizeFlashViewer, 100);
                return
            }
            svContainer.css({
                'position': 'relative'
            });
            svContainer.html(generateSVHtml());
            if (bc.displayMode === 'embed') {
                bh('#' + v + ' .simpleviewer').css({
                    'position': 'relative'
                })
            }
            bh('#' + O + 'sv-mobile').css({
                'background': formatColor(backgroundColor)
            });
            if (!M) {
                bh('#' + P.randomId).click(function(a) {
                    window.open('http://render.kz', 'sv');
                    a.preventDefault();
                    a.stopPropagation()
                })
            }
            B = cvtObjectAttrLowerCase(B);
            var I = decodeURIComponent(window.location.href);
            var J = 'baseURL=';
            var K = I.indexOf(J);
            if (K > 0) {
                if (!B) B = {};
                B.baseurl = I.substring(K + J.length).split('&')[0]
            }
            var L;
            J = 'galleryURL=';
            K = I.indexOf(J);
            if (K > 0) {
                L = I.substring(K + J.length).split('&')[0]
            }
            L = (B && B.galleryurl ? B.galleryurl: (L ? L: 'gallery.xml'));
            if (L.indexOf("://") < 0) {
                if (B.baseurl) {
                    L = L.replace('../', '');
                    L = (bm(B.baseurl, '/') ? B.baseurl: B.baseurl + '/') + L
                } else {
                    L = (svCoreURL !== '' && svCoreURL !== 'svcore/' ? I.substr(0, I.lastIndexOf('/') + 1) : '') + L
                }
            }
            J = 'presetURL=';
            K = I.indexOf(J);
            if (K > 0) {
                if (!B) B = {};
                B.preseturl = I.substring(K + J.length).split('&')[0]
            }
            bh.ajax({
                type: 'GET',
                url: L,
                dataType: (bh.browser.msie) ? 'text': 'xml',
                success: function(s) {
                    var t;
                    if (typeof s === 'string') {
                        t = new ActiveXObject("Microsoft.XMLDOM");
                        t.async = false;
                        t.loadXML(s)
                    } else {
                        t = s
                    }
                    V = parseXML(t, B.baseurl);
                    V = bh.extend(V, B);
                    if (!M) {
                        V.mobileshownav = true;
                        V.mobileshowcaption = true;
                        delete V.preseturl
                    }
                    if (V.preseturl) {
                        getPresetUrlOptions(V.preseturl, B, onFinishXmlLoad)
                    } else {
                        onFinishXmlLoad()
                    }
                    function onFinishXmlLoad() {
                        V.mobileshownav = parseBool(V.mobileshownav, true);
                        V.mobileshowcaption = parseBool(V.mobileshowcaption, true);
                        V.showopenbutton = parseBool(V.showopenbutton, true);
                        V.showfullscreenbutton = parseBool(V.showfullscreenbutton, true);
                        if (V.useflickr) {
                            if (T > 13) T -= 13;
                            if (V.flickrusername) {
                                R.flickrApi.getUserId(function() {
                                    R.flickrApi.getPhotos(initCallback)
                                })
                            } else {
                                R.flickrApi.getPhotos(initCallback)
                            }
                        } else {
                            initCallback()
                        }
                    };
                    function initCallback() {
                        var i, photoHtml;
                        if (!V.images || V.images.length === 0) {
                            errorMessage('No Images Specified in Gallery XML.');
                            return
                        }
                        if (separateNavPanel()) {
                            bc.panelMode = 'navigation';
                            bh('#' + O + 'sv-photo-detail').hide();
                            bh('#' + O + 'sv-photo-navigation').show();
                            var f = bh('#' + O + 'sv-go-nav-panel');
                            f.show();
                            bh('#' + O + 'sv-topmenu-links').width(37);
                            f.click(function() {
                                var b = bh('#' + O + 'sv-photo-detail');
                                b.fadeOut(250,
                                function() {
                                    b.hide();
                                    var a = bh('#' + O + 'sv-photo-navigation');
                                    a.show();
                                    a.fadeIn(250)
                                })
                            })
                        }
                        setPanelsScale();
                        calculateMvSize();
                        if (bc.displayMode === 'embed' && V.showfullscreenbutton && !isInIframe()) {
                            var g = encodeURIComponent(svCoreURL !== '' && svCoreURL !== 'svcore/' ? window.location.href.substr(0, window.location.href.lastIndexOf('/') + 1) : '../');
                            var h = svCoreURL + 'full.html?bg=' + z + '&galleryURL=' + g + (B && B.galleryurl ? B.galleryurl: 'gallery.xml') + (V.preseturl ? '&presetURL=' + g + V.preseturl: '') + (V.baseurl ? '&baseURL=' + V.baseurl: '');
                            bh('#' + O + 'sv-go-fullscreen, #' + O + 'sv-nav-go-fullscreen').attr('href', h);
                            bh('#' + O + 'sv-topmenu-links').width(bh('#' + O + 'sv-topmenu-links').width() + 37);
                            bh('#' + O + 'sv-nav-topmenu-links').width(bh('#' + O + 'sv-nav-topmenu-links').width() + 37);
                            bh('#' + O + 'sv-go-fullscreen, #' + O + 'sv-nav-go-fullscreen, #' + O + 'sv-nav-topmenu').show()
                        }
                        if (V.showopenbutton) {
                            bh('#' + O + 'sv-topmenu-links').width(bh('#' + O + 'sv-topmenu-links').width() + 37);
                            bh('#' + O + 'sv-open-window').show()
                        }
                        if (typeof svMobile !== 'undefined' && svMobile) {
                            bh('#' + O + 'sv-go-fullscreen, #' + O + 'sv-nav-go-fullscreen').click(function(a) {
                                history.back();
                                a.preventDefault();
                                a.stopPropagation()
                            });
                            if (!bh.browser.msie || bh.browser.version >= 8) {
                                bh('#' + O + 'sv-topmenu-links').width(bh('#' + O + 'sv-topmenu-links').width() + 37);
                                bh('#' + O + 'sv-nav-topmenu-links').width(bh('#' + O + 'sv-nav-topmenu-links').width() + 37)
                            }
                            bh('#' + O + 'sv-go-fullscreen, #' + O + 'sv-nav-go-fullscreen, #' + O + 'sv-nav-topmenu').show()
                        }
                        if (isSwipable()) initializeSwipe(bh);
                        bh('#' + O + 'sv-nav-page-prev').click(function() {
                            var a = Z.navListIndex;
                            if (a <= 0) return false;
                            Z.navListIndex--;
                            move2NavListPnl(a, Z.navListIndex);
                            return false
                        });
                        bh('#' + O + 'sv-nav-page-next').click(function() {
                            var a = Z.navListIndex;
                            if (a >= Z.totalPage - 1) return false;
                            Z.navListIndex++;
                            move2NavListPnl(a, Z.navListIndex);
                            return false
                        });
                        V.firstimageindex++;
                        var k = (M && V.firstimageindex) ? parseInt(V.firstimageindex) : 0;
                        if (k > Q || k < 0) k = 0;
                        if (needPageReload()) {
                            var l = true;
                            var m = getCurrentImgIdxFromCookie();
                            if (m) {
                                bg = adjCurrentIndex(m.crntImgIdx);
                                Z.navListIndex = m.crntNavIdx;
                                l = m.navPnlVisible;
                                Y.showOverlay = m.showOverlay;
                                if (m.visitedImages) {
                                    var n = m.visitedImages.split(',');
                                    var o;
                                    for (var j = 0; j < n.length; j++) {
                                        o = parseInt(n[j]);
                                        if (o < 0 || o >= V.images.length) continue;
                                        if (V.images[o]) V.images[o].visited = true
                                    }
                                }
                            } else {
                                bg = 1;
                                Z.navListIndex = 0;
                                if (k > 0) {
                                    bg = k;
                                    l = false
                                }
                            }
                            if (l === false) {
                                bh('#' + O + 'sv-photo-navigation').hide();
                                bh('#' + O + 'sv-photo-detail').show()
                            }
                            V.images[bg - 1].visited = true;
                            populatePhotoList(Z.navListIndex);
                            populatePhotoFrame(bg - 1)
                        } else {
                            if (k > 0) {
                                bg = k;
                                bh('#' + O + 'sv-photo-navigation').hide();
                                bh('#' + O + 'sv-photo-detail').show()
                            } else {
                                bg = 1
                            }
                            V.images[bg - 1].visited = true;
                            populatePhotoList(parseInt((bg - 1) / Z.thumbCountPerPage));
                            populatePhotoFrame(bg - 1)
                        }
                        showOverlayControls(Y.showOverlay);
                        setNavControls(Z.navListIndex, bg - 1);
                        if (supportWebkitAnim()) initializePhotoFrameObjs();
                        if (isSwipable()) {
                            var p = getSlideDuration();
                            var q = bi;
                            var r = Y.width;
                            bh('#' + O + 'sv-next-photo, #' + O + 'sv-prev-photo').detectFlicks({
                                axis: 'x',
                                threshold: 5,
                                flickMove: function(d) {
                                    var a = bg - 1;
                                    var b = document.getElementById(O + 'sv-photo-' + (a - 1));
                                    var c = document.getElementById(O + 'sv-photo-' + a);
                                    var e = document.getElementById(O + 'sv-photo-' + (a + 1));
                                    onSwiping(d, b, c, e)
                                },
                                flickEvent: function(d) {
                                    var a = bg - 1;
                                    var b = document.getElementById(O + 'sv-photo-' + (a - 1));
                                    var c = document.getElementById(O + 'sv-photo-' + a);
                                    var e = document.getElementById(O + 'sv-photo-' + (a + 1));
                                    p.d = getDurationWithSwipeSpeed(d, Z.width);
                                    afterSwiping(a, p, d, b, c, e)
                                },
                                clickEvent: function() {
                                    if (!useClickableOverlay()) return;
                                    toggleOverlay();
                                    showOverlayControlsAnim(Y.showOverlay)
                                }
                            })
                        }
                        bh('#' + O + 'sv-open-window').attr('href', V.images[bg - 1].imageFullURL).attr('target', V.images[bg - 1].linkTarget);
                        if (!V.mobileshowcaption) {
                            bh('#' + O + 'sv-photos .sv-photo .sv-caption').hide()
                        }
                        if (useClickableOverlay()) {
                            if (!isSwipable()) {
                                bh('#' + O + 'sv-prev-photo, #' + O + 'sv-next-photo').click(function(a) {
                                    showOverlayControls(Y.showOverlay)
                                })
                            }
                            bh('#' + O + 'sv-prev-photo span').click(function(a) {
                                if (bg > 1) {
                                    R.prevImage()
                                }
                                a.preventDefault()
                            });
                            bh('#' + O + 'sv-next-photo span').click(function(a) {
                                if (V.images.length > bg) {
                                    R.nextImage()
                                }
                                a.preventDefault()
                            })
                        } else {
                            bh('#' + O + 'sv-prev-photo').click(function(a) {
                                if (bg > 1) {
                                    R.prevImage()
                                }
                                a.preventDefault()
                            });
                            bh('#' + O + 'sv-next-photo').click(function(a) {
                                if (V.images.length > bg) {
                                    R.nextImage()
                                }
                                a.preventDefault()
                            })
                        }
                        bh(window).bind('resize', resizeViewer);
                        window.setTimeout(hideUrlBar.AfterIni, 1000);
                        window.setInterval(checkForResize, 1000)
                    }
                },
                error: function(a, b, c) {
                    if (navigator.userAgent.indexOf('Chrome') > -1 && (window.location.href.indexOf('http://') === -1 && window.location.href.indexOf('https://') === -1)) {
                        errorMessage('SimpleViewer does not display locally in Google Chrome.')
                    } else {
                        errorMessage('Gallery XML Not Found.')
                    }
                }
            })
        },
        saveCrntPg: function() {
            setCurrentImgIdxCookie(bg)
        },
        flickrApi: (function() {
            var g;
            var h = 1;
            var j = 0;
            var k = 'http://api.flickr.com/services/rest/?method=';
            var l = '&api_key=b40dc56c795c0103c6170731e6271e04';
            var m = {
                FLICKR_SEARCH: 'flickr.photos.search',
                FLICKR_INTERESTINGNESS: 'flickr.interestingness.getList',
                FLICKR_SET: 'flickr.photosets.getPhotos',
                FLICKR_GROUP: 'flickr.groups.pools.getPhotos',
                FLICKR_FIND_USER: 'flickr.people.findByUsername',
                FLICKR_PHOTO_INFO: 'flickr.photos.getInfo',
                FLICKR_PEOPLE_FIND: 'flickr.people.findByUsername'
            };
            function getFlickrBaseUrl(a) {
                return k + m[a] + l
            };
            function getFlickrSearchUrl(a) {
                return getFlickrBaseUrl('FLICKR_SEARCH') + (V.flickrtags ? '&tags=' + V.flickrtags: '') + (V.flickruserid ? '&user_id=' + V.flickruserid: '') + '&page=' + h + '&per_page=' + a + '&sort=' + V.flickrsort.toLowerCase() + '&tag_mode=' + V.flickrgagmode.toLowerCase() + (V.flickrextraparams ? '&' + V.flickrextraparams.replace(/,/g, '&') : '') + '&media=photos&extras=url_sq,url_m,url_l,url_o,original_format&format=json&jsoncallback=?'
            };
            function getFlickrSetUrl(a) {
                return getFlickrBaseUrl('FLICKR_SET') + '&photoset_id=' + V.flickrsetid + (V.flickrtags ? '&tags=' + V.flickrtags: '') + '&page=' + h + '&per_page=' + a + '&tag_mode=' + V.flickrgagmode.toLowerCase() + '&media=photos&extras=url_sq,url_m,url_l,url_o,original_format&format=json&jsoncallback=?'
            };
            function getFlickrGroupUrl(a) {
                return getFlickrBaseUrl('FLICKR_GROUP') + '&group_id=' + V.flickrgroupid + (V.flickrtags ? '&tags=' + V.flickrtags: '') + '&page=' + h + '&per_page=' + a + '&tag_mode=' + V.flickrgagmode.toLowerCase() + '&extras=url_sq,url_m,url_l,url_o,original_format&format=json&jsoncallback=?'
            };
            function getFlickrInterestingnessUrl(a) {
                return getFlickrBaseUrl('FLICKR_INTERESTINGNESS') + '&page=' + h + '&per_page=' + a + '&extras=url_sq, url_m, url_l,url_o,original_format&format=json&jsoncallback=?'
            };
            function getFlickrPeopleFindUrl() {
                return getFlickrBaseUrl('FLICKR_PEOPLE_FIND') + '&username=' + V.flickrusername + '&format=json&jsoncallback=?'
            };
            function getFlickrUrl(a) {
                if (!M) {
                    if (V.flickrtags || V.flickrusername) {
                        return getFlickrSearchUrl(a)
                    } else {
                        return getFlickrInterestingnessUrl(a)
                    }
                }
                if (V.flickrsetid) {
                    return getFlickrSetUrl(a)
                } else if (V.flickrgroupid) {
                    return getFlickrGroupUrl(a)
                } else if (V.flickruserid) {
                    return getFlickrSearchUrl(a)
                } else if (V.flickrusername) {
                    return getFlickrSearchUrl()
                } else if (V.flickrtags) {
                    return getFlickrSearchUrl()
                } else {
                    return getFlickrInterestingnessUrl(a)
                }
            };
            function getPhotoPageUrl(a, b) {
                return 'http://www.flickr.com/photos/' + a + '/' + b
            };
            function getThumbUrl(a, b, c, d) {
                return 'http://farm' + a + '.static.flickr.com/' + b + '/' + d + '_' + c + '_s.jpg'
            };
            function getMediumUrl(a, b, c, d) {
                return 'http://farm' + a + '.static.flickr.com/' + b + '/' + d + '_' + c + '.jpg'
            };
            function getLargeUrl(a, b, c, d) {
                return 'http://farm' + a + '.static.flickr.com/' + b + '/' + d + '_' + c + '_b.jpg'
            };
            function getOriginalUrl(a, b, c, d) {
                return 'http://farm' + a + '.static.flickr.com/' + b + '/' + d + '_' + c + '_o.jpg'
            };
            g = {
                getUserId: function(d) {
                    var e = getFlickrPeopleFindUrl();
                    bh.ajax({
                        url: e,
                        dataType: 'json',
                        success: function(a) {
                            if (a.stat === 'ok') {
                                V.flickruserid = a.user.id;
                                if (d) {
                                    d()
                                }
                            } else {
                                errorMessage('Cannot load from Flickr.')
                            }
                        },
                        error: function(a, b, c) {
                            errorMessage('Cannot load from Flickr.')
                        }
                    })
                },
                getPhotos: function(d) {
                    var e = (M ? parseInt(bb.flickrimagecount) : P.maxItemCount);
                    var f = getFlickrUrl(e);
                    bh.ajax({
                        url: f,
                        dataType: 'json',
                        success: function(a) {
                            if (a.photos) {
                                Q = Math.min(a.photos.total, e);
                                j = a.photos.pages
                            } else if (a.photoset) {
                                Q = Math.min(a.photoset.total, e);
                                j = a.photoset.pages
                            }
                            if (a.stat === 'ok') {
                                if (M || V.flickrtags || V.flickrusername) {
                                    g.parseFlickrResponse(a)
                                } else {
                                    V.images = g.parseFlickrResponse4Reg(a)
                                }
                                if (d) {
                                    d()
                                }
                            } else {
                                errorMessage('Cannot load from Flickr.')
                            }
                        },
                        error: function(a, b, c) {
                            errorMessage('Cannot load from Flickr.')
                        }
                    })
                },
                nextPage: function() {
                    if (h < j) {
                        h += 1;
                        return true
                    }
                    return false
                },
                prevPage: function() {
                    if (h > 1) {
                        h -= 1
                    }
                },
                parseFlickrResponse4Reg: function(a) {
                    var b, i, items, item;
                    b = a.photos.photo;
                    items = [];
                    if (Q > b.length) Q = b.length;
                    for (i = 0; i < b.length; i += 1) {
                        item = {
                            thumbURL: getThumbUrl(b[i].farm, b[i].server, b[i].secret, b[i].id),
                            imageFullURL: getPhotoPageUrl(b[i].owner, b[i].id),
                            linkTarget: '_blank',
                            caption: b[i].title || '',
                            description: '',
                            preloadedImage: null,
                            preloaded: false
                        };
                        if (b[i].url_l) {
                            item.imageURL = b[i].url_l
                        } else {
                            item.imageURL = b[i].url_m
                        }
                        items.push(item)
                    }
                    return items
                },
                parseFlickrResponse: function(a) {
                    var b, i, item;
                    var c = 0;
                    var d = "";
                    if (a.photos) {
                        b = a.photos.photo
                    } else if (a.photoset) {
                        b = a.photoset.photo;
                        d = a.photoset.owner
                    }
                    for (i = 0; i < b.length; i += 1) {
                        if (V.images.length < Q) {
                            item = {
                                thumbURL: getThumbUrl(b[i].farm, b[i].server, b[i].secret, b[i].id),
                                imageFullURL: getPhotoPageUrl(b[i].owner || d, b[i].id),
                                linkTarget: '_blank',
                                caption: b[i].title || '',
                                description: '',
                                preloadedImage: null,
                                preloaded: false
                            };
                            if (V.flickrimagesize.toLowerCase() === 'original' && b[i].url_o) {
                                item.imageURL = b[i].url_o
                            } else if ((V.flickrimagesize.toLowerCase() === 'large' || V.flickrimagesize.toLowerCase() === 'original') && b[i].url_l) {
                                item.imageURL = b[i].url_l
                            } else {
                                item.imageURL = b[i].url_m
                            }
                            V.images.push(item);
                            c += 1
                        }
                    }
                }
            };
            return g
        })(),
        refreshPhoto: function() {
            var a = adjCurrentIndex(bg) - 1;
            bh('#' + O + 'sv-photo-' + bg + '.loading').addClass("loading");
            V.images[a].preloadSet = false;
            V.images[a].preloaded = false;
            delete V.images[a].preloadedImage;
            V.images[a].preloadedImage = null;
            preloadImages(a, 1);
            return false
        },
        nextImage: function(a) {
            if (bg + 1 > V.images.length) return;
            bg += 1;
            bg = adjCurrentIndex(bg);
            move2Photo(bg - 2, bg - 1)
        },
        prevImage: function(a) {
            if (bg <= 1) return;
            bg -= 1;
            bg = adjCurrentIndex(bg);
            move2Photo(bg, bg - 1)
        },
        debug: function(a) {
            eval(a)
        }
    };
    return R
};
function initializeSwipe($) {
    $.fn.detectFlicks = function(d) {
        var f;
        var g = 'left2right',
        RightToLeft = 'right2left',
        UpToDown = 'up2down',
        DownToUp = 'down2up';
        var h = {
            direction: '',
            maxMove: 0,
            isFlick: false
        };
        var i = {
            threshold: 5,
            axis: 'x',
            flickEvent: function() {
                return true
            },
            flickMove: function() {
                return true
            }
        };
        var d = $.extend(i, d);
        h.touchStart = function(e) {
            var a = $(e.target);
            this.isFlick = false;
            this.maxMove = 0;
            this.startX = event.targetTouches[0].clientX;
            this.startY = event.targetTouches[0].clientY;
            if (d.axis == 'y') {
                a.bind('touchmove', h.touchMoveY)
            } else {
                a.bind('touchmove', h.touchMoveX)
            }
            a.bind('touchend', h.touchEnd);
            f = new Date()
        };
        h.touchMoveX = function(e) {
            event.preventDefault();
            this.movedX = event.targetTouches[0].clientX;
            var a = Math.abs(Math.abs(this.movedX) - Math.abs(this.startX));
            if (a > this.maxMove) this.maxMove = a;
            if (a > d.threshold) {
                this.isFlick = true;
                if (this.movedX > this.startX) {
                    h.direction = g;
                    h.moveDistance = this.movedX - this.startX
                } else {
                    h.direction = RightToLeft;
                    h.moveDistance = this.startX - this.movedX
                }
                d.flickMove({
                    direction: h.direction,
                    distance: h.moveDistance
                })
            }
        };
        h.touchMoveY = function(e) {
            event.preventDefault();
            this.movedY = event.targetTouches[0].clientY;
            if (Math.abs(Math.abs(this.movedY) - Math.abs(this.startY)) > d.threshold) {
                this.isFlick = true;
                if (this.movedY > this.startY) {
                    h.direction = UpToDown
                } else {
                    h.direction = DownToUp
                }
            }
        };
        h.touchEnd = function(e) {
            var a = $(e.target);
            if (this.isFlick) {
                var b = new Date();
                var c = b.valueOf() - f.valueOf();
                d.flickEvent({
                    direction: h.direction,
                    distance: h.moveDistance,
                    timerValue: c
                })
            } else if (d.clickEvent && this.maxMove < d.threshold) {
                d.clickEvent()
            }
            a.unbind('touchmove touchend')
        };
        obj = $(this);
        obj.bind('touchstart', h.touchStart);
        return h
    }
};
