tops.object("tops.toplets.photoplayer.fullpage", {
    durationLength: 8000,
    transitionSpeed: 7000,
    obj: null,
    callbackFn: null,
    photoTimer: null,
    thumbnailTimer: null,
    canClick: true,
    util: {},
    panelNumber: 0,
    thumbNailPerPanel: 0,
    direction: { FORWARD: 'forward', BACKWARD: 'backward' },
    slider: null,
    usrMsg: {},
    pageRefresh: false,
    pageRefreshPanelNum: 0,
    currentIndex: 0,
    autoPlay: true,
    count: null,
    init: function (obj, durationLength, transitionSpeed, callbackFn, count, thumbNailPerPanel, view, usrMsg, pageRefresh) {

        photoTimer = null;
        thumbnailTimer = null;
        this.obj = obj;
        this.slider = $('div.[data-photoplayer="display"] [data-photoplayer="slider"]', obj);
        this.BaseObj = obj;
        this.durationLength = durationLength;
        this.transitionSpeed = transitionSpeed;
        this.callbackFn = callbackFn;
        this.thumbNailPerPanel = thumbNailPerPanel;
        this.usrMsg = usrMsg;
        this.pageRefresh = pageRefresh;
        this.count = count;
        this.currentIndex = this.getQueryStringParam('ppind');
        this.util = {
            OuterWidth: new Number(this.slider.outerWidth(true)),
            thumbCount: new Number(this.slider.length),
            arrowX: 0,
            menuX: 0
        };
		this.setStartupImage();
        this.autoPlay = (this.pageRefresh ? false : this.autoPlay);

        if (this.count > 1 && this.autoPlay) {
            this.photoTimer = setTimeout($.proxy(function () { this.transitionImg() }, this), this.durationLength);
            this.thumbnailTimer = setTimeout($.proxy(function () { this.transitionThumbnail(this.direction.FORWARD) }, this), this.durationLength);
        }

        this.bindControls();
        this.bindThumbNailEvent();
        this.bindOverlayEvent();
        if (!this.pageRefresh) this.setThumbnailBtnVisibility(count, thumbNailPerPanel);
        this.bindArrowScrollEvent();

        if (this.pageRefresh) this.indexPosRefresh();
    },
	setStartupImage: function () {
		var imgContainer = $('div.[data-photoplayer="imgcontainer"]', this.obj);
		var thumbSlider = $('div.[data-photoplayer="slider"]', this.obj);
		
		if(this.pageRefresh){
			var activeImg = imgContainer.eq(this.currentIndex);
			var activeThm = thumbSlider.eq(this.currentIndex);
			$(activeImg).addClass('pp1_content_active');
			$(activeImg).removeClass('dn');
			$(activeThm).addClass('pp1_display_on');
        	$('[data-photoplayer="imgcounter"]').html(($(imgContainer, this.obj).index($('.pp1_content_active', this.obj)) + 1) + '&nbsp;' + tops.toplets.photoplayer.fullpage.usrMsg.indexmsg + '&nbsp;' + imgContainer.length);
		}
		else{
			var activeImg = imgContainer.eq(this.currentIndex);
			var activeThm = thumbSlider.eq(this.currentIndex);			
			$(activeImg).addClass('pp1_content_active');		
			$(activeImg).removeClass('dn');		
			$(activeThm).addClass('pp1_display_on');										
		}
    },	
    setThumbnailBtnVisibility: function (count, thumbNailPerPanel) {
        if (count > thumbNailPerPanel) {
            $('[data-photoplayer="scrollnext"]', this.obj).removeClass('pp1_inactive_next');
        }
    },
    transitionThumbnail: function (direction) {
        if (direction == this.direction.FORWARD)
            this.moveThumbnail(this.direction.FORWARD);
        else
            moveThumbnail(this.direction.BACKWARD)

        this.thumbnailTimer = setTimeout($.proxy(function () { this.transitionThumbnail(direction) }, this), this.durationLength);
    },
    transitionForward: function () {
        this.moveThumbnail(this.direction.FORWARD);
        this.transitionImg({ "direction": this.direction.FORWARD });
    },
    transitionBackward: function () {
        this.moveThumbnail(this.direction.BACKWARD);
        this.transitionImg({ "direction": this.direction.BACKWARD });
    },
    moveThumbnail: function (direction) {
        var nextImg;
        var endVal;
        var imgContainer = $('div.[data-photoplayer="display"] [data-photoplayer="slider"]', this.obj);
        var activeImg = $('.pp1_display_on', this.obj);
        var index = new Number(imgContainer.index(activeImg));

        if (direction == this.direction.FORWARD)
            nextImg = (index == (imgContainer.length - 1)) ? imgContainer.first() : activeImg.next();
        else
            nextImg = (index == 0) ? imgContainer.last() : activeImg.prev(imgContainer);

        this.switchActiveThumbnail(activeImg, nextImg);

        if (this.pageRefresh) return;

        var imgContainerWidth = $('div.[data-photoplayer="display"]').css('width').replace(/px/, "");
        var _numberOfPanels = Math.ceil(imgContainer.length / this.thumbNailPerPanel);
        var panelWidth = this.thumbNailPerPanel * (this.util.OuterWidth);

        if (direction == this.direction.FORWARD) {
            if (((index + 1) % this.thumbNailPerPanel == 0) && ((index + 1) != (imgContainer.length))) {
                this.panelNumber++;

                $('[data-photoplayer="thumbswrap"]').stop().animate({ left: '-' + (panelWidth * (this.panelNumber)) + 'px' }, 1000);
                $('[data-photoplayer="scrollback"]', this.obj).removeClass('pp1_inactive_prev');
            }
            else if ((index + 1) == (imgContainer.length)) {
                $('[data-photoplayer="thumbswrap"]').stop().animate({ left: '0px' }, 1000);
                this.panelNumber = 0;

                $('[data-photoplayer="scrollnext"]', this.obj).removeClass('pp1_inactive_next');
                $('[data-photoplayer="scrollback"]', this.obj).addClass('pp1_inactive_prev');
            }
            if (this.panelNumber == (_numberOfPanels - 1))
                $('[data-photoplayer="scrollnext"]', this.obj).addClass('pp1_inactive_next');
        }
        else {
            if ((index) % this.thumbNailPerPanel == 0 && index != 0) {
                this.panelNumber--;
                $('[data-photoplayer="thumbswrap"]').stop().animate({ left: '-' + (panelWidth * (this.panelNumber)) + 'px' }, 1000);
                $('[data-photoplayer="scrollnext"]', this.obj).removeClass('pp1_inactive_next');
            }
            else if ((index) == 0) {
                $('[data-photoplayer="thumbswrap"]').stop().animate({ left: '-' + (panelWidth * (_numberOfPanels - 1)) + 'px' }, 1000);
                this.panelNumber = _numberOfPanels - 1;

                $('[data-photoplayer="scrollnext"]', this.obj).addClass('pp1_inactive_next');
                $('[data-photoplayer="scrollback"]', this.obj).removeClass('pp1_inactive_prev');
            }
            if (this.panelNumber == 0)
                $('[data-photoplayer="scrollback"]', this.obj).addClass('pp1_inactive_prev');
        }
    },
    bindControls: function () {
        var _this = this;
        $('[data-photoplayer="back"]', this.obj).click(function () {
            if (_this.canClick) {
                _this.canClick = false;
                _this.clearAllTimeout();
                _this.transitionBackward();
            }
        });
        $('[data-photoplayer="imgwrap"]', this.obj).click(function () {
            if (_this.canClick) {
                _this.canClick = false;
                _this.clearAllTimeout();
                _this.transitionForward();
            }
        });
        $('[data-photoplayer="next"]', this.obj).click(function () {
            if (_this.canClick) {
                _this.canClick = false;
                _this.clearAllTimeout();
                _this.transitionForward();
            }
        });
        $('[data-photoplayer="play"]', this.obj).click(function () {
            if (_this.canClick) {
                _this.canClick = false;

                _this.clearAllTimeout();

                _this.photoTimer = _this.durationLength;
                _this.thumbnailTimer = _this.durationLength;

                _this.transitionImg();
                _this.transitionThumbnail(_this.direction.FORWARD);
            }
        });
    },
    bindThumbNailEvent: function () {
        var _this = this;
        $('div.[data-photoplayer="display"] [data-photoplayer="slider"]', this.obj).click(function () {
            var index = $('div.[data-photoplayer="display"] [data-photoplayer="slider"]', _this.obj).index(this);
            var activeImg = $('.pp1_display_on', _this.obj);
            var nextImg = $('div.[data-photoplayer="display"] [data-photoplayer="slider"]', _this.obj).eq(index);

            if (index != activeImg.index()) {
                _this.switchActiveThumbnail(activeImg, nextImg);
                _this.switchActiveImg(this);
            }
        });
    },
    bindOverlayEvent: function () {
        var _this = this;
        var info = $('[data-photoplayer="info"]', this.obj);
        var show = true;

        $('[data-photoplayer="action"]', this.obj).live('click', function () {
            if (show) {
                info.animate({ "height": "0px" });
                $('[data-photoplayer="credit"],[data-photoplayer="title"],[data-photoplayer="abstract"]').css('display', 'none');
                $('[data-photoplayer="action"] a', _this.obj).html(tops.toplets.photoplayer.fullpage.usrMsg.inactivecaptionmsg);
                $('[data-photoplayer="action"] em', _this.obj).removeClass('hide').addClass('show');
            } else {
                var height = info.height("").height();
                info.height(0);
                info.animate({ "height": height + "px" });
                $('[data-photoplayer="credit"],[data-photoplayer="title"],[data-photoplayer="abstract"]').css('display', 'block');
                $('[data-photoplayer="action"] a', _this.obj).html(tops.toplets.photoplayer.fullpage.usrMsg.activecaptionmsg);
                $('[data-photoplayer="action"] em', _this.obj).removeClass('show').addClass('hide');
            }
            show = !show;
        });
    },
    bindArrowScrollEvent: function () {
        var _this = this;
        $('[data-photoplayer="scrollnext"]', this.obj).live("click", function () {
            moveThumbNailPanel(_this.direction.FORWARD);
        });
        $('[data-photoplayer="scrollback"]', this.obj).live("click", function () {
            moveThumbNailPanel(_this.direction.BACKWARD);
        });
        function moveThumbNailPanel(direction) {

            if (_this.canClick) {
                _this.clearAllTimeout();

                $('[data-photoplayer="scrollback"]', _this.obj).removeClass('pp1_inactive_prev');
                $('[data-photoplayer="scrollnext"]', _this.obj).removeClass('pp1_inactive_next');

                var imgContainer = $('div.[data-photoplayer="display"] [data-photoplayer="slider"]', _this.obj);
                var imgContainerWidth = $('[data-photoplayer="thumbswrap"]').css('width').replace(/px/, "");
                var _numberOfPanels = Math.ceil(imgContainer.length / _this.thumbNailPerPanel);
                var panelWidth = _this.thumbNailPerPanel * (_this.util.OuterWidth);

                var activeImg = $('.pp1_display_on', _this.obj);
                var index = new Number(imgContainer.index(activeImg));

                if (direction == _this.direction.BACKWARD) {
                    if (_this.panelNumber != 0) {
                        _this.panelNumber--;
                        $('[data-photoplayer="thumbswrap"]').stop().animate({ left: '-' + (panelWidth * ((_this.panelNumber))) + 'px' }, 1000);
                        nextImg = imgContainer.eq(_this.thumbNailPerPanel * _this.panelNumber);
                    }
                    if (_this.panelNumber == 0)
                        $('[data-photoplayer="scrollback"]', _this.obj).addClass('pp1_inactive_prev');
                }
                else {
                    if (_this.panelNumber != (_numberOfPanels - 1)) {
                        _this.panelNumber++;
                        $('[data-photoplayer="thumbswrap"]').stop().animate({ left: '-' + (panelWidth * (_this.panelNumber)) + 'px' }, 1000);
                        nextImg = imgContainer.eq(_this.thumbNailPerPanel * _this.panelNumber);

                    }
                    if (_this.panelNumber == (_numberOfPanels - 1))
                        $('[data-photoplayer="scrollnext"]', _this.obj).addClass('pp1_inactive_next');
                }

                if (!_this.pageRefresh) {
                    _this.switchActiveThumbnail(activeImg, nextImg);
                    _this.switchActiveImg(imgContainer.eq(_this.thumbNailPerPanel * _this.panelNumber));
                }
            }
        }
    },
    transitionImg: function (opts) {
        var _this = this;
        var imgContainer = $('div.[data-photoplayer="imgcontainer"]', this.obj);
        var activeImg = $('.pp1_content_active', this.obj);
        var index = imgContainer.index(activeImg);
        var nextImg;

        if (typeof (opts) === 'undefined') {
            nextImg = (index == (imgContainer.length - 1)) ? imgContainer.first() : activeImg.next(imgContainer);

            this._transition(activeImg, nextImg);
            this.photoTimer = setTimeout(function () { _this.transitionImg() }, this.durationLength);
        }
        else {
            if (opts.direction == this.direction.FORWARD)
                nextImg = (index == (imgContainer.length - 1)) ? imgContainer.first() : activeImg.next(imgContainer);
            else
                nextImg = (index == 0) ? imgContainer.last() : activeImg.prev(imgContainer);

            this._transition(activeImg, nextImg);
        }
        $('[data-photoplayer="imgcounter"]').html(($(imgContainer, this.obj).index($('.pp1_content_active', this.obj)) + 1) + '&nbsp;' + tops.toplets.photoplayer.fullpage.usrMsg.indexmsg + '&nbsp;' + imgContainer.length);

        if (this.callbackFn && typeof (this.callbackFn) === "function") {
            this.callbackFn();
        }
    },
    switchActiveThumbnail: function (activeImg, nextImg) {
        if (!this.pageRefresh) {
            activeImg.removeClass('pp1_display_on');
            nextImg.addClass('pp1_display_on');
        }
    },
    switchActiveImg: function (object) {
        this.clearAllTimeout();

        var imgContainer = $('div.[data-photoplayer="imgcontainer"]', this.obj);
        var activeImg = $('.pp1_content_active', this.obj);
        var index = $('[data-photoplayer="slider"]', this.obj).index(object);
        var nextImg = imgContainer.eq(index);

        $('[data-photoplayer="imgcounter"]').html((index + 1) + '&nbsp;' + tops.toplets.photoplayer.fullpage.usrMsg.indexmsg + '&nbsp;' + imgContainer.length);

        if (index != imgContainer.index(activeImg)) {
            this._transition(activeImg, nextImg);
            this.canClick = true;
        }
    },
    _transition: function (activeImg, nextImg) {
        var _this = this;

        if (_this.pageRefresh === true) {
            var imgContainer = $('div.[data-photoplayer="imgcontainer"]', _this.obj);
            var index = imgContainer.index(nextImg);

            _this.currentIndex = index;
            _this.refreshPage(_this.currentIndex);
        }
        else {
            activeImg.stop().fadeOut('fast');
            activeImg.removeClass('pp1_content_active');
            activeImg.addClass('dn');

            nextImg.stop().fadeIn('fast', function () {
                _this.canClick = true;
            });
            nextImg.addClass('pp1_content_active');
            nextImg.removeClass('dn');
        }
    },
    clearAllTimeout: function () {
        if (this.photoTimer != null) clearTimeout(this.photoTimer);
        if (this.thumbnailTimer != null) clearTimeout(this.thumbnailTimer);
    },
    refreshPage: function (pg) {
        var url = window.location.href;

        if (url.indexOf('ppind') != -1) {
            url = url.replace(/ppind.*/gi, 'ppind=' + pg);
            window.location.href = url;
        }
        else if (url.indexOf('?') != -1) {
            url += '&ppind=' + pg;
            window.location.href = url;
        }
        else {
            url += '?ppind=' + pg;
            window.location.href = url;
        }
    },
    getQueryStringParam: function (name) {
        name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
        var regexS = "[\\?&]" + name + "=([^&#]*)";
        var regex = new RegExp(regexS);
        var results = regex.exec(window.location.href);
        if (results == null) {
            return 0;
        }
        else {
            return results[1];
        }
    },
    indexPosRefresh: function () {
        this.moveThumbnail(this.direction.FORWARD);
        var panelWidth = this.thumbNailPerPanel * (this.util.OuterWidth);
        var numberOfPanels = Math.ceil(this.count / this.thumbNailPerPanel);
        var ctr = 0;

        for (var i = 1; i <= numberOfPanels; i++) {
            if (this.currentIndex >= this.thumbNailPerPanel * i && this.currentIndex < this.thumbNailPerPanel * (i + 1)) {
                ctr = i;
            }
        }

        $('[data-photoplayer="thumbswrap"]').css("left", -(ctr * panelWidth) + "px");

        this.panelNumber = ctr;

        if (this.currentIndex < this.thumbNailPerPanel) {
            $('[data-photoplayer="scrollnext"]', this.obj).removeClass('pp1_inactive_next');
        }
        else if (this.currentIndex >= (numberOfPanels - 1) * this.thumbNailPerPanel) {
            $('[data-photoplayer="scrollnext"]', this.obj).addClass('pp1_inactive_next');
            $('[data-photoplayer="scrollback"]', this.obj).removeClass('pp1_inactive_prev');
        }
        else if (this.currentIndex >= this.thumbNailPerPanel * ctr && this.currentIndex < this.thumbNailPerPanel * (ctr + 1)) {
            $('[data-photoplayer="scrollnext"]', this.obj).removeClass('pp1_inactive_next');
            $('[data-photoplayer="scrollback"]', this.obj).removeClass('pp1_inactive_prev');
        }
    }
});

