/*
* Slides, A Slideshow Plugin for jQuery
* Intructions: http://slidesjs.com
* By: Nathan Searles, http://nathansearles.com
* Version: 1.0.9
* Updated: January 4th, 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.
*/

(function(a){a.fn.slides=function(b){b=a.extend({},a.fn.slides.option,b);return this.each(function(){function x(h,i,j){if(!q&&p){q=true;switch(h){case"next":m=o;l=o+1;l=e===l?0:l;s=f*2;h=-f*2;o=l;break;case"prev":m=o;l=o-1;l=l===-1?e-1:l;s=0;h=0;o=l;break;case"pagination":l=parseInt(j,10);m=a("."+b.paginationClass+" li.current a",c).attr("href").match("[^#/]+$");if(l>m){s=f*2;h=-f*2}else{s=0;h=0}o=l;break}if(i==="fade"){b.animationStart();if(b.crossfade){d.children(":eq("+l+")",c).css({zIndex:10}).fadeIn(b.fadeSpeed,function(){if(b.autoHeight){d.animate({height:d.children(":eq("+l+")",c).outerHeight()},b.autoHeightSpeed,function(){d.children(":eq("+m+")",c).css({display:"none",zIndex:0});d.children(":eq("+l+")",c).css({zIndex:0});b.animationComplete(l+1);q=false})}else{d.children(":eq("+m+")",c).css({display:"none",zIndex:0});d.children(":eq("+l+")",c).css({zIndex:0});b.animationComplete(l+1);q=false}})}else{b.animationStart();d.children(":eq("+m+")",c).fadeOut(b.fadeSpeed,function(){if(b.autoHeight){d.animate({height:d.children(":eq("+l+")",c).outerHeight()},b.autoHeightSpeed,function(){d.children(":eq("+l+")",c).fadeIn(b.fadeSpeed)})}else{d.children(":eq("+l+")",c).fadeIn(b.fadeSpeed,function(){if(a.browser.msie){a(this).get(0).style.removeAttribute("filter")}})}b.animationComplete(l+1);q=false})}}else{d.children(":eq("+l+")").css({left:s,display:"block"});if(b.autoHeight){b.animationStart();d.animate({left:h,height:d.children(":eq("+l+")").outerHeight()},b.slideSpeed,function(){d.css({left:-f});d.children(":eq("+l+")").css({left:f,zIndex:5});d.children(":eq("+m+")").css({left:f,display:"none",zIndex:0});b.animationComplete(l+1);q=false})}else{b.animationStart();d.animate({left:h},b.slideSpeed,function(){d.css({left:-f});d.children(":eq("+l+")").css({left:f,zIndex:5});d.children(":eq("+m+")").css({left:f,display:"none",zIndex:0});b.animationComplete(l+1);q=false})}}if(b.pagination){a("."+b.paginationClass+" li.current",c).removeClass("current");a("."+b.paginationClass+" li:eq("+l+")",c).addClass("current")}}}function w(){if(b.pause){clearTimeout(c.data("pause"));clearInterval(c.data("interval"));pauseTimeout=setTimeout(function(){clearTimeout(c.data("pause"));playInterval=setInterval(function(){x("next",j)},b.play);c.data("interval",playInterval)},b.pause);c.data("pause",pauseTimeout)}else{v()}}function v(){clearInterval(c.data("interval"))}a("."+b.container,a(this)).children().wrapAll('<div class="slides_control"/>');var c=a(this),d=a(".slides_control",c),e=d.children().size(),f=d.children().outerWidth(),h=d.children().outerHeight(),i=b.start-1,j=b.effect.indexOf(",")<0?b.effect:b.effect.replace(" ","").split(",")[0],k=b.effect.indexOf(",")<0?j:b.effect.replace(" ","").split(",")[1],l=0,m=0,n=0,o=0,p,q,r,s,t;if(e<2){return}if(i<0){i=0}if(i>e){i=e-1}if(b.start){o=i}if(b.randomize){d.randomize()}a("."+b.container,c).css({overflow:"hidden",position:"relative"});d.css({position:"relative",width:f*3,height:h,left:-f});d.children().css({position:"absolute",top:0,left:f,zIndex:0,display:"none"});if(b.autoHeight){d.animate({height:d.children(":eq("+i+")").outerHeight()},b.autoHeightSpeed)}if(b.preload&&d.children()[0].tagName=="IMG"){c.css({background:"url("+b.preloadImage+") no-repeat 50% 50%"});var u=a("img:eq("+i+")",c).attr("src")+"?"+(new Date).getTime();a("img:eq("+i+")",c).attr("src",u).load(function(){a(this).fadeIn(b.fadeSpeed,function(){a(this).css({zIndex:5});c.css({background:""});p=true})})}else{d.children(":eq("+i+")").fadeIn(b.fadeSpeed,function(){p=true})}if(b.bigTarget){d.children().css({cursor:"pointer"});d.children().click(function(){x("next",j);return false})}if(b.hoverPause&&b.play){d.children().bind("mouseover",function(){v()});d.children().bind("mouseleave",function(){w()})}if(b.generateNextPrev){a("."+b.container,c).after('<a href="#" class="'+b.prev+'">Prev</a>');a("."+b.prev,c).after('<a href="#" class="'+b.next+'">Next</a>')}a("."+b.next,c).click(function(a){a.preventDefault();if(b.play){w()}x("next",j)});a("."+b.prev,c).click(function(a){a.preventDefault();if(b.play){w()}x("prev",j)});if(b.generatePagination){c.append("<ul class="+b.paginationClass+"></ul>");d.children().each(function(){a("."+b.paginationClass,c).append('<li><a href="#'+n+'">'+(n+1)+"</a></li>");n++})}else{a("."+b.paginationClass+" li a",c).each(function(){a(this).attr("href","#"+n);n++})}a("."+b.paginationClass+" li:eq("+i+")",c).addClass("current");a("."+b.paginationClass+" li a",c).click(function(){if(b.play){w()}r=a(this).attr("href").match("[^#/]+$");if(o!=r){x("pagination",k,r)}return false});a("a.link",c).click(function(){if(b.play){w()}r=a(this).attr("href").match("[^#/]+$")-1;if(o!=r){x("pagination",k,r)}return false});if(b.play){playInterval=setInterval(function(){x("next",j)},b.play);c.data("interval",playInterval)}})};a.fn.slides.option={preload:false,preloadImage:"../images/loading.gif",container:"jp-slides-container",generateNextPrev:false,next:"next",prev:"prev",pagination:true,generatePagination:true,paginationClass:"pagination",fadeSpeed:350,slideSpeed:500,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 d=a(this);var e=d.children();var f=e.length;if(f>1){e.hide();var h=[];for(i=0;i<f;i++){h[h.length]=i}h=h.sort(c);a.each(h,function(a,c){var f=e.eq(c);var h=f.clone(true);h.show().appendTo(d);if(b!==undefined){b(f,h)}f.remove()})}})}})(jQuery)
