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