/*
 * symCanvasSlider controller - Written by Ronan Cashell (c) 2010 Symfonip.com
 * Version 1.4 10-Dec-2010
 */
(function(e){e.fn.extend({symCanvasSlider:function(o){function h(b){if((b=e("img",b).attr("stitle"))&&b!=""){for(var g="",f=0;f<b.length;){var d=b.charAt(f);if(d=="+"){g+=" ";f++}else if(d=="%")if(f<b.length-2&&"0123456789ABCDEFabcdef".indexOf(b.charAt(f+1))!=-1&&"0123456789ABCDEFabcdef".indexOf(b.charAt(f+2))!=-1){g+=unescape(b.substr(f,3));f+=3}else{alert("Bad escape combination near ..."+b.substr(f));g+="%[ERROR]";f++}else{g+=d;f++}}b=g;if(a.showCaptions&&b!=""){l.text(b);l.parent().stop().animate({bottom:0},
a.captionAnimationInterval)}}}var a={pauseOnHover:false,canvasTransition:true,autoAdvance:false,slideInterval:5E3,showNavButtons:true,autoHideNavButtons:true,showCaptions:true,captionAnimationInterval:500,transitionType:"fade",animationSpeed:1E3,width:400,height:250,border:10,canvasFadeSpeed:500,navFadeSpeed:500},k=0,i=e(this);o&&e.extend(a,o);a.left=a.width;a.top=a.height;if(a.slideInterval<1E3)a.slideInterval=1E3;if(!a.autoAdvance&&!a.showNavButtons)a.showNavButtons=true;a.showNavButtons||e(".arrow",
i).css("display","none");if(a.autoAdvance)k||(k=setInterval(function(){e(".next",i).click()},a.slideInterval));var p="getContext"in document.createElement("canvas"),m=e(".slide",i),j=0,n={width:0,height:0},l=e(".caption p",i);i.hover(function(){if(a.autoAdvance&&a.pauseOnHover)if(k){clearInterval(k);k=0}a.autoHideNavButtons&&e(".arrow",i).fadeIn(a.navFadeSpeed)},function(){if(a.autoAdvance&&a.pauseOnHover)k||(k=setInterval(function(){e(".next",i).click()},a.slideInterval));a.autoHideNavButtons&&e(".arrow",
i).fadeOut(a.navFadeSpeed)});h(m.eq(j));setTimeout(function(){a.canvasTransition&&p&&e("img",i).each(function(){if(!n.width){n.width=this.width;n.height=this.height}var b=document.createElement("canvas"),g=b.getContext("2d");b.width=this.width;b.height=this.height;g.drawImage(this,0,0);for(var f=g.getImageData(0,0,b.width,b.height),d=f.data,c=0,q=f.data.length;c<q;c++){d[c]=d[c]<128?2*d[c]*d[c]/255:255-2*(255-d[c])*(255-d[c])/255;d[++c]=d[c]<128?2*d[c]*d[c]/255:255-2*(255-d[c])*(255-d[c])/255;d[++c]=
d[c]<128?2*d[c]*d[c]/255:255-2*(255-d[c])*(255-d[c])/255;++c}g.putImageData(f,0,0);this.parentNode.insertBefore(b,this);e(b).css({position:"absolute",left:e(this).css("left"),top:e(this).css("top")})});e(".arrow",i).click(function(){var b=m.eq(j),g=b.find("canvas"),f=0,d=e(this);f=e(this).hasClass("next")?j>=m.length-1?0:j+1:j<=0?m.length-1:j-1;var c=m.eq(f);if(a.canvasTransition&&p)g.fadeIn(a.canvasFadeSpeed,function(){j=f;b.removeClass("slideActive").css({zIndex:1});l.parent().stop().animate({bottom:-(l.height()+
20)},a.captionAnimationInterval);if(a.transitionType=="fade"){b.fadeOut(a.animationSpeed,function(){e(this).css({zIndex:2})});c.css({opacity:0,zIndex:3}).show().animate({opacity:1},a.animationSpeed,function(){b.css({zIndex:1}).hide();g.hide();h(c)})}b.css({zIndex:2});if(a.transitionType=="vertical")if(d.hasClass("next")){b.fadeOut(a.animationSpeed);c.addClass("slideActive").css({top:"-"+a.height+"px",zIndex:3}).show().animate({top:"0px"},a.animationSpeed,function(){b.css({zIndex:1});g.hide();h(c)})}else{c.addClass("slideActive").fadeIn(a.animationSpeed).css({zIndex:2}).show();
b.css({zIndex:3,top:"0px"}).animate({top:"-"+a.height+"px"},a.animationSpeed,function(){b.css({zIndex:1,top:"0px"}).hide();c.css({zIndex:3});g.hide();h(c)})}if(a.transitionType=="horizontal")if(d.hasClass("next")){b.fadeOut(a.animationSpeed).css({zIndex:2});c.addClass("slideActive").css({left:a.left+"px",zIndex:3}).show().animate({left:"0px"},a.animationSpeed,function(){g.hide();b.css({zIndex:1});h(c)})}else{c.css({zIndex:2,left:"0px"}).show();b.css({zIndex:3}).show().animate({left:a.left+"px"},a.animationSpeed,
function(){g.hide();b.css({zIndex:1});c.css({zIndex:3});h(c)})}});else{l.parent().stop().animate({bottom:-(l.height()+20)},a.captionAnimationInterval);j=f;b.removeClass("slideActive").css({zIndex:2});if(a.transitionType=="fade"){b.css({"z-index":2});c.css({opacity:0,"z-index":3}).show().animate({opacity:1},a.animationSpeed,function(){b.css({zIndex:1});h(c)})}if(a.transitionType=="vertical")if(e(this).hasClass("next")){b.fadeOut(a.animationSpeed);c.addClass("slideActive").css({top:"-"+a.height+"px",
zIndex:3}).show().animate({top:"0px"},a.animationSpeed,function(){b.css({zIndex:1});h(c)})}else{c.fadeIn(a.animationSpeed).css({zIndex:2}).show();b.css({zIndex:3}).animate({top:"-"+a.height+"px"},a.animationSpeed,function(){b.css({zIndex:1,top:"0px"}).hide();c.css({zIndex:3});h(c)})}if(a.transitionType=="horizontal")if(e(this).hasClass("next")){b.fadeOut(a.animationSpeed);c.addClass("slideActive").css({left:a.left+"px",zIndex:3}).show().animate({left:"0px"},a.animationSpeed,function(){b.css({zIndex:1});
h(c)})}else{c.fadeIn(a.animationSpeed).css({zIndex:2});b.css({zIndex:3}).animate({left:a.left+"px"},a.animationSpeed,function(){b.css({zIndex:1,left:"0px"}).hide();c.css({zIndex:3});h(c)})}}})},100)}})})(jQuery);
