/* jquery.supersleight plugin */
jQuery.fn.supersleight=function(settings){settings=jQuery.extend({imgs:true,backgrounds:true,shim:'http://localhost/sifacollection/images/blank.gif',apply_positioning:true},settings);return this.each(function(){if(jQuery.browser.msie&&parseInt(jQuery.browser.version,10)<7&&parseInt(jQuery.browser.version,10)>4){jQuery(this).find('*').andSelf().each(function(i,obj){var self=jQuery(obj);if(settings.backgrounds&&self.css('background-image').match(/\.png/i)!==null){var bg=self.css('background-image');var src=bg.substring(5,bg.length-2);var mode=(self.css('background-repeat')=='no-repeat'?'crop':'scale');var styles={'filter':"progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+src+"', sizingMethod='"+mode+"')",'background-image':'url('+settings.shim+')'};self.css(styles);};if(settings.imgs&&self.is('img[src$=png]')){var styles={'width':self.width()+'px','height':self.height()+'px','filter':"progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+self.attr('src')+"', sizingMethod='scale')"};self.css(styles).attr('src',settings.shim);};if(settings.apply_positioning&&self.is('a, input')&&(self.css('position')===''||self.css('position')=='static')){self.css('position','relative');};});};});};

/*
 * jQuery Backstretch
 * Version 1.1.2
 * http://srobbin.com/jquery-plugins/jquery-backstretch/
 * Copyright (c) 2010 Scott Robbin (srobbin.com)
 * Dual licensed under the MIT and GPL licenses.
*/
(function(a){a.backstretch=function(k,i,l){function m(c){try{f={left:0,top:0};d=e.width();b=d/j;if(b>=e.height()){g=(b-e.height())/2;h.centeredY&&a.extend(f,{top:"-"+g+"px"})}else{b=e.height();d=b*j;g=(d-e.width())/2;h.centeredX&&a.extend(f,{left:"-"+g+"px"})}a("#backstretch img").width(d).height(b).css(f)}catch(n){}typeof c=="function"&&c()}var h={centeredX:true,centeredY:true,speed:0},e="onorientationchange"in window?a(document):a(window),j,d,b,g,f;i&&typeof i=="object"&&a.extend(h,i);a(document).ready(function(){if(k){var c= a("<div />").attr("id","backstretch").css({left:0,top:0,position:"fixed",overflow:"hidden",zIndex:-9999}),n=a("<img />").css({position:"relative",display:"none"}).bind("load",function(o){var p=a(this);j=a(o.target).width()/a(o.target).height();m(function(){p.fadeIn(h.speed,function(){typeof l=="function"&&l()})})}).appendTo(c);a("body").prepend(c);n.attr("src",k);a(window).resize(m)}});return this}})(jQuery);;
jQuery(function() {
	jQuery('a[rel^="ext"]').attr('target', '_blank');
	jQuery(".png").supersleight(); // call png supersleight plugin
	
	// sidebar navigation
	/*jQuery("div#sidebar li a").click(function(){
		if(jQuery(this).next().is("ul")){
			jQuery(this).parent().find("ul:first").slideToggle();
			return false;
		}
	});*/
	
	// background image
	if(!bgimage) var bgimage = "/themes/zen/brwa/images/bg01.jpg";
	if (jQuery.browser.msie && jQuery.browser.version == "6.0") {
		jQuery("body").css("background", "url("+bgimage+")");
	}
	else{
		jQuery.backstretch(bgimage);
	}
});

var BRWA = {
	
	jumpMenu : function(base, targ,selObj,restore){
	  eval(targ+".location='"+base+"?filter="+BRWA.urlencode(selObj.options[selObj.selectedIndex].value)+"'");
	  if (restore) selObj.selectedIndex=0;
	},
	
	urlencode : function (str) {
	    str = (str+'').toString();
	    return encodeURIComponent(str).replace(/!/g, '%21').replace(/'/g, '%27').replace(/\(/g, '%28').replace(/\)/g, '%29').replace(/\*/g, '%2A').replace(/%20/g, '+');
	}
	
};;
/**
 * 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, super fade and index status
 *
 * Version: 1.0.2
 * Note: Requires jquery 1.2 or above from version 1.0.1
 */
(function(d){function q(a,r){return parseInt(d.css(a[0],r))||0}d.fn.jCarouselLite=function(a){a=d.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,afterEndIndex:null},a||{});return this.each(function(){function r(){j(b+a.scroll)}function s(){return e.slice(b).slice(0,c)}function j(f){if(!k){a.beforeStart&&a.beforeStart.call(this,s()); if(a.circular)if(f<=a.start-c-1){g.css(m,-((h-c*2)*i)+"px");b=f==a.start-c-1?h-c*2-1:h-c*2-a.scroll}else if(f>=h-c+1){g.css(m,-(c*i)+"px");b=f==h-c+1?c+1:c+a.scroll}else b=f;else if(f<0||f>h-c)return;else b=f;k=true;if(a.fade){var n=m=="left"?"left":"top";g.fadeTo(1200,0.1,function(){g.css(n,-(b*i)).fadeTo(1200,1)});a.afterEnd&&a.afterEnd.call(this,s());a.afterEndIndex&&a.afterEndIndex.call(this,b);k=false}else g.animate(m=="left"?{left:-(b*i)}:{top:-(b*i)},a.speed,a.easing,function(){a.afterEnd&& a.afterEnd.call(this,s());a.afterEndIndex&&a.afterEndIndex.call(this,b);k=false});if(!a.circular){d(a.btnPrev+","+a.btnNext).removeClass("disabled");d(b-a.scroll<0&&a.btnPrev||b+a.scroll>h-c&&a.btnNext||[]).addClass("disabled")}}return false}var o=null,u=false,k=false,m=a.vertical?"top":"left",v=a.vertical?"height":"width",l=d(this),g=d("ul",l),p=d("li",g),t=p.size(),c=a.visible;if(a.circular){g.prepend(p.slice(t-c-1+1).clone()).append(p.slice(0,c).clone());a.start+=c}var e=d("li",g),h=e.size(),b= a.start;l.css("visibility","visible");e.css({overflow:"hidden","float":a.vertical?"none":"left"});g.css({margin:"0",padding:"0",position:"relative","list-style-type":"none","z-index":"1"});l.css({overflow:"hidden",position:"relative","z-index":"2",left:"0px"});var i=a.vertical?e[0].offsetHeight+q(e,"marginTop")+q(e,"marginBottom"):e[0].offsetWidth+q(e,"marginLeft")+q(e,"marginRight");p=i*h;t=i*c;e.css({width:e.width(),height:e.height()});g.css(v,p+"px").css(m,-(b*i));l.css(v,t+"px");a.btnPrev&&d(a.btnPrev).click(function(){return j(b- a.scroll)});a.btnNext&&d(a.btnNext).click(function(){a.beforeStart&&a.beforeStart.call(this,s());return j(b+a.scroll)});a.btnGo&&d.each(a.btnGo,function(f,n){d(n).click(function(){if(o){u=true;clearInterval(o);k=false}return j(a.circular?a.visible+f:f)})});a.mouseWheel&&l.mousewheel&&l.mousewheel(function(f,n){return n>0?j(b-a.scroll):j(b+a.scroll)});if(a.auto){o=setInterval(r,a.auto+a.speed);a.pauseonmouseover&&d(this).hover(function(){k=false;clearInterval(o)},function(){u||(o=setInterval(r,a.auto+ a.speed))})}})}})(jQuery);;
var FarmerSlide = {
	fsdefaults : defaults = {
				featurediv : "features",
				statusdiv : "status",
				statuscontainer : "carousel-status",
				statuscontainerlist : "status-list",
				selectclass : "selected",
				changelink : "ff-link",
        btnNext: "",
        btnPrev: "",
        btnGo: null,
		    auto: 5000,		   
		    speed: 500,
		    vertical: false,
		    circular: true,
		    visible: 1,
		    pauseonmouseover : true,
		    easing: "easeInOutQuad",
		    fade: false
	},

	oMainTemplate: null,
	oFeatures: null,
	oStats: null,
	navClick : false,
	currItem : null,
	clickid: 0,


	init : function (options){
		this.o = jQuery.extend({}, this.fsdefaults, options);
		this.initSlide();
	},

	initSlide: function(){			
		var m = this;
		this.oFeatures = jQuery("#" + this.o.featurediv+" li");
		var c = m.getControls();
		m.setCarouselLink();		
		var ae = this.carouselEnd;
		var cei = this.carouselEndIndex;
		var cs = this.carouselStart;
		jQuery("#"+this.o.featurediv).jCarouselLite({
		    auto: m.o.auto,
		    speed: m.o.speed,
		    vertical: m.o.vertical,
		    easing: m.o.easing,
		    afterEnd: ae,
		    afterEndIndex: cei,
		    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 c = this.oFeatures.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);	
			
			this.oStats = jQuery("#"+thediv+" li");
			this.oStats.click(function () {
		   });
	},
	
	setClick :function(el){
		el = jQuery(el);
		FarmerSlide.oStats.removeClass(FarmerSlide.o.selectclass);
		el.addClass(FarmerSlide.o.selectclass);
		FarmerSlide.navClick = true;
	},
	
	carouselEndIndex: function(i){
		if(i > FarmerSlide.oFeatures.length){
			i = 1;
		}		
		if(i == 0){
			i = FarmerSlide.oFeatures.length;
		}		
		var el = (FarmerSlide.oStats[i-1] !== undefined) ? FarmerSlide.oStats[i-1] : null;			
		FarmerSlide.setClick(el);
		
	},
	
	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}});
;
jQuery(function(){
			FarmerSlide.init({
			    auto: 8000,
			    speed: 500,
			    vertical: false,
			    pauseonmouseover : true,
			    fade : true,
			    featurediv: 'featured-events-slider .item-list'
			});
			
			var cs = jQuery("#carousel-status");
			var w = jQuery("#carousel-status").width();
			
			cs.css({'width' : w+"px", 'margin' : '0 auto', 'display' : 'block'});

});;

