(function($) {
    $.fn.PhotoView = function(o) {
        o = $.extend({
            //thisPadding: "17px 0 14px 7px",
            btnPrev: "previnfo",
            btnNext: "nextinfo",
            //btnPrevCss: { "top": 0, "left": 7 },
           // btnNextCss: { "bottom": 0, "left": 7 },
            speed: 500,
            circular: false,
            visible: 3,
            start: 0,
            scroll: 1,
			vertical: true
        }, o || {});

        var s = $("li", this).size();
		var n = 0;

        //this.css("padding", o.thisPadding);
        this.append('<div class="' + o.btnPrev + ' Ldisabled"></div>');
        this.append('<div class="' + o.btnNext + '"></div>');
        if (s < o.visible) {
            $("." + o.btnNext).addClass("Rdisabled");
        }
        $("." + o.btnPrev).css({ "position": "absolute","z-index": 999 });
        $("." + o.btnNext).css({ "position": "absolute","z-index": 999 });
        return this.each(function() {
            if(o.vertical){
		   		var running = false, animCss = "top", sizeCss = "height";
		    }else{
			    var running = false, animCss = "left", sizeCss = "width";
		    }
            var div = $(this), ul = $("ul", div), tLi = $("li", ul), tl = tLi.size(), v = o.visible;
            if (o.circular && s > o.visible) {
                ul.prepend(tLi.slice(tl - v - 1 + 1).clone()).append(tLi.slice(0, v).clone());
                o.start += v;
            }
            var li = $("li", ul), itemLength = li.size(), curr = o.start;
            div.css("visibility", "visible");
            li.css({ overflow: "hidden", float: o.vertical ? "none" : "left" });
			li.eq(0).addClass("hov");
            ul.css({ margin: "0", padding: "0", position: "relative", "list-style-type": "none", "z-index": "1" });
            div.css({ overflow: "hidden", position: "absolute", "z-index": "2"});
            var liSize = o.vertical ? height(li) : width(li);
            var ulSize = liSize * itemLength;
            var divSize = liSize * v;
            li.css({ width: li.width(), height: li.height() });
            ul.css(sizeCss, ulSize + "px").css(animCss, -(curr * liSize));
            div.css(sizeCss, divSize + "px");
            
            function vis() { return li.slice(curr).slice(0, v); };
			
			ul.everyTime(1500,function(){
				antime();				   
			});
			
			function antime(){
				n++;
				var len = li.length;
				if(n >= len) n = 0;
				var autoscroll = curr + o.scroll;
				if(n == 0) autoscroll = 0;
				go(autoscroll);	
			}
            function go(to) {
                if (!running) {
                    if (o.circular) {
                        if (to <= o.start - v - 1) {
                            ul.css(animCss, -((itemLength - (v * 2)) * liSize) + "px"); curr = to == o.start - v - 1 ? itemLength - (v * 2) - 1 : itemLength - (v * 2) - o.scroll;
                        } else if (to >= itemLength - v + 1) {
                            ul.css(animCss, -((v) * liSize) + "px"); curr = to == itemLength - v + 1 ? v + 1 : v + o.scroll;
                        } else curr = to;
                    } else {
                        if (to < 0 || to > itemLength - v) return; else curr = to;
                    }
                    running = true;
                    ul.animate(animCss == "left" ? { left: -(curr * liSize)} : { top: -(curr * liSize) }, o.speed, function() { running = false; });
                    if (!o.circular) {
                        $("." + o.btnPrev).removeClass("Ldisabled");
                        $("." + o.btnNext).removeClass("Rdisabled");
                        $((curr - o.scroll < 0 && "." + o.btnPrev) || []).addClass("Ldisabled");
                        $((curr + o.scroll > itemLength - v && "." + o.btnNext) || []).addClass("Rdisabled");
                    }

                }
                return false;
            };
        });
    };
    function css(el, prop) { return parseInt($.css(el[0], prop)) || 0; };
    function width(el) { return el[0].offsetWidth + css(el, 'marginLeft') + css(el, 'marginRight'); };
    function height(el) { return el[0].offsetHeight + css(el, 'marginTop') + css(el, 'marginBottom'); };
})(jQuery);

$(".links").PhotoView({visible: 7,vertical: false});


