﻿(function ($) {
    jQuery.fn.carousel = function (n) {
        var o = $.extend({ starter: 1, speed: 600, behind_opac: 0.4, back_opac: 0.15, behind_size: 0.7, back_size: 0.4, behind_distance: 'auto', autoplay: false, autointerval: 3000, freescroll: true, hovergrowth: 0.08, easing: 'easeInOutQuad', move_twice_easein: 'easeInCirc', move_twice_easeout: 'easeOutCirc', text_front_only: false, keyboard: true, move_on_hover: false }, n); $(this).each(function () {
            var c = $(this), $lis = $('li', c); var d, easingplugin, hoverspeed, $newitem1, $newitem2, $newitem3, $newitem4, $newitem5, eazing, zpeed, next, iegrow, container_width, container_height, front_img_width, front_img_height, text_opacity, containerid = c.attr('id'), busy = false, current = o.starter, items = $lis.length, ie = false, ie6 = false, container_100 = false; if ($.browser.msie) { ie = true; if ($.browser.version < 7) { ie6 = true } } if (o.hoverspeed) { hoverspeed = o.hoverspeed } else { hoverspeed = (o.speed / 4) } if (o.starter > items) { o.starter = items } if ($.easing.def) { easingplugin = true; $.easing.def = o.easing } else { easingplugin = false } var x = 1; var f = []; $lis.each(function () { var a = $(this); a.addClass('li' + x); f[x] = a; x++ }); if (items == 1) { f[1].clone().addClass('frame1').prependTo(c); f[1].clone().addClass('frame2').prependTo(c) } else if (o.starter == 2) { f[1].clone().addClass('frame2').prependTo(c); f[items].clone().addClass('frame1').prependTo(c) } else if (o.starter == 1) { f[items - 1].clone().addClass('frame1').prependTo(c); f[items].clone().addClass('frame2').prependTo(c) } else { f[o.starter - 1].clone().addClass('frame2').prependTo(c); f[o.starter - 2].clone().addClass('frame1').prependTo(c) } f[o.starter].clone().addClass('frame3').prependTo(c); if (items == 1) { f[1].clone().addClass('frame4').prependTo(c); f[1].clone().addClass('frame5').prependTo(c) } else if (o.starter == (items - 1)) { f[items].clone().addClass('frame4').prependTo(c); f[1].clone().addClass('frame5').prependTo(c) } else if (o.starter == items) { f[1].clone().addClass('frame4').prependTo(c); f[2].clone().addClass('frame5').prependTo(c) } else { f[o.starter + 1].clone().addClass('frame4').prependTo(c); f[o.starter + 2].clone().addClass('frame5').prependTo(c) } var g = c.find('.frame1'), $item2 = c.find('.frame2'), $item3 = c.find('.frame3'), $item4 = c.find('.frame4'), $item5 = c.find('.frame5'); g.add($item5).show().animate({ opacity: 0 }, 0).addClass('back'); $item2.add($item4).show().animate({ opacity: 0 }, 0).addClass('behind'); $item3.show().animate({ opacity: 0 }, 0).addClass('front'); var h = $('.back', c), $behind = $('.behind', c), $front = $('.front', c); if (o.container_width) { container_width = o.container_width } else { container_width = c.css('width') } if (container_width == '100%') { container_100 = true; container_width = parseInt($(window).width(), 10) } else { container_width = parseInt(container_width, 10) } if (o.front_img_width) { front_img_width = o.front_img_width } else { front_img_width = parseInt($('img', $front).css('width'), 10) } if (o.front_img_height) { front_img_height = o.front_img_height } else { front_img_height = parseInt($('img', $front).css('height')) } if (o.text_opacity) { text_opacity = o.text_opacity } else { text_opacity = parseFloat($('span', c).css('opacity')) } var j = parseInt($lis.css('borderLeftWidth'), 10), li_padding = parseInt($lis.css('padding-left'), 10), front_top = $front.css('margin-top'), front_margin = parseInt($('img', $front).css('margin-left'), 10), front_width = Math.round(front_img_width + (front_margin * 2) + (li_padding * 2) + (j * 2)), front_height = Math.round(front_img_height + (front_margin * 2) + (li_padding * 2) + (j * 2)), behind_img_width = Math.round(front_img_width * o.behind_size), behind_img_height = Math.round(front_img_height * o.behind_size), behind_top = $behind.css('margin-top'), behind_margin = parseInt($('img', $behind).css('margin-left'), 10), behind_width = Math.round(behind_img_width + (behind_margin * 2) + (li_padding * 2) + (j * 2)), behind_height = Math.round(behind_img_height + (behind_margin * 2) + (li_padding * 2) + (j * 2)), back_img_width = Math.round(front_img_width * o.back_size), back_img_height = Math.round(front_img_height * o.back_size), back_top = h.css('margin-top'), back_margin = parseInt($('img', h).css('margin-left'), 10), back_width = Math.round(back_img_width + (back_margin * 2) + (li_padding * 2) + (j * 2)), back_height = Math.round(back_img_height + (back_margin * 2) + (li_padding * 2) + (j * 2)), item3_pos = Math.round((container_width / 2) - (front_width / 2)), item5_pos = (container_width - back_width), item2_pos; if (o.behind_distance != 'auto') { item2_pos = parseInt(o.behind_distance, 10) } else { item2_pos = Math.round((container_width / 4) - (behind_width / 2)) } var k = (container_width - item2_pos - behind_width); h.removeClass('back'); $behind.removeClass('behind'); $front.removeClass('front'); var l = (front_height + parseInt(front_top, 10)), behind_space = (behind_height + parseInt(behind_top, 10)), back_space = (back_height + parseInt(back_top, 10)); if (l > behind_space && l > back_space) { container_height = l } else if (behind_space > l && behind_space > back_space) { container_height = behind_space } else { container_height = back_space } c.height(container_height); g.css({ left: 0, top: back_top }).animate({ opacity: o.back_opac }, 0).find('img').animate({ width: back_img_width + 'px', height: back_img_height + 'px', margin: back_margin + 'px', opacity: 1 }, 0); $item2.css({ left: item2_pos + 'px', top: behind_top, 'z-index': 2 }).animate({ opacity: o.behind_opac }, 0).find('img').animate({ width: behind_img_width + 'px', height: behind_img_height + 'px', margin: behind_margin + 'px', opacity: 1 }, 0); $item3.css({ left: item3_pos + 'px', top: front_top, 'z-index': 3 }).animate({ opacity: 1 }, 0).find('a *').css({ cursor: 'pointer' }).end().find('img').animate({ width: front_img_width + 'px', height: front_img_height + 'px', margin: front_margin + 'px', opacity: 1 }, 0); $item4.css({ left: k + 'px', top: behind_top, 'z-index': 2 }).animate({ opacity: o.behind_opac }, 0).find('img').animate({ width: behind_img_width + 'px', height: behind_img_height + 'px', margin: behind_margin + 'px', opacity: 1 }, 0); $item5.css({ left: item5_pos + 'px', top: back_top }).animate({ opacity: o.back_opac }, 0).find('img').animate({ width: back_img_width + 'px', height: back_img_height + 'px', margin: back_margin + 'px', opacity: 1 }, 0); function setContainerWidth() { var a = parseInt($(window).width(), 10); c.width(a); item2_pos = Math.round((a / 4) - (behind_width / 2)); item3_pos = Math.round((a / 2) - (front_width / 2)); k = (a - item2_pos - behind_width); item5_pos = (a - back_width); $item2.css({ left: item2_pos }); $item3.css({ left: item3_pos }); $item4.css({ left: k }); $item5.css({ left: item5_pos }) } if (container_100) { setContainerWidth() } function stopInterval() { if (d) { clearInterval(d); d = false } } function startInterval() { if (d) { stopInterval() } d = setInterval(function () { moveLeft() }, o.autointerval) } function moveRight(b) { busy = true; eazing = ''; zpeed = o.speed; if (easingplugin) { if (b == 'twice') { eazing = o.move_twice_easein; zpeed = Math.round(o.speed * 0.5) } else if (b == 'twice_end') { eazing = o.move_twice_easeout } else { eazing = o.easing } } if (o.autoplay) { stopInterval() } if (current == (items - 2)) { next = 1 } else if (current == (items - 1)) { next = 2; if (next > items) { next = 1 } } else if (current == items) { next = 3; if (next > items) { next = 1 } } else { next = (current + 3) } g.removeClass('frame1').addClass('remove').css('z-index', -1); $newitem1 = $item2; $newitem1.removeClass('frame2').addClass('frame1').stop().animate({ opacity: o.back_opac, left: 0, top: back_top }, zpeed, eazing).find('img').stop().animate({ width: back_img_width + 'px', height: back_img_height + 'px', marginTop: back_margin + 'px', marginRight: back_margin + 'px', marginBottom: back_margin + 'px', marginLeft: back_margin + 'px', opacity: 1 }, zpeed, eazing).end(); setTimeout(function () { $newitem1.css('z-index', 1) }, (zpeed / 4)); $newitem2 = $item3; $newitem2.removeClass('frame3').addClass('frame2').stop().animate({ opacity: o.behind_opac, left: item2_pos + 'px', top: behind_top }, zpeed, eazing).find('img').stop().animate({ width: behind_img_width + 'px', height: behind_img_height + 'px', marginTop: behind_margin + 'px', marginRight: behind_margin + 'px', marginBottom: behind_margin + 'px', marginLeft: behind_margin + 'px', opacity: 1 }, zpeed, eazing).end(); setTimeout(function () { $newitem2.css('z-index', 2) }, (zpeed / 4)); $newitem3 = $item4; $newitem3.removeClass('frame4').addClass('frame3').stop().animate({ opacity: 1, left: item3_pos + 'px', top: front_top }, zpeed, eazing).find('img').stop().animate({ width: front_img_width + 'px', height: front_img_height + 'px', marginTop: front_margin + 'px', marginRight: front_margin + 'px', marginBottom: front_margin + 'px', marginLeft: front_margin + 'px', opacity: 1 }, zpeed, eazing).end(); setTimeout(function () { $newitem3.css('z-index', 3) }, (zpeed / 4)); $newitem4 = $item5; $newitem4.removeClass('frame5').addClass('frame4').stop().animate({ opacity: o.behind_opac, left: k + 'px', top: behind_top }, zpeed, eazing).find('img').stop().animate({ width: behind_img_width + 'px', height: behind_img_height + 'px', marginTop: behind_margin + 'px', marginRight: behind_margin + 'px', marginBottom: behind_margin + 'px', marginLeft: behind_margin + 'px', opacity: 1 }, zpeed, eazing).end(); setTimeout(function () { $newitem4.css('z-index', 2) }, (zpeed / 4)); f[next].clone().addClass('frame5').prependTo(c).show().animate({ opacity: 0, left: item5_pos + 'px', top: back_top }, 0).animate({ opacity: o.back_opac }, zpeed, function () { $newitem2.find('a *').css({ cursor: 'default' }); if (o.autoplay) { startInterval() } if (b == 'twice') { moveRight('twice_end') } else { $newitem3.find('a *').css({ cursor: 'pointer' }) } if (!$newitem3.is(':animated')) { busy = false; c.find('.remove').stop().fadeOut(zpeed, function () { $(this).remove() }); if (typeof move_callback == 'function') { var a = $newitem3.find('a').attr('href'); if (a != undefined && a != '') { move_callback(a) } } } }).find('img').animate({ width: back_img_width + 'px', height: back_img_height + 'px', margin: back_margin + 'px', opacity: 1 }, 0).end(); g = $newitem1, $item2 = $newitem2, $item3 = $newitem3, $item4 = $newitem4, $item5 = c.find('.frame5'); c.find('.remove').fadeOut(zpeed, function () { $(this).remove() }); if (current == items) { current = 1 } else { current = (current + 1) } } function moveLeft(b) { busy = true; eazing = ''; zpeed = o.speed; if (easingplugin) { if (b == 'twice') { eazing = o.move_twice_easein; zpeed = Math.round(o.speed * 0.5) } else if (b == 'twice_end') { eazing = o.move_twice_easeout } else { eazing = o.easing } } if (o.autoplay) { stopInterval() } if (current == 3) { next = items } else if (current == 2) { next = (items - 1); if (next < 1) { next = items } } else if (current == 1) { next = (items - 2); if (next < 1) { next = items } } else { next = (current - 3) } $item5.removeClass('frame5').addClass('remove').css('z-index', -1); $newitem5 = $item4; $newitem5.removeClass('frame4').addClass('frame5').stop().animate({ opacity: o.back_opac, left: item5_pos + 'px', top: back_top }, zpeed, eazing).find('img').stop().animate({ width: back_img_width + 'px', height: back_img_height + 'px', marginTop: back_margin + 'px', marginRight: back_margin + 'px', marginBottom: back_margin + 'px', marginLeft: back_margin + 'px', opacity: 1 }, zpeed, eazing).end(); setTimeout(function () { $newitem5.css('z-index', 1) }, (zpeed / 4)); $newitem4 = $item3; $newitem4.removeClass('frame3').addClass('frame4').stop().animate({ opacity: o.behind_opac, left: k + 'px', top: behind_top }, zpeed, eazing).find('img').stop().animate({ width: behind_img_width + 'px', height: behind_img_height + 'px', marginTop: behind_margin + 'px', marginRight: behind_margin + 'px', marginBottom: behind_margin + 'px', marginLeft: behind_margin + 'px', opacity: 1 }, zpeed, eazing).end(); setTimeout(function () { $newitem4.css('z-index', 2) }, (zpeed / 4)); $newitem3 = $item2; $newitem3.removeClass('frame2').addClass('frame3').stop().animate({ opacity: 1, left: item3_pos + 'px', top: front_top }, zpeed, eazing).find('img').stop().animate({ width: front_img_width + 'px', height: front_img_height + 'px', marginTop: front_margin + 'px', marginRight: front_margin + 'px', marginBottom: front_margin + 'px', marginLeft: front_margin + 'px', opacity: 1 }, zpeed, eazing).end(); setTimeout(function () { $newitem3.css('z-index', 3) }, (zpeed / 4)); $newitem2 = g; $newitem2.removeClass('frame1').addClass('frame2').stop().animate({ opacity: o.behind_opac, left: item2_pos + 'px', top: behind_top }, zpeed, eazing).find('img').stop().animate({ width: behind_img_width + 'px', height: behind_img_height + 'px', marginTop: behind_margin + 'px', marginRight: behind_margin + 'px', marginBottom: behind_margin + 'px', marginLeft: behind_margin + 'px', opacity: 1 }, zpeed, eazing).end(); setTimeout(function () { $newitem2.css('z-index', 2) }, (zpeed / 4)); f[next].clone().addClass('frame1').prependTo(c).show().animate({ opacity: 0, left: 0, top: back_top }, 0).animate({ opacity: o.back_opac }, zpeed, function () { $newitem4.find('a *').css({ cursor: 'default' }); if (o.autoplay) { startInterval() } if (b == 'twice') { moveLeft('twice_end') } else { $newitem3.find('a *').css({ cursor: 'pointer' }) } if (!$newitem3.is(':animated')) { busy = false; c.find('.remove').stop().fadeOut(zpeed, function () { $(this).remove() }); if (typeof move_callback == 'function') { var a = $newitem3.find('a').attr('href'); if (a != undefined && a != '') { move_callback(a) } } } }).find('img').animate({ width: back_img_width + 'px', height: back_img_height + 'px', margin: back_margin + 'px', opacity: 1 }, 0).end(); g = c.find('.frame1'), $item2 = $newitem2, $item3 = $newitem3, $item4 = $newitem4, $item5 = $newitem5; c.find('.remove').fadeOut(zpeed, function () { $(this).remove() }); if (current == 1) { current = items } else { current = (current - 1) } } var m = $('#ext-ctrl a'); $(m).click(function () {
                o.autoplay = false;stopInterval(); moveit($(m).index(this) + 1); $(m).removeClass('active'); $(this).addClass('active')
            }); function moveit(a) { if (current < a) { for (i = 1; i = (a - current); i++) { moveRight() } } else { for (i = 1; i = (current - a); i++) { moveLeft() } } } if (!ie) { c.find('.frame3:not(.zoomed)').live('mousemove', function () { $item3.mouseover() }) } $item3.find('a').live('click', function () { if (typeof link_callback == 'function') { link_callback($(this).attr('href')) } }); if (o.keyboard) { $(document).keydown(function (e) { if (e.keyCode == 13 || e.keyCode == 32 || e.keyCode == 39) { $item4.click() } if (e.keyCode == 37) { $item2.click() } }) } if (o.autoplay) { startInterval() } if (container_100) { $(window).resize(function () { setContainerWidth() }) } 
        })
    } 
})(jQuery);
