

/**
 * jCarouselLite - jQuery plugin to navigate images/any content in a carousel style widget.
 * @requires jQuery v1.2 or above
 *
 * http://gmarwaha.com/jquery/jcarousellite/
 *
 * Copyright (c) 2007 Ganeshji Marwaha (gmarwaha.com)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 * Modified by FarmerDane to add Pausing, select stop and fade
 *
 * Version: 1.0.1111111111111111111111
 * Note: Requires jquery 1.2 or above from version 1.0.1
 */
(function ($) {
 $.fn.jCarouselLite = function (o) {
 o = $.extend({
 btnPrev: null,
 btnNext: null,
 btnGo: null,
 mouseWheel: false,
 auto: null,
 pauseonmouseover: true,
 speed: 200,
 easing: null,
 vertical: false,
 fade: false,
 circular: true,
 visible: 3,
 start: 0,
 scroll: 1,
 beforeStart: null,
 afterEnd: null
 }, o || {});
 return this.each(function () {
 var auto_on = null;
 var clicked = false;
 var running = false,
 animCss = o.vertical ? "top" : "left",
 sizeCss = o.vertical ? "height" : "width";
 var div = $(this),
 ul = $("ul", div),
 tLi = $("li", ul),
 tl = tLi.size(),
 v = o.visible;
 if (o.circular) {
 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"
 });
 ul.css({
 margin: "0",
 padding: "0",
 position: "relative",
 "list-style-type": "none",
 "z-index": "1"
 });
 div.css({
 overflow: "hidden",
 position: "relative",
 "z-index": "2",
 left: "0px"
 });
 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");
 if (o.btnPrev) $(o.btnPrev).click(function () {
 return go(curr - o.scroll)
 });
 if (o.btnNext) $(o.btnNext).click(function () {
 return go(curr + o.scroll)
 });
 if (o.btnGo) $.each(o.btnGo, function (i, val) {
 $(val).click(function () {
 if (auto_on) {
 clicked = true;
 clearInterval(auto_on);
 running = false
 }
 return go(o.circular ? o.visible + i : i)
 })
 });
 if (o.mouseWheel && div.mousewheel) div.mousewheel(function (e, d) {
 return d > 0 ? go(curr - o.scroll) : go(curr + o.scroll)
 });
 if (o.auto) {
 auto_on = setInterval(startanim, o.auto + o.speed);
 if (o.pauseonmouseover) {
 $(this).hover(function () {
 running = false;
 clearInterval(auto_on)
 }, function () {
 if (!clicked) {
 auto_on = setInterval(startanim, o.auto + o.speed)
 }
 })
 }
 }
 function startanim() {
 go(curr + o.scroll)
 };

 function vis() {
 return li.slice(curr).slice(0, v)
 };

 function go(to) {
 if (!running) {
 if (o.beforeStart) o.beforeStart.call(this, vis());
 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;
 
 if(!o.fade){ 
 ul.animate(animCss == "left" ? {
 left: -(curr * liSize)
 } : {
 top: -(curr * liSize)
 }, o.speed, o.easing, function () {
 if (o.afterEnd) o.afterEnd.call(this, vis());
 running = false
 });
 }else{
 
 var direction = (animCss == "left") ? "left" : "top";
 ul.fadeTo(1500, 0.15, function(){
 ul.css(direction, -(curr * liSize)).fadeTo(1500, 1)
 });
 
 if (o.afterEnd) o.afterEnd.call(this, vis());
 running = false
 }
 

 /*ul.css(direction, -(curr * liSize)); 
 ul.fadeTo(2000, 1);*/
 
 

 if (!o.circular) {
 $(o.btnPrev + "," + o.btnNext).removeClass("disabled");
 $((curr - o.scroll < 0 && o.btnPrev) || (curr + o.scroll > itemLength - v && o.btnNext) || []).addClass("disabled")
 }
 }
 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);


var FarmerSlide = {
 fsdefaults : defaults = {
 featurediv : "features",
 statusdiv : "status",
 statuscontainer : "carousel-status",
 statuscontainerlist : "status-list",
 selectclass : "selected",
 changelink : "ff-link",
 btnNext: "",
 btnPrev: "",
 auto: 5000, 
 speed: 500,
 vertical: false,
 circular: true,
 visible: 1,
 pauseonmouseover : true,
 easing: "easeInOutQuad",
 fade: false
 },

 oMainTemplate: null,
 navClick : false,
 currItem : null,
 clickid: 0,


 init : function (options){
 this.o = jQuery.extend({}, this.fsdefaults, options);
 this.initSlide();
 },

 initSlide: function(){ 
 var m = this;
 var c = m.getControls();
 m.setCarouselLink(); 
 var ae = this.carouselEnd;
 var cs = (this.o.fade) ? this.carouselStart : null;
 
 jQuery("#"+this.o.featurediv).jCarouselLite({
 auto: m.o.auto,
 speed: m.o.speed,
 vertical: m.o.vertical,
 easing: m.o.easing,
 afterEnd: ae,
 beforeStart: cs,
 pauseonmouseover : m.o.pauseonmouseover,
 fade: m.o.fade,
 visible: m.o.visible,
 btnNext: m.o.btnNext,
 btnPrev: m.o.btnPrev,
 circular: m.o.circular,
 btnGo: c
 });

 },

 getControls : function(){
 var temp = [];
 var features = jQuery("#"+this.o.featurediv+" li");
 var c = features.length;
 for(var i = 0; i < c; i++){
 temp.push("."+this.o.statusdiv+"-"+i);
 }
 return temp;
 },
 
 drawStatus : function(thediv){
 var m = this;
 
 var html = '<ul class="'+this.o.statuscontainerlist+'">';
 var c = jQuery("#"+this.o.featurediv+" li").length;
 var alink = '<a href="javascript:void(0)"></a>'
 
 for(var i = 0; i < c; i++){ 
 if(i ==0){
 html += '<li class="'+m.o.selectclass+' status-'+i+'">'+alink+'</li>';
 }else{
 html += '<li class="status-'+i+'">'+alink+'</li>';
 } 
 } 
 html = html + '</ul>';
 jQuery("#"+thediv).html(html); 
 
 var stats = jQuery("#"+thediv+" li");
 stats.click(function () { 
 stats.removeClass(m.o.selectclass);
 jQuery(this).addClass(m.o.selectclass);
 m.navClick = true;
 });
 },
 
 carouselStart : function(el){
 //el = jQuery(el);
 },
 
 carouselEnd : function(el){
 el = jQuery(el);
 if(FarmerSlide.o.fade){
 FarmerSlide.currItem = el;
 }else{ 
 var ana = el.children("a");
 jQuery("#"+FarmerSlide.o.changelink).attr("href",ana.attr("href"));
 }
 
 if(!FarmerSlide.navClick)
 FarmerSlide.incrementStatus(FarmerSlide.o.statuscontainer); 
 },

 setCarouselLink : function(){
 this.drawStatus(this.o.statuscontainer);
 
 var c = jQuery("#"+this.o.featurediv+" li");
 var thelink = jQuery(c[0]).children("a").attr("href");
 jQuery("#"+this.o.changelink).attr("href",thelink);
 },
 
 incrementStatus: function(thediv){
 var lis = jQuery("#"+thediv+" li");
 
 for(var i = 0; i < lis.length; i++){
 lis[i] = jQuery(lis[i]);
 var sel = (lis[i].hasClass(this.o.selectclass)) ? true : false; 
 if(sel){
 lis[i].removeClass(this.o.selectclass);
 if(i == (lis.length-1)){
 jQuery(lis[0]).addClass(this.o.selectclass);
 }else{
 jQuery(lis[parseInt(i+1)]).addClass(this.o.selectclass);
 } 
 break;
 }
 } 
 
 }

};


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}});