(function ($) {
    $.fn.photoplayer_1_fullpage = function (options) {
        var defaults = {
            height: 200,
            width: 930,
            transitionSpeed: 1000,
            durationLength: 7000,
            callbackFn: null,
            imageCount: false,
            usrMsg: {},
            pageRefresh: false
        };
        options = $.extend(defaults, options);

        return this.each(function () {
            tops.toplets.photoplayer.fullpage.init(this, options.durationLength, options.transitionSpeed, options.callbackFn, options.imageCount, options.thumbNailPerPanel, options.view, options.usrMsg, options.pageRefresh);
        });
    };
})(jQuery);tops.object("tops.toplets.photoplayer.inpage", {
    durationLength: 8000,
    transitionSpeed: 7000,
    obj: null,
    callbackFn: null,
    photoTimer: null,
    thumbnailTimer: null,
    canClick: true,
    util: {},
    panelNumber: 0,
    thumbNailPerPanel: 0,
    direction: { FORWARD: 'forward', BACKWARD: 'backward' },
    slider: null,
    view: null,
    usrMsg: {},
    pageRefresh: false,
    currentIndex: 0,
    autoPlay: true,
    init: function (obj, durationLength, transitionSpeed, callbackFn, count, thumbNailPerPanel, view, usrMsg, pageRefresh) {
        photoTimer = null;
        thumbnailTimer = null;
        this.obj = obj;
        this.slider = $('div.[data-photoplayer="display"] [data-photoplayer="slider"]', obj);
        this.view = view;
        this.BaseObj = obj;
        this.durationLength = durationLength;
        this.transitionSpeed = transitionSpeed;
        this.callbackFn = callbackFn;
        this.thumbNailPerPanel = thumbNailPerPanel;
        this.usrMsg = usrMsg;
        this.pageRefresh = pageRefresh;
        this.currentIndex = this.getQueryStringParam('ppind');
        this.util = {
            OuterWidth: new Number(this.slider.outerWidth(true)),
            thumbCount: new Number(this.slider.length),
            arrowX: 0,
            menuX: 0
        };

        this.autoPlay = (this.pageRefresh ? false : this.autoPlay);

        if (this.pageRefresh)
            this.moveThumbnail(this.direction.FORWARD);

        if (count > 1 && this.autoPlay) {
            this.photoTimer = setTimeout($.proxy(function () { this.transitionImg() }, this), this.durationLength);
            this.thumbnailTimer = setTimeout($.proxy(function () { this.transitionThumbnail(this.direction.FORWARD) }, this), this.durationLength);
        }

        this.bindControls();
        this.bindThumbNailEvent();
    },
    transitionThumbnail: function (direction) {
        if (direction == this.direction.FORWARD)
            this.moveThumbnail(this.direction.FORWARD);
        else
            moveThumbnail(this.direction.BACKWARD)

        this.thumbnailTimer = setTimeout($.proxy(function () { this.transitionThumbnail(direction) }, this), this.durationLength);
    },
    transitionForward: function () {
        this.moveThumbnail(this.direction.FORWARD);
        this.transitionImg({ "direction": this.direction.FORWARD });
    },
    transitionBackward: function () {
        this.moveThumbnail(this.direction.BACKWARD);
        this.transitionImg({ "direction": this.direction.BACKWARD });
    },
    moveThumbnail: function (direction) {
        var _this = this;
        var nextImg;
        var endVal;
        var imgContainer = $('div.[data-photoplayer="display"] [data-photoplayer="slider"]', this.obj);
        var activeImg = $('.pp1_display_on', this.obj);
        var activeIndex = new Number(imgContainer.index(activeImg));

        if (direction == this.direction.FORWARD)
            nextImg = (activeIndex == (imgContainer.length - 1)) ? imgContainer.first() : imgContainer.eq(activeIndex + 1);
        else
            nextImg = (activeIndex == 0) ? imgContainer.last() : imgContainer.eq(activeIndex - 1);
        if (!_this.pageRefresh) {
            this.switchActiveThumbnail(activeImg, nextImg);
        }
        if (this.thumbNailPerPanel >= (imgContainer.length - 2)) {
            return;
        }

        var activeIndex = new Number($('div.[data-photoplayer="display"] [data-photoplayer="slider"]', this.obj).index($('.pp1_display_on')));

        $('.fwd_hypthen').remove();
        $('.bk_hypthen').remove();
        imgContainer.addClass('dn');

        if (activeIndex == imgContainer.length || (activeIndex + 1) < (this.thumbNailPerPanel)) {
            $("<span> -- </span>").attr('class', 'bk_hypthen').attr('data-photoplayer', 'next').insertBefore(imgContainer.eq(imgContainer.length - 1))
            imgContainer.each(function (index) {
                if (index == 0 || index == imgContainer.length - 1 || ((index) > 0 && (index) < _this.thumbNailPerPanel + 1)) {
                    $(this).removeClass('dn');
                }
            });
        }
        else if (!(activeIndex > imgContainer.length - this.thumbNailPerPanel - 1 && activeIndex <= imgContainer.length)) {
            imgContainer.each(function (index) {
                if (index == 0 || index == imgContainer.length - 1 || (index >= activeIndex - 1 && index < activeIndex - 1 + _this.thumbNailPerPanel)) {
                    $(this).removeClass('dn');
                }
            });
            $("<span> -- </span>").attr('class', 'fwd_hypthen').attr('data-photoplayer', 'next').insertBefore(imgContainer.eq(imgContainer.length - 1))
            $("<span> -- </span>").attr('class', 'bk_hypthen').attr('data-photoplayer', 'back').insertAfter(imgContainer.eq(0))
        }
        else {

            imgContainer.each(function (index) {
                if (index == 0 || index == imgContainer.length - 1 || (index >= (imgContainer.length - _this.thumbNailPerPanel - 1) && index < imgContainer.length)) {
                    $(this).removeClass('dn');
                }
            });
            $("<span> -- </span>").attr('class', 'fwd_hypthen').attr('data-photoplayer', 'back').insertAfter(imgContainer.eq(0))
        }
    },
    bindControls: function () {
        var _this = this;
        $('[data-photoplayer="back"]', this.obj).live('click', function () {
            if (_this.canClick) {
                _this.canClick = false;
                _this.clearAllTimeout();
                _this.transitionBackward();
            }
        });
        $('[data-photoplayer="imgwrap"]', this.obj).live('click', function () {
            if (_this.canClick) {
                _this.canClick = false;
                _this.clearAllTimeout();
                _this.transitionForward();
            }
        });
        $('[data-photoplayer="next"]', this.obj).live('click', function () {
            if (_this.canClick) {
                _this.canClick = false;
                _this.clearAllTimeout();
                _this.transitionForward();
            }
        });
        $('[data-photoplayer="play"]', this.obj).live('click', function () {
            if (_this.canClick) {
                _this.canClick = false;

                _this.clearAllTimeout();

                _this.photoTimer = _this.durationLength;
                _this.thumbnailTimer = _this.durationLength;

                _this.transitionImg();
                _this.transitionThumbnail(_this.direction.FORWARD);
            }
        });
    },
    bindThumbNailEvent: function () {
        var _this = this;
        $('div.[data-photoplayer="display"] [data-photoplayer="slider"]', this.obj).click(function () {
            var index = $('div.[data-photoplayer="display"] [data-photoplayer="slider"]', _this.obj).index(this);
            var activeImg = $('.pp1_display_on', _this.obj);
            var nextImg = $('div.[data-photoplayer="display"] [data-photoplayer="slider"]', _this.obj).eq(index);

            _this.switchActiveThumbnail(activeImg, nextImg);
            _this.switchActiveImg(this);
        });
    },
    transitionImg: function (opts) {
        var _this = this;
        var imgContainer = $('div.[data-photoplayer="imgcontainer"]', this.obj);
        var activeImg = $('.pp1_content_active', this.obj);
        var index = imgContainer.index(activeImg);
        var nextImg;

        if (typeof (opts) === 'undefined') {
            nextImg = (index == (imgContainer.length - 1)) ? imgContainer.first() : activeImg.next(imgContainer);
            this._transition(activeImg, nextImg);
            this.photoTimer = setTimeout(function () { _this.transitionImg() }, this.durationLength);
        }
        else {
            if (opts.direction == this.direction.FORWARD)
                nextImg = (index == (imgContainer.length - 1)) ? imgContainer.first() : activeImg.next(imgContainer);
            else
                nextImg = (index == 0) ? imgContainer.last() : activeImg.prev(imgContainer);

            this._transition(activeImg, nextImg);
        }
        $('[data-photoplayer="imgcounter"]').html(($(imgContainer, this.obj).index($('.pp1_content_active', this.obj)) + 1) + '&nbsp;' + tops.toplets.photoplayer.inpage.usrMsg.indexmsg + '&nbsp;' + imgContainer.length);

        if (this.callbackFn && typeof (this.callbackFn) === "function") {
            this.callbackFn();
        }
    },
    switchActiveThumbnail: function (activeImg, nextImg) {
        if (!this.pageRefresh) {
            activeImg.removeClass('pp1_display_on');
            nextImg.addClass('pp1_display_on');
        }
    },
    switchActiveImg: function (object) {
        var _this = this;
        this.clearAllTimeout();

        var imgContainer = $('div.[data-photoplayer="imgcontainer"]', this.obj);
        var activeImg = $('.pp1_content_active', this.obj);
        var index = $('[data-photoplayer="slider"]', this.obj).index(object);
        var nextImg = imgContainer.eq(index);


        $('[data-photoplayer="imgcounter"]').html((index + 1) + '&nbsp;' + tops.toplets.photoplayer.inpage.usrMsg.indexmsg + '&nbsp;' + imgContainer.length);

        if (index != imgContainer.index(activeImg)) {
            this._transition(activeImg, nextImg);
            this.canClick = true;
        }

        if (this.thumbNailPerPanel >= (imgContainer.length - 2) || this.pageRefresh) return;

        var thumbContainer = $('div.[data-photoplayer="display"] [data-photoplayer="slider"]', this.obj);

        $('.fwd_hypthen').remove();
        $('.bk_hypthen').remove();
        thumbContainer.addClass('dn');

        var activeIndex = new Number(thumbContainer.index(object));

        if (activeIndex < _this.thumbNailPerPanel) {
            $("<span> -- </span>").attr('class', 'bk_hypthen').attr('data-photoplayer', 'next').insertBefore(thumbContainer.eq(thumbContainer.length - 1))
            thumbContainer.each(function (index) {
                if (index == 0 || index == thumbContainer.length - 1 || ((index) > 0 && (index) < _this.thumbNailPerPanel + 1)) {
                    $(this).removeClass('dn');
                }
            });
        }
        else if (!((activeIndex - 1) >= thumbContainer.length - _this.thumbNailPerPanel - 1 && (activeIndex - 1) <= thumbContainer.length)) {
            thumbContainer.each(function (index) {
                if (index == 0 || index == thumbContainer.length - 1 || (index >= (activeIndex - 1) && index < (activeIndex - 1) + _this.thumbNailPerPanel)) {
                    $(this).removeClass('dn');
                }
            });
            $("<span> -- </span>").attr('class', 'fwd_hypthen').attr('data-photoplayer', 'next').insertBefore(thumbContainer.eq(thumbContainer.length - 1));
            $("<span> -- </span>").attr('class', 'bk_hypthen').attr('data-photoplayer', 'back').insertAfter(thumbContainer.eq(0));
        }
        else if (activeIndex > _this.thumbNailPerPanel - thumbContainer.length) {
            thumbContainer.each(function (index) {
                if (index == 0 || index == thumbContainer.length - 1 || (index >= (thumbContainer.length - _this.thumbNailPerPanel - 1) && index < thumbContainer.length)) {
                    $(this).removeClass('dn');
                }
            });
            $("<span> -- </span>").attr('class', 'fwd_hypthen').attr('data-photoplayer', 'back').insertAfter(thumbContainer.eq(0));
        }
    },
    _transition: function (activeImg, nextImg) {
        var _this = this;

        if (_this.pageRefresh === true) {
            var imgContainer = $('div.[data-photoplayer="imgcontainer"]', _this.obj);
            var index = imgContainer.index(nextImg);
            _this.currentIndex = index;
            _this.refreshPage(_this.currentIndex);
        }
        else {
            activeImg.stop().fadeOut('fast');
            activeImg.removeClass('pp1_content_active');
            activeImg.addClass('dn');

            nextImg.stop().fadeIn('fast', function () {
                _this.canClick = true;
            });
            nextImg.addClass('pp1_content_active');
            nextImg.removeClass('dn');
        }
    },
    clearAllTimeout: function () {
        if (this.photoTimer != null) clearTimeout(this.photoTimer);
        if (this.thumbnailTimer != null) clearTimeout(this.thumbnailTimer);
    },
    refreshPage: function (pg) {
        var url = window.location.href;
        if (url.indexOf('ppind') != -1) {
            url = url.replace(/ppind.*/gi, 'ppind=' + pg);
            window.location.href = url;
        }
        else if (url.indexOf('?') != -1) {
            url += '&ppind=' + pg;
            window.location.href = url;
        }
        else {
            url += '?ppind=' + pg;
            window.location.href = url;
        }
    },
    getQueryStringParam: function (name) {
        name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
        var regexS = "[\\?&]" + name + "=([^&#]*)";
        var regex = new RegExp(regexS);
        var results = regex.exec(window.location.href);
        if (results == null) {
            return 0;
        }
        else {
            return results[1];
        }
    }
});
(function ($) {
    $.fn.photoplayer_1_inpage = function (options) {
        var defaults = {
            height: 200,
            width: 930,
            transitionSpeed: 1000,
            durationLength: 7000,
            callbackFn: null,
            imageCount: false,
            usrMsg: {},
			pageRefresh: false
        };
        options = $.extend(defaults, options);

        return this.each(function () {
            tops.toplets.photoplayer.inpage.init(this, options.durationLength, options.transitionSpeed, options.callbackFn, options.imageCount, options.thumbNailPerPanel, options.view, options.usrMsg, options.pageRefresh);
        });
    };
})(jQuery);
