/*
 * Just Another Carousel v1.0
 * http://intrepidstudios.com/projects/jquery-just-another-carousel/
 *
 * Copyright (c) 2009 Kamran Ayub
 * Licensed under the GPL license.
 * http://intrepidstudios.com/projects/jquery-just-another-carousel/#license
 *
 * Last Modified: Feb 2, 2009
 * This file is part of Just Another Carousel.

    Just Another Carousel is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Just Another Carousel is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Just Another Carousel.  If not, see <http://www.gnu.org/licenses/>.
*/
(function(a){function b(b){var c=a(b).css("left");return Math.round(parseInt(c.replace("px","")))}a.fn.jac=function(c){var d=a.extend({},a.fn.jac.defaults,c);return this.each(function(){function p(){return b(f)}function o(a){switch(a){case"left":if(Math.round(p())>=0)return true;break;case"right":var b=Math.round(m()-e+p());if(b<=0)return true;break}return false}function n(){if(o("left")){c.find(h.leftArrowSelector).addClass("disabled")}else{c.find(h.leftArrowSelector).removeClass("disabled")}if(o("right")){c.find(h.rightArrowSelector).addClass("disabled")}else{c.find(h.rightArrowSelector).removeClass("disabled")}}function m(){var b=0;if(g.childFixedSize){b=f.find(h.childSelector).length*i}else{f.find(h.childSelector).each(function(){b+=a(this).outerWidth()})}return b}var c=a(this);var e=Math.round(c.width());var f=c.children("ul:only-child");if(f.length>1)return;var g=a.meta?a.extend({},d,c.data()):d;var h={carouselSelector:"."+g.carouselSelector,childSelector:"."+g.childSelector,leftArrowSelector:"."+g.leftArrowSelector,rightArrowSelector:"."+g.rightArrowSelector};c.addClass("jac").children("ul").addClass(g.carouselSelector).children("li").addClass(g.childSelector);f.css("width",m()).wrapAll(a("<div class='carousel-wrapper'></div>").css({overflow:"hidden",width:e,height:c.height(),position:"relative"}));if(m()<=e)return;var i=f.find(h.childSelector+":eq(0)").outerWidth();var j=Math.floor(e/i);f.find(h.childSelector).hover(function(b){if(!g.enableMouse)return;var d;if(g.childSizeFixed){d=f.children().index(this)*i}else{d=Math.round(a(this).position().left)}var h=d+p();var j=d+Math.round(a(this).width()/2);var k=Math.round(b.pageX)-c.offset().left;var l=k-j;var m=j-k;var o=d-m;var q=a(this).width()+d-m;if(!g.childFixedSize)q+=1;if(o<=0)m=m+o;if(q>=e)m=m+(q-e);f.stop().animate({left:-m},g.childSlideSpeed,g.easingStyle,n)},function(a){if(!g.enableMouse)return;f.stop()});if(m()>e){c.append("<span class='"+g.leftArrowSelector+"'></span>");c.append("<span class='"+g.rightArrowSelector+"'></span>");var k=c.find(h.rightArrowSelector).html("<a href='javascript:void(0)' title='"+g.rightText+"'>"+g.rightText+"</a>");var l=c.find(h.leftArrowSelector).html("<a href='javascript:void(0)' title='"+g.leftText+"'>"+g.leftText+"</a>");l.click(function(){var a,b;b=p()+e;if(o("left")){n();return}if(!g.enableMouse&&g.childSizeFixed){a=j*i}else{a=e}if(b>0){a=-p()}a=a+p();f.stop();f.animate({left:a},g.parentSlideSpeed,g.easingStyle,n)});k.click(function(){var a,b;b=-p()+e;if(!g.enableMouse&&g.childSizeFixed){a=j*i}else{a=e}if(b>=m()-e){a=m()-e+p()}a=a-p();f.stop();f.animate({left:-a},g.parentSlideSpeed,g.easingStyle,n)});if(o("left")){c.find(h.leftArrowSelector).addClass("disabled")}if(o("right")){c.find(h.rightArrowSelector).addClass("disabled")}}})};a.fn.jac.defaults={carouselSelector:"carousel",childSelector:"jac-content",leftArrowSelector:"arrow-left",rightArrowSelector:"arrow-right",easingStyle:"swing",rightText:"Next",leftText:"Previous",childSizeFixed:true,childSlideSpeed:300,parentSlideSpeed:600,fadeSpeed:300,enableMouse:false}})(jQuery)
