(function () {
    $.fn.carousel = function (speed, h, easingEffect, time, movePlaces) {
        return this.each(function () {
            var wrapper = $("> div", this).css("overflow", "hidden"),
                ul = wrapper.find("> ul").width(9999),
                lis = ul.find("> li"),
                li = lis.filter(":first"),
                B, oWidth = li.outerWidth(true),
                prodsInWindow = Math.floor(wrapper.innerWidth() / oWidth),
                a = prodsInWindow + Math.ceil(prodsInWindow / 2),
                numLis = lis.length,
                d = null,
                z = null,
                v = (h > 0) ? true : false;
                
                var liWidth = oWidth * prodsInWindow;
                var difference = wrapper.width() - liWidth;
                var addpadding = Math.floor((difference / prodsInWindow) / 2);
                
            h = (h < prodsInWindow) ? h : prodsInWindow;
            
            var paused = null;
            
            if (time == null && movePlaces == null) {
                time = 3000;
                movePlaces = 1
            }
            if (numLis <= prodsInWindow) {
                return
            }
            lis.removeAttr("style");
            lis.filter(":first").before(lis.slice(-a).clone(true).addClass("cloned"));
            lis.filter(":last").after(lis.slice(0, a).clone(true).addClass("cloned"));
            lis = ul.find("> li");
            B = ul.find(".cloned");
            cloneAmount = B.length / 2;
            
            lis.css("padding", "0 " + addpadding + "px");
            oWidth += (addpadding * 2);
            
            wrapper.scrollLeft(oWidth * cloneAmount);

            function scroll(l, m) {
                var n = oWidth * l;
                var k = (wrapper.scrollLeft() % oWidth);
                if (m && wrapper.filter(":animated").length > 0) {
                    return
                }
                if (l > 0) {
                    n -= k
                } else {
                    n += (k > 0) ? oWidth - k : 0
                }
                wrapper.filter(":animated").stop(true);
                wrapper.animate({
                    scrollLeft: "+=" + n
                },
                {
                    queue: false,
                    duration: speed,
                    easing: easingEffect
                },
                w())
            }
            function w() {
                var k = wrapper.scrollLeft() / oWidth;
                if (k <= prodsInWindow) {
                    wrapper.scrollLeft(oWidth * (k + numLis))
                } else {
                    if (k >= numLis + cloneAmount - Math.ceil(prodsInWindow / 2) - 1) {
                        wrapper.scrollLeft(oWidth * (k - numLis))
                    }
                }
            }
            function D() {
                if (time > 0 && movePlaces != 0 && !paused) {
                    z = setInterval(function () {
                        scroll(movePlaces, true)
                    },
                    (speed + time));
                }
            }
            wrapper.after('<div class="CarouselControls"><a href="#" class="arrow back">&lt;</a><a class="pause" href="#">Pause</a><a href="#" class="arrow forward">&gt;</a></div>');
            $("a.back", this).click(function () {
                scroll(-prodsInWindow, false);
                return false
            });
            $("a.forward", this).click(function () {
                scroll(+prodsInWindow, false);
                return false
            });
            $("a.pause", this).click(function()
            {
                if(paused == null || paused == false)
                {
                    clearInterval(z);
                    paused = true;
                }
                else
                {
                    paused = false;
                    D();
                }
                
                return false;
            });
            D();
            if (v) {
                $("a.forward", this).hover(function () {
                    clearInterval(z);
                    scroll(h, true);
                    d = setInterval(function () {
                        scroll(h, true)
                    },
                    (speed * 2))
                },


                function () {
                    clearInterval(d);
                    D()
                });
                $("a.back", this).hover(function () {
                    clearInterval(z);
                    scroll(-h, true);
                    d = setInterval(function () {
                        scroll(-h, true)
                    },
                    (speed * 2))
                },


                function () {
                    clearInterval(d);
                    D()
                })
            }
        })
    }
})(jQuery);
jQuery.easing.jswing = jQuery.easing.swing;
jQuery.extend(jQuery.easing, {
    def: "easeOutQuad",
    swing: function (e, f, a, h, g) {
        return jQuery.easing[jQuery.easing.def](e, f, a, h, g)
    },
    easeInQuad: function (e, f, a, h, g) {
        return h * (f /= g) * f + a
    },
    easeOutQuad: function (e, f, a, h, g) {
        return -h * (f /= g) * (f - 2) + a
    },
    easeInOutQuad: function (e, f, a, h, g) {
        if ((f /= g / 2) < 1) {
            return h / 2 * f * f + a
        }
        return -h / 2 * ((--f) * (f - 2) - 1) + a
    },
    easeInCubic: function (e, f, a, h, g) {
        return h * (f /= g) * f * f + a
    },
    easeOutCubic: function (e, f, a, h, g) {
        return h * ((f = f / g - 1) * f * f + 1) + a
    },
    easeInOutCubic: function (e, f, a, h, g) {
        if ((f /= g / 2) < 1) {
            return h / 2 * f * f * f + a
        }
        return h / 2 * ((f -= 2) * f * f + 2) + a
    },
    easeInQuart: function (e, f, a, h, g) {
        return h * (f /= g) * f * f * f + a
    },
    easeOutQuart: function (e, f, a, h, g) {
        return -h * ((f = f / g - 1) * f * f * f - 1) + a
    },
    easeInOutQuart: function (e, f, a, h, g) {
        if ((f /= g / 2) < 1) {
            return h / 2 * f * f * f * f + a
        }
        return -h / 2 * ((f -= 2) * f * f * f - 2) + a
    },
    easeInQuint: function (e, f, a, h, g) {
        return h * (f /= g) * f * f * f * f + a
    },
    easeOutQuint: function (e, f, a, h, g) {
        return h * ((f = f / g - 1) * f * f * f * f + 1) + a
    },
    easeInOutQuint: function (e, f, a, h, g) {
        if ((f /= g / 2) < 1) {
            return h / 2 * f * f * f * f * f + a
        }
        return h / 2 * ((f -= 2) * f * f * f * f + 2) + a
    },
    easeInSine: function (e, f, a, h, g) {
        return -h * Math.cos(f / g * (Math.PI / 2)) + h + a
    },
    easeOutSine: function (e, f, a, h, g) {
        return h * Math.sin(f / g * (Math.PI / 2)) + a
    },
    easeInOutSine: function (e, f, a, h, g) {
        return -h / 2 * (Math.cos(Math.PI * f / g) - 1) + a
    },
    easeInExpo: function (e, f, a, h, g) {
        return (f == 0) ? a : h * Math.pow(2, 10 * (f / g - 1)) + a
    },
    easeOutExpo: function (e, f, a, h, g) {
        return (f == g) ? a + h : h * (-Math.pow(2, -10 * f / g) + 1) + a
    },
    easeInOutExpo: function (e, f, a, h, g) {
        if (f == 0) {
            return a
        }
        if (f == g) {
            return a + h
        }
        if ((f /= g / 2) < 1) {
            return h / 2 * Math.pow(2, 10 * (f - 1)) + a
        }
        return h / 2 * (-Math.pow(2, -10 * --f) + 2) + a
    },
    easeInCirc: function (e, f, a, h, g) {
        return -h * (Math.sqrt(1 - (f /= g) * f) - 1) + a
    },
    easeOutCirc: function (e, f, a, h, g) {
        return h * Math.sqrt(1 - (f = f / g - 1) * f) + a
    },
    easeInOutCirc: function (e, f, a, h, g) {
        if ((f /= g / 2) < 1) {
            return -h / 2 * (Math.sqrt(1 - f * f) - 1) + a
        }
        return h / 2 * (Math.sqrt(1 - (f -= 2) * f) + 1) + a
    },
    easeInElastic: function (f, h, e, l, k) {
        var i = 1.70158;
        var j = 0;
        var g = l;
        if (h == 0) {
            return e
        }
        if ((h /= k) == 1) {
            return e + l
        }
        if (!j) {
            j = k * 0.3
        }
        if (g < Math.abs(l)) {
            g = l;
            var i = j / 4
        } else {
            var i = j / (2 * Math.PI) * Math.asin(l / g)
        }
        return - (g * Math.pow(2, 10 * (h -= 1)) * Math.sin((h * k - i) * (2 * Math.PI) / j)) + e
    },
    easeOutElastic: function (f, h, e, l, k) {
        var i = 1.70158;
        var j = 0;
        var g = l;
        if (h == 0) {
            return e
        }
        if ((h /= k) == 1) {
            return e + l
        }
        if (!j) {
            j = k * 0.3
        }
        if (g < Math.abs(l)) {
            g = l;
            var i = j / 4
        } else {
            var i = j / (2 * Math.PI) * Math.asin(l / g)
        }
        return g * Math.pow(2, -10 * h) * Math.sin((h * k - i) * (2 * Math.PI) / j) + l + e
    },
    easeInOutElastic: function (f, h, e, l, k) {
        var i = 1.70158;
        var j = 0;
        var g = l;
        if (h == 0) {
            return e
        }
        if ((h /= k / 2) == 2) {
            return e + l
        }
        if (!j) {
            j = k * (0.3 * 1.5)
        }
        if (g < Math.abs(l)) {
            g = l;
            var i = j / 4
        } else {
            var i = j / (2 * Math.PI) * Math.asin(l / g)
        }
        if (h < 1) {
            return -0.5 * (g * Math.pow(2, 10 * (h -= 1)) * Math.sin((h * k - i) * (2 * Math.PI) / j)) + e
        }
        return g * Math.pow(2, -10 * (h -= 1)) * Math.sin((h * k - i) * (2 * Math.PI) / j) * 0.5 + l + e
    },
    easeInBack: function (e, f, a, i, h, g) {
        if (g == undefined) {
            g = 1.70158
        }
        return i * (f /= h) * f * ((g + 1) * f - g) + a
    },
    easeOutBack: function (e, f, a, i, h, g) {
        if (g == undefined) {
            g = 1.70158
        }
        return i * ((f = f / h - 1) * f * ((g + 1) * f + g) + 1) + a
    },
    easeInOutBack: function (e, f, a, i, h, g) {
        if (g == undefined) {
            g = 1.70158
        }
        if ((f /= h / 2) < 1) {
            return i / 2 * (f * f * (((g *= (1.525)) + 1) * f - g)) + a
        }
        return i / 2 * ((f -= 2) * f * (((g *= (1.525)) + 1) * f + g) + 2) + a
    },
    easeInBounce: function (e, f, a, h, g) {
        return h - jQuery.easing.easeOutBounce(e, g - f, 0, h, g) + a
    },
    easeOutBounce: function (e, f, a, h, g) {
        if ((f /= g) < (1 / 2.75)) {
            return h * (7.5625 * f * f) + a
        } else {
            if (f < (2 / 2.75)) {
                return h * (7.5625 * (f -= (1.5 / 2.75)) * f + 0.75) + a
            } else {
                if (f < (2.5 / 2.75)) {
                    return h * (7.5625 * (f -= (2.25 / 2.75)) * f + 0.9375) + a
                } else {
                    return h * (7.5625 * (f -= (2.625 / 2.75)) * f + 0.984375) + a
                }
            }
        }
    },
    easeInOutBounce: function (e, f, a, h, g) {
        if (f < g / 2) {
            return jQuery.easing.easeInBounce(e, f * 2, 0, h, g) * 0.5 + a
        }
        return jQuery.easing.easeOutBounce(e, f * 2 - g, 0, h, g) * 0.5 + h * 0.5 + a
    }
});
(function () {
    $.fn.textTruncate = function (b) {
        return this.each(function () {
            var j = $(this),
                a = "...";
            if (j.height() <= b) {
                return
            }
            var g = j.text().split(" "),
                h = "";
            for (var i = 0; i < g.length; i++) {
                j.text(h + " " + g[i] + a);
                if (j.height() > b) {
                    myRegExp = /\W+$/;
                    h = h.replace(myRegExp, "");
                    j.text(h + a);
                    break
                }
                h += g[i] + " "
            }
        })
    }
})(jQuery);

(function($){$.fn.jTruncate=function(h){var i={length:300,minTrail:20,moreText:"more",lessText:"less",ellipsisText:"...",moreAni:"",lessAni:""};var h=$.extend(i,h);return this.each(function(){obj=$(this);var a=obj.html();if(a.length>h.length+h.minTrail){var b=a.indexOf(' ',h.length);if(b!=-1){var b=a.indexOf(' ',h.length);var c=a.substring(0,b);var d=a.substring(b,a.length-1);obj.html(c+'<span class="truncate_ellipsis">'+h.ellipsisText+'</span>'+'<span class="truncate_more">'+d+'</span>');obj.find('.truncate_more').css("display","none");obj.append('<div class="clearboth">'+'<a href="#" class="truncate_more_link">'+h.moreText+'</a>'+'</div>');var e=$('.truncate_more_link',obj);var f=$('.truncate_more',obj);var g=$('.truncate_ellipsis',obj);e.click(function(){if(e.text()==h.moreText){f.show(h.moreAni);e.text(h.lessText);g.css("display","none")}else{f.hide(h.lessAni);e.text(h.moreText);g.css("display","inline")}return false})}}})}})(jQuery);
