(function(a){function w(){if(f>d.length-1){f=0}t(d,b,f,e)}function v(d,e,g,h){c=a(document).everyTime(e,j["timerName"],function(a){if(f>d.length-1){f=0}t(d,b,f,g)},h)}function u(){if(g<0){g=d.length-1}t(d,b,g,e)}function t(c,d,e,l){if(h){return}h=true;if(j["manualSeconds"]){a(document).stopTime(j["timerName"])}if(j["browseButton"]){a(j["browseRight"]).unbind("click");a(j["browseLeft"]).unbind("click")}var m=false;if(parseInt(d)<l.length&&j["infoboxOn"]){a(l[parseInt(d)+1]).animate({height:"hide",opacity:0,queue:true},j["multipleSpeed"]/2,s(c,d,e,l,m))}else if(!j["infoboxOn"]){s(c,d,e,l,m)}if(!m){b=parseInt(e);g=parseInt(e)-1;f=0;while(f<=b){f++}}a(i[parseInt(d)]).removeClass("active");a(i[parseInt(e)]).addClass("active");if(j["manualSeconds"]){var n=a(k[b]);v(c,a(n).val(),l,0)}}function s(c,d,e,i,k){if(parseInt(e)==0&&parseInt(d)==c.length-1){a(j["imagesUl"]).animate({left:"-="+j["imageWidth"]+"px"},j["multipleSpeed"],function(){a(j["imagesUl"]).attr("style","left:-"+j["imageWidth"]+"px");if(parseInt(e)<i.length&&j["infoboxOn"]){a(i[1]).animate({height:"show",opacity:1,queue:true},j["multipleSpeed"]/2,function(){a(this).removeAttr("style")})}h=false});b=0;g=c.length-1;f=1;k=true}else if(!(parseInt(e)==parseInt(d)-1||parseInt(e)==parseInt(d)+1)){if(parseInt(e)<parseInt(d)){var l=parseInt(d)-parseInt(e);var m=l*j["imageWidth"];a(j["imagesUl"]).animate({left:"+="+m+"px"},j["multipleSpeed"],function(){if(parseInt(e)<i.length&&j["infoboxOn"]){a(i[parseInt(e)+1]).animate({height:"show",opacity:1,queue:true},j["multipleSpeed"]/2,function(){a(this).removeAttr("style")})}h=false})}else if(d==0&&e==c.length-1){var l=parseInt(e)-parseInt(d);var n=(l+1)*j["imageWidth"];a(j["imagesUl"]).animate({left:"+="+j["imageWidth"]+"px"},j["multipleSpeed"],function(){a(j["imagesUl"]).attr("style","left:-"+n+"px");if(parseInt(e)<i.length&&j["infoboxOn"]){a(i[i.length-2]).animate({height:"show",opacity:1,queue:true},j["multipleSpeed"]/2,function(){a(this).removeAttr("style")})}h=false})}else{var l=parseInt(e)-parseInt(d);var n=l*j["imageWidth"];a(j["imagesUl"]).animate({left:"-="+n+"px"},j["multipleSpeed"],function(){if(parseInt(e)<parseInt(i.length)&&j["infoboxOn"]){a(i[parseInt(e)+1]).animate({height:"show",opacity:1,queue:true},j["multipleSpeed"]/2,function(){a(this).removeAttr("style")})}h=false})}}else if(parseInt(e)<parseInt(d)){a(j["imagesUl"]).animate({left:"+="+j["imageWidth"]+"px"},j["singleSpeed"],function(){if(parseInt(e)<i.length&&j["infoboxOn"]){a(i[parseInt(e)+1]).animate({height:"show",opacity:1,queue:true},j["singleSpeed"]/2,function(){a(this).removeAttr("style")})}h=false})}else{a(j["imagesUl"]).animate({left:"-="+j["imageWidth"]+"px"},j["singleSpeed"],function(){if(parseInt(e)<i.length&&j["infoboxOn"]){a(i[parseInt(e)+1]).animate({height:"show",opacity:1,queue:true},j["singleSpeed"]/2,function(){a(this).removeAttr("style")})}h=false})}}function r(c,d,e,h){if(j["manualSeconds"]){a(document).stopTime(j["timerName"])}var l=parseInt(e)+1;if(d<h.length&&j["infoboxOn"]){a(h[d+1]).animate({height:"hide",opacity:0,queue:true},j["multipleSpeed"]/2,q(c,d,e,h,l))}else if(!j["infoboxOn"]){q(c,d,e,h,l)}if(e==c.length-1){b=parseInt(e);g=parseInt(e)-1;f=0}else if(e==0){b=parseInt(e);g=c.length-1;f=1}else{b=parseInt(e);g=parseInt(e)-1;f=0;while(f<=b){f++}}a(i[d]).removeClass("active");a(i[e]).addClass("active");if(j["manualSeconds"]){var m=a(k[b]);v(c,a(m).val(),h,0)}}function q(b,c,d,e,f){if(d>c){var g=d-c;var h=g*j["imageWidth"];a(j["imagesUl"]).animate({left:"-="+h+"px",queue:true},j["multipleSpeed"],function(){if(d<e.length&&j["infoboxOn"]){a(e[f]).animate({height:"show",opacity:1,queue:true},j["multipleSpeed"]/2,function(){a(this).removeAttr("style")})}})}else if(d<c){var g=c-d;var i=g*j["imageWidth"];a(j["imagesUl"]).animate({left:"+="+i+"px"},j["multipleSpeed"],function(){if(d<e.length&&j["infoboxOn"]){a(e[f]).animate({height:"show",opacity:1,queue:true},j["multipleSpeed"]/2,function(){a(this).removeAttr("style")})}})}}function p(c,d,e){var f=a(c).attr("href");f=f.split("#")[1];r(d,b,f,e)}function o(){var b=a(j["infoboxWrapper"]);return b}function n(b){try{var c=b[0];var d='<li class="firstitem cloned">'+a(c).html()+"</li>";var e=b[b.length-1];var f='<li class="cloned">'+a(e).html()+"</li>";a(j["imagesUl"]).html(function(a,b){var c=f+b+d;return c});return true}catch(g){a.error("error during cloning: "+g);return false}}function m(b){var c="";for(var d=0;d<b.length;d++){c+="<a class='' href='#"+d+"'></a>"}a(j["navWrapper"]).html(c);naviElems=a(j["navWrapper"]+" a");return naviElems}var b=0;var c=null;var d=null;var e=null;var f=1;var g=0;var h=false;var i=null;var j=null;var k=null;var l={init:function(b){return this.each(function(){var c=a(this),d=c.data("carrousel");if(!d){var e={secondsInterval:"4s",manualSeconds:false,timerName:"scrollable",singleSpeed:1e3,multipleSpeed:1e3,navWrapper:"#navi",browseButtons:true,browseLeft:".browseLeft",browseRight:".browseRight",imageGallery:".imageGallery",imagesUl:"#scrollBanner",infoboxOn:true,infoboxWrapper:".innerPushbox",stopOnMouse:true,imageWidth:970}}if(b){a.extend(e,b)}a(this).data("carrousel",e)})},start:function(c){var f=a(this);j=f.data("carrousel");if(!j){l["init"].apply(this,arguments)}return this.each(function(){var c;var f=a(this);j=f.data("carrousel");if(!j){a.error("plugin not yet initialized")}else if(a(j["imagesUl"]).length<=0){a.error("plugin couldn't find the carrousel")}else{a(this).removeClass("noNavigation");var h=a(j["imagesUl"]).find("li");if(j["manualSeconds"]){k=a(":input",h)}i=m(h);var l=n(h);var q=[0,0];e=q;if(j["infoboxOn"]){var q=o();e=q;a(j["infoboxWrapper"]).animate({height:"hide",opacity:0,queue:true},100,function(){})}d=h;a(j["imagesUl"]).attr("style","left: -"+j["imageWidth"]+"px");if(j["infoboxOn"]){a(q[1]).delay(500).animate({height:"show",opacity:1,queue:true},j["singleSpeed"]/2,function(){})}g=h.length-1;if(h.length>1){if(j["browseButton"]){a(j["browseLeft"]).click(function(){u();return false});a(j["browseRight"]).click(function(){w();return false})}if(j["stopOnMouse"]){a(j["imageGallery"]).mouseenter(function(){a(document).stopTime(j["timerName"])});a(j["imageGallery"]).mouseleave(function(){a(document).stopTime(j["timerName"]);if(!j["manualSeconds"]){v(h,j["secondsInterval"],q,0)}})}window.onblur=function(){a(document).stopTime(j["timerName"])};window.onfocus=function(){a(document).stopTime(j["timerName"]);if(j["manualSeconds"]){c=a(k[b]);v(h,a(c).val(),q,0)}else{v(h,j["secondsInterval"],q,0)}};document.onblur=window.onblur;document.focus=window.focus;a(i[0]).addClass("active");a(i).click(function(){p(a(this),h,q);return false});if(j["manualSeconds"]){c=a(k[b]);v(h,a(c).val(),q,0)}else{v(h,j["secondsInterval"],q,0)}a(j["browseLeft"]).click(u);a(j["browseRight"]).click(w)}else{if(j["browseButton"]){a(j["browseLeft"]).hide();a(j["browseRight"]).hide()}}}})},stop:function(){return this.each(function(){var b=a(this);j=b.data("carrousel");if(!j){a.error("the plugin hasn't even started yet, how do you expect to stop it?")}a(document).stopTime(j["timerName"])})},destroy:function(){return this.each(function(){var b=a(this),c=b.data("carrousel");a(window).unbind(".carrousel");c.carrousel.remove();b.removeData("carrousel")})}};a.fn.carrousel=function(b){if(l[b]){return l[b].apply(this,Array.prototype.slice.call(arguments,1))}else if(typeof b==="object"||!b){return l.init.apply(this,arguments)}else{a.error("Method "+b+" does not exist on jQuery.carrousel")}}})(jQuery)
