/*
* Slides, A Slideshow Plugin for jQuery
* Intructions: http://slidesjs.com
* By: Nathan Searles, http://nathansearles.com
* Version: 1.1.2
* Updated: February 14th, 2011
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* This has been modified to include the pause functionality by SID.org
*/

(function(a){a.fn.slides=function(b){b=a.extend({},a.fn.slides.option,b);return this.each(function(){a("."+b.container,a(this)).children().wrapAll('<div class="slides_control"/>');var d=a(this),c=a(".slides_control",d),q=c.children().size(),g=c.children().outerWidth(),v=c.children().outerHeight(),f=b.start-1,m=b.effect.indexOf(",")<0?b.effect:b.effect.replace(" ","").split(",")[0],u=b.effect.indexOf(",")<0?m:b.effect.replace(" ","").split(",")[1],e=0,i=0,o=0,h=0,s,k,l,n,x,r;if(q<2)return;if(f<0)f=0;if(f>q)f=q-1;if(b.start)h=f;b.randomize&&c.randomize();a("."+b.container,d).css({overflow:"hidden",position:"relative"});c.children().css({position:"absolute",top:0,left:c.children().outerWidth(),zIndex:0,display:"none"});c.css({position:"relative",width:g*3,height:v,left:-g});a("."+b.container,d).css({display:"block"});if(b.autoHeight){c.children().css({height:"auto"});c.animate({height:c.children(":eq("+f+")").outerHeight()},b.autoHeightSpeed)}if(b.preload&&c.find("img").length){a("."+b.container,d).css({background:"url("+b.preloadImage+") no-repeat 50% 50%"});var w=c.find("img:eq("+f+")").attr("src")+"?"+(new Date).getTime();if(a("img",d).parent().attr("class")!="slides_control")r=c.children(":eq(0)")[0].tagName.toLowerCase();else r=c.find("img:eq("+f+")");c.find("img:eq("+f+")").attr("src",w).load(function(){c.find(r+":eq("+f+")").fadeIn(b.fadeSpeed,function(){a(this).css({zIndex:5});d.css({background:""});s=true})})}else c.children(":eq("+f+")").fadeIn(b.fadeSpeed,function(){s=true});if(b.bigTarget){c.children().css({cursor:"pointer"});c.children().click(function(){j("next",m);return false})}if(b.hoverPause&&b.play){c.children().bind("mouseover",function(){t()});c.children().bind("mouseleave",function(){p()})}if(b.generateNextPrev){a("."+b.container,d).after('<a href="#" class="'+b.prev+'">Prev</a>');a("."+b.prev,d).after('<a href="#" class="'+b.next+'">Next</a>')}a("."+b.next,d).click(function(a){a.preventDefault();b.play&&p();j("next",m)});a("."+b.prev,d).click(function(a){a.preventDefault();b.play&&p();j("prev",m)});a("."+b.pauseButton,d).click(function(a){a.preventDefault();t()});if(b.generatePagination){d.append("<ul class="+b.paginationClass+"></ul>");c.children().each(function(){a("."+b.paginationClass,d).append('<li><a href="#'+o+'">'+(o+1)+"</a></li>");o++})}else a("."+b.paginationClass+" li a",d).each(function(){a(this).attr("href","#"+o);o++});a("."+b.paginationClass+" li:eq("+f+")",d).addClass("current");a("."+b.paginationClass+" li a",d).click(function(){b.play&&p();l=a(this).attr("href").match("[^#/]+$");h!=l&&j("pagination",u,l);return false});a("a.link",d).click(function(){b.play&&p();l=a(this).attr("href").match("[^#/]+$")-1;h!=l&&j("pagination",u,l);return false});if(b.play){playInterval=setInterval(function(){j("next",m)},b.play);d.data("interval",playInterval)}function t(){clearInterval(d.data("interval"))}function p(){if(b.pause){clearTimeout(d.data("pause"));clearInterval(d.data("interval"));pauseTimeout=setTimeout(function(){clearTimeout(d.data("pause"));playInterval=setInterval(function(){j("next",m)},b.play);d.data("interval",playInterval)},b.pause);d.data("pause",pauseTimeout)}else t()}function j(f,l,j){if(!k&&s){k=true;switch(f){case"next":i=h;e=h+1;e=q===e?0:e;n=g*2;f=-g*2;h=e;break;case"prev":i=h;e=h-1;e=e===-1?q-1:e;n=0;f=0;h=e;break;case"pagination":e=parseInt(j,10);i=a("."+b.paginationClass+" li.current a",d).attr("href").match("[^#/]+$");if(e>i){n=g*2;f=-g*2}else{n=0;f=0}h=e}if(l==="fade"){b.animationStart();if(b.crossfade)c.children(":eq("+e+")",d).css({zIndex:10}).fadeIn(b.fadeSpeed,function(){if(b.autoHeight)c.animate({height:c.children(":eq("+e+")",d).outerHeight()},b.autoHeightSpeed,function(){c.children(":eq("+i+")",d).css({display:"none",zIndex:0});c.children(":eq("+e+")",d).css({zIndex:0});b.animationComplete(e+1);k=false});else{c.children(":eq("+i+")",d).css({display:"none",zIndex:0});c.children(":eq("+e+")",d).css({zIndex:0});b.animationComplete(e+1);k=false}});else{b.animationStart();c.children(":eq("+i+")",d).fadeOut(b.fadeSpeed,function(){if(b.autoHeight)c.animate({height:c.children(":eq("+e+")",d).outerHeight()},b.autoHeightSpeed,function(){c.children(":eq("+e+")",d).fadeIn(b.fadeSpeed)});else c.children(":eq("+e+")",d).fadeIn(b.fadeSpeed,function(){a.browser.msie&&a(this).get(0).style.removeAttribute("filter")});b.animationComplete(e+1);k=false})}}else{c.children(":eq("+e+")").css({left:n,display:"block"});if(b.autoHeight){b.animationStart();c.animate({left:f,height:c.children(":eq("+e+")").outerHeight()},b.slideSpeed,function(){c.css({left:-g});c.children(":eq("+e+")").css({left:g,zIndex:5});c.children(":eq("+i+")").css({left:g,display:"none",zIndex:0});b.animationComplete(e+1);k=false})}else{b.animationStart();c.animate({left:f},b.slideSpeed,function(){c.css({left:-g});c.children(":eq("+e+")").css({left:g,zIndex:5});c.children(":eq("+i+")").css({left:g,display:"none",zIndex:0});b.animationComplete(e+1);k=false})}}if(b.pagination){a("."+b.paginationClass+" li.current",d).removeClass("current");a("."+b.paginationClass+" li:eq("+e+")",d).addClass("current")}}}})};a.fn.slides.option={preload:false,preloadImage:"/img/loading.gif",container:"slides_container",generateNextPrev:false,next:"next",prev:"prev",pauseButton:"pause",pagination:true,generatePagination:true,paginationClass:"pagination",fadeSpeed:350,slideSpeed:350,start:1,effect:"slide",crossfade:false,randomize:false,play:0,pause:0,hoverPause:false,autoHeight:false,autoHeightSpeed:350,bigTarget:false,animationStart:function(){},animationComplete:function(){}};a.fn.randomize=function(b){function c(){return Math.round(Math.random())-.5}return a(this).each(function(){var g=a(this),e=g.children(),f=e.length;if(f>1){e.hide();var d=[];for(i=0;i<f;i++)d[d.length]=i;d=d.sort(c);a.each(d,function(f,d){var a=e.eq(d),c=a.clone(true);c.show().appendTo(g);b!==undefined&&b(a,c);a.remove()})}})}})(jQuery)
