﻿// --------------------------------
//  Plugin author: Robert Koritnik
// --------------------------------
//  Depends on Plugin.Timer.js
// --------------------------------
(function(a) { a.fn.carousel = function(b) { if (!a.run) { return this } b = a.extend({ delay: 5000, animationSpeed: 500, itemSelector: "div.item", linkSelector: "div.controls ul li a", linkParentSelector: "ul", autoPlay: true, addControls: true, replaceLinkContent: true, timerKey: a.fn.carousel.id++ }, b || {}); return this.each(function() { var o = this; b.addControls === true && a(b.linkSelector, this).eq(0).closest(b.linkParentSelector).append('<li class="stop"><a href="">Play/Stop</a></li>').append('<li class="previous"><a href="">Nazaj</a></li>').append('<li class="next"><a href="">Naprej</a></li>'); var j = a(b.itemSelector, this); var n = a(b.linkSelector, this); if (j.length + (b.addControls === true ? 3 : 0) != n.length) { return } var h = j.length; var m = 0; var g = b.autoPlay; var p = false; for (var d = 0; d < h; d++) { a(j[d]).css({ position: "absolute", display: d === 0 ? "block" : "none" }); a(n[d]).data("itemNumber", d).click(function(q) { q.preventDefault(); var i = m; m = a(this).data("itemNumber"); if (i != m) { l.call(o, i, true) } }); b.replaceLinkContent === true && a(n[d]).text(d + 1); d === 0 && a(n[d]).parent().addClass("selected") } if (b.addControls) { a(n[h]).click(function(i) { i.preventDefault(); if (g) { k.call(o) } else { e.call(o); c.call(o) } }); a(n[h + 1]).click(function(i) { i.preventDefault(); f.call(o, true) }); a(n[h + 2]).click(function(i) { i.preventDefault(); e.call(o, true) }) } var e = function(q) { if (p) { return } var r = m; if (++m == h) { m = 0 } l.call(this, r, q) }; var f = function(q) { if (p) { return } var r = m; if (--m < 0) { m = h - 1 } l.call(this, r, q) }; var l = function(q, i) { if (i === true) { k.call(this) } p = true; a(j[q]).fadeOut(b.animationSpeed, function() { a(n[q]).parent().removeClass("selected") }); a(j[m]).fadeIn(b.animationSpeed, function() { a(n[m]).parent().addClass("selected"); p = false }) }; var c = function() { if (b.addControls) { a(n[h]).parent().removeClass("play").addClass("stop") } g = true; a.run("Carousel-" + b.timerKey, e, b.delay, true, this) }; var k = function() { a.stopRun("Carousel-" + b.timerKey); g = false; if (b.addControls === true) { a(n[h]).parent().removeClass("stop").addClass("play") } }; if (b.autoPlay === true) { c() } else { k() } }) }; a.fn.carousel.id = 1 })(jQuery);


