/*!
 *
 * jQuery Duotive Presentation Slider v2.1
 * http://duotive.org
 *
 * Copyright 2011, Duotive
 * Dual licensed under the MIT or GPL Version 2 licenses.
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 * 
 * Date: Sat November 5th 13:47 GMT+2 2011
 *
 */

(function(a){a.fn.dtPresentationSlider=function(c){var e={height:500,autoAdvance:true,autoAdvDuration:800,autoAdvInterval:8000,autoAdvPauseOnHover:false,showArrows:true,showTimer:true,showGallery:true,showGalleryNumber:true,showGalleryTitle:true,showScroll:true,keyboardControl:false,showDescription:false,autoHideDescription:false,showIcon:false};c=a.extend(e,c);function b(g){var f;f=parseInt(g.css("padding-left"),10)+parseInt(g.css("padding-right"),10);f+=parseInt(g.css("margin-left"),10)+parseInt(g.css("margin-right"),10);f+=parseInt(g.css("border-left-width"),10)+parseInt(g.css("border-right-width"),10);return f}function d(g){var f;f=parseInt(g.css("padding-top"),10)+parseInt(g.css("padding-bottom"),10);f+=parseInt(g.css("margin-top"),10)+parseInt(g.css("margin-bottom"),10);f+=parseInt(g.css("border-top-width"),10)+parseInt(g.css("border-bottom-width"),10);return f}return this.each(function(){var n=a(this),j=0,S=j,T=0,t=n.find(".slider-images"),A=n.find(".slider-images li"),y='<div class="slider-controls"><a class="slider-control-left" href="javascript: void(0)">left</a><a class="slider-control-right" href="javascript: void(0)">right</a>',p="",H="",I='<div class="slider-timer"><div class="timer"></div></div>',q='<div class="slider-gallery"><ul></ul></div>',g="",k="",o="",i=0,U=n.find(".slider-descriptions"),M=U.find("ul"),h=U.find("li"),E=0,f='<div class="slider-scroll"><a class="slider-scroll-left" title="scroll left" href="javascript: void(0);">scroll left</a><div class="slider-scroll-bar"></div><a class="slider-scroll-right" title="scroll right" href="javascript: void(0);">scroll right</a></div>',r="",B="",x="",J="",z="100%",Q=0;n.addClass("dt_presentationslider");function L(){var W=c.height;if(c.showGalleryNumber===false&&c.showGalleryTitle===false){c.showGallery=false}if(c.autoAdvance===false){c.showTimer=false}if(c.showGallery===false){c.showScroll=false}if(c.showTimer===true){W+=16}if(c.showGallery===true){if(c.showGalleryNumber===true&&c.showGalleryTitle){W+=84}else{W+=64}}if(c.showScroll===true&&c.showGallery===true){W+=47}if(c.showTimer===false&&c.showGallery===false&&c.showScroll===false){n.addClass("rounded")}t.find("ul").stop().animate({height:c.height},c.autoAdvDuration,"");n.stop().animate({height:W},c.autoAdvDuration,"");A.css({opacity:0})}function l(X,W,Y){if(X===undefined||X>A.size()-1){X=0}if(X<0){X=A.size()-1}A.eq(W).stop().animate({opacity:0,"z-index":10},Y,"");A.eq(X).stop().animate({opacity:1,"z-index":20},Y,"");if(c.autoAdvance===true&&c.showTimer===true){N(c.autoAdvInterval,"reset")}if(c.showGallery===true){Q=A.size()-Math.ceil(parseInt(q.css("width"),10)/o);i=parseInt(g.css("width"),10)-parseInt(q.css("width"),10);u(X,W);v(X)}if(c.showDescription===true){R(X,W)}W=X;X++;S=W;j=X}function V(W){T=setInterval(function(){l(j,S,c.autoAdvDuration)},W)}function D(){clearInterval(T);V(c.autoAdvInterval)}function C(){n.append(y);y=n.find(".slider-controls");p=y.find(".slider-control-left");H=y.find(".slider-control-right");H.click(function(){l(j,S,c.autoAdvDuration);if(c.autoAdvance===true){D()}});p.click(function(){j=j-2;l(j,S,c.autoAdvDuration);if(c.autoAdvance===true){D()}})}function w(){t.after(I);I=n.find(".slider-timer");if(c.showGallery===false){I.addClass("rounded")}}function N(X,W){if(W===undefined){W="reset"}switch(W){case"reset":I.find(".timer").css({width:"0%"});I.find(".timer").stop().animate({width:"100%"},X,"linear");break;case"pause":I.find(".timer").stop();X=((c.timerWidth-parseInt(I.css("width"),10))*X)/c.timerWidth;break;case"resume":X=((c.timerWidth-parseInt(I.css("width"),10))*X)/c.timerWidth;I.find(".timer").stop().animate({width:"100%"},X,"linear");break}}function F(){n.append(f);f=n.find(".slider-scroll");r=f.find(".slider-scroll-left");x=f.find(".slider-scroll-bar").wrap('<div class="scroll-bar-parent"></div>');B=f.find(".slider-scroll-right");x.slider({animate:"slow",start:function(W,X){if(c.autoAdvance===true){clearInterval(T);if(c.showTimer===true){N(c.autoAdvInterval,"pause")}}O()},slide:function(W,X){g.stop().animate({left:-Math.floor(X.value*i/100)},500)},stop:function(X,Y){var Z=Math.round(Y.value*Q/100),W=Z*o;if(Z===Q){W=i}g.stop().animate({left:-W},c.autoAdvDuration,"")}});J=x.find(".ui-slider-handle");J.wrap('<div class="handle-parent"></div>').mousedown(function(){x.css("width",parseInt(a(this).parent().css("width"),10))}).mouseup(function(){x.css("width",parseInt(x.parent().css("width"),10))}).mouseleave(function(){x.css("width",parseInt(x.parent().css("width"),10))});r.click(function(){if(x.slider("value")!==0&&x.slider("option","disabled")!==true){var X=Math.round(x.slider("value")-(100/Q)),Y=Math.round(X*Q/100),W=Y*o;if(X<0){W=0}if(X>100){W=i}if(c.autoAdvance===true){clearInterval(T);if(c.showTimer===true){N(c.autoAdvInterval,"pause")}}x.slider("value",X);g.stop().animate({left:-W},c.autoAdvDuration,"")}});B.click(function(){if(x.slider("value")!==100&&x.slider("option","disabled")!==true){var X=Math.round(x.slider("value")+(100/Q)),Y=Math.round(X*Q/100),W=Y*o;if(X<0){W=0}if(X>100){W=i}if(c.autoAdvance===true){clearInterval(T);if(c.showTimer===true){N(c.autoAdvInterval,"pause")}}x.slider("value",X);g.stop().animate({left:-W},c.autoAdvDuration,"")}});if(A.size()<=6){x.slider("disable")}if(c.showArrows===true){p.addClass("moveup");H.addClass("moveup")}}function O(){var X=parseInt(x.parent().css("width"),10),W=parseInt(q.css("width"),10);if(Q<0){Q=0}z=Math.floor(parseInt(x.parent().css("width"),10)/(Q+1));if(z<50){z=50}if(z>X||Q===0){z=X}J.stop().animate({width:z,"margin-left":-z/2},c.autoAdvDuration,"linear");J.parent().css("width",X-z)}function G(){var X,W,Y="",Z;if(c.showTimer===true){I.after(q)}else{t.after(q)}q=n.find(".slider-gallery");g=q.find("ul");for(X=0,W=A.length;X<W;X++){Z=(X+1);if(X<9){Z="0"+(X+1)}if(c.showGalleryTitle===true){Z=Z+"."}Y+='<li><a title="'+A.eq(X).find("a").attr("title")+'" href="javascript: void(0);">';if(c.showGalleryNumber===true){Y+='<span class="nr">'+Z+"</span>"}else{q.addClass("single-content")}if(c.showGalleryTitle===true){Y+='<span class="title">'+A.eq(X).find("a").attr("title")+"</span>"}else{q.addClass("single-content")}Y+="</a></li>";g.append(Y)}k=g.find("li");if(A.size()<6){k.css({width:Math.floor(parseInt(q.css("width"),10)/A.size())})}o=parseInt(k.css("width"),10);g.css("width",A.size()*o);for(X=0,W=k.length;X<W;X++){k.eq(X).find("a").attr("rel",X).click(function(aa){aa.preventDefault();j=parseInt(a(this).attr("rel"),10);if(c.autoAdvance===true){D()}l(j,S,c.autoAdvDuration)})}}function u(X,W){k.eq(W).attr("class","");k.eq(X).attr("class","active")}function v(X){var W=0,Y=0,Z=Math.ceil(parseInt(q.css("width"),10)/o);if(X===0||A.size()<Z){W=0}else{W=(X-1)*o}if(W>=i){W=i}g.stop().animate({left:-W},c.autoAdvDuration,"");if(c.showScroll===true){O();Y=Math.round(W/(Q/100*o));x.slider("value",Y)}}function P(){var Y,X,W;t.append(U);h.css("opacity",0);for(Y=0,X=h.length;Y<X;Y++){W=parseInt(h.eq(Y).css("height"),10)+d(h.eq(Y));if(W>E){E=W+5}}M.css({height:parseInt(h.eq(0).css("height"),10)+d(h.eq(0))})}function R(X,W){var Y=parseInt(h.eq(X).css("height"),10)+d(h.eq(X));if(Y>c.height){Y=c.height}M.stop().animate({height:Y},c.autoAdvDuration/1.5,"swing");h.eq(W).stop().animate({opacity:0},c.autoAdvDuration/2,"");h.eq(X).stop().animate({opacity:1},c.autoAdvDuration,"")}function s(W,X){if(W===undefined){W="show"}if(W==="show"){M.stop().animate({bottom:0},X,"swing")}else{M.stop().animate({bottom:-E},X,"swing")}}function K(){if(n.find(".icon").size()>0){c.showIcon=true;n.find(".icon").css("opacity",0)}else{showIcon=false}}function m(W){if(W===undefined){W="show"}if(W==="show"){A.eq(j-1).find(".icon").stop().animate({opacity:1},c.autoAdvDuration/2,"linear")}else{A.eq(j-1).find(".icon").stop().animate({opacity:0},c.autoAdvDuration/2,"linear")}}if(A.size()>0){L();K();if(c.showArrows===true){C()}if(c.showTimer===true&&c.autoAdvance===true){w()}if(c.showGallery===true){G()}if(c.showScroll===true&&c.showGallery&&A.size()>6){F()}else{c.showScroll=false}if(c.showDescription===true){P()}l(j,S,c.autoAdvDuration);if(c.autoAdvance===true){V(c.autoAdvInterval)}if(c.autoHideDescription===true){s("hide",c.autoAdvDuration*2)}}if(c.keyboardControl===true){a(document).keydown(function(W){if(W.keyCode===39){l(j,S,c.autoAdvDuration);if(c.autoAdvance===true){D()}}if(W.keyCode===37){j=j-2;l(j,S,c.autoAdvDuration);if(c.autoAdvance===true){D()}}})}t.hover(function(){if(c.autoAdvance===true&&c.autoAdvPauseOnHover===true){clearInterval(T);if(c.showTimer===true){N(c.autoAdvInterval,"pause")}}if(c.autoHideDescription===true&&c.showDescription===true){s("show",c.autoAdvDuration/2)}if(c.showIcon===true){m("show")}},function(){if(c.autoAdvance===true&&c.autoAdvPauseOnHover===true){D();if(c.showTimer===true){N(c.autoAdvInterval,"reset")}}if(c.autoHideDescription===true&&c.showDescription===true){s("hide",c.autoAdvDuration/2)}if(c.showIcon===true){m("hide")}})})}}(jQuery));
